Skip to content

Commit

Permalink
Merge pull request #5678 from xmake-io/cmake
Browse files Browse the repository at this point in the history
shrink cmake arguments
  • Loading branch information
waruqi authored Sep 30, 2024
2 parents 0f7e1ea + 38b735f commit 654f149
Showing 1 changed file with 23 additions and 0 deletions.
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

0 comments on commit 654f149

Please sign in to comment.