summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2025-07-11 22:13:14 +0200
committerArthur LAURENT <[email protected]>2025-07-11 22:13:14 +0200
commit5005dd98f65f808d0f5414af5c708843dbb2a047 (patch)
treef968524f1c8b4cf1912aeb308b7529dab8ed2d3b
parent11daac22809387276f81acf64887b8472bfff4ba (diff)
(cmake) fix default flags detection on windows platform
-rw-r--r--xmake/modules/package/tools/cmake.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index 74c1b80f8..1a1c14b7a 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -458,7 +458,7 @@ function _get_configs_for_windows(package, configs, opt)
end
end
- -- use clang-cl
+ -- use clang-cl or clang
if package:has_tool("cc", "clang", "clang_cl") then
envs.CMAKE_C_COMPILER = _translate_bin_path(package:build_getenv("cc"))
end
@@ -819,12 +819,16 @@ end
function _get_default_flags(package, configs, buildtype, opt)
-- The default flags are different for different platforms
-- @see https://github.com/xmake-io/xmake-repo/pull/4038#issuecomment-2116489448
- local cachekey = buildtype .. package:plat() .. package:arch()
+ local cachekey = buildtype .. package:plat() .. package:arch() .. package:build_getenv("cc") .. package:build_getenv("cxx")
local cmake_default_flags = _g.cmake_default_flags and _g.cmake_default_flags[cachekey]
if not cmake_default_flags then
local tmpdir = path.join(os.tmpfile() .. ".dir", package:displayname(), package:mode())
local dummy_cmakelist = path.join(tmpdir, "CMakeLists.txt")
+ -- set compiler
+ local cc_flag = "-DCMAKE_C_COMPILER=" .. _translate_bin_path(package:build_getenv("cc"))
+ local cxx_flag = "-DCMAKE_CXX_COMPILER=" .. _translate_bin_path(package:build_getenv("cxx"))
+
-- About the minimum cmake version requirement
-- @see https://github.com/xmake-io/xmake/pull/6032
io.writefile(dummy_cmakelist, format([[
@@ -849,7 +853,7 @@ function _get_default_flags(package, configs, buildtype, opt)
local runenvs = opt.envs or buildenvs(package)
local cmake = find_tool("cmake")
- local _configs = table.join(configs, "-S " .. path.directory(dummy_cmakelist), "-B " .. tmpdir)
+ local _configs = table.join(configs, "-S " .. path.directory(dummy_cmakelist), "-B " .. tmpdir, cc_flag, cxx_flag)
local outdata = try{ function() return os.iorunv(cmake.program, _configs, {envs = runenvs}) end}
if outdata and outdata ~= "" then
cmake_default_flags = {}