summaryrefslogtreecommitdiff
path: root/xmake/modules/package/tools/cmake.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-07-14 22:48:24 +0800
committerGitHub <[email protected]>2025-07-14 22:48:24 +0800
commitf2cbab00b89a75f56e847c200b03f26f271de68b (patch)
tree86515129c651ca657394c636ae91cc66e39ae9d5 /xmake/modules/package/tools/cmake.lua
parent11fef79ad901e7cfbd883421b4e68c433e0a6d7d (diff)
parenta00e43947f33574abf0c7be43067f17162efb75b (diff)
Merge pull request #6619 from Arthapz/fix-cmake-clang-windows
(cmake) fix default flags detection on windows platform
Diffstat (limited to 'xmake/modules/package/tools/cmake.lua')
-rw-r--r--xmake/modules/package/tools/cmake.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index c27ab99bb..67b4da572 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,23 @@ 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 cc = package:build_getenv("cc")
+ local cxx = package:build_getenv("cxx")
+ local cachekey = buildtype .. package:plat() .. package:arch() .. (cc or "") .. (cxx or "")
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")
+ local cflags
+ if cc then
+ cflags = "-DCMAKE_C_COMPILER=" .. _translate_bin_path(cc)
+ end
+ local cxxflags
+ if cxx then
+ cxxflags = "-DCMAKE_CXX_COMPILER=" .. _translate_bin_path(cxx)
+ end
+
-- About the minimum cmake version requirement
-- @see https://github.com/xmake-io/xmake/pull/6032
io.writefile(dummy_cmakelist, format([[
@@ -849,7 +860,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, cflags or {}, cxxflags)
local outdata = try{ function() return os.iorunv(cmake.program, _configs, {envs = runenvs}) end}
if outdata and outdata ~= "" then
cmake_default_flags = {}