VS: Use unordered_map to write HLSL settings.
This commit is contained in:
parent
863b0fa2ac
commit
53116d3942
@ -1754,20 +1754,37 @@ void cmVisualStudio10TargetGenerator::WriteHeaderSource(Elem& e1,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmVisualStudio10TargetGenerator::cmPropertyIsSameInAllConfigs(
|
||||||
|
const ConfigToSettings& toolSettings, const std::string& propName)
|
||||||
|
{
|
||||||
|
std::string firstPropValue = "";
|
||||||
|
for (const auto& configToSettings : toolSettings) {
|
||||||
|
const std::unordered_map<std::string, std::string>& settings =
|
||||||
|
configToSettings.second;
|
||||||
|
|
||||||
|
if (firstPropValue.empty()) {
|
||||||
|
if (settings.find(propName) != settings.end()) {
|
||||||
|
firstPropValue = settings.find(propName)->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.find(propName) == settings.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.find(propName)->second != firstPropValue) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
|
void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
|
||||||
cmSourceFile const* sf)
|
cmSourceFile const* sf)
|
||||||
{
|
{
|
||||||
bool toolHasSettings = false;
|
bool toolHasSettings = false;
|
||||||
const char* tool = "None";
|
const char* tool = "None";
|
||||||
std::string shaderType;
|
|
||||||
std::string shaderEntryPoint;
|
|
||||||
std::string shaderModel;
|
|
||||||
std::string shaderAdditionalFlags;
|
|
||||||
std::string shaderDisableOptimizations;
|
|
||||||
std::string shaderEnableDebug;
|
|
||||||
std::string shaderObjectFileName;
|
|
||||||
std::string outputHeaderFile;
|
|
||||||
std::string variableName;
|
|
||||||
std::string settingsGenerator;
|
std::string settingsGenerator;
|
||||||
std::string settingsLastGenOutput;
|
std::string settingsLastGenOutput;
|
||||||
std::string sourceLink;
|
std::string sourceLink;
|
||||||
@ -1775,6 +1792,11 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
|
|||||||
std::string copyToOutDir;
|
std::string copyToOutDir;
|
||||||
std::string includeInVsix;
|
std::string includeInVsix;
|
||||||
std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
|
std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
|
||||||
|
ConfigToSettings toolSettings;
|
||||||
|
for (const auto& config : this->Configurations) {
|
||||||
|
toolSettings[config];
|
||||||
|
}
|
||||||
|
|
||||||
if (this->ProjectType == csproj && !this->InSourceBuild) {
|
if (this->ProjectType == csproj && !this->InSourceBuild) {
|
||||||
toolHasSettings = true;
|
toolHasSettings = true;
|
||||||
}
|
}
|
||||||
@ -1782,47 +1804,72 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
|
|||||||
tool = "FXCompile";
|
tool = "FXCompile";
|
||||||
// Figure out the type of shader compiler to use.
|
// Figure out the type of shader compiler to use.
|
||||||
if (const char* st = sf->GetProperty("VS_SHADER_TYPE")) {
|
if (const char* st = sf->GetProperty("VS_SHADER_TYPE")) {
|
||||||
shaderType = st;
|
for (const std::string& config : this->Configurations) {
|
||||||
toolHasSettings = true;
|
toolSettings[config]["ShaderType"] = st;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Figure out which entry point to use if any
|
// Figure out which entry point to use if any
|
||||||
if (const char* se = sf->GetProperty("VS_SHADER_ENTRYPOINT")) {
|
if (const char* se = sf->GetProperty("VS_SHADER_ENTRYPOINT")) {
|
||||||
shaderEntryPoint = se;
|
for (const std::string& config : this->Configurations) {
|
||||||
toolHasSettings = true;
|
toolSettings[config]["EntryPointName"] = se;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Figure out which shader model to use if any
|
// Figure out which shader model to use if any
|
||||||
if (const char* sm = sf->GetProperty("VS_SHADER_MODEL")) {
|
if (const char* sm = sf->GetProperty("VS_SHADER_MODEL")) {
|
||||||
shaderModel = sm;
|
for (const std::string& config : this->Configurations) {
|
||||||
toolHasSettings = true;
|
toolSettings[config]["ShaderModel"] = sm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Figure out which output header file to use if any
|
// Figure out which output header file to use if any
|
||||||
if (const char* ohf = sf->GetProperty("VS_SHADER_OUTPUT_HEADER_FILE")) {
|
if (const char* ohf = sf->GetProperty("VS_SHADER_OUTPUT_HEADER_FILE")) {
|
||||||
outputHeaderFile = ohf;
|
for (const std::string& config : this->Configurations) {
|
||||||
toolHasSettings = true;
|
toolSettings[config]["HeaderFileOutput"] = ohf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Figure out which variable name to use if any
|
// Figure out which variable name to use if any
|
||||||
if (const char* vn = sf->GetProperty("VS_SHADER_VARIABLE_NAME")) {
|
if (const char* vn = sf->GetProperty("VS_SHADER_VARIABLE_NAME")) {
|
||||||
variableName = vn;
|
for (const std::string& config : this->Configurations) {
|
||||||
toolHasSettings = true;
|
toolSettings[config]["VariableName"] = vn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Figure out if there's any additional flags to use
|
// Figure out if there's any additional flags to use
|
||||||
if (const char* saf = sf->GetProperty("VS_SHADER_FLAGS")) {
|
if (const char* saf = sf->GetProperty("VS_SHADER_FLAGS")) {
|
||||||
shaderAdditionalFlags = saf;
|
for (const std::string& config : this->Configurations) {
|
||||||
toolHasSettings = true;
|
toolSettings[config]["AdditionalOptions"] = saf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Figure out if debug information should be generated
|
// Figure out if debug information should be generated
|
||||||
if (const char* sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) {
|
if (const char* sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) {
|
||||||
shaderEnableDebug = sed;
|
cmGeneratorExpression ge;
|
||||||
toolHasSettings = true;
|
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(sed);
|
||||||
|
|
||||||
|
for (const std::string& config : this->Configurations) {
|
||||||
|
std::string evaluated = cge->Evaluate(this->LocalGenerator, config);
|
||||||
|
|
||||||
|
if (!evaluated.empty()) {
|
||||||
|
toolSettings[config]["EnableDebuggingInformation"] =
|
||||||
|
cmIsOn(evaluated) ? "true" : "false";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Figure out if optimizations should be disabled
|
// Figure out if optimizations should be disabled
|
||||||
if (const char* sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) {
|
if (const char* sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) {
|
||||||
shaderDisableOptimizations = sdo;
|
cmGeneratorExpression ge;
|
||||||
toolHasSettings = true;
|
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(sdo);
|
||||||
|
|
||||||
|
for (const std::string& config : this->Configurations) {
|
||||||
|
std::string evaluated = cge->Evaluate(this->LocalGenerator, config);
|
||||||
|
|
||||||
|
if (!evaluated.empty()) {
|
||||||
|
toolSettings[config]["DisableOptimizations"] =
|
||||||
|
cmIsOn(evaluated) ? "true" : "false";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (const char* sofn = sf->GetProperty("VS_SHADER_OBJECT_FILE_NAME")) {
|
if (const char* sofn = sf->GetProperty("VS_SHADER_OBJECT_FILE_NAME")) {
|
||||||
shaderObjectFileName = sofn;
|
for (const std::string& config : this->Configurations) {
|
||||||
toolHasSettings = true;
|
toolSettings[config]["ObjectFileOutput"] = sofn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (ext == "jpg" || ext == "png") {
|
} else if (ext == "jpg" || ext == "png") {
|
||||||
tool = "Image";
|
tool = "Image";
|
||||||
@ -1892,11 +1939,37 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!toolSettings.empty()) {
|
||||||
|
toolHasSettings = true;
|
||||||
|
}
|
||||||
|
|
||||||
Elem e2(e1, tool);
|
Elem e2(e1, tool);
|
||||||
this->WriteSource(e2, sf);
|
this->WriteSource(e2, sf);
|
||||||
if (toolHasSettings) {
|
if (toolHasSettings) {
|
||||||
e2.SetHasElements();
|
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 (cmPropertyIsSameInAllConfigs(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!deployContent.empty()) {
|
if (!deployContent.empty()) {
|
||||||
cmGeneratorExpression ge;
|
cmGeneratorExpression ge;
|
||||||
std::unique_ptr<cmCompiledGeneratorExpression> cge =
|
std::unique_ptr<cmCompiledGeneratorExpression> cge =
|
||||||
@ -1922,73 +1995,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!shaderType.empty()) {
|
|
||||||
e2.Element("ShaderType", shaderType);
|
|
||||||
}
|
|
||||||
if (!shaderEntryPoint.empty()) {
|
|
||||||
e2.Element("EntryPointName", shaderEntryPoint);
|
|
||||||
}
|
|
||||||
if (!shaderModel.empty()) {
|
|
||||||
e2.Element("ShaderModel", shaderModel);
|
|
||||||
}
|
|
||||||
if (!outputHeaderFile.empty()) {
|
|
||||||
for (size_t i = 0; i != this->Configurations.size(); ++i) {
|
|
||||||
e2.WritePlatformConfigTag("HeaderFileOutput",
|
|
||||||
"'$(Configuration)|$(Platform)'=='" +
|
|
||||||
this->Configurations[i] + "|" +
|
|
||||||
this->Platform + "'",
|
|
||||||
outputHeaderFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!variableName.empty()) {
|
|
||||||
for (size_t i = 0; i != this->Configurations.size(); ++i) {
|
|
||||||
e2.WritePlatformConfigTag("VariableName",
|
|
||||||
"'$(Configuration)|$(Platform)'=='" +
|
|
||||||
this->Configurations[i] + "|" +
|
|
||||||
this->Platform + "'",
|
|
||||||
variableName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!shaderEnableDebug.empty()) {
|
|
||||||
cmGeneratorExpression ge;
|
|
||||||
std::unique_ptr<cmCompiledGeneratorExpression> cge =
|
|
||||||
ge.Parse(shaderEnableDebug);
|
|
||||||
|
|
||||||
for (size_t i = 0; i != this->Configurations.size(); ++i) {
|
|
||||||
const std::string& enableDebug =
|
|
||||||
cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
|
|
||||||
if (!enableDebug.empty()) {
|
|
||||||
e2.WritePlatformConfigTag("EnableDebuggingInformation",
|
|
||||||
"'$(Configuration)|$(Platform)'=='" +
|
|
||||||
this->Configurations[i] + "|" +
|
|
||||||
this->Platform + "'",
|
|
||||||
cmIsOn(enableDebug) ? "true" : "false");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!shaderDisableOptimizations.empty()) {
|
|
||||||
cmGeneratorExpression ge;
|
|
||||||
std::unique_ptr<cmCompiledGeneratorExpression> cge =
|
|
||||||
ge.Parse(shaderDisableOptimizations);
|
|
||||||
|
|
||||||
for (size_t i = 0; i != this->Configurations.size(); ++i) {
|
|
||||||
const std::string& disableOptimizations =
|
|
||||||
cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
|
|
||||||
if (!disableOptimizations.empty()) {
|
|
||||||
e2.WritePlatformConfigTag(
|
|
||||||
"DisableOptimizations",
|
|
||||||
"'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
|
|
||||||
"|" + this->Platform + "'",
|
|
||||||
(cmIsOn(disableOptimizations) ? "true" : "false"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!shaderObjectFileName.empty()) {
|
|
||||||
e2.Element("ObjectFileOutput", shaderObjectFileName);
|
|
||||||
}
|
|
||||||
if (!shaderAdditionalFlags.empty()) {
|
|
||||||
e2.Element("AdditionalOptions", shaderAdditionalFlags);
|
|
||||||
}
|
|
||||||
if (!settingsGenerator.empty()) {
|
if (!settingsGenerator.empty()) {
|
||||||
e2.Element("Generator", settingsGenerator);
|
e2.Element("Generator", settingsGenerator);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class cmComputeLinkInformation;
|
class cmComputeLinkInformation;
|
||||||
@ -236,6 +237,12 @@ private:
|
|||||||
|
|
||||||
using ToolSourceMap = std::map<std::string, ToolSources>;
|
using ToolSourceMap = std::map<std::string, ToolSources>;
|
||||||
ToolSourceMap Tools;
|
ToolSourceMap Tools;
|
||||||
|
|
||||||
|
using ConfigToSettings =
|
||||||
|
std::unordered_map<std::string,
|
||||||
|
std::unordered_map<std::string, std::string>>;
|
||||||
|
bool cmPropertyIsSameInAllConfigs(const ConfigToSettings& toolSettings,
|
||||||
|
const std::string& propName);
|
||||||
std::string GetCMakeFilePath(const char* name) const;
|
std::string GetCMakeFilePath(const char* name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user