@@ -27,6 +27,57 @@ macro(yggdrasil_rapidjson_options_create)
2727 option (YGGDRASIL_RAPIDJSON_ENABLE_INSTRUMENTATION_OPT "Build yggdrasil_rapidjson with -march or -mcpu options" ON )
2828endmacro ()
2929
30+ macro (yggdrasil_rapidjson_global_config LANGUAGE PREFIX )
31+ add_compile_options (
32+ ${${PREFIX} _PUBLIC_COMPILE_FLAGS}
33+ ${${PREFIX} _PUBLIC_${LANGUAGE}_FLAGS}
34+ )
35+ add_link_options (
36+ ${${PREFIX} _PUBLIC_LINK_FLAGS}
37+ ${${PREFIX} _PUBLIC_${LANGUAGE}_LINK_FLAGS}
38+ )
39+ include_directories (${${PREFIX} _INCLUDE_DIRS} )
40+ link_libraries (${${PREFIX} _PUBLIC_LIBRARIES} )
41+ endmacro ()
42+
43+ macro (yggdrasil_rapidjson_target_config TARGET TYPE PREFIX )
44+ target_link_libraries (
45+ ${TARGET} ${TYPE} ${${PREFIX} _PUBLIC_LIBRARIES}
46+ "$<$<LINK_LANGUAGE :C >:${${PREFIX} _PUBLIC_C_LIBS }>"
47+ "$<$<LINK_LANGUAGE :CXX >:${${PREFIX} _PUBLIC_CXX_LIBS }>"
48+ "$<$<LINK_LANGUAGE :Fortran >:${${PREFIX} _PUBLIC_Fortran_LIBS }>"
49+ )
50+ target_include_directories (
51+ ${TARGET} ${TYPE} ${${PREFIX} _INCLUDE_DIRS}
52+ )
53+ target_compile_options (
54+ ${TARGET} ${TYPE} ${${PREFIX} _PUBLIC_COMPILE_FLAGS}
55+ "$<$<COMPILE_LANGUAGE :C >:${${PREFIX} _PUBLIC_C_COMPILE_FLAGS }>"
56+ "$<$<COMPILE_LANGUAGE :CXX >:${${PREFIX} _PUBLIC_CXX_COMPILE_FLAGS }>"
57+ "$<$<COMPILE_LANGUAGE :Fortran >:${${PREFIX} _PUBLIC_Fortran_COMPILE_FLAGS }>"
58+ )
59+ target_link_options (
60+ ${TARGET} ${TYPE} ${${PREFIX} _PUBLIC_LINK_FLAGS}
61+ "$<$<LINK_LANGUAGE :C >:${${PREFIX} _PUBLIC_C_LINK_FLAGS }>"
62+ "$<$<LINK_LANGUAGE :CXX >:${${PREFIX} _PUBLIC_CXX_LINK_FLAGS }>"
63+ "$<$<LINK_LANGUAGE :Fortran >:${${PREFIX} _PUBLIC_Fortran_LINK_FLAGS }>"
64+ )
65+ if (NOT TYPE STREQUAL "INTERFACE" )
66+ target_link_libraries (
67+ ${TARGET} ${TYPE} ${${PREFIX} _PRIVATE_LIBRARIES}
68+ )
69+ # target_include_directories(
70+ # ${TARGET} ${TYPE} ${${PREFIX}_INCLUDE_DIRS_PRIVATE}
71+ # )
72+ # target_compile_options(
73+ # ${TARGET} ${TYPE} ${${PREFIX}_PRIVATE_COMPILE_FLAGS}
74+ # )
75+ # target_link_options(
76+ # ${TARGET} ${TYPE} ${${PREFIX}_PRIVATE_LINK_FLAGS}
77+ # )
78+ endif ()
79+ endmacro ()
80+
3081macro (yggdrasil_rapidjson_options_config OUTPUT_PREFIX )
3182 if (DISABLE_YGGDRASIL_RAPIDJSON)
3283 list (
@@ -51,9 +102,9 @@ macro(yggdrasil_rapidjson_options_config OUTPUT_PREFIX)
51102 )
52103 else ()
53104 if (NOT YGGDRASIL_RAPIDJSON_PYTHON_WRAPPER)
54- list (APPEND ${OUTPUT_PREFIX} _LIBRARIES Python3::Python)
105+ list (APPEND ${OUTPUT_PREFIX} _PUBLIC_LIBRARIES Python3::Python)
55106 endif ()
56- list (APPEND ${OUTPUT_PREFIX} _LIBRARIES Python3::NumPy)
107+ list (APPEND ${OUTPUT_PREFIX} _PUBLIC_LIBRARIES Python3::NumPy)
57108 list (
58109 APPEND ${OUTPUT_PREFIX} _PUBLIC_COMPILE_FLAGS
59110 -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
@@ -81,60 +132,57 @@ macro(yggdrasil_rapidjson_options_config OUTPUT_PREFIX)
81132 -DYGGDRASIL_RAPIDJSON_PYTHON_WRAPPER
82133 )
83134 endif ()
84- if (YGGDRASIL_RAPIDJSON_BUILD_UBSAN )
135+ if (YGGDRASIL_RAPIDJSON_BUILD_ASAN )
85136 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
86137 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.0" )
87138 message (FATAL_ERROR "GCC < 4.8 doesn't support the address sanitizer" )
88139 else ()
89140 list (APPEND ${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS -fsanitize=address)
90- list (APPEND ${OUTPUT_PREFIX} _ASAN_LINK_FLAGS -fsanitize=address)
91141 endif ()
92142 elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
93143 list (APPEND ${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS -fsanitize=address)
94- list (APPEND ${OUTPUT_PREFIX} _ASAN_LINK_FLAGS -fsanitize=address)
95144 else ()
96145 message (FATAL_ERROR "ASAN unsupported by compiler ${CMAKE_CXX_COMPILER_ID } " )
97146 endif ()
98147 endif ()
99- if (YGGDRASIL_RAPIDJSON_BUILD_ASAN )
148+ if (YGGDRASIL_RAPIDJSON_BUILD_UBSAN )
100149 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
101150 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9.0" )
102151 message (FATAL_ERROR "GCC < 4.9 doesn't support the undefined behavior sanitizer" )
103152 else ()
104153 list (APPEND ${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS -fsanitize=undefined)
105- list (APPEND ${OUTPUT_PREFIX} _ASAN_LINK_FLAGS -fsanitize=undefined)
106154 endif ()
107155 elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
108156 if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
109157 list (APPEND ${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS -fsanitize=undefined-trap -fsanitize-undefined-trap-on -error)
110- list (APPEND ${OUTPUT_PREFIX} _ASAN_LINK_FLAGS -fsanitize=undefined-trap -fsanitize-undefined-trap-on -error)
111158 else ()
112159 list (APPEND ${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS -fsanitize=undefined)
113- list (APPEND ${OUTPUT_PREFIX} _ASAN_LINK_FLAGS -fsanitize=undefined)
114160 endif ()
115161 else ()
116162 message (FATAL_ERROR "UBSAN unsupported by compiler ${CMAKE_CXX_COMPILER_ID } " )
117163 endif ()
118164 endif ()
119- if (${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS)
120- list (
121- APPEND ${OUTPUT_PREFIX} _PUBLIC_C_COMPILE_FLAGS
122- ${${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS}
123- )
124- list (
125- APPEND ${OUTPUT_PREFIX} _PUBLIC_CXX_COMPILE_FLAGS
126- ${${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS}
165+ if (YGGDRASIL_RAPIDJSON_BUILD_ASAN OR YGGDRASIL_RAPIDJSON_BUILD_UBSAN
166+ AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
167+ execute_process (
168+ COMMAND ${CMAKE_CXX_COMPILER } -print-file-name=libclang_rt.asan_osx_dynamic.dylib
169+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR }
170+ OUTPUT_VARIABLE ${OUTPUT_PREFIX} _ASAN_LIB
171+ RESULT_VARIABLE ${OUTPUT_PREFIX} _ASAN_RESULT
127172 )
173+ if (${OUTPUT_PREFIX} _ASAN_RESULT)
174+ set (${OUTPUT_PREFIX} _ASAN_LIB)
175+ endif ()
128176 endif ()
129- if (${OUTPUT_PREFIX} _ASAN_LINK_FLAGS )
130- list (
131- APPEND ${OUTPUT_PREFIX} _PUBLIC_C_LINK_FLAGS
132- ${${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS}
133- )
134- list (
135- APPEND ${ OUTPUT_PREFIX}_PUBLIC_CXX_LINK_FLAGS
136- ${${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS}
137- )
177+ if (${OUTPUT_PREFIX} _ASAN_COMPILE_FLAGS )
178+ # Compilation flags are same as link flags for ASAN & UBSAN
179+ foreach (suffix PUBLIC_C_COMPILE_FLAGS PUBLIC_CXX_COMPILE_FLAGS
180+ PUBLIC_C_LINK_FLAGS PUBLIC_CXX_LINK_FLAGS)
181+ list (
182+ APPEND ${OUTPUT_PREFIX} _ ${suffix}
183+ ${${ OUTPUT_PREFIX}_ASAN_COMPILE_FLAGS}
184+ )
185+ endforeach ( )
138186 endif ()
139187
140188 if (YGGDRASIL_RAPIDJSON_ENABLE_INSTRUMENTATION_OPT
0 commit comments