[Bf-blender-cvs] [18c5d4ccb39] master: CMake: use LINKER flags instead of CFLAGS for setting the linker

Campbell Barton noreply at git.blender.org
Sat Jan 15 06:22:29 CET 2022


Commit: 18c5d4ccb39d6301892b02d6ffc3cdac85462900
Author: Campbell Barton
Date:   Sat Jan 15 16:12:13 2022 +1100
Branches: master
https://developer.blender.org/rB18c5d4ccb39d6301892b02d6ffc3cdac85462900

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

===================================================================

M	build_files/cmake/platform/platform_unix.cmake

===================================================================

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()



More information about the Bf-blender-cvs mailing list