Skip to content

Commit 78371cb

Browse files
committed
improve cmake for ninja
1 parent 014838d commit 78371cb

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

xmake/modules/package/tools/cmake.lua

+5-9
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,6 @@ function _get_configs_for_mingw(package, configs, opt)
601601
if is_subhost("windows") and opt.cmake_generator ~= "Ninja" then
602602
envs.CMAKE_MAKE_PROGRAM = _get_mingw32_make(package)
603603
end
604-
if opt.cmake_generator == "Ninja" then
605-
envs.CMAKE_MAKE_PROGRAM = "ninja"
606-
end
607604
_fix_cxx_compiler_cmake(package, envs)
608605
_insert_configs_from_envs(configs, envs, opt)
609606
end
@@ -618,12 +615,7 @@ function _get_configs_for_wasm(package, configs, opt)
618615
assert(emscripten_cmakefile, "Emscripten.cmake not found!")
619616
table.insert(configs, "-DCMAKE_TOOLCHAIN_FILE=" .. emscripten_cmakefile)
620617
if is_subhost("windows") then
621-
if opt.cmake_generator == "Ninja" then
622-
local ninja = _get_ninja(package)
623-
if ninja then
624-
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja)
625-
end
626-
else
618+
if opt.cmake_generator ~= "Ninja" then
627619
local mingw_make = _get_mingw32_make(package)
628620
if mingw_make then
629621
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make)
@@ -783,6 +775,10 @@ function _get_configs_for_generator(package, configs, opt)
783775
table.insert(configs, "-DCMAKE_JOB_POOL_LINK:STRING=link")
784776
table.insert(configs, ("-DCMAKE_JOB_POOLS:STRING=compile=%s;link=%s"):format(jobs, linkjobs))
785777
end
778+
local ninja = _get_ninja(package)
779+
if ninja then
780+
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja)
781+
end
786782
end
787783
elseif package:is_plat("mingw") and is_subhost("msys") then
788784
table.insert(configs, "-G")

xmake/modules/private/action/require/impl/package.lua

+8
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,14 @@ function _must_depend_on(package, dep)
14371437
local librarydeps = hashset.from(manifest.librarydeps)
14381438
return librarydeps:has(dep:name())
14391439
end
1440+
-- If we mark it as public, even if binary package is already installed,
1441+
-- we need also to install it's public dep and export the it's envs.
1442+
--
1443+
-- @see https://github.com/xmake-io/xmake-repo/pull/6207
1444+
-- https://github.com/xmake-io/xmake/pull/6101
1445+
if package:is_binary() and package:extraconf("deps", dep:name(), "public") then
1446+
return true
1447+
end
14401448
end
14411449

14421450
-- compatible with all previous link dependencies?

xmake/rules/c++/xmake.lua

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ rule("c.build")
2323
add_deps("c.build.pcheader", "c.build.optimization", "c.build.sanitizer")
2424
on_build_files("private.action.build.object", {batch = true, distcc = true})
2525
on_config(function (target)
26+
-- enable vs runtime as MD by default
27+
if target:is_plat("windows") and not target:get("runtimes") then
28+
local vs_runtime_default = target:policy("build.c++.msvc.runtime")
29+
if vs_runtime_default and target:has_tool("cc", "cl", "clang_cl") then
30+
if is_mode("debug") then
31+
vs_runtime_default = vs_runtime_default .. "d"
32+
end
33+
target:set("runtimes", vs_runtime_default)
34+
end
35+
end
2636
-- https://github.com/xmake-io/xmake/issues/4621
2737
if target:is_plat("windows") and target:is_static() and target:has_tool("cc", "tcc") then
2838
target:set("extension", ".a")

0 commit comments

Comments
 (0)