84
84
# up a VFS overlay for the SDK headers and case-correcting symlinks for the
85
85
# libraries when running on a case-sensitive filesystem.
86
86
87
+ include_guard (GLOBAL )
87
88
88
89
# When configuring CMake with a toolchain file against a top-level CMakeLists.txt,
89
90
# it will actually run CMake many times, once for each small test program used to
@@ -251,6 +252,8 @@ list(APPEND _CTF_NATIVE_DEFAULT "-DCMAKE_ASM_COMPILER=${LLVM_NATIVE_TOOLCHAIN}/b
251
252
list (APPEND _CTF_NATIVE_DEFAULT "-DCMAKE_C_COMPILER=${LLVM_NATIVE_TOOLCHAIN} /bin/clang" )
252
253
list (APPEND _CTF_NATIVE_DEFAULT "-DCMAKE_CXX_COMPILER=${LLVM_NATIVE_TOOLCHAIN} /bin/clang++" )
253
254
255
+ # These flags are used during build time. So if CFLAGS/CXXFLAGS/LDFLAGS is set
256
+ # for the target, makes sure these are unset during build time.
254
257
set (CROSS_TOOLCHAIN_FLAGS_NATIVE "${_CTF_NATIVE_DEFAULT} " CACHE STRING "" )
255
258
256
259
set (COMPILE_FLAGS
@@ -277,18 +280,8 @@ if(case_sensitive_filesystem)
277
280
endif ()
278
281
279
282
string (REPLACE ";" " " COMPILE_FLAGS "${COMPILE_FLAGS} " )
280
-
281
- # We need to preserve any flags that were passed in by the user. However, we
282
- # can't append to CMAKE_C_FLAGS and friends directly, because toolchain files
283
- # will be re-invoked on each reconfigure and therefore need to be idempotent.
284
- # The assignments to the _INITIAL cache variables don't use FORCE, so they'll
285
- # only be populated on the initial configure, and their values won't change
286
- # afterward.
287
- set (_CMAKE_C_FLAGS_INITIAL "${CMAKE_C_FLAGS} " CACHE STRING "" )
288
- set (CMAKE_C_FLAGS "${_CMAKE_C_FLAGS_INITIAL} ${COMPILE_FLAGS} " CACHE STRING "" FORCE )
289
-
290
- set (_CMAKE_CXX_FLAGS_INITIAL "${CMAKE_CXX_FLAGS} " CACHE STRING "" )
291
- set (CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS_INITIAL} ${COMPILE_FLAGS} " CACHE STRING "" FORCE )
283
+ string (APPEND CMAKE_C_FLAGS_INIT " ${COMPILE_FLAGS} " )
284
+ string (APPEND CMAKE_CXX_FLAGS_INIT " ${COMPILE_FLAGS} " )
292
285
293
286
set (LINK_FLAGS
294
287
# Prevent CMake from attempting to invoke mt.exe. It only recognizes the slashed form and not the dashed form.
@@ -312,16 +305,9 @@ if(case_sensitive_filesystem)
312
305
endif ()
313
306
314
307
string (REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS} " )
315
-
316
- # See explanation for compiler flags above for the _INITIAL variables.
317
- set (_CMAKE_EXE_LINKER_FLAGS_INITIAL "${CMAKE_EXE_LINKER_FLAGS} " CACHE STRING "" )
318
- set (CMAKE_EXE_LINKER_FLAGS "${_CMAKE_EXE_LINKER_FLAGS_INITIAL} ${LINK_FLAGS} " CACHE STRING "" FORCE )
319
-
320
- set (_CMAKE_MODULE_LINKER_FLAGS_INITIAL "${CMAKE_MODULE_LINKER_FLAGS} " CACHE STRING "" )
321
- set (CMAKE_MODULE_LINKER_FLAGS "${_CMAKE_MODULE_LINKER_FLAGS_INITIAL} ${LINK_FLAGS} " CACHE STRING "" FORCE )
322
-
323
- set (_CMAKE_SHARED_LINKER_FLAGS_INITIAL "${CMAKE_SHARED_LINKER_FLAGS} " CACHE STRING "" )
324
- set (CMAKE_SHARED_LINKER_FLAGS "${_CMAKE_SHARED_LINKER_FLAGS_INITIAL} ${LINK_FLAGS} " CACHE STRING "" FORCE )
308
+ string (APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${LINK_FLAGS} " )
309
+ string (APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " ${LINK_FLAGS} " )
310
+ string (APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " ${LINK_FLAGS} " )
325
311
326
312
# CMake populates these with a bunch of unnecessary libraries, which requires
327
313
# extra case-correcting symlinks and what not. Instead, let projects explicitly
0 commit comments