Skip to content

Commit fbde611

Browse files
committed
build: fix crossplatform builds
1 parent 4ae3b07 commit fbde611

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

cmake/modules/Utilities.cmake

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ function(generate_build_configurations)
7373
${${platform_type}_FLAGS})
7474

7575
# Convert lists to strings for CMake variables
76+
# Append to preserve any flags set by toolchain files or CMake initialization
7677
listToString(final_compiler_flags "${DEFAULT_COMPILER_FLAGS}" "${compiler_flags}")
77-
set(CMAKE_CXX_FLAGS_${triplet_upper} "${final_compiler_flags}" CACHE STRING "" FORCE)
78-
set(CMAKE_C_FLAGS_${triplet_upper} "${final_compiler_flags}" CACHE STRING "" FORCE)
78+
set(CMAKE_CXX_FLAGS_${triplet_upper} "${CMAKE_CXX_FLAGS_${triplet_upper}} ${final_compiler_flags}" CACHE STRING "" FORCE)
79+
set(CMAKE_C_FLAGS_${triplet_upper} "${CMAKE_C_FLAGS_${triplet_upper}} ${final_compiler_flags}" CACHE STRING "" FORCE)
7980

8081
list(APPEND TARGET_COMPILE_OPTIONS_LOCAL "$<$<NOT:$<COMPILE_LANGUAGE:ASM_MASM>>:$<$<STREQUAL:$<CONFIG>,${triplet}>:${compiler_flags}>>")
8182

@@ -92,13 +93,15 @@ function(generate_build_configurations)
9293
# and add to TARGET_LINK_OPTIONS for per-config generator expressions
9394
# For single-config generators (Ninja), only set the base CMAKE flags for the active config
9495
if(is_multi_config)
95-
set(CMAKE_EXE_LINKER_FLAGS_${triplet_upper} "${exe_linker_flags}" CACHE STRING "" FORCE)
96-
set(CMAKE_SHARED_LINKER_FLAGS_${triplet_upper} "${shared_linker_flags}" CACHE STRING "" FORCE)
96+
# Append to existing flags to preserve CMake's defaults (including standard libraries)
97+
set(CMAKE_EXE_LINKER_FLAGS_${triplet_upper} "${CMAKE_EXE_LINKER_FLAGS_${triplet_upper}} ${exe_linker_flags}" CACHE STRING "" FORCE)
98+
set(CMAKE_SHARED_LINKER_FLAGS_${triplet_upper} "${CMAKE_SHARED_LINKER_FLAGS_${triplet_upper}} ${shared_linker_flags}" CACHE STRING "" FORCE)
9799
list(APPEND TARGET_LINK_OPTIONS_LOCAL "$<$<STREQUAL:$<CONFIG>,${triplet}>:${linker_flags}>")
98100
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "${triplet}")
99-
# For single-config, set base flags directly (don't use TARGET_LINK_OPTIONS to avoid duplication)
100-
set(CMAKE_EXE_LINKER_FLAGS "${exe_linker_flags}" CACHE STRING "" FORCE)
101-
set(CMAKE_SHARED_LINKER_FLAGS "${shared_linker_flags}" CACHE STRING "" FORCE)
101+
# For single-config, append to base flags (don't use TARGET_LINK_OPTIONS to avoid duplication)
102+
# Preserve CMake's defaults including standard libraries
103+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${exe_linker_flags}" CACHE STRING "" FORCE)
104+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${shared_linker_flags}" CACHE STRING "" FORCE)
102105
message(STATUS "Single-config: Applied ${triplet} linker flags to base CMAKE linker flags")
103106
endif()
104107

0 commit comments

Comments
 (0)