From b996df0d1ceb8c9074839dd504c2baae491a0bbc Mon Sep 17 00:00:00 2001 From: Thomas Lieb Date: Wed, 12 Apr 2023 18:16:36 +0200 Subject: [PATCH 1/2] Add option to install target with cmake --- CMakeLists.txt | 41 +++++++++++++++++++++++++++++++++++++++++ Config.cmake.in | 5 +++++ 2 files changed, 46 insertions(+) create mode 100644 Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 4003e08..2aac57a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,3 +42,44 @@ endif () #=============================================================================== set (CMAKE_SUPPRESS_REGENERATION true) + +#=============================================================================== +include (CMakePackageConfigHelpers) + +install (TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +install (FILES ${PROJECT_SOURCE_DIR}/AudioFile.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} +) + +install (EXPORT ${PROJECT_NAME}Targets + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +configure_package_config_file ( + ${PROJECT_SOURCE_DIR}/Config.cmake.in + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +write_basic_package_version_file ( + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion + ARCH_INDEPENDENT +) + +install (FILES + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 0000000..8c9ad12 --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") + +check_required_components(@PROJECT_NAME@) From 722d3b775c68b62e90de376eda712e7ab75f3122 Mon Sep 17 00:00:00 2001 From: Thomas Lieb Date: Wed, 19 Apr 2023 14:53:18 +0200 Subject: [PATCH 2/2] Generate config file --- CMakeLists.txt | 12 ++++++++---- Config.cmake.in | 5 ----- 2 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 2aac57a..fa32740 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,13 +59,17 @@ install (FILES ${PROJECT_SOURCE_DIR}/AudioFile.h ) install (EXPORT ${PROJECT_NAME}Targets - FILE ${PROJECT_NAME}Targets.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +file (WRITE ${PROJECT_BINARY_DIR}/Config.cmake.in + "@PACKAGE_INIT@\n\ninclude(\"\${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake\")\n\ncheck_required_components(@PROJECT_NAME@)\n" ) configure_package_config_file ( - ${PROJECT_SOURCE_DIR}/Config.cmake.in + ${PROJECT_BINARY_DIR}/Config.cmake.in ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} diff --git a/Config.cmake.in b/Config.cmake.in deleted file mode 100644 index 8c9ad12..0000000 --- a/Config.cmake.in +++ /dev/null @@ -1,5 +0,0 @@ -@PACKAGE_INIT@ - -include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") - -check_required_components(@PROJECT_NAME@)