summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-21 00:59:00 +0800
committerruki <[email protected]>2024-08-21 00:59:00 +0800
commit0f9a4976e600d9b13bc2484162e3b8c1aee07dfd (patch)
tree7739caac0f59cc6bdf386ded4bdf6daae99f2a65
parentde66ec45791dbc955905ce2ed2af34b3d426b0f7 (diff)
fix compiler for cmake
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua16
1 files changed, 6 insertions, 10 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index d5e305c41..48a637a78 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -26,6 +26,7 @@ import("core.tool.compiler")
import("core.base.semver")
import("core.base.hashset")
import("core.project.rule")
+import("core.platform.platform")
import("lib.detect.find_tool")
import("private.utils.batchcmds")
import("private.utils.rule_groups")
@@ -298,15 +299,14 @@ function _get_flags_from_target(target, flagkind)
end
-- set compiler
-function _set_target_compiler(cmakelists, target)
- -- use custom toolchain?
- if config.get("toolchain") or target:get("toolchains") then
- local cc = target:tool("cc")
+function _set_compiler(cmakelists)
+ if config.get("toolchain") then
+ local cc = platform.tool("cc")
if cc then
cc = path.unix(cc)
cmakelists:print("set(CMAKE_C_COMPILER \"%s\")", cc)
end
- local cxx, cxx_name = target:tool("cxx")
+ local cxx, cxx_name = platform.tool("cxx")
if cxx then
if cxx_name == "clang" or cxx_name == "gcc" then
local dir = path.directory(cxx)
@@ -344,11 +344,7 @@ function _add_project(cmakelists, outputdir)
-- set compilers, we need set it before project( LANGUAGES..)
-- @see https://github.com/xmake-io/xmake/issues/5448
- for _, target in table.orderpairs(project.targets()) do
- if target:is_binary() or target:is_static() or target:is_shared() then
- _set_target_compiler(cmakelists, target)
- end
- end
+ _set_compiler(cmakelists)
-- set project name
local project_name = project.name()