Skip to content

Commit 646305e

Browse files
committed
fix cmake build when ZSTD_BUILD_TESTS is disabled
1 parent 75abb8b commit 646305e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

build/cmake/CMakeModules/AddZstdCompilationFlags.cmake

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,35 @@ function(EnableCompilerFlag _flag _C _CXX _LD)
1515
string(REGEX REPLACE "[^A-Za-z0-9]+" "_" varname "${varname}")
1616
string(REGEX REPLACE "^_+" "" varname "${varname}")
1717
string(TOUPPER "${varname}" varname)
18+
19+
# _C is expected to be a direct boolean-like value (e.g., "ON", "OFF", true, false)
20+
# passed from ADD_ZSTD_COMPILATION_FLAGS, indicating if the C flag should be checked.
1821
if (_C)
1922
CHECK_C_COMPILER_FLAG(${_flag} C_FLAG_${varname})
2023
if (C_FLAG_${varname})
2124
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag}" PARENT_SCOPE)
2225
endif ()
2326
endif ()
24-
if (_CXX)
27+
28+
# _CXX is unique: it can be a direct boolean-like value (e.g., false) or
29+
# the *name* of a variable (e.g., "ZSTD_ENABLE_CXX") that holds the boolean-like value.
30+
# Therefore, it must be dereferenced with ${} to get its actual value.
31+
if (${_CXX}) # Dereference _CXX to get the value of the variable whose name is passed
2532
CHECK_CXX_COMPILER_FLAG(${_flag} CXX_FLAG_${varname})
2633
if (CXX_FLAG_${varname})
2734
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}" PARENT_SCOPE)
2835
endif ()
36+
# If CHECK_CXX_COMPILER_FLAG was run, CXX_FLAG_${varname} is now defined (as TRUE or FALSE).
37+
else()
38+
# If the condition ${_CXX} is false (e.g., ZSTD_ENABLE_CXX is OFF),
39+
# CHECK_CXX_COMPILER_FLAG is skipped.
40+
# We must ensure CXX_FLAG_${varname} is defined as FALSE for subsequent logic
41+
# that might read it (e.g., for ZSTD_HAS_NOEXECSTACK).
42+
set(CXX_FLAG_${varname} FALSE PARENT_SCOPE)
2943
endif ()
44+
45+
# _LD is expected to be a direct boolean-like value (e.g., "ON", "OFF", true, false)
46+
# passed from ADD_ZSTD_COMPILATION_FLAGS, indicating if the Linker flag should be checked.
3047
if (_LD)
3148
# We never add a linker flag with CMake < 3.18. We will
3249
# implement CHECK_LINKER_FLAG() like feature for CMake < 3.18

0 commit comments

Comments
 (0)