My issue is that it generates a target Alglib without namespace and, in my own framework I expect only dependencies in the form package::component. Whenever I’m finding a target without namespace, I create a fake (INTERFACE IMPORTED) configuring it from the original target _INCLUDE_DIR(S) and LIBRARY or LIBRARIES. This strategy has worked, so far, with all third-party library I encountered.
But in the case of alglib-cmake it seems that none of these variables exists and I don’t get why.
So far my obvious workaround has been to modify the provided CMakeLists.txt to create Alglib::Alglib but I’d like to understand why I don’t get the expected variables and if I should adapt my strategy for this situation (and how).
I wanted to enforce the format package::component. Does ALIAS allows something like add_library(Alglib::Alglib ALIAS Alglib)?. In this case it will simplify a great lot my wrapping .
# ${CompName} is set to ${PackName} by default
# ${TargetName} the target that will link ${PackName}
# ${Inheritance} is one of PUBLIC/PRIVATE/INTERFACE
if(NOT(${PackName}_FOUND))
# No one has called find_package previously
find_package(${PackName} REQUIRED)
endif()
# ${CompName} is set to ${PackName} by default
if(${PackName}_FOUND AND NOT TARGET ${PackName}::${CompName})
message("${PackName} found")
add_library(${PackName}::${PackName} ALIAS ${PackName})
target_link_libraries(${TargetName} ${Inheritance} ${PackName}::${PackName})
endif()
But, for instance, with OpenSSL as ${PackName}, I’m getting
OpenSSL found
Then an error on add_library:
add_library cannot create ALIAS target “OpenSSL::OpenSSL” because target
“OpenSSL” does not already exist
ah maybe. It’s a situation I didn’t think about.
I’ll check and if it’s the case I’ll need a different strategy:
Is there a way to enumerate the components found and merge them into a single one? (ie merging OpenSSL::Crypto and OpenSSL::SSL into OpenSSL::OpenSSL).
You’ll probably have to play around with that to get what you want.
Otherwise I typically just get the possible targets from the documentation and give up on automatic discovery.