summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-09-11 15:38:40 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-09-11 15:38:58 (GMT)
commit46629d6a49d8a12378778b39bc8827ae2808f3dd (patch)
tree5259f503de23d773dbba2f82a43826aa783b130a
parent7f46e4a73a4d7aaa4029a04c532d2c99635383b9 (diff)
parent30006e199bb6ac3649332b26c94ccf864e1416b1 (diff)
downloadCMake-46629d6a49d8a12378778b39bc8827ae2808f3dd.zip
CMake-46629d6a49d8a12378778b39bc8827ae2808f3dd.tar.gz
CMake-46629d6a49d8a12378778b39bc8827ae2808f3dd.tar.bz2
Merge topic 'fileapiAddMoreBacktraces'
30006e199b fileapi: add backtraces for compile/link options 291c83f063 cmLocalGenerator: Add GetTargetCompileFlags overload with backtraces 8e973b8e8d cmLocalGenerator: Add GetTargetFlags overload with backtraces 4d5bbb7704 cmLocalGenerator: Add GetStaticLibraryFlags overload with backtraces 1f6a436bf4 cmLocalGenerator: Add AddCompileOptions overload with backtraces 5355a60fd0 cmLocalGenerator: Add AppendCompileOptions overload with backtraces a20d2c85d0 cmLocalGenerator: Add AppendFlags overload with backtraces b13207910e cmLocalGenerator: Clarify AddCompileOptions filter logic ... Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3775
-rw-r--r--Source/cmFileAPICodemodel.cxx20
-rw-r--r--Source/cmLocalGenerator.cxx260
-rw-r--r--Source/cmLocalGenerator.h20
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.h1
-rw-r--r--Tests/RunCMake/FileAPI/codemodel-v2-check.py130
-rw-r--r--Tests/RunCMake/FileAPI/cxx/CMakeLists.txt3
6 files changed, 359 insertions, 75 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<BT<std::string>> flags =
+ lg->GetTargetCompileFlags(this->GT, this->Config, lang);
+
+ cd.Flags.reserve(flags.size());
+ for (const BT<std::string>& f : flags) {
+ cd.Flags.emplace_back(this->ToJBT(f));
+ }
}
std::set<BT<std::string>> 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<BT<std::string>> 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<std::string> frag : linkFlags) {
+ frag.Value = cmTrimWhitespace(frag.Value);
+ linkFragments.append(
+ this->DumpCommandFragment(this->ToJBT(frag), "flags"));
+ }
}
if (!frameworkPath.empty()) {
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 8bb3bc1..9f22277 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -833,29 +833,50 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags,
const std::string& lang,
const std::string& config)
{
+ std::vector<BT<std::string>> tmpFlags;
+ this->AddCompileOptions(tmpFlags, target, lang, config);
+ this->AppendFlags(flags, tmpFlags);
+}
+
+void cmLocalGenerator::AddCompileOptions(std::vector<BT<std::string>>& flags,
+ cmGeneratorTarget* target,
+ const std::string& lang,
+ const std::string& config)
+{
std::string langFlagRegexVar = std::string("CMAKE_") + lang + "_FLAG_REGEX";
if (const char* langFlagRegexStr =
this->Makefile->GetDefinition(langFlagRegexVar)) {
// Filter flags acceptable to this language.
- std::vector<std::string> opts;
if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) {
+ std::vector<std::string> opts;
cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
+ // Re-escape these flags since COMPILE_FLAGS were already parsed
+ // as a command line above.
+ std::string compileOpts;
+ this->AppendCompileOptions(compileOpts, opts, langFlagRegexStr);
+ if (!compileOpts.empty()) {
+ flags.emplace_back(std::move(compileOpts));
+ }
}
- 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<BT<std::string>> 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<std::string> opts;
- target->GetCompileOptions(opts, config, lang);
+ std::vector<BT<std::string>> targetCompileOpts =
+ target->GetCompileOptions(config, lang);
// COMPILE_OPTIONS are escaped.
- this->AppendCompileOptions(flags, opts);
+ this->AppendCompileOptions(flags, targetCompileOpts);
}
for (auto const& it : target->GetMaxLanguageStandards()) {
@@ -882,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();
@@ -903,7 +929,11 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags,
std::string isJMCEnabled = cge->Evaluate(this, config);
if (cmIsOn(isJMCEnabled)) {
std::vector<std::string> optVec = cmExpandedList(jmc);
- this->AppendCompileOptions(flags, optVec);
+ std::string jmcFlags;
+ this->AppendCompileOptions(jmcFlags, optVec);
+ if (!jmcFlags.empty()) {
+ flags.emplace_back(std::move(jmcFlags));
+ }
}
}
}
@@ -1118,24 +1148,49 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
std::string const& linkLanguage,
cmGeneratorTarget* target)
{
+ std::vector<BT<std::string>> tmpFlags =
+ this->GetStaticLibraryFlags(config, linkLanguage, target);
+ this->AppendFlags(flags, tmpFlags);
+}
+
+std::vector<BT<std::string>> cmLocalGenerator::GetStaticLibraryFlags(
+ std::string const& config, std::string const& linkLanguage,
+ cmGeneratorTarget* target)
+{
+ std::vector<BT<std::string>> flags;
if (linkLanguage != "Swift") {
+ std::string staticLibFlags;
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));
+ }
+ if (!staticLibFlags.empty()) {
+ flags.emplace_back(std::move(staticLibFlags));
}
}
- this->AppendFlags(flags, target->GetSafeProperty("STATIC_LIBRARY_FLAGS"));
+
+ std::string staticLibFlags;
+ 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));
+ }
+
+ if (!staticLibFlags.empty()) {
+ flags.emplace_back(std::move(staticLibFlags));
}
- std::vector<std::string> options;
- target->GetStaticLibraryLinkOptions(options, config, linkLanguage);
+ std::vector<BT<std::string>> staticLibOpts =
+ target->GetStaticLibraryLinkOptions(config, linkLanguage);
// STATIC_LIBRARY_OPTIONS are escaped.
- this->AppendCompileOptions(flags, options);
+ this->AppendCompileOptions(flags, staticLibOpts);
+
+ return flags;
}
void cmLocalGenerator::GetTargetFlags(
@@ -1143,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<BT<std::string>> 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<BT<std::string>>& linkFlags, std::string& frameworkPath,
+ std::string& linkPath, cmGeneratorTarget* target)
+{
const std::string buildType = cmSystemTools::UpperCase(config);
cmComputeLinkInformation* pcli = target->GetLinkInformation(config);
const char* libraryLinkVariable =
@@ -1153,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<cmLinkLineDeviceComputer*>(linkLineComputer)) {
// Compute the required cuda device link libraries when
// resolving cuda device symbols
@@ -1165,13 +1232,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 +1250,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,36 +1261,40 @@ 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 += " ";
}
}
- std::vector<std::string> opts;
- target->GetLinkOptions(opts, config, linkLanguage);
+ if (!sharedLibFlags.empty()) {
+ linkFlags.emplace_back(std::move(sharedLibFlags));
+ }
+
+ std::vector<BT<std::string>> linkOpts =
+ target->GetLinkOptions(config, linkLanguage);
// LINK_OPTIONS are escaped.
- this->AppendCompileOptions(linkFlags, opts);
+ this->AppendCompileOptions(linkFlags, linkOpts);
if (pcli) {
this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
frameworkPath, linkPath);
}
} 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 +1304,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,43 +1329,52 @@ 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 += " ";
}
}
- std::vector<std::string> opts;
- target->GetLinkOptions(opts, config, linkLanguage);
+ if (!exeFlags.empty()) {
+ linkFlags.emplace_back(std::move(exeFlags));
+ }
+
+ std::vector<BT<std::string>> linkOpts =
+ target->GetLinkOptions(config, linkLanguage);
// LINK_OPTIONS are escaped.
- this->AppendCompileOptions(linkFlags, opts);
+ this->AppendCompileOptions(linkFlags, linkOpts);
} break;
default:
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,
@@ -1301,26 +1382,45 @@ void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target,
std::string const& lang,
std::string& flags)
{
+ std::vector<BT<std::string>> tmpFlags =
+ this->GetTargetCompileFlags(target, config, lang);
+ this->AppendFlags(flags, tmpFlags);
+}
+
+std::vector<BT<std::string>> cmLocalGenerator::GetTargetCompileFlags(
+ cmGeneratorTarget* target, std::string const& config,
+ std::string const& lang)
+{
+ std::vector<BT<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));
+
+ 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,
@@ -2116,6 +2216,14 @@ void cmLocalGenerator::AppendFlags(std::string& flags,
}
}
+void cmLocalGenerator::AppendFlags(
+ std::string& flags, const std::vector<BT<std::string>>& newFlags) const
+{
+ for (BT<std::string> const& flag : newFlags) {
+ this->AppendFlags(flags, flag.Value);
+ }
+}
+
void cmLocalGenerator::AppendFlagEscape(std::string& flags,
const std::string& rawFlag) const
{
@@ -2391,6 +2499,30 @@ void cmLocalGenerator::AppendCompileOptions(
}
}
+void cmLocalGenerator::AppendCompileOptions(
+ std::vector<BT<std::string>>& options,
+ const std::vector<BT<std::string>>& options_vec, const char* regex) const
+{
+ if (regex != nullptr) {
+ // Filter flags upon specified regular expressions.
+ cmsys::RegularExpression r(regex);
+
+ for (BT<std::string> 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<std::string> 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<std::string>& includes, const char* includes_list,
const cmSourceFile& sourceFile) const
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index e6ba333..34f58bd 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<BT<std::string>>& newFlags) const;
virtual void AppendFlagEscape(std::string& flags,
const std::string& rawFlag) const;
void AddPchDependencies(cmGeneratorTarget* target,
@@ -197,6 +199,9 @@ public:
void AppendCompileOptions(std::string& options,
const std::vector<std::string>& options_vec,
const char* regex = nullptr) const;
+ void AppendCompileOptions(std::vector<BT<std::string>>& options,
+ const std::vector<BT<std::string>>& options_vec,
+ const char* regex = nullptr) const;
/**
* Join a set of defines into a definesString with a space separator.
@@ -283,6 +288,9 @@ public:
void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
const std::string& lang, const std::string& config);
+ void AddCompileOptions(std::vector<BT<std::string>>& flags,
+ cmGeneratorTarget* target, const std::string& lang,
+ const std::string& config);
std::string GetProjectName() const;
@@ -363,6 +371,9 @@ public:
void GetStaticLibraryFlags(std::string& flags, std::string const& config,
std::string const& linkLanguage,
cmGeneratorTarget* target);
+ std::vector<BT<std::string>> 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. */
@@ -371,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<BT<std::string>>& linkFlags,
+ std::string& frameworkPath, std::string& linkPath,
+ cmGeneratorTarget* target);
void GetTargetDefines(cmGeneratorTarget const* target,
std::string const& config, std::string const& lang,
std::set<std::string>& defines) const;
@@ -380,6 +397,9 @@ public:
void GetTargetCompileFlags(cmGeneratorTarget* target,
std::string const& config,
std::string const& lang, std::string& flags);
+ std::vector<BT<std::string>> GetTargetCompileFlags(cmGeneratorTarget* target,
+ std::string const& config,
+ std::string const& lang);
std::string GetFrameworkFlags(std::string const& l,
std::string const& config,
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
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)