Skip to content

Commit

Permalink
improve cmake for ninja
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 21, 2025
1 parent 014838d commit a44e82a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
5 changes: 3 additions & 2 deletions tests/test_utils/test_build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ function test_build:build(argv)
os.exec("xmake f -c -D -y")
os.exec("xmake")
os.rm("build")
os.exec("xmake f -c -D -y --policies=compatibility.version:3.0")
os.exec("xmake -r")
print("xmake f -c -D -y --policies=compatibility.version:3.0")
os.exec("xmake f -c -D -y --policies=compatibility.version:3.0,package.precompiled:n")
os.exec("xmake -rvD")
end

function main()
Expand Down
18 changes: 9 additions & 9 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,6 @@ function _get_configs_for_mingw(package, configs, opt)
if is_subhost("windows") and opt.cmake_generator ~= "Ninja" then
envs.CMAKE_MAKE_PROGRAM = _get_mingw32_make(package)
end
if opt.cmake_generator == "Ninja" then
envs.CMAKE_MAKE_PROGRAM = "ninja"
end
_fix_cxx_compiler_cmake(package, envs)
_insert_configs_from_envs(configs, envs, opt)
end
Expand All @@ -618,12 +615,7 @@ function _get_configs_for_wasm(package, configs, opt)
assert(emscripten_cmakefile, "Emscripten.cmake not found!")
table.insert(configs, "-DCMAKE_TOOLCHAIN_FILE=" .. emscripten_cmakefile)
if is_subhost("windows") then
if opt.cmake_generator == "Ninja" then
local ninja = _get_ninja(package)
if ninja then
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja)
end
else
if opt.cmake_generator ~= "Ninja" then
local mingw_make = _get_mingw32_make(package)
if mingw_make then
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. mingw_make)
Expand Down Expand Up @@ -783,6 +775,10 @@ function _get_configs_for_generator(package, configs, opt)
table.insert(configs, "-DCMAKE_JOB_POOL_LINK:STRING=link")
table.insert(configs, ("-DCMAKE_JOB_POOLS:STRING=compile=%s;link=%s"):format(jobs, linkjobs))
end
local ninja = _get_ninja(package)
if ninja then
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. ninja)
end
end
elseif package:is_plat("mingw") and is_subhost("msys") then
table.insert(configs, "-G")
Expand Down Expand Up @@ -964,6 +960,7 @@ function _get_configs(package, configs, opt)
table.insert(configs, "-DCMAKE_CXX_COMPILER_LAUNCHER=" .. ccache)
end

print("configs", configs)
return configs
end

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

-- do configure
local cmake = assert(find_tool("cmake"), "cmake not found!")
print(argv)
print(package:name(), package:plat(), package:arch(), opt)
os.vrunv(cmake.program, argv, {envs = opt.envs or buildenvs(package, opt)})
os.cd(oldir)
end
Expand Down
4 changes: 4 additions & 0 deletions xmake/modules/private/action/require/impl/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,10 @@ function _must_depend_on(package, dep)
local librarydeps = hashset.from(manifest.librarydeps)
return librarydeps:has(dep:name())
end
print(package:name(), package:extraconf("deps", dep:name()))
if package:is_binary() and package:extraconf("deps", dep:name(), "public") then
return true
end
end

-- compatible with all previous link dependencies?
Expand Down
10 changes: 10 additions & 0 deletions xmake/rules/c++/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ rule("c.build")
add_deps("c.build.pcheader", "c.build.optimization", "c.build.sanitizer")
on_build_files("private.action.build.object", {batch = true, distcc = true})
on_config(function (target)
-- enable vs runtime as MD by default
if target:is_plat("windows") and not target:get("runtimes") then
local vs_runtime_default = target:policy("build.c++.msvc.runtime")
if vs_runtime_default and target:has_tool("cc", "cl", "clang_cl") then
if is_mode("debug") then
vs_runtime_default = vs_runtime_default .. "d"
end
target:set("runtimes", vs_runtime_default)
end
end
-- https://github.com/xmake-io/xmake/issues/4621
if target:is_plat("windows") and target:is_static() and target:has_tool("cc", "tcc") then
target:set("extension", ".a")
Expand Down

0 comments on commit a44e82a

Please sign in to comment.