summaryrefslogtreecommitdiff
path: root/xmake/modules/package/tools/cmake.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-03-04 23:42:17 +0800
committerruki <[email protected]>2022-03-04 23:42:17 +0800
commit5b4fb54904dd927d0190a0a50affedbc81732640 (patch)
tree6b82d4bdf2b84fa68b15ccfeb7ae3e53d5bc3db3 /xmake/modules/package/tools/cmake.lua
parent06b58860c03f2b76f92c71bb065ff44fd8bbe6d5 (diff)
fix tools/cmake for linker
Diffstat (limited to 'xmake/modules/package/tools/cmake.lua')
-rw-r--r--xmake/modules/package/tools/cmake.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index 5aebc74ef..a97402f94 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -401,7 +401,15 @@ function _get_configs_for_cross(package, configs, opt)
envs.CMAKE_CXX_COMPILER = _translate_bin_path(package:build_getenv("cxx"))
envs.CMAKE_ASM_COMPILER = _translate_bin_path(package:build_getenv("as"))
envs.CMAKE_AR = _translate_bin_path(package:build_getenv("ar"))
+ -- @note The link command line is set in Modules/CMake{C,CXX,Fortran}Information.cmake and defaults to using the compiler, not CMAKE_LINKER,
+ -- so we need set CMAKE_CXX_LINK_EXECUTABLE to use CMAKE_LINKER as linker.
+ --
+ -- https://github.com/xmake-io/xmake-repo/pull/1039
+ -- https://stackoverflow.com/questions/1867745/cmake-use-a-custom-linker/25274328#25274328
envs.CMAKE_LINKER = _translate_bin_path(package:build_getenv("ld"))
+ if package:has_tool("ld", "gxx", "clangxx") then
+ envs.CMAKE_CXX_LINK_EXECUTABLE = "<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
+ end
envs.CMAKE_RANLIB = _translate_bin_path(package:build_getenv("ranlib"))
envs.CMAKE_C_FLAGS = _get_cflags(package, opt)
envs.CMAKE_CXX_FLAGS = _get_cxxflags(package, opt)