From 18c5d4ccb39d6301892b02d6ffc3cdac85462900 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 15 Jan 2022 16:12:13 +1100 Subject: CMake: use LINKER flags instead of CFLAGS for setting the linker Set the linker using CMAKE_*_LINKER_FLAGS instead of {C/CXX}FLAGS. There is no advantage in using the CFLAGS to set the linker, it has the downside of triggering a full rebuild when changing the linker. Tested building Blender and the bpy.so Python module. Ref D13833 Reviewed by: sergey, brecht --- build_files/cmake/platform/platform_unix.cmake | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'build_files') diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake index 4ba3f81fe93..c7637dbee7e 100644 --- a/build_files/cmake/platform/platform_unix.cmake +++ b/build_files/cmake/platform/platform_unix.cmake @@ -671,8 +671,9 @@ if(CMAKE_COMPILER_IS_GNUCC) COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) if("${LD_VERSION}" MATCHES "GNU gold") - string(APPEND CMAKE_C_FLAGS " -fuse-ld=gold") - string(APPEND CMAKE_CXX_FLAGS " -fuse-ld=gold") + string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=gold") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=gold") + string(APPEND CMAKE_MODULE_LINKER_FLAGS " -fuse-ld=gold") else() message(STATUS "GNU gold linker isn't available, using the default system linker.") endif() @@ -684,8 +685,9 @@ if(CMAKE_COMPILER_IS_GNUCC) COMMAND ${CMAKE_C_COMPILER} -fuse-ld=lld -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) if("${LD_VERSION}" MATCHES "LLD") - string(APPEND CMAKE_C_FLAGS " -fuse-ld=lld") - string(APPEND CMAKE_CXX_FLAGS " -fuse-ld=lld") + string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=lld") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=lld") + string(APPEND CMAKE_MODULE_LINKER_FLAGS " -fuse-ld=lld") else() message(STATUS "LLD linker isn't available, using the default system linker.") endif() @@ -738,8 +740,9 @@ if(CMAKE_COMPILER_IS_GNUCC) if(WITH_LINKER_MOLD) # GCC will search for `ld` in this directory first. - string(APPEND CMAKE_CXX_FLAGS " -B \"${MOLD_BIN_DIR}\"") - string(APPEND CMAKE_C_FLAGS " -B \"${MOLD_BIN_DIR}\"") + string(APPEND CMAKE_EXE_LINKER_FLAGS " -B \"${MOLD_BIN_DIR}\"") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " -B \"${MOLD_BIN_DIR}\"") + string(APPEND CMAKE_MODULE_LINKER_FLAGS " -B \"${MOLD_BIN_DIR}\"") endif() unset(MOLD_BIN) unset(MOLD_BIN_DIR) @@ -758,8 +761,12 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") else() if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0) string(APPEND CMAKE_EXE_LINKER_FLAGS " --ld-path=\"${MOLD_BIN}\"") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " --ld-path=\"${MOLD_BIN}\"") + string(APPEND CMAKE_MODULE_LINKER_FLAGS " --ld-path=\"${MOLD_BIN}\"") else() string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=\"${MOLD_BIN}\"") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=\"${MOLD_BIN}\"") + string(APPEND CMAKE_MODULE_LINKER_FLAGS " -fuse-ld=\"${MOLD_BIN}\"") endif() endif() endif() -- cgit v1.2.3