Skip to content

Commit 2df0093

Browse files
authored
🔧 improve QDMI installation setup and header management (#228)
## Description This pull request refactors the CMake build and installation setup for the `qdmi` library to improve header file management, installation consistency, and package configuration. The changes modernize how headers are handled, align installation paths and components, and ensure that all necessary CMake scripts are installed and loaded with the package. Header management improvements: * Switched from manually setting include directories to using `target_sources` with a `FILE_SET` for headers, ensuring more robust and modern header management for the `qdmi` target. Installation and packaging enhancements: * Refactored installation instructions to use project-specific runtime and development components, aligned header installation with library and archive installation using `FILE_SET`, and set a consistent config install directory (`QDMI_CONFIG_INSTALL_DIR`). * Updated package configuration to install and load additional CMake scripts (`Cache.cmake`, `PrefixHandling.cmake`) needed for consumers, and ensured these are included in the installed package config file. * Changed the compatibility mode for the package version file from `SameMajorVersion` to `SameMinorVersion` for more precise version matching. ## Checklist: <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are focused and relevant to this change. - [x] I have added appropriate tests that cover the new/changed functionality. - [x] I have updated the documentation to reflect these changes. - [ ] I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals. - [x] I have added migration instructions to the upgrade guide (if needed). - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes. --------- Signed-off-by: burgholzer <burgholzer@me.com>
1 parent dd2e862 commit 2df0093

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ clients compiled against a different minor or major version.
3131

3232
### Changed
3333

34+
- 🔧 Improve library installation setup and header management ([#228]) ([\@burgholzer])
3435
- 🔧 Set c++ standard target based ([#165]) ([\@ystade])
3536
- **Breaking**: 🚸 Change order of `QDMI_SESSION_PARAMETER` and `QDMI_DEVICE_SESSION` enum values
3637
due to new authentication options ([#160]) ([\@ystade], [\@burgholzer])
@@ -61,6 +62,7 @@ changelogs._
6162

6263
<!-- PR links -->
6364

65+
[#228]: https://github.com/Munich-Quantum-Software-Stack/QDMI/pull/228
6466
[#214]: https://github.com/Munich-Quantum-Software-Stack/QDMI/pull/214
6567
[#211]: https://github.com/Munich-Quantum-Software-Stack/QDMI/pull/211
6668
[#210]: https://github.com/Munich-Quantum-Software-Stack/QDMI/pull/210

‎CMakeLists.txt‎

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ if(NOT TARGET qdmi::qdmi)
117117
# add main library code
118118
add_library(qdmi INTERFACE)
119119

120-
# set include directories
121-
target_include_directories(
122-
qdmi INTERFACE $<BUILD_INTERFACE:${QDMI_INCLUDE_BUILD_DIR}>
123-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
120+
# collect header files
121+
file(GLOB_RECURSE QDMI_HEADERS ${QDMI_INCLUDE_BUILD_DIR}/qdmi/*.h)
122+
123+
# add headers using file sets
124+
target_sources(qdmi PUBLIC FILE_SET HEADERS BASE_DIRS
125+
${QDMI_INCLUDE_BUILD_DIR} FILES ${QDMI_HEADERS})
124126

125127
# set required C standard
126128
target_compile_features(qdmi INTERFACE c_std_11)
@@ -174,35 +176,52 @@ endif()
174176

175177
# Installation instructions for the main library
176178
if(QDMI_INSTALL)
177-
install(
178-
TARGETS qdmi qdmi_project_warnings
179-
EXPORT ${PROJECT_NAME}-targets
180-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development
181-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
182-
COMPONENT Runtime
183-
NAMELINK_COMPONENT Development
184-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
185-
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
179+
set(QDMI_CONFIG_INSTALL_DIR
180+
"${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
181+
CACHE INTERNAL "Config install directory")
186182

187183
include(CMakePackageConfigHelpers)
188-
write_basic_package_version_file(
189-
"${PROJECT_NAME}-config-version.cmake"
190-
VERSION ${PROJECT_VERSION}
191-
COMPATIBILITY SameMajorVersion)
192184
configure_package_config_file(
193185
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
194186
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
195-
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
187+
INSTALL_DESTINATION ${QDMI_CONFIG_INSTALL_DIR}
188+
NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
189+
write_basic_package_version_file(
190+
"${PROJECT_NAME}-config-version.cmake"
191+
VERSION ${PROJECT_VERSION}
192+
COMPATIBILITY SameMinorVersion)
193+
194+
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
195+
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
196+
DESTINATION ${QDMI_CONFIG_INSTALL_DIR})
197+
198+
# FILE_SET should be aligned with LIBRARY and ARCHIVE, so we turn cmake-format
199+
# off
200+
# cmake-format: off
201+
install(
202+
TARGETS qdmi qdmi_project_warnings
203+
EXPORT ${PROJECT_NAME}-targets
204+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${PROJECT_NAME}_Runtime
205+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
206+
COMPONENT ${PROJECT_NAME}_Runtime
207+
NAMELINK_COMPONENT ${PROJECT_NAME}_Development
208+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${PROJECT_NAME}_Development
209+
FILE_SET HEADERS
210+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
211+
COMPONENT ${PROJECT_NAME}_Development)
212+
# cmake-format: on
196213

197214
install(
198215
EXPORT ${PROJECT_NAME}-targets
199216
FILE ${PROJECT_NAME}-targets.cmake
200217
NAMESPACE ${PROJECT_NAME}::
201-
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
218+
DESTINATION ${QDMI_CONFIG_INSTALL_DIR}
219+
COMPONENT ${PROJECT_NAME}_Development)
202220

203-
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
204-
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
205-
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
206-
207-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/qdmi DESTINATION include)
221+
install(
222+
FILES ${PROJECT_SOURCE_DIR}/cmake/Cache.cmake
223+
${PROJECT_SOURCE_DIR}/cmake/prefix_defs.txt
224+
${PROJECT_SOURCE_DIR}/cmake/PrefixHandling.cmake
225+
DESTINATION ${QDMI_CONFIG_INSTALL_DIR}
226+
COMPONENT ${PROJECT_NAME}_Development)
208227
endif()

‎cmake/qdmi-config.cmake.in‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ if(TARGET qdmi::qdmi)
2626
return()
2727
endif()
2828

29+
include("${CMAKE_CURRENT_LIST_DIR}/Cache.cmake")
30+
include("${CMAKE_CURRENT_LIST_DIR}/PrefixHandling.cmake")
2931
include("${CMAKE_CURRENT_LIST_DIR}/qdmi-targets.cmake")
3032

3133
if(NOT qdmi_FIND_QUIETLY)

0 commit comments

Comments
 (0)