My issue may be a bit more complicated than anticipated and related to another issue: Findmodule transitivity?
What I want exactly do is:
L may depend on a third party library TP that is not properly packaged.
If L uses TP, it imports TP with a FindTP.cmake file and defines a compile definition TPNEEDED
What I’d like to do is, when, in A, I find_package(L) then TP is automatically linked with A, but only if L actually needed TP.
the FindTP.cmake does not seem to be used “transitively”, and I can’t retrieve if TPNEEDED is defined so far. Besides, I suppose that it may be only defined after find_package(L) that will generate an error because TP is not found, before I can do anything about it.
Thus, what would be the proper way to manage this optional dependency?
Also an interesting link that rises some questions:
1- target_include_directories(JSONUtils … PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
Why is not the PRIVATE part within the BUILD_INTERFACE)
2- in the FindModule.cmake example, what does the pkg_check_modules function (I’ve just looked at https://cmake.org/cmake/help/v3.22/module/FindPkgConfig.html but have nor really understood its usage)
3- what is the difference between RapidJSON_INCLUDE_DIR and RapidJSON_INCLUDE_DIRS and why are they not set in the same way?
I’m now checking if my practice is on line with the rest of the post but it seems to.
Anyway, it does not enlight me on my optional dependency issue…