From 2ec672aef4e271c6d08e889576809cd6443934b3 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 30 Sep 2024 22:44:13 +0800 Subject: [PATCH 1/2] shrink cmake arguments --- xmake/modules/package/tools/cmake.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index d4eeabe56b..493b30d80c 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 From 38b735fdaab5b1f1717820462aa294af7587bd4f Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 30 Sep 2024 22:44:40 +0800 Subject: [PATCH 2/2] fix match pattern --- xmake/modules/package/tools/cmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 493b30d80c..56be714428 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -1209,7 +1209,7 @@ function configure(package, configs, opt) "CMAKE_SHARED_LINKER_FLAGS") local shrink = false table.remove_if(argv, function (idx, value) - local k, v = value:match("-D(.*)=(.*)") + 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