From eac8700c7853d88f0682492ccefc70b4246ccf4a Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: cmLocalGenerator: Improve local variable names --- Source/cmLocalGenerator.cxx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 25e4d01..361b005 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -852,10 +852,10 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, // COMPILE_FLAGS are not escaped for historical reasons. this->AppendFlags(flags, targetFlags); } - std::vector opts; - target->GetCompileOptions(opts, config, lang); + std::vector targetCompileOpts; + target->GetCompileOptions(targetCompileOpts, config, lang); // COMPILE_OPTIONS are escaped. - this->AppendCompileOptions(flags, opts); + this->AppendCompileOptions(flags, targetCompileOpts); } for (auto const& it : target->GetMaxLanguageStandards()) { @@ -1132,10 +1132,10 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags, this->AppendFlags(flags, target->GetSafeProperty(name)); } - std::vector options; - target->GetStaticLibraryLinkOptions(options, config, linkLanguage); + std::vector staticLibOpts; + target->GetStaticLibraryLinkOptions(staticLibOpts, config, linkLanguage); // STATIC_LIBRARY_OPTIONS are escaped. - this->AppendCompileOptions(flags, options); + this->AppendCompileOptions(flags, staticLibOpts); } void cmLocalGenerator::GetTargetFlags( @@ -1205,10 +1205,10 @@ void cmLocalGenerator::GetTargetFlags( } } - std::vector opts; - target->GetLinkOptions(opts, config, linkLanguage); + std::vector linkOpts; + target->GetLinkOptions(linkOpts, config, linkLanguage); // LINK_OPTIONS are escaped. - this->AppendCompileOptions(linkFlags, opts); + this->AppendCompileOptions(linkFlags, linkOpts); if (pcli) { this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, frameworkPath, linkPath); @@ -1282,10 +1282,10 @@ void cmLocalGenerator::GetTargetFlags( } } - std::vector opts; - target->GetLinkOptions(opts, config, linkLanguage); + std::vector linkOpts; + target->GetLinkOptions(linkOpts, config, linkLanguage); // LINK_OPTIONS are escaped. - this->AppendCompileOptions(linkFlags, opts); + this->AppendCompileOptions(linkFlags, linkOpts); } break; default: break; -- cgit v0.12 From ca7b90dcf2fc6ef5345de162ec2532454376fe2f Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: cmLocalGenerator: Use local variables to collect flags --- Source/cmLocalGenerator.cxx | 100 ++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 361b005..69866c4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1118,20 +1118,26 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags, std::string const& linkLanguage, cmGeneratorTarget* target) { + std::string staticLibFlags; if (linkLanguage != "Swift") { this->AppendFlags( - flags, this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS")); + staticLibFlags, + this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS")); if (!config.empty()) { std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config; - this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name)); + this->AppendFlags(staticLibFlags, + this->Makefile->GetSafeDefinition(name)); } } - this->AppendFlags(flags, target->GetSafeProperty("STATIC_LIBRARY_FLAGS")); + this->AppendFlags(staticLibFlags, + target->GetSafeProperty("STATIC_LIBRARY_FLAGS")); if (!config.empty()) { std::string name = "STATIC_LIBRARY_FLAGS_" + config; - this->AppendFlags(flags, target->GetSafeProperty(name)); + this->AppendFlags(staticLibFlags, target->GetSafeProperty(name)); } + flags = std::move(staticLibFlags); + std::vector staticLibOpts; target->GetStaticLibraryLinkOptions(staticLibOpts, config, linkLanguage); // STATIC_LIBRARY_OPTIONS are escaped. @@ -1165,13 +1171,14 @@ void cmLocalGenerator::GetTargetFlags( libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS"; CM_FALLTHROUGH; case cmStateEnums::SHARED_LIBRARY: { + std::string sharedLibFlags; if (linkLanguage != "Swift") { - linkFlags = cmStrCat( + sharedLibFlags = cmStrCat( this->Makefile->GetSafeDefinition(libraryLinkVariable), ' '); if (!buildType.empty()) { std::string build = cmStrCat(libraryLinkVariable, '_', buildType); - linkFlags += this->Makefile->GetSafeDefinition(build); - linkFlags += " "; + sharedLibFlags += this->Makefile->GetSafeDefinition(build); + sharedLibFlags += " "; } if (this->Makefile->IsOn("WIN32") && !(this->Makefile->IsOn("CYGWIN") || @@ -1182,10 +1189,10 @@ void cmLocalGenerator::GetTargetFlags( this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG"); for (cmSourceFile* sf : sources) { if (sf->GetExtension() == "def") { - linkFlags += defFlag; - linkFlags += this->ConvertToOutputFormat( + sharedLibFlags += defFlag; + sharedLibFlags += this->ConvertToOutputFormat( cmSystemTools::CollapseFullPath(sf->ResolveFullPath()), SHELL); - linkFlags += " "; + sharedLibFlags += " "; } } } @@ -1193,18 +1200,20 @@ void cmLocalGenerator::GetTargetFlags( const char* targetLinkFlags = target->GetProperty("LINK_FLAGS"); if (targetLinkFlags) { - linkFlags += targetLinkFlags; - linkFlags += " "; + sharedLibFlags += targetLinkFlags; + sharedLibFlags += " "; } if (!buildType.empty()) { targetLinkFlags = target->GetProperty(cmStrCat("LINK_FLAGS_", buildType)); if (targetLinkFlags) { - linkFlags += targetLinkFlags; - linkFlags += " "; + sharedLibFlags += targetLinkFlags; + sharedLibFlags += " "; } } + linkFlags = std::move(sharedLibFlags); + std::vector linkOpts; target->GetLinkOptions(linkOpts, config, linkLanguage); // LINK_OPTIONS are escaped. @@ -1215,14 +1224,14 @@ void cmLocalGenerator::GetTargetFlags( } } break; case cmStateEnums::EXECUTABLE: { + std::string exeFlags; if (linkLanguage != "Swift") { - linkFlags += - this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); - linkFlags += " "; + exeFlags = this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); + exeFlags += " "; if (!buildType.empty()) { - linkFlags += this->Makefile->GetSafeDefinition( + exeFlags += this->Makefile->GetSafeDefinition( cmStrCat("CMAKE_EXE_LINKER_FLAGS_", buildType)); - linkFlags += " "; + exeFlags += " "; } if (linkLanguage.empty()) { cmSystemTools::Error( @@ -1232,19 +1241,19 @@ void cmLocalGenerator::GetTargetFlags( } if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) { - linkFlags += + exeFlags += this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE"); - linkFlags += " "; + exeFlags += " "; } else { - linkFlags += + exeFlags += this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE"); - linkFlags += " "; + exeFlags += " "; } if (target->IsExecutableWithExports()) { - linkFlags += this->Makefile->GetSafeDefinition( + exeFlags += this->Makefile->GetSafeDefinition( cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG")); - linkFlags += " "; + exeFlags += " "; } } @@ -1257,31 +1266,33 @@ void cmLocalGenerator::GetTargetFlags( if (cmIsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) { std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") + linkLanguage + std::string("_FLAGS"); - linkFlags += this->Makefile->GetSafeDefinition(sFlagVar); - linkFlags += " "; + exeFlags += this->Makefile->GetSafeDefinition(sFlagVar); + exeFlags += " "; } std::string cmp0065Flags = this->GetLinkLibsCMP0065(linkLanguage, *target); if (!cmp0065Flags.empty()) { - linkFlags += cmp0065Flags; - linkFlags += " "; + exeFlags += cmp0065Flags; + exeFlags += " "; } const char* targetLinkFlags = target->GetProperty("LINK_FLAGS"); if (targetLinkFlags) { - linkFlags += targetLinkFlags; - linkFlags += " "; + exeFlags += targetLinkFlags; + exeFlags += " "; } if (!buildType.empty()) { targetLinkFlags = target->GetProperty(cmStrCat("LINK_FLAGS_", buildType)); if (targetLinkFlags) { - linkFlags += targetLinkFlags; - linkFlags += " "; + exeFlags += targetLinkFlags; + exeFlags += " "; } } + linkFlags = std::move(exeFlags); + std::vector linkOpts; target->GetLinkOptions(linkOpts, config, linkLanguage); // LINK_OPTIONS are escaped. @@ -1301,25 +1312,32 @@ void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target, std::string const& lang, std::string& flags) { + std::string compileFlags; + cmMakefile* mf = this->GetMakefile(); // Add language-specific flags. - this->AddLanguageFlags(flags, target, lang, config); + this->AddLanguageFlags(compileFlags, target, lang, config); if (target->IsIPOEnabled(lang, config)) { - this->AppendFeatureOptions(flags, lang, "IPO"); + this->AppendFeatureOptions(compileFlags, lang, "IPO"); } - this->AddArchitectureFlags(flags, target, lang, config); + this->AddArchitectureFlags(compileFlags, target, lang, config); if (lang == "Fortran") { - this->AppendFlags(flags, this->GetTargetFortranFlags(target, config)); + this->AppendFlags(compileFlags, + this->GetTargetFortranFlags(target, config)); } - this->AddCMP0018Flags(flags, target, lang, config); - this->AddVisibilityPresetFlags(flags, target, lang); - this->AppendFlags(flags, mf->GetDefineFlags()); - this->AppendFlags(flags, this->GetFrameworkFlags(lang, config, target)); + this->AddCMP0018Flags(compileFlags, target, lang, config); + this->AddVisibilityPresetFlags(compileFlags, target, lang); + this->AppendFlags(compileFlags, mf->GetDefineFlags()); + this->AppendFlags(compileFlags, + this->GetFrameworkFlags(lang, config, target)); + + flags = std::move(compileFlags); + this->AddCompileOptions(flags, target, lang, config); } -- cgit v0.12 From b13207910e848d3c980e4b3dc176e113a3c04bbc Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: cmLocalGenerator: Clarify AddCompileOptions filter logic --- Source/cmLocalGenerator.cxx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 69866c4..042c108 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -838,14 +838,17 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, if (const char* langFlagRegexStr = this->Makefile->GetDefinition(langFlagRegexVar)) { // Filter flags acceptable to this language. - std::vector opts; if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) { + std::vector opts; cmSystemTools::ParseWindowsCommandLine(targetFlags, opts); + // Re-escape these flags since COMPILE_FLAGS were already parsed + // as a command line above. + this->AppendCompileOptions(flags, opts, langFlagRegexStr); } - target->GetCompileOptions(opts, config, lang); - // (Re-)Escape these flags. COMPILE_FLAGS were already parsed - // as a command line above, and COMPILE_OPTIONS are escaped. - this->AppendCompileOptions(flags, opts, langFlagRegexStr); + std::vector targetCompileOpts; + target->GetCompileOptions(targetCompileOpts, config, lang); + // COMPILE_OPTIONS are escaped. + this->AppendCompileOptions(flags, targetCompileOpts, langFlagRegexStr); } else { // Use all flags. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) { -- cgit v0.12 From a20d2c85d02842a23ef1105daa078a821172cb4e Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: cmLocalGenerator: Add AppendFlags overload with backtraces --- Source/cmLocalGenerator.cxx | 8 ++++++++ Source/cmLocalGenerator.h | 2 ++ Source/cmLocalUnixMakefileGenerator3.h | 1 + 3 files changed, 11 insertions(+) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 042c108..144d995 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2138,6 +2138,14 @@ void cmLocalGenerator::AppendFlags(std::string& flags, } } +void cmLocalGenerator::AppendFlags( + std::string& flags, const std::vector>& newFlags) const +{ + for (BT const& flag : newFlags) { + this->AppendFlags(flags, flag.Value); + } +} + void cmLocalGenerator::AppendFlagEscape(std::string& flags, const std::string& rawFlag) const { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index e6ba333..3c4e897 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -121,6 +121,8 @@ public: //! Append flags to a string. virtual void AppendFlags(std::string& flags, const std::string& newFlags) const; + virtual void AppendFlags(std::string& flags, + const std::vector>& newFlags) const; virtual void AppendFlagEscape(std::string& flags, const std::string& rawFlag) const; void AddPchDependencies(cmGeneratorTarget* target, diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 745e251..c02c0dc 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -90,6 +90,7 @@ public: // append flags to a string void AppendFlags(std::string& flags, const std::string& newFlags) const override; + using cmLocalCommonGenerator::AppendFlags; // append an echo command enum EchoColor -- cgit v0.12 From 5355a60fd02417a004c6b4b6b8848ce0ff1ea9fa Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: cmLocalGenerator: Add AppendCompileOptions overload with backtraces --- Source/cmLocalGenerator.cxx | 24 ++++++++++++++++++++++++ Source/cmLocalGenerator.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 144d995..bd5e5a2 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2422,6 +2422,30 @@ void cmLocalGenerator::AppendCompileOptions( } } +void cmLocalGenerator::AppendCompileOptions( + std::vector>& options, + const std::vector>& options_vec, const char* regex) const +{ + if (regex != nullptr) { + // Filter flags upon specified regular expressions. + cmsys::RegularExpression r(regex); + + for (BT const& opt : options_vec) { + if (r.find(opt.Value)) { + std::string flag; + this->AppendFlagEscape(flag, opt.Value); + options.emplace_back(std::move(flag), opt.Backtrace); + } + } + } else { + for (BT const& opt : options_vec) { + std::string flag; + this->AppendFlagEscape(flag, opt.Value); + options.emplace_back(std::move(flag), opt.Backtrace); + } + } +} + void cmLocalGenerator::AppendIncludeDirectories( std::vector& includes, const char* includes_list, const cmSourceFile& sourceFile) const diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 3c4e897..ec97ac2 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -199,6 +199,9 @@ public: void AppendCompileOptions(std::string& options, const std::vector& options_vec, const char* regex = nullptr) const; + void AppendCompileOptions(std::vector>& options, + const std::vector>& options_vec, + const char* regex = nullptr) const; /** * Join a set of defines into a definesString with a space separator. -- cgit v0.12 From 1f6a436bf4188007b87d2582367cde8f970d5e1f Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: cmLocalGenerator: Add AddCompileOptions overload with backtraces --- Source/cmLocalGenerator.cxx | 43 +++++++++++++++++++++++++++++++++++-------- Source/cmLocalGenerator.h | 3 +++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index bd5e5a2..44ba79a 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -833,6 +833,16 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, const std::string& lang, const std::string& config) { + std::vector> tmpFlags; + this->AddCompileOptions(tmpFlags, target, lang, config); + this->AppendFlags(flags, tmpFlags); +} + +void cmLocalGenerator::AddCompileOptions(std::vector>& flags, + cmGeneratorTarget* target, + const std::string& lang, + const std::string& config) +{ std::string langFlagRegexVar = std::string("CMAKE_") + lang + "_FLAG_REGEX"; if (const char* langFlagRegexStr = @@ -843,20 +853,28 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, cmSystemTools::ParseWindowsCommandLine(targetFlags, opts); // Re-escape these flags since COMPILE_FLAGS were already parsed // as a command line above. - this->AppendCompileOptions(flags, opts, langFlagRegexStr); + std::string compileOpts; + this->AppendCompileOptions(compileOpts, opts, langFlagRegexStr); + if (!compileOpts.empty()) { + flags.emplace_back(std::move(compileOpts)); + } } - std::vector targetCompileOpts; - target->GetCompileOptions(targetCompileOpts, config, lang); + std::vector> targetCompileOpts = + target->GetCompileOptions(config, lang); // COMPILE_OPTIONS are escaped. this->AppendCompileOptions(flags, targetCompileOpts, langFlagRegexStr); } else { // Use all flags. if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) { // COMPILE_FLAGS are not escaped for historical reasons. - this->AppendFlags(flags, targetFlags); + std::string compileFlags; + this->AppendFlags(compileFlags, targetFlags); + if (!compileFlags.empty()) { + flags.emplace_back(std::move(compileFlags)); + } } - std::vector targetCompileOpts; - target->GetCompileOptions(targetCompileOpts, config, lang); + std::vector> targetCompileOpts = + target->GetCompileOptions(config, lang); // COMPILE_OPTIONS are escaped. this->AppendCompileOptions(flags, targetCompileOpts); } @@ -885,7 +903,12 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, return; } } - this->AddCompilerRequirementFlag(flags, target, lang); + + std::string compReqFlag; + this->AddCompilerRequirementFlag(compReqFlag, target, lang); + if (!compReqFlag.empty()) { + flags.emplace_back(std::move(compReqFlag)); + } // Add compile flag for the MSVC compiler only. cmMakefile* mf = this->GetMakefile(); @@ -906,7 +929,11 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, std::string isJMCEnabled = cge->Evaluate(this, config); if (cmIsOn(isJMCEnabled)) { std::vector optVec = cmExpandedList(jmc); - this->AppendCompileOptions(flags, optVec); + std::string jmcFlags; + this->AppendCompileOptions(jmcFlags, optVec); + if (!jmcFlags.empty()) { + flags.emplace_back(std::move(jmcFlags)); + } } } } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index ec97ac2..52f8ac8 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -288,6 +288,9 @@ public: void AddCompileOptions(std::string& flags, cmGeneratorTarget* target, const std::string& lang, const std::string& config); + void AddCompileOptions(std::vector>& flags, + cmGeneratorTarget* target, const std::string& lang, + const std::string& config); std::string GetProjectName() const; -- cgit v0.12 From 4d5bbb7704a44e56f43585b3f811f37c5200bdd0 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: cmLocalGenerator: Add GetStaticLibraryFlags overload with backtraces --- Source/cmLocalGenerator.cxx | 27 +++++++++++++++++++++++---- Source/cmLocalGenerator.h | 3 +++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 44ba79a..36e1115 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1148,8 +1148,18 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags, std::string const& linkLanguage, cmGeneratorTarget* target) { - std::string staticLibFlags; + std::vector> tmpFlags = + this->GetStaticLibraryFlags(config, linkLanguage, target); + this->AppendFlags(flags, tmpFlags); +} + +std::vector> cmLocalGenerator::GetStaticLibraryFlags( + std::string const& config, std::string const& linkLanguage, + cmGeneratorTarget* target) +{ + std::vector> flags; if (linkLanguage != "Swift") { + std::string staticLibFlags; this->AppendFlags( staticLibFlags, this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS")); @@ -1158,7 +1168,12 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags, this->AppendFlags(staticLibFlags, this->Makefile->GetSafeDefinition(name)); } + if (!staticLibFlags.empty()) { + flags.emplace_back(std::move(staticLibFlags)); + } } + + std::string staticLibFlags; this->AppendFlags(staticLibFlags, target->GetSafeProperty("STATIC_LIBRARY_FLAGS")); if (!config.empty()) { @@ -1166,12 +1181,16 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags, this->AppendFlags(staticLibFlags, target->GetSafeProperty(name)); } - flags = std::move(staticLibFlags); + if (!staticLibFlags.empty()) { + flags.emplace_back(std::move(staticLibFlags)); + } - std::vector staticLibOpts; - target->GetStaticLibraryLinkOptions(staticLibOpts, config, linkLanguage); + std::vector> staticLibOpts = + target->GetStaticLibraryLinkOptions(config, linkLanguage); // STATIC_LIBRARY_OPTIONS are escaped. this->AppendCompileOptions(flags, staticLibOpts); + + return flags; } void cmLocalGenerator::GetTargetFlags( diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 52f8ac8..0a41f2a 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -371,6 +371,9 @@ public: void GetStaticLibraryFlags(std::string& flags, std::string const& config, std::string const& linkLanguage, cmGeneratorTarget* target); + std::vector> GetStaticLibraryFlags( + std::string const& config, std::string const& linkLanguage, + cmGeneratorTarget* target); /** Fill out these strings for the given target. Libraries to link, * flags, and linkflags. */ -- cgit v0.12 From 8e973b8e8d6542b5dd15173884bde68a9a390949 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: cmLocalGenerator: Add GetTargetFlags overload with backtraces --- Source/cmLocalGenerator.cxx | 39 ++++++++++++++++++++++++++++++--------- Source/cmLocalGenerator.h | 6 ++++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 36e1115..b73f5d2 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1198,6 +1198,18 @@ void cmLocalGenerator::GetTargetFlags( std::string& linkLibs, std::string& flags, std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target) { + std::vector> tmpLinkFlags; + this->GetTargetFlags(linkLineComputer, config, linkLibs, flags, tmpLinkFlags, + frameworkPath, linkPath, target); + this->AppendFlags(linkFlags, tmpLinkFlags); +} + +void cmLocalGenerator::GetTargetFlags( + cmLinkLineComputer* linkLineComputer, const std::string& config, + std::string& linkLibs, std::string& flags, + std::vector>& linkFlags, std::string& frameworkPath, + std::string& linkPath, cmGeneratorTarget* target) +{ const std::string buildType = cmSystemTools::UpperCase(config); cmComputeLinkInformation* pcli = target->GetLinkInformation(config); const char* libraryLinkVariable = @@ -1208,7 +1220,7 @@ void cmLocalGenerator::GetTargetFlags( switch (target->GetType()) { case cmStateEnums::STATIC_LIBRARY: - this->GetStaticLibraryFlags(linkFlags, buildType, linkLanguage, target); + linkFlags = this->GetStaticLibraryFlags(buildType, linkLanguage, target); if (pcli && dynamic_cast(linkLineComputer)) { // Compute the required cuda device link libraries when // resolving cuda device symbols @@ -1261,10 +1273,12 @@ void cmLocalGenerator::GetTargetFlags( } } - linkFlags = std::move(sharedLibFlags); + if (!sharedLibFlags.empty()) { + linkFlags.emplace_back(std::move(sharedLibFlags)); + } - std::vector linkOpts; - target->GetLinkOptions(linkOpts, config, linkLanguage); + std::vector> linkOpts = + target->GetLinkOptions(config, linkLanguage); // LINK_OPTIONS are escaped. this->AppendCompileOptions(linkFlags, linkOpts); if (pcli) { @@ -1340,10 +1354,12 @@ void cmLocalGenerator::GetTargetFlags( } } - linkFlags = std::move(exeFlags); + if (!exeFlags.empty()) { + linkFlags.emplace_back(std::move(exeFlags)); + } - std::vector linkOpts; - target->GetLinkOptions(linkOpts, config, linkLanguage); + std::vector> linkOpts = + target->GetLinkOptions(config, linkLanguage); // LINK_OPTIONS are escaped. this->AppendCompileOptions(linkFlags, linkOpts); } break; @@ -1351,9 +1367,14 @@ void cmLocalGenerator::GetTargetFlags( break; } - this->AppendPositionIndependentLinkerFlags(linkFlags, target, config, + std::string extraLinkFlags; + this->AppendPositionIndependentLinkerFlags(extraLinkFlags, target, config, linkLanguage); - this->AppendIPOLinkerFlags(linkFlags, target, config, linkLanguage); + this->AppendIPOLinkerFlags(extraLinkFlags, target, config, linkLanguage); + + if (!extraLinkFlags.empty()) { + linkFlags.emplace_back(std::move(extraLinkFlags)); + } } void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target, diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 0a41f2a..89472e0 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -382,6 +382,12 @@ public: std::string& flags, std::string& linkFlags, std::string& frameworkPath, std::string& linkPath, cmGeneratorTarget* target); + void GetTargetFlags(cmLinkLineComputer* linkLineComputer, + const std::string& config, std::string& linkLibs, + std::string& flags, + std::vector>& linkFlags, + std::string& frameworkPath, std::string& linkPath, + cmGeneratorTarget* target); void GetTargetDefines(cmGeneratorTarget const* target, std::string const& config, std::string const& lang, std::set& defines) const; -- cgit v0.12 From 291c83f063d310f700e3e1afa756dcdf968d0f09 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: cmLocalGenerator: Add GetTargetCompileFlags overload with backtraces --- Source/cmLocalGenerator.cxx | 16 ++++++++++++++-- Source/cmLocalGenerator.h | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index b73f5d2..bc1ff1f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1382,6 +1382,16 @@ void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target, std::string const& lang, std::string& flags) { + std::vector> tmpFlags = + this->GetTargetCompileFlags(target, config, lang); + this->AppendFlags(flags, tmpFlags); +} + +std::vector> cmLocalGenerator::GetTargetCompileFlags( + cmGeneratorTarget* target, std::string const& config, + std::string const& lang) +{ + std::vector> flags; std::string compileFlags; cmMakefile* mf = this->GetMakefile(); @@ -1406,9 +1416,11 @@ void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target, this->AppendFlags(compileFlags, this->GetFrameworkFlags(lang, config, target)); - flags = std::move(compileFlags); - + if (!compileFlags.empty()) { + flags.emplace_back(std::move(compileFlags)); + } this->AddCompileOptions(flags, target, lang, config); + return flags; } static std::string GetFrameworkFlags(const std::string& lang, diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 89472e0..34f58bd 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -397,6 +397,9 @@ public: void GetTargetCompileFlags(cmGeneratorTarget* target, std::string const& config, std::string const& lang, std::string& flags); + std::vector> GetTargetCompileFlags(cmGeneratorTarget* target, + std::string const& config, + std::string const& lang); std::string GetFrameworkFlags(std::string const& l, std::string const& config, -- cgit v0.12 From 30006e199bb6ac3649332b26c94ccf864e1416b1 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 3 Sep 2019 10:25:44 -0700 Subject: fileapi: add backtraces for compile/link options --- Source/cmFileAPICodemodel.cxx | 20 +++-- Tests/RunCMake/FileAPI/codemodel-v2-check.py | 130 ++++++++++++++++++++++++++- Tests/RunCMake/FileAPI/cxx/CMakeLists.txt | 3 + 3 files changed, 142 insertions(+), 11 deletions(-) diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 3ac769c..805da81 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -802,9 +802,13 @@ void Target::ProcessLanguage(std::string const& lang) { // FIXME: Add flags from end section of ExpandRuleVariable, // which may need to be factored out. - std::string flags; - lg->GetTargetCompileFlags(this->GT, this->Config, lang, flags); - cd.Flags.emplace_back(std::move(flags), JBTIndex()); + std::vector> flags = + lg->GetTargetCompileFlags(this->GT, this->Config, lang); + + cd.Flags.reserve(flags.size()); + for (const BT& f : flags) { + cd.Flags.emplace_back(this->ToJBT(f)); + } } std::set> defines = lg->GetTargetDefines(this->GT, this->Config, lang); @@ -1264,7 +1268,7 @@ Json::Value Target::DumpLinkCommandFragments() Json::Value linkFragments = Json::arrayValue; std::string linkLanguageFlags; - std::string linkFlags; + std::vector> linkFlags; std::string frameworkPath; std::string linkPath; std::string linkLibs; @@ -1275,7 +1279,6 @@ Json::Value Target::DumpLinkCommandFragments() linkLanguageFlags, linkFlags, frameworkPath, linkPath, this->GT); linkLanguageFlags = cmTrimWhitespace(linkLanguageFlags); - linkFlags = cmTrimWhitespace(linkFlags); frameworkPath = cmTrimWhitespace(frameworkPath); linkPath = cmTrimWhitespace(linkPath); linkLibs = cmTrimWhitespace(linkLibs); @@ -1286,8 +1289,11 @@ Json::Value Target::DumpLinkCommandFragments() } if (!linkFlags.empty()) { - linkFragments.append( - this->DumpCommandFragment(std::move(linkFlags), "flags")); + for (BT frag : linkFlags) { + frag.Value = cmTrimWhitespace(frag.Value); + linkFragments.append( + this->DumpCommandFragment(this->ToJBT(frag), "flags")); + } } if (!frameworkPath.empty()) { diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-check.py b/Tests/RunCMake/FileAPI/codemodel-v2-check.py index 89f63d0..2a24421 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-check.py +++ b/Tests/RunCMake/FileAPI/codemodel-v2-check.py @@ -232,17 +232,37 @@ def check_target(c): assert is_string(obj["link"]["language"], expected["link"]["language"]) - # FIXME: Properly test commandFragments if "commandFragments" in obj["link"]: link_keys.append("commandFragments") assert is_list(obj["link"]["commandFragments"]) for f in obj["link"]["commandFragments"]: assert is_dict(f) - assert sorted(f.keys()) == ["fragment", "role"] + assert sorted(f.keys()) == ["fragment", "role"] or sorted(f.keys()) == ["backtrace", "fragment", "role"] assert is_string(f["fragment"]) assert is_string(f["role"]) assert f["role"] in ("flags", "libraries", "libraryPath", "frameworkPath") + if expected["link"]["commandFragments"] is not None: + def check_link_command_fragments(actual, expected): + assert is_dict(actual) + expected_keys = ["fragment", "role"] + + if expected["backtrace"] is not None: + expected_keys.append("backtrace") + assert actual["fragment"] == expected["fragment"] + assert actual["role"] == expected["role"] + check_backtrace(obj, actual["backtrace"], expected["backtrace"]) + + assert sorted(actual.keys()) == sorted(expected_keys) + + check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]), + obj["link"]["commandFragments"], expected["link"]["commandFragments"], + check=check_link_command_fragments, + check_exception=lambda a, e: "Link fragment: %s" % a["fragment"], + missing_exception=lambda e: "Link fragment: %s" % e["fragment"], + extra_exception=lambda a: "Link fragment: %s" % a["fragment"], + allow_extra=True) + if expected["link"]["lto"] is not None: link_keys.append("lto") assert is_bool(obj["link"]["lto"], expected["link"]["lto"]) @@ -327,15 +347,33 @@ def check_target(c): missing_exception=lambda e: "Source path: %s" % e, extra_exception=lambda a: "Source path: %s" % obj["sources"][a]["path"]) - # FIXME: Properly test compileCommandFragments if "compileCommandFragments" in actual: expected_keys.append("compileCommandFragments") assert is_list(actual["compileCommandFragments"]) for f in actual["compileCommandFragments"]: assert is_dict(f) - assert sorted(f.keys()) == ["fragment"] assert is_string(f["fragment"]) + if expected["compileCommandFragments"] is not None: + def check_compile_command_fragments(actual, expected): + assert is_dict(actual) + expected_keys = ["fragment"] + + if expected["backtrace"] is not None: + expected_keys.append("backtrace") + assert actual["fragment"] == expected["fragment"] + check_backtrace(obj, actual["backtrace"], expected["backtrace"]) + + assert sorted(actual.keys()) == sorted(expected_keys) + + check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]), + actual["compileCommandFragments"], expected["compileCommandFragments"], + check=check_compile_command_fragments, + check_exception=lambda a, e: "Compile fragment: %s" % a["fragment"], + missing_exception=lambda e: "Compile fragment: %s" % e["fragment"], + extra_exception=lambda a: "Compile fragment: %s" % a["fragment"], + allow_extra=True) + if expected["includes"] is not None: expected_keys.append("includes") @@ -931,6 +969,7 @@ def gen_check_targets(c, g, inSource): "backtrace": None, }, ], + "compileCommandFragments": None, }, ], "backtrace": [ @@ -998,6 +1037,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1064,6 +1104,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1171,6 +1212,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1217,6 +1259,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1317,6 +1360,7 @@ def gen_check_targets(c, g, inSource): "backtrace": None, }, ], + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1367,6 +1411,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": True, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1433,6 +1478,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1479,6 +1525,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": True, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1574,6 +1621,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1681,6 +1729,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -1727,6 +1776,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -1979,6 +2029,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2062,6 +2113,25 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": [ + { + "fragment" : "TargetCompileOptions", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 17, + "command": "target_compile_options", + "hasParent": True, + }, + { + "file" : "^cxx/CMakeLists\\.txt$", + "line": None, + "command": None, + "hasParent": False, + }, + ], + } + ], }, ], "backtrace": [ @@ -2129,6 +2199,26 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": [ + { + "fragment" : "TargetLinkOptions", + "role" : "flags", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 18, + "command": "target_link_options", + "hasParent": True, + }, + { + "file" : "^cxx/CMakeLists\\.txt$", + "line": None, + "command": None, + "hasParent": False, + }, + ], + }, + ], }, "archive": None, "dependencies": [ @@ -2205,6 +2295,7 @@ def gen_check_targets(c, g, inSource): "backtrace": None, }, ], + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2243,6 +2334,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -2297,6 +2389,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2331,6 +2424,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -2402,6 +2496,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2485,6 +2580,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2519,6 +2615,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -2743,6 +2840,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2777,6 +2875,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -2848,6 +2947,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -2882,6 +2982,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3114,6 +3215,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3221,6 +3323,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3276,6 +3379,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3337,6 +3441,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3444,6 +3549,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3499,6 +3605,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3725,6 +3832,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3759,6 +3867,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3813,6 +3922,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3847,6 +3957,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3901,6 +4012,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -3935,6 +4047,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -3989,6 +4102,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -4023,6 +4137,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -4077,6 +4192,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -4111,6 +4227,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -4401,6 +4518,7 @@ def gen_check_targets(c, g, inSource): ], "includes": None, "defines": None, + "compileCommandFragments": None, }, ], "backtrace": [ @@ -4435,6 +4553,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "C", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ @@ -4748,6 +4867,7 @@ def gen_check_targets(c, g, inSource): ], }, ], + "compileCommandFragments": None, }, { "language": "CXX", @@ -4810,6 +4930,7 @@ def gen_check_targets(c, g, inSource): ], }, ], + "compileCommandFragments": None, }, ], "backtrace": [ @@ -4844,6 +4965,7 @@ def gen_check_targets(c, g, inSource): "link": { "language": "CXX", "lto": None, + "commandFragments": None, }, "archive": None, "dependencies": [ diff --git a/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt b/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt index 29b61b8..17ff455 100644 --- a/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt +++ b/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt @@ -13,3 +13,6 @@ target_link_libraries(cxx_shared_exe PRIVATE cxx_shared_lib) add_library(cxx_static_lib STATIC ../empty.cxx) add_executable(cxx_static_exe ../empty.cxx) target_link_libraries(cxx_static_exe PRIVATE cxx_static_lib) + +target_compile_options(cxx_exe PUBLIC TargetCompileOptions) +target_link_options(cxx_exe PUBLIC TargetLinkOptions) -- cgit v0.12