summaryrefslogtreecommitdiffstats
path: root/Source/cmNinjaNormalTargetGenerator.cxx
diff options
context:
space:
mode:
authorChristian Pfeiffer <cpfeiffer@live.de>2017-04-18 21:06:39 (GMT)
committerBrad King <brad.king@kitware.com>2017-04-19 15:02:24 (GMT)
commitbbb5c3efe2a17d046506b7c27008c77ea244f0bc (patch)
treeefa83801c7982bd247727af35fa6e7f15a13aedc /Source/cmNinjaNormalTargetGenerator.cxx
parentddd2b02455db9b0ef3604af1b9b10c22af56bff9 (diff)
downloadCMake-bbb5c3efe2a17d046506b7c27008c77ea244f0bc.zip
CMake-bbb5c3efe2a17d046506b7c27008c77ea244f0bc.tar.gz
CMake-bbb5c3efe2a17d046506b7c27008c77ea244f0bc.tar.bz2
Ninja,Makefile: Unify command line limit logic
Move the logic to cmSystemTools to be shared among the generators. Revise the implementation and add comments justifying each possible source for a limit.
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx46
1 files changed, 6 insertions, 40 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index aaeb659..edab2ba 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -5,11 +5,9 @@
#include <algorithm>
#include <assert.h>
#include <iterator>
-#include <limits>
#include <map>
#include <set>
#include <sstream>
-#include <stddef.h>
#include "cmAlgorithms.h"
#include "cmCustomCommand.h"
@@ -35,10 +33,6 @@
#include "cm_auto_ptr.hxx"
#include "cmake.h"
-#ifndef _WIN32
-#include <unistd.h>
-#endif
-
cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator(
cmGeneratorTarget* target)
: cmNinjaTargetGenerator(target)
@@ -546,36 +540,6 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
return std::vector<std::string>();
}
-static int calculateCommandLineLengthLimit(int linkRuleLength)
-{
- static int const limits[] = {
-#ifdef _WIN32
- 8000,
-#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 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;
- }
-
- return sz - linkRuleLength;
-}
-
void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
{
cmGeneratorTarget& genTarget = *this->GetGeneratorTarget();
@@ -761,8 +725,9 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
// Device linking currently doesn't support response files so
// do not check if the user has explicitly forced a response file.
- int const commandLineLengthLimit = calculateCommandLineLengthLimit(
- globalGen.GetRuleCmdLength(this->LanguageLinkerDeviceRule()));
+ int const commandLineLengthLimit =
+ static_cast<int>(cmSystemTools::CalculateCommandLineLengthLimit()) -
+ globalGen.GetRuleCmdLength(this->LanguageLinkerDeviceRule());
const std::string rspfile =
std::string(cmake::GetCMakeFilesDirectoryPostSlash()) +
@@ -1048,8 +1013,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
!(this->TargetLinkLanguage == "RC" || this->TargetLinkLanguage == "CUDA");
int commandLineLengthLimit = -1;
if (!lang_supports_response || !this->ForceResponseFile()) {
- commandLineLengthLimit = calculateCommandLineLengthLimit(
- globalGen.GetRuleCmdLength(this->LanguageLinkerRule()));
+ commandLineLengthLimit =
+ static_cast<int>(cmSystemTools::CalculateCommandLineLengthLimit()) -
+ globalGen.GetRuleCmdLength(this->LanguageLinkerRule());
}
const std::string rspfile =