Skip to content

Commit bcc8f0e

Browse files
committed
Add macro for setting interface properties during import & update config file to use it
Add macro for clearing config variables Change some macros to functions where possible to hide utility variables & use/unset more specific variables in macros
1 parent 06eb109 commit bcc8f0e

3 files changed

Lines changed: 93 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Because YggdrasilRapidJSON continues to merge updates from RapidJSON, the RapidJ
55

66
## X.X.X.X - XXXX-XX-XX
77

8-
## 1.1.0.4 - 2026-06-XX
8+
## 1.1.0.4 - 2026-06-25
99

1010
### Bug fixes
1111
* Fix bug where version could not be set in the conda recipe build since it is created from a tar instead of the git repo
@@ -18,6 +18,7 @@ Because YggdrasilRapidJSON continues to merge updates from RapidJSON, the RapidJ
1818
* Check for ASAN library and store it in <PREFIX>_ASAN_LIB when using clang ASAN/UBSAN so it can be used via DYLD_INSERT_LIBRARIES for Python tests
1919
* Added cmake macros yggdrasil_rapidjson_target_config and yggdrasil_rapidjson_global_config for adding option based flags to a target or the current scope (and subscopes)
2020
* Remove conda build version of conda recipe build and associated test jobs (only rattler build will be used from now on as that is the version available on conda-forge)
21+
* Improve macros to avoid polluting the namespace with utility variables during import
2122

2223
## 1.1.0.3 - 2026-05-29
2324

YggdrasilRapidJSONConfig.cmake.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ endif()
3535

3636
yggdrasil_rapidjson_config_init(@PROJECT_NAME@_INTERFACE)
3737
yggdrasil_rapidjson_options_config(@PROJECT_NAME@_INTERFACE)
38-
yggdrasil_rapidjson_target_config(
39-
@PROJECT_NAME@ INTERFACE @PROJECT_NAME@_INTERFACE
38+
yggdrasil_rapidjson_target_config_import(
39+
@PROJECT_NAME@ @PROJECT_NAME@_INTERFACE
4040
)
41+
yggdrasil_rapidjson_config_cleanup(@PROJECT_NAME@_INTERFACE)
4142

4243
set_and_check(
4344
@PROJECT_NAME@_INCLUDE_DIRS "${@PROJECT_NAME@_INCLUDE_DIR}"

YggdrasilRapidJSONMacros.cmake

Lines changed: 88 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ macro(yggdrasil_rapidjson_options_create)
2727
option(YGGDRASIL_RAPIDJSON_ENABLE_INSTRUMENTATION_OPT "Build yggdrasil_rapidjson with -march or -mcpu options" ON)
2828
endmacro()
2929

30-
macro(yggdrasil_rapidjson_config_vars PREFIX)
31-
list(
32-
APPEND ${PREFIX}_CONFIG_VARS
33-
${PREFIX}_ASAN_COMPILE_FLAGS
34-
)
30+
function(yggdrasil_rapidjson_config_vars PREFIX)
31+
if(${PREFIX}_CONFIG_VARS)
32+
return()
33+
endif()
34+
set(${PREFIX}_CONFIG_VARS ${PREFIX}_ASAN_COMPILE_FLAGS)
35+
# list(
36+
# APPEND ${PREFIX}_CONFIG_VARS
37+
# ${PREFIX}_ASAN_COMPILE_FLAGS
38+
# )
3539
foreach(tool GNU Clang AppleClang MSVC)
3640
list(
3741
APPEND ${PREFIX}_CONFIG_VARS
@@ -64,7 +68,15 @@ macro(yggdrasil_rapidjson_config_vars PREFIX)
6468
)
6569
endforeach()
6670
endforeach()
67-
endmacro()
71+
foreach(suffix LIBRARIES INCLUDE_DIRS COMPILE_FLAGS LINK_FLAGS)
72+
list(
73+
APPEND ${PREFIX}_CONFIG_VARS
74+
${PREFIX}_ALL_PUBLIC_${suffix}
75+
${PREFIX}_ALL_PRIVATE_${suffix}
76+
)
77+
endforeach()
78+
set(${PREFIX}_CONFIG_VARS ${${PREFIX}_CONFIG_VARS} PARENT_SCOPE)
79+
endfunction()
6880

6981
macro(yggdrasil_rapidjson_config_init PREFIX)
7082
yggdrasil_rapidjson_config_vars(${PREFIX})
@@ -73,13 +85,22 @@ macro(yggdrasil_rapidjson_config_init PREFIX)
7385
endforeach()
7486
endmacro()
7587

88+
macro(yggdrasil_rapidjson_config_cleanup PREFIX)
89+
if(${PREFIX}_CONFIG_VARS)
90+
foreach(var IN LISTS ${PREFIX}_CONFIG_VARS)
91+
unset(${var})
92+
endforeach()
93+
unset(${PREFIX}_CONFIG_VARS)
94+
endif()
95+
endmacro()
96+
7697
macro(yggdrasil_rapidjson_config_show PREFIX LEVEL)
7798
foreach(var IN LISTS ${PREFIX}_CONFIG_VARS)
7899
message(${LEVEL} "${var} = ${${var}}")
79100
endforeach()
80101
endmacro()
81102

82-
macro(yggdrasil_rapidjson_config_accum PREFIX)
103+
function(yggdrasil_rapidjson_config_accum PREFIX)
83104
foreach(suffix LIBRARIES INCLUDE_DIRS COMPILE_FLAGS LINK_FLAGS)
84105
set(${PREFIX}_ALL_PUBLIC_${suffix} ${${PREFIX}_PUBLIC_${suffix}}
85106
${${PREFIX}_${suffix}})
@@ -128,8 +149,10 @@ macro(yggdrasil_rapidjson_config_accum PREFIX)
128149
endforeach()
129150
message(DEBUG "${PREFIX}_ALL_PUBLIC_${suffix} = ${${PREFIX}_ALL_PUBLIC_${suffix}}")
130151
message(DEBUG "${PREFIX}_ALL_PRIVATE_${suffix} = ${${PREFIX}_ALL_PRIVATE_${suffix}}")
152+
set(${PREFIX}_ALL_PUBLIC_${suffix} "${${PREFIX}_ALL_PUBLIC_${suffix}}" PARENT_SCOPE)
153+
set(${PREFIX}_ALL_PRIVATE_${suffix} "${${PREFIX}_ALL_PRIVATE_${suffix}}" PARENT_SCOPE)
131154
endforeach()
132-
endmacro()
155+
endfunction()
133156

134157
macro(yggdrasil_rapidjson_global_compiler_flags LANGUAGE)
135158
# TODO: Some of these should be interface flags
@@ -180,25 +203,25 @@ endmacro()
180203

181204
macro(yggdrasil_rapidjson_global_config LANGUAGE PREFIX)
182205
yggdrasil_rapidjson_config_show(${PREFIX} DEBUG)
183-
set(global_compiler ${CMAKE_${LANGUAGE}_COMPILER_ID})
184-
set(global_linker ${global_compiler})
206+
set(_yggdrasil_rapidjson_global_compiler ${CMAKE_${LANGUAGE}_COMPILER_ID})
207+
set(_yggdrasil_rapidjson_global_linker ${_yggdrasil_rapidjson_global_compiler})
185208
list(
186209
APPEND EXTRA_${LANGUAGE}_FLAGS
187210
${${PREFIX}_PUBLIC_COMPILE_FLAGS}
188211
${${PREFIX}_PUBLIC_${LANGUAGE}_COMPILE_FLAGS}
189-
${${PREFIX}_PUBLIC_${global_compiler}_COMPILE_FLAGS}
212+
${${PREFIX}_PUBLIC_${_yggdrasil_rapidjson_global_compiler}_COMPILE_FLAGS}
190213
)
191214
add_compile_options(
192215
${${PREFIX}_COMPILE_FLAGS}
193216
${${PREFIX}_PUBLIC_COMPILE_FLAGS}
194217
${${PREFIX}_PUBLIC_${LANGUAGE}_COMPILE_FLAGS}
195-
${${PREFIX}_PUBLIC_${global_compiler}_COMPILE_FLAGS}
218+
${${PREFIX}_PUBLIC_${_yggdrasil_rapidjson_global_compiler}_COMPILE_FLAGS}
196219
)
197220
add_link_options(
198221
${${PREFIX}_LINK_FLAGS}
199222
${${PREFIX}_PUBLIC_LINK_FLAGS}
200223
${${PREFIX}_PUBLIC_${LANGUAGE}_LINK_FLAGS}
201-
${${PREFIX}_PUBLIC_${global_linker}_LINK_FLAGS}
224+
${${PREFIX}_PUBLIC_${_yggdrasil_rapidjson_global_linker}_LINK_FLAGS}
202225
)
203226
include_directories(
204227
${${PREFIX}_INCLUDE_DIRS}
@@ -210,6 +233,45 @@ macro(yggdrasil_rapidjson_global_config LANGUAGE PREFIX)
210233
${${PREFIX}_PUBLIC_LIBRARIES}
211234
${${PREFIX}_PUBLIC_${LANGUAGE}_LIBRARIES}
212235
)
236+
unset(_yggdrasil_rapidjson_global_compiler)
237+
unset(_yggdrasil_rapidjson_global_linker)
238+
endmacro()
239+
240+
function(yggdrasil_rapidjson_update_target_interface_property TARGET PREFIX SUFFIX NAME)
241+
if(NOT ${PREFIX}_ALL_PUBLIC_${SUFFIX})
242+
return()
243+
endif()
244+
get_target_property(EXISTING ${TARGET} ${NAME})
245+
if(EXISTING)
246+
set(EXISTING "${EXISTING};${${PREFIX}_ALL_PUBLIC_${SUFFIX}}")
247+
else()
248+
set(EXISTING "${${PREFIX}_ALL_PUBLIC_${SUFFIX}}")
249+
endif()
250+
set_target_properties(
251+
${TARGET} PROPERTIES
252+
${NAME} "${EXISTING}"
253+
)
254+
endfunction()
255+
256+
macro(yggdrasil_rapidjson_target_config_import TARGET PREFIX)
257+
yggdrasil_rapidjson_config_show(${PREFIX} DEBUG)
258+
yggdrasil_rapidjson_config_accum(${PREFIX})
259+
yggdrasil_rapidjson_update_target_interface_property(
260+
${TARGET} ${PREFIX}
261+
LIBRARIES INTERFACE_LINK_LIBRARIES
262+
)
263+
yggdrasil_rapidjson_update_target_interface_property(
264+
${TARGET} ${PREFIX}
265+
INCLUDE_DIRS INTERFACE_INCLUDE_DIRECTORIES
266+
)
267+
yggdrasil_rapidjson_update_target_interface_property(
268+
${TARGET} ${PREFIX}
269+
COMPILE_FLAGS INTERFACE_COMPILE_OPTIONS
270+
)
271+
yggdrasil_rapidjson_update_target_interface_property(
272+
${TARGET} ${PREFIX}
273+
LINK_FLAGS INTERFACE_LINK_OPTIONS
274+
)
213275
endmacro()
214276

215277
macro(yggdrasil_rapidjson_target_config TARGET TYPE PREFIX)
@@ -314,17 +376,17 @@ macro(yggdrasil_rapidjson_options_config OUTPUT_PREFIX)
314376
)
315377
endif()
316378
if(YGGDRASIL_RAPIDJSON_BUILD_ASAN)
317-
foreach(tool GNU Clang AppleClang)
379+
foreach(_yggdrasil_rapidjson_asan_tool GNU Clang AppleClang)
318380
list(
319-
APPEND ${OUTPUT_PREFIX}_${tool}_ASAN_COMPILE_FLAGS
381+
APPEND ${OUTPUT_PREFIX}_${_yggdrasil_rapidjson_asan_tool}_ASAN_COMPILE_FLAGS
320382
-fsanitize=address
321383
)
322384
endforeach()
323385
endif()
324386
if(YGGDRASIL_RAPIDJSON_BUILD_UBSAN)
325-
foreach(tool GNU Clang)
387+
foreach(_yggdrasil_rapidjson_asan_tool GNU Clang)
326388
list(
327-
APPEND ${OUTPUT_PREFIX}_${tool}_ASAN_COMPILE_FLAGS
389+
APPEND ${OUTPUT_PREFIX}_${_yggdrasil_rapidjson_asan_tool}_ASAN_COMPILE_FLAGS
328390
-fsanitize=undefined
329391
)
330392
endforeach()
@@ -347,14 +409,16 @@ macro(yggdrasil_rapidjson_options_config OUTPUT_PREFIX)
347409
${OUTPUT_PREFIX}_ASAN_COMPILE_FLAGS
348410
${${OUTPUT_PREFIX}_${CMAKE_CXX_COMPILER_ID}_ASAN_COMPILE_FLAGS}
349411
)
350-
foreach(tool GNU Clang AppleClang MSVC)
351-
set(k ${OUTPUT_PREFIX}_${tool}_ASAN_COMPILE_FLAGS)
412+
foreach(_yggdrasil_rapidjson_asan_tool GNU Clang AppleClang MSVC)
413+
set(k ${OUTPUT_PREFIX}_${_yggdrasil_rapidjson_asan_tool}_ASAN_COMPILE_FLAGS)
352414
if(${k})
353-
foreach(suffix COMPILE_FLAGS LINK_FLAGS)
354-
list(APPEND ${OUTPUT_PREFIX}_PUBLIC_${tool}_${suffix} ${${k}})
415+
foreach(_yggdrasil_rapidjson_asan_suffix COMPILE_FLAGS LINK_FLAGS)
416+
list(APPEND ${OUTPUT_PREFIX}_PUBLIC_${_yggdrasil_rapidjson_asan_tool}_${_yggdrasil_rapidjson_asan_suffix} ${${k}})
355417
endforeach()
356418
endif()
357419
endforeach()
420+
unset(_yggdrasil_rapidjson_asan_tool)
421+
unset(_yggdrasil_rapidjson_asan_suffix)
358422

359423
if(YGGDRASIL_RAPIDJSON_ENABLE_INSTRUMENTATION_OPT
360424
AND (NOT CMAKE_CROSSCOMPILING)
@@ -375,7 +439,7 @@ macro(yggdrasil_rapidjson_options_config OUTPUT_PREFIX)
375439

376440
endmacro()
377441

378-
macro(yggdrasil_rapidjson_gitversion OUTPUT_VARIABLE DEFAULT)
442+
function(yggdrasil_rapidjson_gitversion OUTPUT_VARIABLE DEFAULT)
379443
find_package(Git)
380444
if(NOT Git_FOUND)
381445
message(STATUS "Could not find Git cmake package, falling back to version ${DEFAULT}")
@@ -407,7 +471,8 @@ macro(yggdrasil_rapidjson_gitversion OUTPUT_VARIABLE DEFAULT)
407471
set(${OUTPUT_VARIABLE} ${GIT_DESCRIBE_VERSION})
408472
endif()
409473
endif()
410-
endmacro()
474+
set(${OUTPUT_VARIABLE} "${${OUTPUT_VARIABLE}}" PARENT_SCOPE)
475+
endfunction()
411476

412477
function(yggdrasil_rapidjson_version_header MACRO_PREFIX VERSION_STRING SRC DST)
413478
set(rem ${VERSION_STRING})

0 commit comments

Comments
 (0)