daixtrose / cmake_utilities

CMake utilities addressing configuration management and dependency hell mitigation
MIT License
7 stars 1 forks source link

Dependency target not found #5

Open daixtrose opened 1 year ago

daixtrose commented 1 year ago

How to reproduce

Use the testsuite in https://github.com/dep-heaven/tool_1:

git clone https://github.com/dep-heaven/tool_1
cd tool_1/
mkdir build
cd build/
cmake ..

Output

Cloning into 'tool_1'...
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 33 (delta 9), reused 25 (delta 5), pack-reused 0
Receiving objects: 100% (33/33), 8.45 KiB | 577.00 KiB/s, done.
Resolving deltas: 100% (9/9), done.
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Resolving dependencies of project /home/markus/PROJECT/GARBAGE/tool_1
-- Checking dependency 'lib_A': https://github.com/dep-heaven/lib_A @ master-yoda
-- Initializing in '/home/markus/PROJECT/GARBAGE/tool_1/ws/lib_A'
-- Checking dependency 'lib_B': https://github.com/dep-heaven/lib_B @ master-yoda
-- Initializing in '/home/markus/PROJECT/GARBAGE/tool_1/ws/lib_B'
-- Checking dependency 'libFreeAssange': https://github.com/dep-heaven/libFreeAssange @ belmarsh
-- Initializing in '/home/markus/PROJECT/GARBAGE/tool_1/ws/libFreeAssange'
-- Checking dependency 'catch2': https://github.com/catchorg/Catch2 @ v2.x
-- Initializing in '/home/markus/PROJECT/GARBAGE/tool_1/ws/catch2'
-- Checking dependency 'fmt': https://github.com/fmtlib/fmt @ master
-- Initializing in '/home/markus/PROJECT/GARBAGE/tool_1/ws/fmt'
-- The C compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Version: 10.1.1
-- Build type: 
WARNING! Something is still wrong here!
   RepoMan should populate selected name, not original name
==> Toplevel: catch2_SOURCE_DIR = ''
==> Toplevel: Catch2_SOURCE_DIR = '/home/markus/PROJECT/GARBAGE/tool_1/ws/catch2'
==> Toplevel: lib_A_SOURCE_DIR = '/home/markus/PROJECT/GARBAGE/tool_1/ws/lib_A'
Catch path is '/home/markus/PROJECT/GARBAGE/tool_1/ws/catch2/extras'
-- DEFINE_UNIT_TEST_NAME = test_tool_1
-- DEFINE_UNIT_TEST_FILES = ../src/fn.cpp;test_main.cpp;test_tool_1.cpp
-- Dependencies:
--     lib_A @ master-yoda, chosen from [master-yoda]
--     lib_B @ master-yoda, chosen from [master-yoda]
--     libFreeAssange @ belmarsh, chosen from [belmarsh]
--     catch2 @ v2.x, chosen from [v2.x]
--     fmt @ master, chosen from [master]
-- Configuring done
CMake Error at test-catch/CMakeLists.txt:24 (add_executable):
  Target "test_tool_1" links to target "Daixtrose::lib_A" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  test-catch/CMakeLists.txt:43 (define_unit_test)

CMake Error at CMakeLists.txt:47 (add_executable):
  Target "tool_1" links to target "Daixtrose::lib_A" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
daixtrose commented 1 year ago

@cpp-entwickler-de This may be mitigated by either changing cmake_utilities or how it is used in the demo.

cpp-entwickler-de commented 1 year ago

The issue is in the CompilerFlags module, which is included in lib_A and sets the project name to compiler_flags, which wrecks the library name. Since this is a module, we should remove the project() call.

See https://github.com/daixtrose/cmake_utilities/pull/9 for the suggested change.

daixtrose commented 1 year ago

OMG. How did you find THAT one?

cpp-entwickler-de commented 1 year ago

Good old printf debugging :smile:. There are only a handful of probable reasons for CMake not to find a target. A message with the target name right next to target creation shows if the naming variable is correct and if the target definition is reached at all. When the printed name suddenly contains another project's name, it is quite clear where to look for the issue.