summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-09-10 13:33:44 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-09-10 13:34:17 (GMT)
commit293070c325ec4cb91668dbe75dd259b7dfb0aa7d (patch)
tree7db865e54cf7bcc1d714a60fd8476736bf7a835b
parent595502c03992a185678ffeaca7c73ee21426f53d (diff)
parentf21158cdfe8a1938401f86b85b1ae1239372115b (diff)
downloadCMake-293070c325ec4cb91668dbe75dd259b7dfb0aa7d.zip
CMake-293070c325ec4cb91668dbe75dd259b7dfb0aa7d.tar.gz
CMake-293070c325ec4cb91668dbe75dd259b7dfb0aa7d.tar.bz2
Merge topic 'vs_settings'
f21158cdfe VS: Honor VS_SETTINGS source file property on all sources 3bf013632d cmVisualStudio10TargetGenerator: Factor out helper to write VS_SETTINGS Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6492
-rw-r--r--Help/prop_sf/VS_SETTINGS.rst7
-rw-r--r--Help/release/dev/vs_settings.rst5
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx80
-rw-r--r--Source/cmVisualStudio10TargetGenerator.h14
-rw-r--r--Tests/RunCMake/VS10Project/VsSettings-check.cmake15
-rw-r--r--Tests/RunCMake/VS10Project/VsSettings.cmake2
6 files changed, 79 insertions, 44 deletions
diff --git a/Help/prop_sf/VS_SETTINGS.rst b/Help/prop_sf/VS_SETTINGS.rst
index 322f5a6..871e36e 100644
--- a/Help/prop_sf/VS_SETTINGS.rst
+++ b/Help/prop_sf/VS_SETTINGS.rst
@@ -3,7 +3,12 @@ VS_SETTINGS
.. versionadded:: 3.18
-Set any item metadata on a non-built file.
+Set any item metadata on a file.
+
+.. versionadded:: 3.22
+
+ This property is honored for all source file types.
+ Previously it worked only for non-built files.
Takes a list of ``Key=Value`` pairs. Tells the Visual Studio generator to set
``Key`` to ``Value`` as item metadata on the file.
diff --git a/Help/release/dev/vs_settings.rst b/Help/release/dev/vs_settings.rst
new file mode 100644
index 0000000..64f3ced
--- /dev/null
+++ b/Help/release/dev/vs_settings.rst
@@ -0,0 +1,5 @@
+vs_settings
+-----------
+
+* The :prop_sf:`VS_SETTINGS` source file property is now supported for
+ all source file types. Previously it worked only for non-built sources.
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 8a2acf3..75fb05f 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -1799,8 +1799,8 @@ void cmVisualStudio10TargetGenerator::WriteGroupSources(
}
}
-void cmVisualStudio10TargetGenerator::WriteHeaderSource(Elem& e1,
- cmSourceFile const* sf)
+void cmVisualStudio10TargetGenerator::WriteHeaderSource(
+ Elem& e1, cmSourceFile const* sf, ConfigToSettings const& toolSettings)
{
std::string const& fileName = sf->GetFullPath();
Elem e2(e1, "ClInclude");
@@ -1811,6 +1811,7 @@ void cmVisualStudio10TargetGenerator::WriteHeaderSource(Elem& e1,
e2.Element("DependentUpon",
fileName.substr(0, fileName.find_last_of(".")));
}
+ this->FinishWritingSource(e2, toolSettings);
}
void cmVisualStudio10TargetGenerator::ParseSettingsProperty(
@@ -1867,8 +1868,8 @@ bool cmVisualStudio10TargetGenerator::PropertyIsSameInAllConfigs(
return true;
}
-void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
- cmSourceFile const* sf)
+void cmVisualStudio10TargetGenerator::WriteExtraSource(
+ Elem& e1, cmSourceFile const* sf, ConfigToSettings& toolSettings)
{
bool toolHasSettings = false;
const char* tool = "None";
@@ -1879,10 +1880,6 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
std::string copyToOutDir;
std::string includeInVsix;
std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
- ConfigToSettings toolSettings;
- for (const auto& config : this->Configurations) {
- toolSettings[config];
- }
if (this->ProjectType == csproj && !this->InSourceBuild) {
toolHasSettings = true;
@@ -2050,10 +2047,6 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
}
}
- if (cmProp p = sf->GetProperty("VS_SETTINGS")) {
- ParseSettingsProperty(*p, toolSettings);
- }
-
if (!toolSettings.empty()) {
toolHasSettings = true;
}
@@ -2063,27 +2056,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
if (toolHasSettings) {
e2.SetHasElements();
- std::vector<std::string> writtenSettings;
- for (const auto& configSettings : toolSettings) {
- for (const auto& setting : configSettings.second) {
-
- if (std::find(writtenSettings.begin(), writtenSettings.end(),
- setting.first) != writtenSettings.end()) {
- continue;
- }
-
- if (PropertyIsSameInAllConfigs(toolSettings, setting.first)) {
- e2.Element(setting.first, setting.second);
- writtenSettings.push_back(setting.first);
- } else {
- e2.WritePlatformConfigTag(setting.first,
- "'$(Configuration)|$(Platform)'=='" +
- configSettings.first + "|" +
- this->Platform + "'",
- setting.second);
- }
- }
- }
+ this->FinishWritingSource(e2, toolSettings);
if (!deployContent.empty()) {
cmGeneratorExpression ge;
@@ -2220,6 +2193,15 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
// Skip explicit reference to CMakeLists.txt source.
continue;
}
+
+ ConfigToSettings toolSettings;
+ for (const auto& config : this->Configurations) {
+ toolSettings[config];
+ }
+ if (cmProp p = si.Source->GetProperty("VS_SETTINGS")) {
+ ParseSettingsProperty(*p, toolSettings);
+ }
+
const char* tool = nullptr;
switch (si.Kind) {
case cmGeneratorTarget::SourceKindAppManifest:
@@ -2247,10 +2229,10 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
}
break;
case cmGeneratorTarget::SourceKindExtra:
- this->WriteExtraSource(e1, si.Source);
+ this->WriteExtraSource(e1, si.Source, toolSettings);
break;
case cmGeneratorTarget::SourceKindHeader:
- this->WriteHeaderSource(e1, si.Source);
+ this->WriteHeaderSource(e1, si.Source, toolSettings);
break;
case cmGeneratorTarget::SourceKindIDL:
tool = "Midl";
@@ -2360,6 +2342,8 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
if (!isCSharp && !exclude_configs.empty()) {
this->WriteExcludeFromBuild(e2, exclude_configs);
}
+
+ this->FinishWritingSource(e2, toolSettings);
}
}
@@ -2368,6 +2352,32 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
}
}
+void cmVisualStudio10TargetGenerator::FinishWritingSource(
+ Elem& e2, ConfigToSettings const& toolSettings)
+{
+ std::vector<std::string> writtenSettings;
+ for (const auto& configSettings : toolSettings) {
+ for (const auto& setting : configSettings.second) {
+
+ if (std::find(writtenSettings.begin(), writtenSettings.end(),
+ setting.first) != writtenSettings.end()) {
+ continue;
+ }
+
+ if (PropertyIsSameInAllConfigs(toolSettings, setting.first)) {
+ e2.Element(setting.first, setting.second);
+ writtenSettings.push_back(setting.first);
+ } else {
+ e2.WritePlatformConfigTag(setting.first,
+ "'$(Configuration)|$(Platform)'=='" +
+ configSettings.first + "|" +
+ this->Platform + "'",
+ setting.second);
+ }
+ }
+ }
+}
+
void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
Elem& e2, cmSourceFile const* source)
{
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index 55c5444..a5ce5e5 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -58,6 +58,10 @@ private:
struct Elem;
struct OptionsHelper;
+ using ConfigToSettings =
+ std::unordered_map<std::string,
+ std::unordered_map<std::string, std::string>>;
+
std::string ConvertPath(std::string const& path, bool forceRelative);
std::string CalcCondition(const std::string& config) const;
void WriteProjectConfigurations(Elem& e0);
@@ -66,12 +70,15 @@ private:
void WriteCEDebugProjectConfigurationValues(Elem& e0);
void WriteMSToolConfigurationValuesManaged(Elem& e1,
std::string const& config);
- void WriteHeaderSource(Elem& e1, cmSourceFile const* sf);
- void WriteExtraSource(Elem& e1, cmSourceFile const* sf);
+ void WriteHeaderSource(Elem& e1, cmSourceFile const* sf,
+ ConfigToSettings const& toolSettings);
+ void WriteExtraSource(Elem& e1, cmSourceFile const* sf,
+ ConfigToSettings& toolSettings);
void WriteNsightTegraConfigurationValues(Elem& e1,
std::string const& config);
void WriteAndroidConfigurationValues(Elem& e1, std::string const& config);
void WriteSource(Elem& e2, cmSourceFile const* sf);
+ void FinishWritingSource(Elem& e2, ConfigToSettings const& toolSettings);
void WriteExcludeFromBuild(Elem& e2,
std::vector<size_t> const& exclude_configs);
void WriteAllSources(Elem& e0);
@@ -252,9 +259,6 @@ private:
void ClassifyAllConfigSources();
void ClassifyAllConfigSource(cmGeneratorTarget::AllConfigSource const& acs);
- using ConfigToSettings =
- std::unordered_map<std::string,
- std::unordered_map<std::string, std::string>>;
std::unordered_map<std::string, ConfigToSettings> ParsedToolTargetSettings;
bool PropertyIsSameInAllConfigs(const ConfigToSettings& toolSettings,
const std::string& propName);
diff --git a/Tests/RunCMake/VS10Project/VsSettings-check.cmake b/Tests/RunCMake/VS10Project/VsSettings-check.cmake
index 0f8b26c..13cc8e2 100644
--- a/Tests/RunCMake/VS10Project/VsSettings-check.cmake
+++ b/Tests/RunCMake/VS10Project/VsSettings-check.cmake
@@ -4,20 +4,29 @@ macro(ensure_props_set projectFile)
return()
endif()
- set(SettingFound FALSE)
+ set(Setting1Found FALSE)
+ set(Setting2Found FALSE)
file(STRINGS "${projectFile}" lines)
foreach(line IN LISTS lines)
if(line MATCHES "<SourceProperty1.*Debug.*>SourceProperty1Value</SourceProperty1>")
message("SourceProperty1 setting found")
- set(SettingFound TRUE)
+ set(Setting1Found TRUE)
+ endif()
+ if(line MATCHES "<SourceProperty2.*Debug.*>SourceProperty2Value</SourceProperty2>")
+ message("SourceProperty2 setting found")
+ set(Setting2Found TRUE)
endif()
endforeach()
- if (NOT SettingFound)
+ if (NOT Setting1Found)
set(RunCMake_TEST_FAILED "SourceProperty1 setting was not found")
return()
endif()
+ if (NOT Setting2Found)
+ set(RunCMake_TEST_FAILED "SourceProperty2 setting was not found")
+ return()
+ endif()
endmacro()
ensure_props_set("${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
diff --git a/Tests/RunCMake/VS10Project/VsSettings.cmake b/Tests/RunCMake/VS10Project/VsSettings.cmake
index a4b321b..3a046f1 100644
--- a/Tests/RunCMake/VS10Project/VsSettings.cmake
+++ b/Tests/RunCMake/VS10Project/VsSettings.cmake
@@ -3,3 +3,5 @@ enable_language(CXX)
add_library(foo foo.cpp shader.hlsl)
set_property(SOURCE shader.hlsl PROPERTY VS_SETTINGS
"$<$<CONFIG:DEBUG>:SourceProperty1=SourceProperty1Value>")
+set_property(SOURCE foo.cpp PROPERTY VS_SETTINGS
+ "$<$<CONFIG:DEBUG>:SourceProperty2=SourceProperty2Value>")