My need as described in the topic subject is occurring with the GMP library (Gnu Multiple Precision).
On my system it does not seem to be detectable by find_package so I tried to make it detectable through a Findgmp.cmake.
The issue is that it is actually made fo two libraries gmp (C API) and gmpxx (C++ API, which depend on the first one).
I can link both using two different find modules, and generating two targets (gmp::gmp and gmpxx::gmpxx) but I’d like to have only one target (say gmp::gmp) that allows me to link both libraries.
So far I cannot write my findmodule accordingly (example attached).
Can someone tell me how to fix it?
By the way, I’m utterly confused with the difference between _LIBRARY and _LIBRARIES, _INCLUDE_DIR and _INCLUDE_DIRS. I’d appreciate some clarifications on this topic.
Nothing ever sets gmpxx_FOUND. Additionally, you should guard target creation with if (NOT TARGET …) because find_package(gmp) running twice within a scope is otherwise a hard error on the target re-creation.
I find_package(gmp) then target_link_libraries(MyTargetName PRIVATE gmp::gmp) but on link, only libgmpxx is passed to the linker whereas libgmp is also expected and needed.
You still need to wrap all of the post-FPHSA stuff in if (gmp_FOUND). But the gmp::gmp target is completely wrong. It needs to be an INTERFACE, not an UNKNOWN library. You’re setting the same property twice which means that the first setting is completely ignored.
works properly
But anyway, whatever the commands used, variables gmp_LIBRARY and gmp_INCLUDE_DIR with incorrect values are created. How to set them correctly?
yet, when running CMake, I have the following error:
CMake Error at …/Findgmp.cmake:50 (target_link_libraries):
Cannot specify link libraries for target “gmp::gmp” which is not built by this project.
What does it mean? How can I fix it.
Thanks Findgmp.cmake (1.6 KB)