Hello,
I am facing a strange problem when trying to use CPack (dh_cmake
for Debian packaging) to install the CMake export scripts. I am not sure if I am doing something wrong or if this is bug or feature of CMake, but I have been looking at it for some time and I am ready to ask for help.
I have a project which has multiple libraries - mostly shared, some INTERFACE (basically for headers as some of the shared libraries are loaded dynamically) and some static libraries - and each library has its own export. (In CMake terms each target has its own export, as it allows me to then manually group them into COMPONENT
s for find_package()
call. The *Config.cmake
itself is then created with configure_package_config_file()
and write_basic_package_version_file()
.) The core of my CMakeLists.txt
s looks like this:
install(
TARGETS SuperLib
EXPORT project_superlib
LIBRARY DESTINATION "${LIBRARY_DIRECTORY}"
COMPONENT Project_Library_SuperLib_Libraries
NAMELINK_COMPONENT Project_Library_SuperLib_Namelinks
PUBLIC_HEADER DESTINATION "${INTERFACE_DIRECTORY}/superlib"
COMPONENT Project_Library_SuperLib_Headers)
install(
EXPORT project_superlib
DESTINATION ${CMAKE_PACKAGE_DIRECTORY}
NAMESPACE "${PROJECT_NAMESPACE}::"
FILE "ProjectSuperLibTarget.cmake"
COMPONENT Project_Library_SuperLib_Package_Exports)
export(
EXPORT project_superlib
NAMESPACE "${PROJECT_NAMESPACE}::"
FILE "${CMAKE_PACKAGE_OUTPUT_DIRECTORY}/ProjectSuperLibTarget.cmake"
)
cpack_add_component(Project_Library_SuperLib_Libraries
GROUP Project_Library_SuperLib)
cpack_add_component(
Project_Library_SuperLib_Namelinks
GROUP Project_Library_SuperLib_Development
DEPENDS Project_Library_SuperLib_Libraries)
cpack_add_component(
Project_Library_SuperLib_Headers
GROUP Project_Library_SuperLib_Development
DEPENDS Project_Library_SuperLib_Libraries)
cpack_add_component(
Project_Library_SuperLib_Package_Exports
GROUP Project_Library_SuperLib_Export)
# Specification of artifacts placement in package tree
cpack_add_component_group(Project_Library_SuperLib
PARENT_GROUP Project_Package_Base_Libraries)
cpack_add_component_group(
Project_Library_SuperLib_Development
PARENT_GROUP Project_Package_Base_Libraries_Development)
cpack_add_component_group(
Project_Library_SuperLib_Export
PARENT_GROUP Project_Package_Base_Libraries_Development)
And this works for the execution from a binary tree (development setup) and when installed fine. Either all CMake *Target.cmake
are generated or are installed.
However, when I try to build the packages, only very few *Target.cmake
files are copied over into the package. The cpack-metadata.json
file does not contain the aforementioned Project_Library_SuperLib_Package_Exports
CPack components, however it includes the header and namelink components - these are in the came CPack group. Also, the CPackConfic.cmake
file has about 3 mentions of Project_Library_SuperLib_Package_Exports
, but about 400 of Project_Library_SuperLib_Namelinks
. Also, when I try to isolate all *_Package_exports
components to its own group, which I then add to the *.cpack-component-groups
, the build fails, because that group has nothing to install.
I am thinking, what can cause a behavior like this? The file exists (created both by the export(EXPORT)
and install(EXPORT)
- this created two files: *Target.cmake
and *Target-$<CONFIG>.cmake
), it is just not installed.