From 810f5b5088253a60e6638e3fc079a5253736a66e Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Wed, 24 Sep 2025 21:42:53 -0500 Subject: [PATCH] [cmake] Make SwiftCompilerSources support debug info in RelWithDebInfoMode and use -Os instead of -O with MinSizeRel. --- SwiftCompilerSources/CMakeLists.txt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/SwiftCompilerSources/CMakeLists.txt b/SwiftCompilerSources/CMakeLists.txt index 335c060fad1af..f559638880537 100644 --- a/SwiftCompilerSources/CMakeLists.txt +++ b/SwiftCompilerSources/CMakeLists.txt @@ -6,6 +6,8 @@ # See http://swift.org/LICENSE.txt for license information # See http://swift.org/CONTRIBUTORS.txt for Swift project authors +include(SwiftUtils) + # Following function are needed as a workaround until it's possible to compile # swift code with cmake's builtin swift support. @@ -121,10 +123,19 @@ function(add_swift_compiler_modules_library name) list(APPEND swift_compile_options "-Xfrontend" "-cxx-interop-use-opaque-pointer-for-moveonly") endif() - if(CMAKE_BUILD_TYPE STREQUAL "Debug") + is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE}" debug) + if (debug) list(APPEND swift_compile_options "-g") - else() - list(APPEND swift_compile_options "-O" "-cross-module-optimization") + endif() + + is_build_type_optimized("${CMAKE_BUILD_TYPE}" optimized) + if (optimized) + if("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel") + list(APPEND swift_compile_options "-Osize") + else() + list(APPEND swift_compile_options "-O") + endif() + list(APPEND swift_compile_options "-cross-module-optimization") endif() if(LLVM_ENABLE_ASSERTIONS)