summaryrefslogtreecommitdiffstats
path: root/Source/cmNinjaNormalTargetGenerator.cxx
diff options
context:
space:
mode:
authorChristian Pfeiffer <cpfeiffer@live.de>2017-03-27 17:04:50 (GMT)
committerBrad King <brad.king@kitware.com>2017-03-27 17:42:19 (GMT)
commit92fe00d33cb029a583de20a16e5bc17bd337ed57 (patch)
treead58c901f5a9ea687d43dae33c52b8068003f405 /Source/cmNinjaNormalTargetGenerator.cxx
parent1adbe223cd10ee133f5137da028ed86ddef7cc4d (diff)
downloadCMake-92fe00d33cb029a583de20a16e5bc17bd337ed57.zip
CMake-92fe00d33cb029a583de20a16e5bc17bd337ed57.tar.gz
CMake-92fe00d33cb029a583de20a16e5bc17bd337ed57.tar.bz2
Ninja: Fix command line limit when sysconf has no ARG_MAX
The `sysconf(3)` manual explains that the return value can be `-1` for limits if there is no definite limit. Recognize this case and skip using the value as a limit candidate. Otherwise we use response files unconditionally on such systems instead of checking other limits. Fixes: #16740
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx14
1 files changed, 9 insertions, 5 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 4fc664d..b1374c2 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -550,10 +550,6 @@ static int calculateCommandLineLengthLimit(int linkRuleLength)
#ifdef _WIN32
8000,
#endif
-#if defined(_SC_ARG_MAX)
- // 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,
@@ -562,7 +558,15 @@ static int calculateCommandLineLengthLimit(int linkRuleLength)
};
size_t const arrSz = cmArraySize(limits);
- int const sz = *std::min_element(limits, limits + arrSz);
+ int sz = *std::min_element(limits, limits + arrSz);
+#if defined(_SC_ARG_MAX)
+ // for instance ARG_MAX is 2096152 on Ubuntu or 262144 on Mac
+ int const szArgMax = static_cast<int>(sysconf(_SC_ARG_MAX));
+ // a return value of -1 signifies an unrestricted value
+ if (szArgMax != -1) {
+ sz = std::min(sz, szArgMax - 1000);
+ }
+#endif
if (sz == std::numeric_limits<int>::max()) {
return 0;
}