Skip to content

Commit

Permalink
Feature/use file matching patterns (#29)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* apply cmake-format

Co-authored-by: Lars Melchior <[email protected]>
  • Loading branch information
ClausKlein and TheLartians authored Apr 10, 2022
1 parent 19ccf94 commit 1d467b7
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion test/dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.14...3.22)

project(
dependency
Expand Down
3 changes: 2 additions & 1 deletion test/namespaced_dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.14...3.22)

project(
namespaced_dependency
Expand Down Expand Up @@ -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 ""
)
2 changes: 1 addition & 1 deletion test/transitive_dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.14...3.22)

project(
transitive_dependency
Expand Down
2 changes: 1 addition & 1 deletion test/transitive_dependency/cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -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 (~)
Expand Down

0 comments on commit 1d467b7

Please sign in to comment.