@@ -66,8 +66,8 @@ function(initialize_wasi_toolchain)
6666 WASI_SYSROOT_OUTPUT CMAKE_SYSROOT
6767 WASI_SDK_BIN_OUTPUT WASI_SDK_BIN
6868 )
69- set ( CMAKE_CXX_FLAGS "${ CMAKE_CXX_FLAGS } -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -lunwind" PARENT_SCOPE )
70- set ( CMAKE_EXE_LINKER_FLAGS "${ CMAKE_EXE_LINKER_FLAGS } -lunwind" PARENT_SCOPE )
69+ string ( APPEND CMAKE_CXX_FLAGS " -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false -lunwind" )
70+ string ( APPEND CMAKE_EXE_LINKER_FLAGS " -lunwind" )
7171 else ()
7272 include (${CMAKE_CURRENT_FUNCTION_LIST_DIR } /wasi-sdk.bootstrap.cmake )
7373 wasi_sdk_bootstrap (
@@ -119,36 +119,44 @@ function(initialize_wasi_toolchain)
119119 # Include libc-stubs static library for linking
120120 set (LIBC_STUBS_LIB_PATH "${CMAKE_CURRENT_FUNCTION_LIST_DIR } /libc-stubs/install/lib/libc-stubs.a" CACHE FILEPATH "Path to libc stubs" )
121121 set (LIBCXX_STUBS_LIB_PATH "${CMAKE_CURRENT_FUNCTION_LIST_DIR } /libc-stubs/install/lib/libcxx-stubs.a" CACHE FILEPATH "Path to libcxx stubs" )
122- set ( CMAKE_EXE_LINKER_FLAGS "${ CMAKE_EXE_LINKER_FLAGS } ${LIBCXX_STUBS_LIB_PATH} ${LIBC_STUBS_LIB_PATH} " PARENT_SCOPE )
122+ string ( APPEND CMAKE_EXE_LINKER_FLAGS " ${LIBCXX_STUBS_LIB_PATH} ${LIBC_STUBS_LIB_PATH} " )
123123 endif ()
124124
125125 if (arg_ENABLE_EXPERIMENTAL_SETJMP)
126126 # Enable SJLJ support
127- set ( CMAKE_C_FLAGS "${ CMAKE_C_FLAGS } -mllvm -wasm-enable-sjlj -lsetjmp -lunwind -mllvm -wasm-use-legacy-eh=false" PARENT_SCOPE )
128- set ( CMAKE_CXX_FLAGS "${ CMAKE_CXX_FLAGS } -mllvm -wasm-enable-sjlj -lsetjmp -lunwind -mllvm -wasm-use-legacy-eh=false" PARENT_SCOPE )
129- set ( CMAKE_EXE_LINKER_FLAGS "${ CMAKE_EXE_LINKER_FLAGS } -lsetjmp -lunwind -Wl,-mllvm,-wasm-enable-sjlj,-mllvm,-wasm-use-legacy-eh=false" PARENT_SCOPE )
127+ string ( APPEND CMAKE_C_FLAGS " -mllvm -wasm-enable-sjlj -lsetjmp -lunwind -mllvm -wasm-use-legacy-eh=false" )
128+ string ( APPEND CMAKE_CXX_FLAGS " -mllvm -wasm-enable-sjlj -lsetjmp -lunwind -mllvm -wasm-use-legacy-eh=false" )
129+ string ( APPEND CMAKE_EXE_LINKER_FLAGS " -lsetjmp -lunwind -Wl,-mllvm,-wasm-enable-sjlj,-mllvm,-wasm-use-legacy-eh=false" )
130130 endif ()
131131
132132 # Add a DEBUG_ENABLED definition for debug builds
133133 add_compile_definitions ($<$<CONFIG :Debug >:DEBUG_ENABLED =1>)
134134
135135 # Build type specific compiler and linker optimization flags
136- set (common_release_opt_compiler_flags "-O3 -flto -ffast-math -msimd128 -mbulk-memory -mmultivalue -msign-ext -mnontrapping-fptoint -finline-functions -funroll-loops -fvectorize -fslp-vectorize -fomit-frame-pointer -fstrict-aliasing -fdata-sections -ffunction-sections -fmerge-all-constants" )
137- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS } $<$<CONFIG :Release >:${common_release_opt_compiler_flags} >" PARENT_SCOPE )
138- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } $<$<CONFIG :Release >:${common_release_opt_compiler_flags} >" PARENT_SCOPE )
136+ if (CMAKE_BUILD_TYPE STREQUAL "Release" )
137+ # Compiler options for release builds
138+ set (common_release_opt_compiler_flags "-O3 -flto -ffast-math -msimd128 -mbulk-memory -mmultivalue -msign-ext -mnontrapping-fptoint -finline-functions -funroll-loops -fvectorize -fslp-vectorize -fomit-frame-pointer -fstrict-aliasing -fdata-sections -ffunction-sections -fmerge-all-constants" )
139+ string (APPEND CMAKE_C_FLAGS " ${common_release_opt_compiler_flags} " )
140+ string (APPEND CMAKE_CXX_FLAGS " ${common_release_opt_compiler_flags} " )
139141
140- # Linker options for release builds
141- set (common_release_opt_linker_flags "-O3 -flto -Wl,-O3,--lto-O3,--lto-CGO3 -Wl,-s,--strip-all,--strip-debug -Wl,--gc-sections -Wl,--initial-memory=67108864 -Wl,-z,stack-size=2097152" )
142- set ( CMAKE_EXE_LINKER_FLAGS "${ CMAKE_EXE_LINKER_FLAGS } $<$< CONFIG : Release >: $ {common_release_opt_linker_flags}>" PARENT_SCOPE )
142+ # Linker options for release builds
143+ set (common_release_opt_linker_flags "-O3 -flto -Wl,-O3,--lto-O3,--lto-CGO3 -Wl,-s,--strip-all,--strip-debug -Wl,--gc-sections -Wl,--initial-memory=67108864 -Wl,-z,stack-size=2097152" )
144+ string ( APPEND CMAKE_EXE_LINKER_FLAGS " $ {common_release_opt_linker_flags}" )
143145
144- # Enable IPO/LTO for release builds
145- set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE PARENT_SCOPE )
146+ # Enable IPO/LTO for release builds
147+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE PARENT_SCOPE )
148+ endif ()
146149
147150 # Emulated libc functions that require additional support from the toolchain
148151 set (common_emulated_compiler_flags "-D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_MMAN -D_WASI_EMULATED_GETPID" )
149- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -stdlib=libc++ ${common_emulated_compiler_flags} " PARENT_SCOPE )
150- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS } ${common_emulated_compiler_flags} " PARENT_SCOPE )
151- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS } -lwasi-emulated-signal -lwasi-emulated-mman -lwasi-emulated-process-clocks -lwasi-emulated-getpid" PARENT_SCOPE )
152+ string (APPEND CMAKE_CXX_FLAGS " -stdlib=libc++ ${common_emulated_compiler_flags} " )
153+ string (APPEND CMAKE_C_FLAGS " ${common_emulated_compiler_flags} " )
154+ string (APPEND CMAKE_EXE_LINKER_FLAGS " -lwasi-emulated-signal -lwasi-emulated-mman -lwasi-emulated-process-clocks -lwasi-emulated-getpid" )
155+
156+ # Export accumulated flags to parent scope
157+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS } " PARENT_SCOPE )
158+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } " PARENT_SCOPE )
159+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS } " PARENT_SCOPE )
152160
153161 # Interface library to enable reactor model WebAssembly files
154162 add_library (wasi_sdk_reactor_module INTERFACE )
0 commit comments