summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2023-04-10 21:34:30 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-04-10 21:34:47 (GMT)
commit453cf8a1968081731b667edd01ff942adf1f7bcc (patch)
tree498c41966a110aad3189ce364ec1f92c26bf2bfc /Source
parent83525bfd7a247b6daca4445fd4c003c2315f45ce (diff)
parent6b58cdd4cf59d6d5c66c66daf81112f911e84238 (diff)
downloadCMake-453cf8a1968081731b667edd01ff942adf1f7bcc.zip
CMake-453cf8a1968081731b667edd01ff942adf1f7bcc.tar.gz
CMake-453cf8a1968081731b667edd01ff942adf1f7bcc.tar.bz2
Merge topic 'ninja-nvhpc-fortran-Werror'
6b58cdd4cf Ninja: Exclude NVHPC -Werror flags during Fortran preprocessing Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8393
Diffstat (limited to 'Source')
-rw-r--r--Source/cmNinjaTargetGenerator.cxx25
1 files changed, 23 insertions, 2 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index e163edb..5dbc283 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -21,6 +21,8 @@
#include <cm3p/json/value.h>
#include <cm3p/json/writer.h>
+#include "cmsys/RegularExpression.hxx"
+
#include "cmComputeLinkInformation.h"
#include "cmCustomCommandGenerator.h"
#include "cmDyndepCollation.h"
@@ -1259,6 +1261,7 @@ namespace {
cmNinjaBuild GetScanBuildStatement(const std::string& ruleName,
const std::string& ppFileName,
bool compilePP, bool compilePPWithDefines,
+ cmValue ppExcludeFlagsRegex,
cmNinjaBuild& objBuild, cmNinjaVars& vars,
const std::string& objectFileName,
cmLocalGenerator* lg)
@@ -1287,6 +1290,20 @@ cmNinjaBuild GetScanBuildStatement(const std::string& ruleName,
// Scanning and compilation generally use the same flags.
scanBuild.Variables["FLAGS"] = vars["FLAGS"];
+ // Exclude flags not valid during preprocessing.
+ if (compilePP && !ppExcludeFlagsRegex.IsEmpty()) {
+ std::string in = std::move(scanBuild.Variables["FLAGS"]);
+ std::string out;
+ cmsys::RegularExpression regex(*ppExcludeFlagsRegex);
+ std::string::size_type pos = 0;
+ while (regex.find(in.c_str() + pos)) {
+ out = cmStrCat(out, in.substr(pos, regex.start()), ' ');
+ pos += regex.end();
+ }
+ out = cmStrCat(out, in.substr(pos));
+ scanBuild.Variables["FLAGS"] = std::move(out);
+ }
+
if (compilePP && !compilePPWithDefines) {
// Move preprocessor definitions to the scan/preprocessor build statement.
std::swap(scanBuild.Variables["DEFINES"], vars["DEFINES"]);
@@ -1511,18 +1528,22 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
std::string scanRuleName;
std::string ppFileName;
+ cmValue ppExcludeFlagsRegex;
if (compilePP) {
scanRuleName = this->LanguagePreprocessAndScanRule(language, config);
ppFileName = this->ConvertToNinjaPath(
this->GetPreprocessedFilePath(source, config));
+ ppExcludeFlagsRegex = this->Makefile->GetDefinition(cmStrCat(
+ "CMAKE_", language, "_PREPROCESS_SOURCE_EXCLUDE_FLAGS_REGEX"));
} else {
scanRuleName = this->LanguageScanRule(language, config);
ppFileName = cmStrCat(objectFileName, ".ddi.i");
}
cmNinjaBuild ppBuild = GetScanBuildStatement(
- scanRuleName, ppFileName, compilePP, compilePPWithDefines, objBuild,
- vars, objectFileName, this->LocalGenerator);
+ scanRuleName, ppFileName, compilePP, compilePPWithDefines,
+ ppExcludeFlagsRegex, objBuild, vars, objectFileName,
+ this->LocalGenerator);
if (compilePP) {
// In case compilation requires flags that are incompatible with