From 1d467b76fd81808f87ead44817aff947c2ec96f6 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Sun, 10 Apr 2022 15:18:09 +0200 Subject: [PATCH] Feature/use file matching patterns (#29) * use file matching pattern for header to install * add optional INCLUDE_HEADER_PATTERN this may be used to prevent installation of other files i.e. idl, in, txt, ... files * clang-format CMakeLists.txt add new options to README.md too * add INCLUDE_HEADER_PATTERN to .cmake-format too * Update CMakeLists.txt Co-authored-by: Lars Melchior * apply cmake-format Co-authored-by: Lars Melchior --- .cmake-format | 1 + CMakeLists.txt | 8 +++++++- README.md | 2 ++ test/CMakeLists.txt | 2 +- test/dependency/CMakeLists.txt | 2 +- test/namespaced_dependency/CMakeLists.txt | 3 ++- test/transitive_dependency/CMakeLists.txt | 2 +- test/transitive_dependency/cmake/CPM.cmake | 2 +- 8 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.cmake-format b/.cmake-format index 86664ab..790c74c 100644 --- a/.cmake-format +++ b/.cmake-format @@ -51,6 +51,7 @@ parse: NAMESPACE: 1 INCLUDE_DIR: 1 INCLUDE_DESTINATION: 1 + INCLUDE_HEADER_PATTERN: 1 BINARY_DIR: 1 COMPATIBILITY: 1 VERSION_HEADER: 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 125d673..f2e27d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ function(packageProject) cmake_parse_arguments( PROJECT "" - "NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;EXPORT_HEADER;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT" + "NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;EXPORT_HEADER;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT;INCLUDE_HEADER_PATTERN" "DEPENDENCIES" ${ARGN} ) @@ -161,10 +161,16 @@ function(packageProject) COMPONENT "${PROJECT_NAME}_Development" ) + if(NOT DEFINED PROJECT_INCLUDE_HEADER_PATTERN) + set(PROJECT_INCLUDE_HEADER_PATTERN "*") + endif() + install( DIRECTORY ${PROJECT_INCLUDE_DIR}/ DESTINATION ${PROJECT_INCLUDE_DESTINATION} COMPONENT "${PROJECT_NAME}_Development" + FILES_MATCHING + PATTERN "${PROJECT_INCLUDE_HEADER_PATTERN}" ) set(${PROJECT_NAME}_VERSION diff --git a/README.md b/README.md index 1b6540d..e3e8092 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ packageProject( INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include # should match the target's INSTALL_INTERFACE include directory INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} + # (optional) option to install only header files with matching pattern + INCLUDE_HEADER_PATTERN "*.h" # semicolon separated list of the project's dependencies DEPENDENCIES "fmt 7.1.3;cxxopts 2.2.0" # (optional) create a header containing the version info diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9ae215d..f573dbe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.14...3.22) option(TEST_INSTALLED_VERSION "Test the version found by find_package" OFF) diff --git a/test/dependency/CMakeLists.txt b/test/dependency/CMakeLists.txt index c08de73..f321b8f 100644 --- a/test/dependency/CMakeLists.txt +++ b/test/dependency/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.14...3.22) project( dependency diff --git a/test/namespaced_dependency/CMakeLists.txt b/test/namespaced_dependency/CMakeLists.txt index 6c154b3..cb6cc5b 100644 --- a/test/namespaced_dependency/CMakeLists.txt +++ b/test/namespaced_dependency/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.14...3.22) project( namespaced_dependency @@ -26,5 +26,6 @@ packageProject( INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} VERSION_HEADER "namespaced_dependency/version.h" + INCLUDE_HEADER_PATTERN "*.h" DEPENDENCIES "" ) diff --git a/test/transitive_dependency/CMakeLists.txt b/test/transitive_dependency/CMakeLists.txt index 4abba0a..21ab90d 100644 --- a/test/transitive_dependency/CMakeLists.txt +++ b/test/transitive_dependency/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.14...3.22) project( transitive_dependency diff --git a/test/transitive_dependency/cmake/CPM.cmake b/test/transitive_dependency/cmake/CPM.cmake index 5df65a1..bc06845 100644 --- a/test/transitive_dependency/cmake/CPM.cmake +++ b/test/transitive_dependency/cmake/CPM.cmake @@ -1,4 +1,4 @@ -set(CPM_DOWNLOAD_VERSION 0.30.0) +set(CPM_DOWNLOAD_VERSION 0.35.0) if(CPM_SOURCE_CACHE) # Expand relative path. This is important if the provided path contains a tilde (~)