Skip to content

Commit a7ff815

Browse files
authored
[cmake] Check correctly for different flags. Don't check twice -Wall (#73144)
check_cxx_compiler_flag caches its results for the same variable, since all the flags were using the same variable, only the first check was done, and the rest of the flags were just using the result of the first flag. Make each of the check_cxx_compiler_flag use a different variable (by interpolating the flag name) and reorder the list of compiler flags to check. -Wall was added twice, and in the case of MSVC, the equivalent was added last. It doesn't really seem to affect a lot of things.
1 parent 1faeb50 commit a7ff815

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

stdlib/toolchain/CMakeLists.txt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ set(CXX_COMPILE_FLAGS)
88
set(CXX_LINK_FLAGS)
99

1010

11-
set(compile_flags
12-
# Build the runtime with -Wall to catch, e.g., uninitialized variables
13-
# warnings.
14-
"-Wall"
15-
16-
# C++ code in the runtime and standard library should generally avoid
17-
# introducing static constructors or destructors.
18-
"-Wglobal-constructors"
19-
"-Wexit-time-destructors")
20-
21-
2211
# Build the runtime with -Wall to catch, e.g., uninitialized variables
2312
# warnings.
2413
if(SWIFT_COMPILER_IS_MSVC_LIKE)
@@ -27,10 +16,15 @@ else()
2716
list(APPEND compile_flags "-Wall")
2817
endif()
2918

19+
list(APPEND compile_flags
20+
# C++ code in the runtime and standard library should generally avoid
21+
# introducing static constructors or destructors.
22+
"-Wglobal-constructors"
23+
"-Wexit-time-destructors")
3024

3125
foreach(flag ${compile_flags})
32-
check_cxx_compiler_flag("${flag}" is_supported)
33-
if(is_supported)
26+
check_cxx_compiler_flag("${flag}" cxx_compiler_flag_${flag}_is_supported)
27+
if(cxx_compiler_flag_${flag}_is_supported)
3428
list(APPEND CXX_COMPILE_FLAGS "${flag}")
3529
endif()
3630
endforeach()

0 commit comments

Comments
 (0)