From b6c49713b35cf1ab9c0bff30cb7a6e20a8f3b481 Mon Sep 17 00:00:00 2001 From: Viktor Mukha Date: Wed, 16 May 2018 10:04:04 +0200 Subject: Makefile: Fix command line limits for static libs I have been hitting the Windows command-line limit when cross-compiling static library (POCO) and having more than 8000 characters in the call to "ar". Calculating exact limits here are tricky, since this particular limit will only take into account object file strings, which is correct for response files, but not for the archive rules (link.txt files), since they also contain the call to "ar" and its arguments. Also, there can be other additional arguments if "ar" tool is wrapped into something else, so it is a good idea to leave more space than trying to exactly fit the limit. Since response files use half of the limit as a heuristic, we reproduce it here for consistency. --- Source/cmMakefileLibraryTargetGenerator.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 27fae04..c538992 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -5,6 +5,7 @@ #include #include // IWYU pragma: keep #include +#include #include #include "cmGeneratedFileStream.h" @@ -732,10 +733,14 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( // Archiving rules never use a response file. useResponseFileForObjects = false; - // Limit the length of individual object lists to less than the - // 32K command line length limit on Windows. We could make this a - // platform file variable but this should work everywhere. - archiveCommandLimit = 30000; + // Limit the length of individual object lists to less than half of + // the command line length limit (leaving half for other flags). + // This may result in several calls to the archiver. + if (size_t limit = cmSystemTools::CalculateCommandLineLengthLimit()) { + archiveCommandLimit = limit / 2; + } else { + archiveCommandLimit = 8000; + } } // Expand the rule variables. -- cgit v0.12