Skip to content

Commit 2405f4c

Browse files
committed
improve cmake for ninja
1 parent 014838d commit 2405f4c

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

xmake/modules/package/tools/cmake.lua

+9-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")
@@ -964,6 +960,7 @@ function _get_configs(package, configs, opt)
964960
table.insert(configs, "-DCMAKE_CXX_COMPILER_LAUNCHER=" .. ccache)
965961
end
966962

963+
print("configs", configs)
967964
return configs
968965
end
969966

@@ -1312,13 +1309,16 @@ function configure(package, configs, opt)
13121309
table.insert(argv, "-D" .. name .. "=" .. value)
13131310
end
13141311
end
1312+
print("before shrink", argv)
13151313
-- shrink cmake arguments, fix too long arguments
13161314
-- @see https://github.com/xmake-io/xmake-repo/pull/5247#discussion_r1780302212
13171315
_shrink_cmake_arguments(argv, oldir, opt)
13181316
table.insert(argv, oldir)
13191317

13201318
-- do configure
13211319
local cmake = assert(find_tool("cmake"), "cmake not found!")
1320+
print(argv)
1321+
print(package:name(), package:plat(), package:arch(), opt)
13221322
os.vrunv(cmake.program, argv, {envs = opt.envs or buildenvs(package, opt)})
13231323
os.cd(oldir)
13241324
end

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

+4
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,10 @@ function _must_depend_on(package, dep)
14371437
local librarydeps = hashset.from(manifest.librarydeps)
14381438
return librarydeps:has(dep:name())
14391439
end
1440+
print(package:name(), package:extraconf("deps", dep:name()))
1441+
if package:is_binary() and package:extraconf("deps", dep:name(), "public") then
1442+
return true
1443+
end
14401444
end
14411445

14421446
-- 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)