@@ -128,11 +128,6 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
128
128
SOURCE_DIR llvm_config_src_dir
129
129
)
130
130
131
- # Assertions should follow llvm-config's setting by default.
132
- set (LLVM_ENABLE_ASSERTIONS ${llvm_config_enable_assertions}
133
- CACHE BOOL "Enable assertions" )
134
- mark_as_advanced (LLVM_ENABLE_ASSERTIONS )
135
-
136
131
set (LLVM_TOOLS_BINARY_DIR "${llvm_config_tools_binary_dir} " CACHE PATH "Path to llvm/bin" )
137
132
138
133
set (${product} _NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR} " )
@@ -162,10 +157,32 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
162
157
163
158
# Save and restore variables that LLVM configuration overrides.
164
159
set (LLVM_TOOLS_BINARY_DIR_saved "${LLVM_TOOLS_BINARY_DIR} " )
165
- set (LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS} " )
160
+
161
+ # If we already have a cached value for LLVM_ENABLE_ASSERTIONS, save the value.
162
+ if (DEFINED LLVM_ENABLE_ASSERTIONS )
163
+ set (LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS} " )
164
+ endif ()
165
+ # Then we import LLVMCONFIG_FILE. This is going to override whatever cached
166
+ # value we have for LLVM_ENABLE_ASSERTIONS.
166
167
include (${LLVMCONFIG_FILE} )
167
168
set (LLVM_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR_saved} " )
168
- set (LLVM_ENABLE_ASSERTIONS "${LLVM_ENABLE_ASSERTIONS_saved} " )
169
+
170
+ # If we did not have a cached value for LLVM_ENABLE_ASSERTIONS, set
171
+ # LLVM_ENABLE_ASSERTIONS_saved to be the ENABLE_ASSERTIONS value from LLVM so
172
+ # we follow LLVMConfig.cmake's value by default if nothing is provided.
173
+ if (NOT DEFINED LLVM_ENABLE_ASSERTIONS_saved )
174
+ set (LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS} " )
175
+ endif ()
176
+
177
+ # Then set LLVM_ENABLE_ASSERTIONS with a default value of
178
+ # LLVM_ENABLE_ASSERTIONS_saved.
179
+ #
180
+ # The effect of this is that if LLVM_ENABLE_ASSERTION did not have a cached
181
+ # value, then LLVM_ENABLE_ASSERTIONS_saved is set to LLVM's value, so we get a
182
+ # default value from LLVM.
183
+ set (LLVM_ENABLE_ASSERTIONS "${LLVM_ENABLE_ASSERTIONS_saved} "
184
+ CACHE BOOL "Enable assertions" )
185
+ mark_as_advanced (LLVM_ENABLE_ASSERTIONS )
169
186
170
187
precondition_translate_flag (LLVM_BUILD_LIBRARY_DIR LLVM_LIBRARY_DIR )
171
188
precondition_translate_flag (LLVM_BUILD_MAIN_INCLUDE_DIR LLVM_MAIN_INCLUDE_DIR )
0 commit comments