summaryrefslogtreecommitdiffstats
path: root/Source/cmNinjaNormalTargetGenerator.cxx
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2015-01-14 18:11:44 (GMT)
committerBrad King <brad.king@kitware.com>2015-01-23 15:54:13 (GMT)
commit097e26f4908b3099f112c3fdc5e043234f9adc53 (patch)
treec429841a470c3eb03ca057655e9f720fec3285e7 /Source/cmNinjaNormalTargetGenerator.cxx
parent57622bd19d3fd013038d34f497b106a7e2bfd26d (diff)
downloadCMake-097e26f4908b3099f112c3fdc5e043234f9adc53.zip
CMake-097e26f4908b3099f112c3fdc5e043234f9adc53.tar.gz
CMake-097e26f4908b3099f112c3fdc5e043234f9adc53.tar.bz2
ninja: use the minimum of all command line length limits (#14892)
When choosing whether to use a response file, consider several possible command line length limits for the current operating system, and choose the smallest.
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx29
1 files changed, 22 insertions, 7 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index a05719d..5595557 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -22,6 +22,7 @@
#include <assert.h>
#include <algorithm>
+#include <limits>
#ifndef _WIN32
#include <unistd.h>
@@ -371,15 +372,29 @@ cmNinjaNormalTargetGenerator
static int calculateCommandLineLengthLimit(int linkRuleLength)
{
+ static int const limits[] = {
#ifdef _WIN32
- return 8000 - linkRuleLength;
-#elif defined(__linux) || defined(__APPLE__) || defined(__HAIKU__)
- // for instance ARG_MAX is 2096152 on Ubuntu or 262144 on Mac
- return ((int)sysconf(_SC_ARG_MAX)) - linkRuleLength - 1000;
-#else
- (void)linkRuleLength;
- return -1;
+ 8000,
#endif
+#if defined(__APPLE__) || defined(__HAIKU__) || defined(__linux)
+ // for instance ARG_MAX is 2096152 on Ubuntu or 262144 on Mac
+ ((int)sysconf(_SC_ARG_MAX)) - 1000,
+#endif
+#if defined(__linux)
+ // #define MAX_ARG_STRLEN (PAGE_SIZE * 32) in Linux's binfmts.h
+ ((int)sysconf(_SC_PAGESIZE) * 32) - 1000,
+#endif
+ std::numeric_limits<int>::max()
+ };
+
+ size_t const arrSz = cmArraySize(limits);
+ int const sz = *std::min_element(limits, limits + arrSz);
+ if (sz == std::numeric_limits<int>::max())
+ {
+ return -1;
+ }
+
+ return sz - linkRuleLength;
}