Skip to content

Commit 87fc9ca

Browse files
committed
[cmake] Get the default value for LLVM_ENABLE_ASSERTIONS from LLVMConfig.cmake.
rdar://26154980
1 parent ea3914d commit 87fc9ca

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
128128
SOURCE_DIR llvm_config_src_dir
129129
)
130130

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-
136131
set(LLVM_TOOLS_BINARY_DIR "${llvm_config_tools_binary_dir}" CACHE PATH "Path to llvm/bin")
137132

138133
set(${product}_NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR}")
@@ -162,10 +157,32 @@ macro(swift_common_standalone_build_config product is_cross_compiling)
162157

163158
# Save and restore variables that LLVM configuration overrides.
164159
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.
166167
include(${LLVMCONFIG_FILE})
167168
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)
169186

170187
precondition_translate_flag(LLVM_BUILD_LIBRARY_DIR LLVM_LIBRARY_DIR)
171188
precondition_translate_flag(LLVM_BUILD_MAIN_INCLUDE_DIR LLVM_MAIN_INCLUDE_DIR)

0 commit comments

Comments
 (0)