CMAKE find_package successful, but TARGET not found

603 Views Asked by At

In my CMakeLists.txt file I’m trying to build “Bob”, which is a library that gets linked to later. The find_package request is successful, but the "if(NOT TARGET..." check fails. I figured if Bob was found then Bob::Bob would also be found. I could obviously be wrong.

What is “if(NOT TARGET Bob::Bob)” using to determine true or false? How do I set it up correctly?

CMakeLists.txt:

find_package(Bob ${BOB_VERSION} EXACT REQUIRED ${CMAKE_PREFIX_PATH})


if (${Bob_FOUND})
    message(STATUS "Found Bob")
else (${Bob_FOUND})
    message(FATAL_ERROR "Could not locate Bob! Abort!")
endif (${Bob_FOUND})


if(NOT TARGET Bob::Bob)
    message(WARNING "Cannot build without Bob::Bob!”)
...

Output:

#13 3.210 Finding Bob...
#13 3.210
#13 3.210 Entered BobConfigVersion.cmake
#13 3.210 Value of BOB_VERSION is: 2022.12.01
#13 3.210    PACKAGE_VERSION           : 2022.12.01
#13 3.210    Bob_VERSION          : 2022.12.01
#13 3.210    PACKAGE_FIND_VERSION      : 2022.12.01
#13 3.210    PACKAGE_VERSION_COMPATIBLE: TRUE
#13 3.210    PACKAGE_VERSION_EXACT     : TRUE
#13 3.210 Exiting BobConfigVersion.cmake

#13 3.213 -- Found Bob
#13 3.320   Cannot build without Bob::Bob!
0

There are 0 best solutions below