Skip to content

Commit 1d467b7

Browse files
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 <TheLartians@users.noreply.github.com> * apply cmake-format Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
1 parent 19ccf94 commit 1d467b7

8 files changed

Lines changed: 16 additions & 6 deletions

File tree

.cmake-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ parse:
5151
NAMESPACE: 1
5252
INCLUDE_DIR: 1
5353
INCLUDE_DESTINATION: 1
54+
INCLUDE_HEADER_PATTERN: 1
5455
BINARY_DIR: 1
5556
COMPATIBILITY: 1
5657
VERSION_HEADER: 1

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function(packageProject)
1212
cmake_parse_arguments(
1313
PROJECT
1414
""
15-
"NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;EXPORT_HEADER;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT"
15+
"NAME;VERSION;INCLUDE_DIR;INCLUDE_DESTINATION;BINARY_DIR;COMPATIBILITY;EXPORT_HEADER;VERSION_HEADER;NAMESPACE;DISABLE_VERSION_SUFFIX;ARCH_INDEPENDENT;INCLUDE_HEADER_PATTERN"
1616
"DEPENDENCIES"
1717
${ARGN}
1818
)
@@ -161,10 +161,16 @@ function(packageProject)
161161
COMPONENT "${PROJECT_NAME}_Development"
162162
)
163163

164+
if(NOT DEFINED PROJECT_INCLUDE_HEADER_PATTERN)
165+
set(PROJECT_INCLUDE_HEADER_PATTERN "*")
166+
endif()
167+
164168
install(
165169
DIRECTORY ${PROJECT_INCLUDE_DIR}/
166170
DESTINATION ${PROJECT_INCLUDE_DESTINATION}
167171
COMPONENT "${PROJECT_NAME}_Development"
172+
FILES_MATCHING
173+
PATTERN "${PROJECT_INCLUDE_HEADER_PATTERN}"
168174
)
169175

170176
set(${PROJECT_NAME}_VERSION

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ packageProject(
2626
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
2727
# should match the target's INSTALL_INTERFACE include directory
2828
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
29+
# (optional) option to install only header files with matching pattern
30+
INCLUDE_HEADER_PATTERN "*.h"
2931
# semicolon separated list of the project's dependencies
3032
DEPENDENCIES "fmt 7.1.3;cxxopts 2.2.0"
3133
# (optional) create a header containing the version info

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14)
1+
cmake_minimum_required(VERSION 3.14...3.22)
22

33
option(TEST_INSTALLED_VERSION "Test the version found by find_package" OFF)
44

test/dependency/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14)
1+
cmake_minimum_required(VERSION 3.14...3.22)
22

33
project(
44
dependency

test/namespaced_dependency/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14)
1+
cmake_minimum_required(VERSION 3.14...3.22)
22

33
project(
44
namespaced_dependency
@@ -26,5 +26,6 @@ packageProject(
2626
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
2727
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
2828
VERSION_HEADER "namespaced_dependency/version.h"
29+
INCLUDE_HEADER_PATTERN "*.h"
2930
DEPENDENCIES ""
3031
)

test/transitive_dependency/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14)
1+
cmake_minimum_required(VERSION 3.14...3.22)
22

33
project(
44
transitive_dependency

test/transitive_dependency/cmake/CPM.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(CPM_DOWNLOAD_VERSION 0.30.0)
1+
set(CPM_DOWNLOAD_VERSION 0.35.0)
22

33
if(CPM_SOURCE_CACHE)
44
# Expand relative path. This is important if the provided path contains a tilde (~)

0 commit comments

Comments
 (0)