mirror of
https://github.com/reactos/CMake.git
synced 2024-12-05 02:06:34 +00:00
Merge topic 'vs_csharp_prop_for_all_extensions'
c90630c5
Vs: add support for VS_CSHARP_* target property for additional file extensions
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !961
This commit is contained in:
commit
f3ffd18ab6
@ -1595,6 +1595,10 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
|
||||
toolHasSettings = true;
|
||||
}
|
||||
|
||||
// Collect VS_CSHARP_* property values (if some are set)
|
||||
std::map<std::string, std::string> sourceFileTags;
|
||||
this->GetCSharpSourceProperties(sf, sourceFileTags);
|
||||
|
||||
if (this->NsightTegra) {
|
||||
// Nsight Tegra needs specific file types to check up-to-dateness.
|
||||
std::string name = cmSystemTools::LowerCase(sf->GetLocation().GetName());
|
||||
@ -1711,7 +1715,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
|
||||
(*this->BuildFileStream) << cmVS10EscapeXML(includeInVsix)
|
||||
<< "</IncludeInVSIX>\n";
|
||||
}
|
||||
|
||||
// write source file specific tags
|
||||
this->WriteCSharpSourceProperties(sourceFileTags);
|
||||
this->WriteString("</", 2);
|
||||
(*this->BuildFileStream) << tool << ">\n";
|
||||
} else {
|
||||
@ -2047,34 +2052,13 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
||||
sourceFileTags["Link"] = link;
|
||||
}
|
||||
}
|
||||
const cmPropertyMap& props = sf.GetProperties();
|
||||
for (cmPropertyMap::const_iterator p = props.begin(); p != props.end();
|
||||
++p) {
|
||||
static const std::string propNamePrefix = "VS_CSHARP_";
|
||||
if (p->first.find(propNamePrefix.c_str()) == 0) {
|
||||
std::string tagName = p->first.substr(propNamePrefix.length());
|
||||
if (!tagName.empty()) {
|
||||
const std::string val = props.GetPropertyValue(p->first);
|
||||
if (!val.empty()) {
|
||||
sourceFileTags[tagName] = val;
|
||||
} else {
|
||||
sourceFileTags.erase(tagName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this->GetCSharpSourceProperties(&sf, sourceFileTags);
|
||||
// write source file specific tags
|
||||
if (!sourceFileTags.empty()) {
|
||||
hasFlags = true;
|
||||
(*this->BuildFileStream) << firstString;
|
||||
firstString = "";
|
||||
for (CsPropMap::const_iterator i = sourceFileTags.begin();
|
||||
i != sourceFileTags.end(); ++i) {
|
||||
this->WriteString("<", 3);
|
||||
(*this->BuildFileStream)
|
||||
<< i->first << ">" << cmVS10EscapeXML(i->second) << "</" << i->first
|
||||
<< ">\n";
|
||||
}
|
||||
this->WriteCSharpSourceProperties(sourceFileTags);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4318,6 +4302,42 @@ bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
|
||||
return true;
|
||||
}
|
||||
|
||||
void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties(
|
||||
cmSourceFile const* sf, std::map<std::string, std::string>& tags)
|
||||
{
|
||||
if (csproj == this->ProjectType) {
|
||||
const cmPropertyMap& props = sf->GetProperties();
|
||||
for (cmPropertyMap::const_iterator p = props.begin(); p != props.end();
|
||||
++p) {
|
||||
static const std::string propNamePrefix = "VS_CSHARP_";
|
||||
if (p->first.find(propNamePrefix.c_str()) == 0) {
|
||||
std::string tagName = p->first.substr(propNamePrefix.length());
|
||||
if (!tagName.empty()) {
|
||||
const std::string val = props.GetPropertyValue(p->first);
|
||||
if (!val.empty()) {
|
||||
tags[tagName] = val;
|
||||
} else {
|
||||
tags.erase(tagName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmVisualStudio10TargetGenerator::WriteCSharpSourceProperties(
|
||||
const std::map<std::string, std::string>& tags)
|
||||
{
|
||||
if (!tags.empty()) {
|
||||
for (std::map<std::string, std::string>::const_iterator i = tags.begin();
|
||||
i != tags.end(); ++i) {
|
||||
this->WriteString("<", 3);
|
||||
(*this->BuildFileStream) << i->first << ">" << cmVS10EscapeXML(i->second)
|
||||
<< "</" << i->first << ">\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath(
|
||||
const char* relativeFilePath) const
|
||||
{
|
||||
|
@ -154,6 +154,11 @@ private:
|
||||
|
||||
bool ForceOld(const std::string& source) const;
|
||||
|
||||
void GetCSharpSourceProperties(cmSourceFile const* sf,
|
||||
std::map<std::string, std::string>& tags);
|
||||
void WriteCSharpSourceProperties(
|
||||
const std::map<std::string, std::string>& tags);
|
||||
|
||||
private:
|
||||
typedef cmVisualStudioGeneratorOptions Options;
|
||||
typedef std::map<std::string, Options*> OptionsMap;
|
||||
|
@ -4,20 +4,31 @@ if(NOT EXISTS "${csProjectFile}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(tagFound FALSE)
|
||||
# test VS_CSHARP_* for the following extensions
|
||||
set(fileExtensions
|
||||
"cs"
|
||||
"png"
|
||||
"jpg"
|
||||
"xml"
|
||||
"settings")
|
||||
|
||||
#
|
||||
set(tagName "MyCustomTag")
|
||||
set(tagValue "MyCustomValue")
|
||||
|
||||
file(STRINGS "${csProjectFile}" lines)
|
||||
foreach(line IN LISTS lines)
|
||||
if(line MATCHES "^ *<${tagName}>${tagValue}</${tagName}>")
|
||||
message(STATUS "foo.csproj has tag ${tagName} with value ${tagValue} defined")
|
||||
set(tagFound TRUE)
|
||||
|
||||
foreach(e ${fileExtensions})
|
||||
string(TOUPPER ${e} eUC)
|
||||
set(tagFound FALSE)
|
||||
foreach(line IN LISTS lines)
|
||||
if(line MATCHES "^ *<${tagName}${eUC}>${tagValue}${eUC}</${tagName}${eUC}>")
|
||||
message(STATUS "foo.csproj has tag ${tagName}${eUC} with value ${tagValue}${eUC} defined")
|
||||
set(tagFound TRUE)
|
||||
endif()
|
||||
endforeach()
|
||||
if(NOT tagFound)
|
||||
set(RunCMake_TEST_FAILED "Source file tag ${tagName}${eUC} with value ${tagValue}${eUC} not found.")
|
||||
return()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT tagFound)
|
||||
set(RunCMake_TEST_FAILED "Source file tag ${tagName} with value ${tagValue} not found.")
|
||||
return()
|
||||
endif()
|
||||
|
@ -1,11 +1,27 @@
|
||||
enable_language(CSharp)
|
||||
add_library(foo foo.cs)
|
||||
|
||||
set(props_file "${CMAKE_CURRENT_SOURCE_DIR}/my.props")
|
||||
# test VS_CSHARP_* for the following extensions
|
||||
set(fileExtensions
|
||||
"cs"
|
||||
"png"
|
||||
"jpg"
|
||||
"xml"
|
||||
"settings")
|
||||
|
||||
#
|
||||
set(tagName "MyCustomTag")
|
||||
set(tagValue "MyCustomValue")
|
||||
|
||||
set_source_files_properties(foo.cs
|
||||
PROPERTIES
|
||||
VS_CSHARP_${tagName} "${tagValue}")
|
||||
set(fileNames)
|
||||
foreach(e ${fileExtensions})
|
||||
set(currentFile "${CMAKE_CURRENT_BINARY_DIR}/foo.${e}")
|
||||
list(APPEND fileNames ${currentFile})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E touch
|
||||
"${currentFile}")
|
||||
string(TOUPPER ${e} eUC)
|
||||
set_source_files_properties("${currentFile}"
|
||||
PROPERTIES
|
||||
VS_CSHARP_${tagName}${eUC} "${tagValue}${eUC}")
|
||||
endforeach()
|
||||
|
||||
add_library(foo ${fileNames})
|
||||
|
Loading…
Reference in New Issue
Block a user