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 20, 2025
1 parent 014838d commit 689ebab
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ end
-- get ninja
function _get_ninja(package)
local ninja = find_tool("ninja")
print("ninja", ninja)
os.exec("ninja --version")
if ninja then
return ninja.program
end
Expand Down Expand Up @@ -601,9 +603,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 +617,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 +777,11 @@ 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)
print("_get_configs_for_generator", cmake_generator, ninja)
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 +963,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 +1312,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

0 comments on commit 689ebab

Please sign in to comment.