build(cmake): install public headers with a header file set

- Add the public headers and the generated Version.h to the file set
  HEADERS of FairMQ
- Install the file set instead of one install(FILES) per header
- The file set gives the include directory include/fairmq; the exported
  target also adds it for CMake versions before 3.23
- The installed headers are the same

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-09 23:03:53 +00:00
committed by Dennis Klein
parent 230a614bb1
commit e2a150d9e8
2 changed files with 14 additions and 16 deletions

View File

@@ -217,8 +217,9 @@ The package does not export the example programs.
`FairMQ::FairMQ` gives these usage requirements to the targets that link to it: `FairMQ::FairMQ` gives these usage requirements to the targets that link to it:
- C++17 (`cxx_std_17`). - C++17 (`cxx_std_17`).
- The include directories `include/fairmq` and `include` of the prefix. Thus `#include <fairmq/Device.h>` and the deprecated `#include <FairMQDevice.h>` both work. See [Move from the FairMQ* names](/guides/migrate-names/). - The include directories `include` and `include/fairmq` of the prefix. Thus `#include <fairmq/Device.h>` and the deprecated `#include <FairMQDevice.h>` both work. See [Move from the FairMQ* names](/guides/migrate-names/).
- The [compile definitions](#compile-definitions). - The [compile definitions](#compile-definitions).
- The public headers in the header file set `HEADERS` of the target. IDEs and tools that read file sets can list them.
- The libraries `Threads::Threads`, `dl`, `rt` (Linux only), `Boost::headers`, `Boost::container`, `Boost::program_options`, `Boost::filesystem`, `Boost::regex` and `FairLogger::FairLogger`. - The libraries `Threads::Threads`, `dl`, `rt` (Linux only), `Boost::headers`, `Boost::container`, `Boost::program_options`, `Boost::filesystem`, `Boost::regex` and `FairLogger::FairLogger`.
:::caution[Find the dependencies before you link] :::caution[Find the dependencies before you link]

View File

@@ -19,9 +19,6 @@ if(BUILD_FAIRMQ)
${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}/Version.h ${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}/Version.h
@ONLY @ONLY
) )
install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}/Version.h
DESTINATION ${PROJECT_INSTALL_INCDIR}
)
########################## ##########################
# libFairMQ header files # # libFairMQ header files #
@@ -155,9 +152,19 @@ if(BUILD_FAIRMQ)
set(target FairMQ) set(target FairMQ)
add_library(${target} add_library(${target}
${FAIRMQ_SOURCE_FILES} ${FAIRMQ_SOURCE_FILES}
${FAIRMQ_PUBLIC_HEADER_FILES} # for IDE integration
${FAIRMQ_PRIVATE_HEADER_FILES} # for IDE integration ${FAIRMQ_PRIVATE_HEADER_FILES} # for IDE integration
) )
# The file set installs the public headers with their relative paths and
# adds the base directories to the include directories.
target_sources(${target}
PUBLIC FILE_SET HEADERS
BASE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}
FILES
${FAIRMQ_PUBLIC_HEADER_FILES}
${PROJECT_BINARY_DIR}/${PROJECT_NAME_LOWER}/Version.h
)
add_library(${PROJECT_NAME}::${target} ALIAS ${target}) add_library(${PROJECT_NAME}::${target} ALIAS ${target})
target_compile_features(${target} PUBLIC cxx_std_17) target_compile_features(${target} PUBLIC cxx_std_17)
set_target_properties(${target} PROPERTIES LABELS coverage) set_target_properties(${target} PROPERTIES LABELS coverage)
@@ -195,10 +202,8 @@ if(BUILD_FAIRMQ)
####################### #######################
target_include_directories(${target} target_include_directories(${target}
PUBLIC # consumers inherit public include directories PUBLIC # consumers inherit public include directories
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:${PROJECT_INSTALL_INCDIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
) )
@@ -324,14 +329,6 @@ if(BUILD_FAIRMQ)
RUNTIME DESTINATION ${PROJECT_INSTALL_BINDIR} RUNTIME DESTINATION ${PROJECT_INSTALL_BINDIR}
LIBRARY DESTINATION ${PROJECT_INSTALL_LIBDIR} LIBRARY DESTINATION ${PROJECT_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${PROJECT_INSTALL_LIBDIR} ARCHIVE DESTINATION ${PROJECT_INSTALL_LIBDIR}
FILE_SET HEADERS DESTINATION ${PROJECT_INSTALL_INCDIR}
) )
# preserve relative path and prepend fairmq
foreach(HEADER ${FAIRMQ_PUBLIC_HEADER_FILES})
get_filename_component(_path ${HEADER} DIRECTORY)
file(TO_CMAKE_PATH ${PROJECT_INSTALL_INCDIR}/${_path} _destination)
install(FILES ${HEADER}
DESTINATION ${_destination}
)
endforeach()
endif() endif()