diff options
| author | ruki <[email protected]> | 2024-09-30 22:44:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-09-30 22:44:13 +0800 |
| commit | 2ec672aef4e271c6d08e889576809cd6443934b3 (patch) | |
| tree | f5a6d7244e611f29e3f1ddcc12de645ee7a2acf5 | |
| parent | 0f7e1ea9a5f790364d44d3f759347620113ad7db (diff) | |
shrink cmake arguments
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index d4eeabe56..493b30d80 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -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") @@ -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 |
