summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorPigeonF <fnoegip@gmail.com>2021-09-08 17:08:28 (GMT)
committerBrad King <brad.king@kitware.com>2021-09-10 13:53:31 (GMT)
commitccfe1b0b401863a8ac9ef07bb88ef970af587edc (patch)
tree677d05150c8e1605f2b4fe5d0df841260abc2579 /Source
parentcf5ed709915bde5cef4a649ca2255833cc7afcd3 (diff)
downloadCMake-ccfe1b0b401863a8ac9ef07bb88ef970af587edc.zip
CMake-ccfe1b0b401863a8ac9ef07bb88ef970af587edc.tar.gz
CMake-ccfe1b0b401863a8ac9ef07bb88ef970af587edc.tar.bz2
IWYU: Add `--driver-mode=cl` when applicable
We already do this for `clang-tidy`. Fixes: #16554
Diffstat (limited to 'Source')
-rw-r--r--Source/cmMakefileTargetGenerator.cxx20
-rw-r--r--Source/cmNinjaTargetGenerator.cxx22
2 files changed, 39 insertions, 3 deletions
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index c83a7ab..70b6d27 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -999,7 +999,25 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
}
if (cmNonempty(iwyu)) {
run_iwyu += " --iwyu=";
- run_iwyu += this->LocalGenerator->EscapeForShell(*iwyu);
+
+ // Only add --driver-mode if it is not already specified, as adding
+ // it unconditionally might override a user-specified driver-mode
+ if (iwyu.Get()->find("--driver-mode=") == std::string::npos) {
+ cmProp p = this->Makefile->GetDefinition(
+ cmStrCat("CMAKE_", lang, "_INCLUDE_WHAT_YOU_USE_DRIVER_MODE"));
+ std::string driverMode;
+
+ if (cmNonempty(p)) {
+ driverMode = *p;
+ } else {
+ driverMode = lang == "C" ? "gcc" : "g++";
+ }
+
+ run_iwyu += this->LocalGenerator->EscapeForShell(
+ cmStrCat(*iwyu, ";--driver-mode=", driverMode));
+ } else {
+ run_iwyu += this->LocalGenerator->EscapeForShell(*iwyu);
+ }
}
if (cmNonempty(tidy)) {
run_iwyu += " --tidy=";
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 1b6b834..f1ea229 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -874,8 +874,26 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
compilerLauncher.clear();
}
if (cmNonempty(iwyu)) {
- run_iwyu += cmStrCat(" --iwyu=",
- this->GetLocalGenerator()->EscapeForShell(*iwyu));
+ run_iwyu += " --iwyu=";
+
+ // Only add --driver-mode if it is not already specified, as adding
+ // it unconditionally might override a user-specified driver-mode
+ if (iwyu.Get()->find("--driver-mode=") == std::string::npos) {
+ cmProp p = this->Makefile->GetDefinition(
+ cmStrCat("CMAKE_", lang, "_INCLUDE_WHAT_YOU_USE_DRIVER_MODE"));
+ std::string driverMode;
+
+ if (cmNonempty(p)) {
+ driverMode = *p;
+ } else {
+ driverMode = lang == "C" ? "gcc" : "g++";
+ }
+
+ run_iwyu += this->LocalGenerator->EscapeForShell(
+ cmStrCat(*iwyu, ";--driver-mode=", driverMode));
+ } else {
+ run_iwyu += this->LocalGenerator->EscapeForShell(*iwyu);
+ }
}
if (cmNonempty(tidy)) {
run_iwyu += " --tidy=";