Just a clarification.
There are several configuration files that are exported. With given snippet:
<Target_Name>Targets.cmake
: automatically generated<Target_Name>Config.cmake
: manually crafted and partialy edited by cmake (see also Correctly exporting configuration: second part)<Target_Name>Targets-<Config>.cmake
: automatically generated
NB1 <Target_Name>Config.cmake
must finishes with a line including <Target_Name>Targets.cmake
NB2 In the example given in the second part of the question (linked above), I’m doing include("${CMAKE_CURRENT_LIST_DIR}/@TARGET_NAME@Targets.cmake")
. How does it happen that ${CMAKE_CURRENT_LIST_DIR}
is always resolving to the actual installation directory of the configuration file (maybe, from cmake documentation: When CMake starts processing commands in a source file it sets this variable to the directory where this file is located
)
Then doing:
install (EXPORT ${TARGET_NAME}Targets
NAMESPACE ${TARGET_NAME}::
DESTINATION "${COMPUTED_ABSOLUTE_PATH_TO_A_DEDICATED_DIRECTORY}"
)
seems to have two effects:
declaring my target as <TargetName>::<TargetName>
, a component named <TargetName>
in a namespace TargetName
: It’s at this step that I can have a different namespace name that my target one.
So it rises another question: when I want to link against some library, I’ve got in fact 3 independant names:
- the name which is the root of the
Config.cmake
file - a namespace name
- a component name
Am I correct in saying that find_package(<name1> COMPONENT <name2>)
will look for all components <name2>
described in Config.cmake`, possibly finding several ones in different namespaces:
<namespace1>::<name2>
<namespace2>::<name2>
- …`
?
And they I’ll have to pass the rightly namespace-qualified one to target_link_directory