8484# up a VFS overlay for the SDK headers and case-correcting symlinks for the
8585# libraries when running on a case-sensitive filesystem.
8686
87+ include_guard (GLOBAL )
8788
8889# When configuring CMake with a toolchain file against a top-level CMakeLists.txt,
8990# 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
251252list (APPEND _CTF_NATIVE_DEFAULT "-DCMAKE_C_COMPILER=${LLVM_NATIVE_TOOLCHAIN} /bin/clang" )
252253list (APPEND _CTF_NATIVE_DEFAULT "-DCMAKE_CXX_COMPILER=${LLVM_NATIVE_TOOLCHAIN} /bin/clang++" )
253254
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.
254257set (CROSS_TOOLCHAIN_FLAGS_NATIVE "${_CTF_NATIVE_DEFAULT} " CACHE STRING "" )
255258
256259set (COMPILE_FLAGS
@@ -277,18 +280,8 @@ if(case_sensitive_filesystem)
277280endif ()
278281
279282string (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} " )
292285
293286set (LINK_FLAGS
294287 # 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)
312305endif ()
313306
314307string (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} " )
325311
326312# CMake populates these with a bunch of unnecessary libraries, which requires
327313# extra case-correcting symlinks and what not. Instead, let projects explicitly
0 commit comments