Binary package name in find_package() and target_link_libraries()

I’m searching for a rule of thumb to discover how the binary package name used in find_package() is modified for use in target_link_libraries(). In this fragment of CMakeLists.txt file:

find_package(fmt REQUIRED)
find_package(OpenMP REQUIRED)
find_package(OpenCV REQUIRED)
find_package(ufomap REQUIRED)
target_link_libraries (hello 

each package name follows different rules. Documentation at

find_package(SomePackage REQUIRED)
target_link_libraries(MyExe PRIVATE SomePrefix::LibName)

doesn’t help with finding transformation from SomePackage to SomePrefix::LibName.

All binary packages listed in my example provide a package configuration file, but I don’t see that information there. Is there any other place to search for it?

There are no rules for this, what target(s) a package provides is fully within its control. So the only place to look for such information is that package’s documentation (or, failing that, in the package config file itself).

1 Like

Thank you. Unfortunately, very few packages have as nice configuration file as, for example, OpenCV does:

#    In your CMakeLists.txt, add these lines:
#    find_package(OpenCV REQUIRED)
#    include_directories(${OpenCV_INCLUDE_DIRS}) # Not needed for CMake >= 2.8.11
#    target_link_libraries(MY_TARGET_NAME ${OpenCV_LIBS})