Skip to content

Commit 59de52e

Browse files
authored
Merge pull request #610 from elbeno/use-file-sets
Use `target_sources` instead of `target_include_directories`
2 parents bc30926 + 1220284 commit 59de52e

File tree

2 files changed

+213
-25
lines changed

2 files changed

+213
-25
lines changed

CMakeLists.txt

Lines changed: 196 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,181 @@ add_versioned_package("gh:intel/cpp-baremetal-senders-and-receivers#113eeff")
3030

3131
add_library(cib INTERFACE)
3232
target_compile_features(cib INTERFACE cxx_std_20)
33-
target_include_directories(cib INTERFACE include)
3433
target_link_libraries_system(cib INTERFACE async concurrency
3534
fmt::fmt-header-only stdx)
3635

36+
target_sources(
37+
cib
38+
INTERFACE FILE_SET
39+
cib
40+
TYPE
41+
HEADERS
42+
BASE_DIRS
43+
include
44+
FILES
45+
include/cib/builder_meta.hpp
46+
include/cib/built.hpp
47+
include/cib/callback.hpp
48+
include/cib/cib.hpp
49+
include/cib/config.hpp
50+
include/cib/detail/components.hpp
51+
include/cib/detail/conditional.hpp
52+
include/cib/detail/config_details.hpp
53+
include/cib/detail/config_item.hpp
54+
include/cib/detail/exports.hpp
55+
include/cib/detail/extend.hpp
56+
include/cib/detail/nexus_details.hpp
57+
include/cib/func_decl.hpp
58+
include/cib/nexus.hpp
59+
include/cib/top.hpp)
60+
61+
target_sources(
62+
cib
63+
INTERFACE FILE_SET
64+
flow
65+
TYPE
66+
HEADERS
67+
BASE_DIRS
68+
include
69+
FILES
70+
include/flow/builder.hpp
71+
include/flow/common.hpp
72+
include/flow/detail/par.hpp
73+
include/flow/detail/seq.hpp
74+
include/flow/detail/walk.hpp
75+
include/flow/flow.hpp
76+
include/flow/graph_builder.hpp
77+
include/flow/graphviz_builder.hpp
78+
include/flow/impl.hpp
79+
include/flow/run.hpp
80+
include/flow/step.hpp)
81+
82+
target_sources(
83+
cib
84+
INTERFACE FILE_SET
85+
interrupt
86+
TYPE
87+
HEADERS
88+
BASE_DIRS
89+
include
90+
FILES
91+
include/interrupt/concepts.hpp
92+
include/interrupt/config.hpp
93+
include/interrupt/dynamic_controller.hpp
94+
include/interrupt/fwd.hpp
95+
include/interrupt/hal.hpp
96+
include/interrupt/impl.hpp
97+
include/interrupt/manager.hpp
98+
include/interrupt/policies.hpp)
99+
100+
target_sources(
101+
cib
102+
INTERFACE FILE_SET
103+
log
104+
TYPE
105+
HEADERS
106+
BASE_DIRS
107+
include
108+
FILES
109+
include/log/catalog/catalog.hpp
110+
include/log/catalog/mipi_encoder.hpp
111+
include/log/fmt/logger.hpp
112+
include/log/level.hpp
113+
include/log/log.hpp)
114+
115+
target_sources(
116+
cib
117+
INTERFACE FILE_SET
118+
lookup
119+
TYPE
120+
HEADERS
121+
BASE_DIRS
122+
include
123+
FILES
124+
include/lookup/detail/select.hpp
125+
include/lookup/entry.hpp
126+
include/lookup/input.hpp
127+
include/lookup/linear_search_lookup.hpp
128+
include/lookup/lookup.hpp
129+
include/lookup/pseudo_pext_lookup.hpp
130+
include/lookup/strategies.hpp
131+
include/lookup/strategy_failed.hpp)
132+
133+
target_sources(
134+
cib
135+
INTERFACE FILE_SET
136+
match
137+
TYPE
138+
HEADERS
139+
BASE_DIRS
140+
include
141+
FILES
142+
include/match/and.hpp
143+
include/match/bin_op.hpp
144+
include/match/concepts.hpp
145+
include/match/constant.hpp
146+
include/match/cost.hpp
147+
include/match/implies.hpp
148+
include/match/negate.hpp
149+
include/match/not.hpp
150+
include/match/ops.hpp
151+
include/match/or.hpp
152+
include/match/predicate.hpp
153+
include/match/simplify.hpp
154+
include/match/sum_of_products.hpp)
155+
156+
target_sources(
157+
cib
158+
INTERFACE FILE_SET
159+
msg
160+
TYPE
161+
HEADERS
162+
BASE_DIRS
163+
include
164+
FILES
165+
include/msg/callback.hpp
166+
include/msg/detail/indexed_builder_common.hpp
167+
include/msg/detail/indexed_handler_common.hpp
168+
include/msg/detail/separate_sum_terms.hpp
169+
include/msg/field.hpp
170+
include/msg/field_matchers.hpp
171+
include/msg/handler_builder.hpp
172+
include/msg/handler.hpp
173+
include/msg/handler_interface.hpp
174+
include/msg/indexed_builder.hpp
175+
include/msg/indexed_handler.hpp
176+
include/msg/indexed_service.hpp
177+
include/msg/message.hpp
178+
include/msg/send.hpp
179+
include/msg/service.hpp)
180+
181+
target_sources(
182+
cib
183+
INTERFACE FILE_SET
184+
sc
185+
TYPE
186+
HEADERS
187+
BASE_DIRS
188+
include
189+
FILES
190+
include/sc/format.hpp
191+
include/sc/fwd.hpp
192+
include/sc/lazy_string_format.hpp
193+
include/sc/string_constant.hpp)
194+
195+
target_sources(
196+
cib
197+
INTERFACE FILE_SET
198+
seq
199+
TYPE
200+
HEADERS
201+
BASE_DIRS
202+
include
203+
FILES
204+
include/seq/builder.hpp
205+
include/seq/impl.hpp
206+
include/seq/step.hpp)
207+
37208
target_compile_options(
38209
cib
39210
INTERFACE
@@ -50,32 +221,32 @@ if(PROJECT_IS_TOP_LEVEL)
50221
add_subdirectory(tools)
51222

52223
# Build single-header release.
53-
file(GLOB_RECURSE include_files
54-
"${CMAKE_CURRENT_SOURCE_DIR}/include/cib/*.hpp")
55-
add_custom_command(
56-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_release_header.py
57-
${include_files}
58-
COMMAND ${CMAKE_COMMAND} -E make_directory
59-
${CMAKE_CURRENT_BINARY_DIR}/include/cib
60-
COMMAND
61-
${Python3_EXECUTABLE}
62-
${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_release_header.py
63-
${CMAKE_CURRENT_SOURCE_DIR}/include/cib/cib.hpp >
64-
${CMAKE_CURRENT_BINARY_DIR}/include/cib/cib.hpp
65-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/cib/cib.hpp)
66-
67-
add_custom_target(release_header
68-
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/include/cib/cib.hpp)
69-
endif()
224+
include(cmake/single_header.cmake)
225+
gen_single_header(
226+
TARGET
227+
release_header
228+
GEN_HEADER
229+
${CMAKE_SOURCE_DIR}/tools/gen_release_header.py
230+
SOURCE_TARGET
231+
cib
232+
SOURCE_FILESET
233+
cib
234+
INPUT_HEADER
235+
${CMAKE_SOURCE_DIR}/include/cib/cib.hpp
236+
OUTPUT_HEADER
237+
${CMAKE_BINARY_DIR}/include/cib/cib.hpp)
70238

71-
if(DEFINED ENV{SINGLE_HEADER})
72-
add_dependencies(cib release_header)
239+
if(DEFINED ENV{SINGLE_HEADER})
240+
add_dependencies(cib release_header)
73241

74-
target_include_directories(
75-
cib INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/>
242+
target_include_directories(
243+
cib
244+
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/>
76245
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/>)
77-
else()
78-
target_include_directories(
79-
cib INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
246+
else()
247+
target_include_directories(
248+
cib
249+
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
80250
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/>)
251+
endif()
81252
endif()

cmake/single_header.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function(gen_single_header)
2+
set(oneValueArgs TARGET GEN_HEADER SOURCE_TARGET SOURCE_FILESET
3+
INPUT_HEADER OUTPUT_HEADER)
4+
cmake_parse_arguments(SH "" "${oneValueArgs}" "" ${ARGN})
5+
6+
get_target_property(HEADERS ${SH_SOURCE_TARGET}
7+
HEADER_SET_${SH_SOURCE_FILESET})
8+
get_filename_component(OUTPUT_DIR ${SH_OUTPUT_HEADER} DIRECTORY)
9+
add_custom_command(
10+
DEPENDS ${SH_GEN_HEADER} ${HEADERS}
11+
COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIR}
12+
COMMAND ${Python3_EXECUTABLE} ${SH_GEN_HEADER} ${SH_INPUT_HEADER} >
13+
${SH_OUTPUT_HEADER}
14+
OUTPUT ${SH_OUTPUT_HEADER})
15+
16+
add_custom_target(${SH_TARGET} DEPENDS ${SH_OUTPUT_HEADER})
17+
endfunction()

0 commit comments

Comments
 (0)