Skip to content

Commit 3de1f75

Browse files
committed
Use uppercase CMAKE_BUILD_TYPE when asking for CMAKE_CXX_FLAGS, explicitly use -O0 for Debug builds
1 parent 6aebda5 commit 3de1f75

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,10 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQU
630630
endif()
631631

632632
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
633+
# CMake's default for CMAKE_CXX_FLAGS_DBEUG is "-g". Let's add "-O0", because we want to be able
634+
# to append CMAKE_CXX_FLAGS_DEBUG to a list of compile flags that already contains a -O flag.
635+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
636+
633637
# CMake's default for CMAKE_CXX_FLAGS_RELEASE is "-O3 -DNDEBUG". Let's avoid "-O3" for consistency
634638
# between Release and RelWithDebInfo. Dropping -DNDEBUG from this setting is blocked by triggering
635639
# a test failure of Swift-Unit :: Syntax/./SwiftSyntaxTests/TypeSyntaxTests.MetatypeTypeWithAPIs

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ function(_add_host_variant_c_compile_flags target)
133133
is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE}" debuginfo)
134134

135135
# Add -O0/-O2/-O3/-Os/-g/-momit-leaf-frame-pointer/... based on CMAKE_BUILD_TYPE.
136-
target_compile_options(${target} PRIVATE "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}")
136+
string(TOUPPER ${CMAKE_BUILD_TYPE} build_type_upper)
137+
string(REPLACE " " ";" cxx_flags_list "${CMAKE_CXX_FLAGS_${build_type_upper}}")
138+
target_compile_options(${target} PRIVATE ${cxx_flags_list})
137139

138140
if(optimized)
139141
# Omit leaf frame pointers on x86 production builds (optimized, no debug

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ function(_add_target_variant_c_compile_flags)
167167
is_build_type_with_debuginfo("${CFLAGS_BUILD_TYPE}" debuginfo)
168168

169169
# Add -O0/-O2/-O3/-Os/-g/... based on CFLAGS_BUILD_TYPE.
170-
list(APPEND result "${CMAKE_CXX_FLAGS_${CFLAGS_BUILD_TYPE}}")
170+
string(TOUPPER ${CFLAGS_BUILD_TYPE} build_type_upper)
171+
string(REPLACE " " ";" cxx_flags_list "${CMAKE_CXX_FLAGS_${build_type_upper}}")
172+
list(APPEND result ${cxx_flags_list})
171173

172174
if(optimized)
173175
# Omit leaf frame pointers on x86 production builds (optimized, no debug

0 commit comments

Comments
 (0)