Skip to content

Commit f2dd276

Browse files
committed
Install header sets from CMake target property
Iterate over the target property for header sets to gather which header sets are installed. Extracted from https://github.com/ClausKlein/exemplar/blob/feature/add_cxx_module/cmake/beman-install-library.cmake and discussed in bemanproject/infra#19
1 parent 40c14f8 commit f2dd276

File tree

2 files changed

+71
-37
lines changed

2 files changed

+71
-37
lines changed

.pre-commit-config.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@ repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
55
rev: v6.0.0
66
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-yaml
10-
- id: check-added-large-files
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
1111

12-
# Clang-format for C++
13-
# This brings in a portable version of clang-format.
14-
# See also: https://github.com/ssciwr/clang-format-wheel
12+
# Clang-format for C++
13+
# This brings in a portable version of clang-format.
14+
# See also: https://github.com/ssciwr/clang-format-wheel
1515
- repo: https://github.com/pre-commit/mirrors-clang-format
1616
rev: v21.1.8
1717
hooks:
18-
- id: clang-format
19-
types_or: [c++, c]
18+
- id: clang-format
19+
types_or: [c++, c]
2020

21-
# CMake linting and formatting
21+
# CMake linting and formatting
2222
- repo: https://github.com/BlankSpruce/gersemi
2323
rev: 0.26.0
2424
hooks:
25-
- id: gersemi
26-
name: CMake linting
25+
- id: gersemi
26+
name: CMake linting
2727

28-
# Markdown linting
29-
# Config file: .markdownlint.yaml
28+
# Markdown linting
29+
# Config file: .markdownlint.yaml
3030
- repo: https://github.com/igorshubovych/markdownlint-cli
3131
rev: v0.47.0
3232
hooks:
33-
- id: markdownlint
34-
args: ['--disable', 'MD013', ' --']
35-
exclude: ^papers/
33+
- id: markdownlint
34+
args: ['--disable', 'MD013', ' --']
35+
exclude: ^papers/
3636

37-
# Config file: .codespell_ignore
37+
# Config file: .codespell_ignore
3838
- repo: https://github.com/codespell-project/codespell
3939
rev: v2.4.1
4040
hooks:

infra/cmake/beman-install-library-config.cmake

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ function(beman_install_library name)
3838
#
3939
set(options "")
4040
set(multiValueArgs "")
41-
set(multiValueArgs "FILE_SET")
41+
set(multiValueArgs TARGETS)
42+
4243
cmake_parse_arguments(
4344
BEMAN_INSTALL_LIBRARY
4445
"${options}"
@@ -51,8 +52,11 @@ function(beman_install_library name)
5152
message(FATAL_ERROR "Target '${name}' does not exist.")
5253
endif()
5354

54-
if(NOT BEMAN_INSTALL_LIBRARY_FILE_SET)
55-
set(BEMAN_INSTALL_LIBRARY_FILE_SET "HEADERS")
55+
if(NOT BEMAN_INSTALL_LIBRARY_TARGETS)
56+
if(NOT TARGET "${name}")
57+
message(FATAL_ERROR "Target '${name}' does not exist and TARGETS not specified.")
58+
endif()
59+
set(BEMAN_INSTALL_LIBRARY_TARGETS ${name})
5660
endif()
5761

5862
# Given foo.bar, the component name is bar
@@ -66,23 +70,56 @@ function(beman_install_library name)
6670
)
6771
endif()
6872

69-
set(target_name "${name}")
70-
set(install_component_name "${name}")
71-
set(export_name "${name}")
72-
set(package_name "${name}")
73-
list(GET name_parts -1 component_name)
74-
75-
install(
73+
foreach(_tgt IN LISTS BEMAN_INSTALL_LIBRARY_TARGETS)
74+
if(NOT TARGET "${_tgt}")
75+
message(
76+
WARNING
77+
"beman_install_library(${name}): '${_tgt}' is not a target"
78+
)
79+
continue()
80+
endif()
81+
82+
set(target_name "${_tgt}")
83+
set(install_component_name "${_tgt}")
84+
set(export_name "${name}")
85+
set(package_name "${name}")
86+
list(GET name_parts -1 component_name)
87+
88+
set(_install_header_set_args)
89+
get_target_property(
90+
_available_header_sets
91+
${_tgt}
92+
INTERFACE_HEADER_SETS
93+
)
94+
if(_available_header_sets)
95+
message(
96+
VERBOSE
97+
"beman-install-library(${name}): '${_tgt}' has INTERFACE_HEADER_SETS=${_available_header_sets}"
98+
)
99+
foreach(_install_header_set IN LISTS _available_header_sets)
100+
list(
101+
APPEND _install_header_set_args
102+
FILE_SET
103+
"${_install_header_set}"
104+
COMPONENT
105+
"${install_component_name}"
106+
)
107+
endforeach()
108+
else()
109+
set(_install_header_set_args FILE_SET HEADERS)
110+
endif()
111+
112+
install(
76113
TARGETS "${target_name}"
77-
COMPONENT "${install_component_name}"
78114
EXPORT "${export_name}"
79-
FILE_SET "${BEMAN_INSTALL_LIBRARY_FILE_SET}"
80-
)
115+
${_install_header_set_args}
116+
)
81117

82-
set_target_properties(
118+
set_target_properties(
83119
"${target_name}"
84120
PROPERTIES EXPORT_NAME "${component_name}"
85-
)
121+
)
122+
endforeach()
86123

87124
include(GNUInstallDirs)
88125

@@ -129,10 +166,7 @@ function(beman_install_library name)
129166
find_file(
130167
config_file_template
131168
NAMES "${package_name}-config.cmake.in"
132-
PATHS
133-
"${CMAKE_CURRENT_SOURCE_DIR}"
134-
"${PROJECT_SOURCE_DIR}/cmake"
135-
"${CMAKE_SOURCE_DIR}/cmake"
169+
PATHS "${PROJECT_SOURCE_DIR}/cmake"
136170
NO_DEFAULT_PATH
137171
NO_CACHE
138172
REQUIRED

0 commit comments

Comments
 (0)