Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shrink cmake arguments #5678

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
-- imports
import("core.base.option")
import("core.base.semver")
import("core.base.hashset")
import("core.tool.toolchain")
import("core.project.config")
import("core.project.project")
Expand Down Expand Up @@ -1197,6 +1198,28 @@ function configure(package, configs, opt)
table.insert(argv, "-D" .. name .. "=" .. value)
end
end
-- shrink cmake arguments, fix too long arguments
-- @see https://github.com/xmake-io/xmake-repo/pull/5247#discussion_r1780302212
local cmake_argv = {}
local long_options = hashset.of(
"CMAKE_C_FLAGS",
"CMAKE_CXX_FLAGS",
"CMAKE_ASM_FLAGS",
"CMAKE_EXE_LINKER_FLAGS",
"CMAKE_SHARED_LINKER_FLAGS")
local shrink = false
table.remove_if(argv, function (idx, value)
local k, v = value:match("%-D(.*)=(.*)")
if k and v and long_options:has(k) and #v > 128 then
table.insert(cmake_argv, ("set(%s \"%s\")"):format(k, tostring(v)))
shrink = true
return true
end
end)
if shrink then
local cmakefile = path.join(opt.curdir and opt.curdir or oldir, "CMakeLists.txt")
io.insert(cmakefile, 1, table.concat(cmake_argv, "\n"))
end
table.insert(argv, oldir)

-- do configure
Expand Down
Loading