diff options
Diffstat (limited to 'Source/cmVisualStudio10TargetGenerator.cxx')
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 215 |
1 files changed, 135 insertions, 80 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 965ac3e..e7ef7ea 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -490,15 +490,12 @@ void cmVisualStudio10TargetGenerator::Generate() e1.Element("Platform", this->Platform); cmProp projLabel = this->GeneratorTarget->GetProperty("PROJECT_LABEL"); - if (!projLabel) { - projLabel = &this->Name; - } - e1.Element("ProjectName", *projLabel); + e1.Element("ProjectName", projLabel ? projLabel : this->Name); { cmProp targetFramework = this->GeneratorTarget->GetProperty("DOTNET_TARGET_FRAMEWORK"); if (targetFramework) { - if (std::strchr(targetFramework->c_str(), ';') != nullptr) { + if (targetFramework->find(';') != std::string::npos) { e1.Element("TargetFrameworks", *targetFramework); } else { e1.Element("TargetFramework", *targetFramework); @@ -511,15 +508,15 @@ void cmVisualStudio10TargetGenerator::Generate() p = this->GeneratorTarget->GetProperty( "DOTNET_TARGET_FRAMEWORK_VERSION"); } - const char* targetFrameworkVersion = cmToCStr(p); - if (!targetFrameworkVersion && this->ProjectType == csproj && + std::string targetFrameworkVersion = p; + if (targetFrameworkVersion.empty() && this->ProjectType == csproj && this->GlobalGenerator->TargetsWindowsCE() && this->GlobalGenerator->GetVersion() == cmGlobalVisualStudioGenerator::VS12) { // VS12 .NETCF default to .NET framework 3.9 targetFrameworkVersion = "v3.9"; } - if (targetFrameworkVersion) { + if (!targetFrameworkVersion.empty()) { e1.Element("TargetFrameworkVersion", targetFrameworkVersion); } } @@ -545,7 +542,7 @@ void cmVisualStudio10TargetGenerator::Generate() e1.Element( "CudaToolkitCustomDir", this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString() + - "nvcc"); + this->GlobalGenerator->GetPlatformToolsetCudaNvccSubdirString()); } } @@ -581,6 +578,10 @@ void cmVisualStudio10TargetGenerator::Generate() } if (this->Managed) { + if (this->LocalGenerator->GetVersion() >= + cmGlobalVisualStudioGenerator::VS17) { + e1.Element("ManagedAssembly", "true"); + } std::string outputType; switch (this->GeneratorTarget->GetType()) { case cmStateEnums::OBJECT_LIBRARY: @@ -654,8 +655,9 @@ void cmVisualStudio10TargetGenerator::Generate() std::string cudaPath = customDir.empty() ? "$(VCTargetsPath)\\BuildCustomizations\\" : customDir + - "CUDAVisualStudioIntegration\\extras\\" - "visual_studio_integration\\MSBuildExtensions\\"; + this->GlobalGenerator + ->GetPlatformToolsetCudaVSIntegrationSubdirString() + + "extras\\visual_studio_integration\\MSBuildExtensions\\"; Elem(e1, "Import") .Attribute("Project", std::move(cudaPath) + "CUDA " + @@ -747,8 +749,9 @@ void cmVisualStudio10TargetGenerator::Generate() std::string cudaPath = customDir.empty() ? "$(VCTargetsPath)\\BuildCustomizations\\" : customDir + - "CUDAVisualStudioIntegration\\extras\\" - "visual_studio_integration\\MSBuildExtensions\\"; + this->GlobalGenerator + ->GetPlatformToolsetCudaVSIntegrationSubdirString() + + "extras\\visual_studio_integration\\MSBuildExtensions\\"; Elem(e1, "Import") .Attribute("Project", std::move(cudaPath) + "CUDA " + @@ -766,6 +769,11 @@ void cmVisualStudio10TargetGenerator::Generate() Elem(e1, "Import").Attribute("Project", nasmTargets); } } + if (this->ProjectType == vcxproj && this->HaveCustomCommandDepfile) { + std::string depfileTargets = + GetCMakeFilePath("Templates/MSBuild/CustomBuildDepFile.targets"); + Elem(e0, "Import").Attribute("Project", depfileTargets); + } if (this->ProjectType == csproj) { for (std::string const& c : this->Configurations) { Elem e1(e0, "PropertyGroup"); @@ -1458,10 +1466,13 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( e2.SetHasElements(); } for (std::string const& c : this->Configurations) { - cmCustomCommandGenerator ccg(command, c, lg); + cmCustomCommandGenerator ccg(command, c, lg, true); std::string comment = lg->ConstructComment(ccg); comment = cmVS10EscapeComment(comment); - std::string script = lg->ConstructScript(ccg); + cmLocalVisualStudioGenerator::IsManaged isManaged = (this->Managed) + ? cmLocalVisualStudioGenerator::managed + : cmLocalVisualStudioGenerator::unmanaged; + std::string script = lg->ConstructScript(ccg, isManaged); bool symbolic = false; // input files for custom command std::stringstream additional_inputs; @@ -1522,10 +1533,10 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( std::string name = "CustomCommand_" + c + "_" + cmSystemTools::ComputeStringMD5(sourcePath); this->WriteCustomRuleCSharp(e0, c, name, script, additional_inputs.str(), - outputs.str(), comment); + outputs.str(), comment, ccg); } else { this->WriteCustomRuleCpp(*spe2, c, script, additional_inputs.str(), - outputs.str(), comment, symbolic); + outputs.str(), comment, ccg, symbolic); } } } @@ -1533,7 +1544,8 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp( Elem& e2, std::string const& config, std::string const& script, std::string const& additional_inputs, std::string const& outputs, - std::string const& comment, bool symbolic) + std::string const& comment, cmCustomCommandGenerator const& ccg, + bool symbolic) { const std::string cond = this->CalcCondition(config); e2.WritePlatformConfigTag("Message", cond, comment); @@ -1552,13 +1564,29 @@ void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp( // outputs is marked SYMBOLIC and not expected to be created. e2.WritePlatformConfigTag("VerifyInputsAndOutputsExist", cond, "false"); } + + std::string depfile = ccg.GetFullDepfile(); + if (!depfile.empty()) { + this->HaveCustomCommandDepfile = true; + std::string internal_depfile = ccg.GetInternalDepfile(); + ConvertToWindowsSlash(internal_depfile); + e2.WritePlatformConfigTag("DepFileAdditionalInputsFile", cond, + internal_depfile); + } } void cmVisualStudio10TargetGenerator::WriteCustomRuleCSharp( Elem& e0, std::string const& config, std::string const& name, std::string const& script, std::string const& inputs, - std::string const& outputs, std::string const& comment) + std::string const& outputs, std::string const& comment, + cmCustomCommandGenerator const& ccg) { + if (!ccg.GetFullDepfile().empty()) { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("CSharp target \"", this->GeneratorTarget->GetName(), + "\" does not support add_custom_command DEPFILE.")); + } this->CSharpCustomCommandNames.insert(name); Elem e1(e0, "Target"); e1.Attribute("Condition", this->CalcCondition(config)); @@ -1775,8 +1803,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"); @@ -1787,6 +1815,7 @@ void cmVisualStudio10TargetGenerator::WriteHeaderSource(Elem& e1, e2.Element("DependentUpon", fileName.substr(0, fileName.find_last_of("."))); } + this->FinishWritingSource(e2, toolSettings); } void cmVisualStudio10TargetGenerator::ParseSettingsProperty( @@ -1843,8 +1872,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"; @@ -1855,10 +1884,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; @@ -2026,10 +2051,6 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1, } } - if (cmProp p = sf->GetProperty("VS_SETTINGS")) { - ParseSettingsProperty(*p, toolSettings); - } - if (!toolSettings.empty()) { toolHasSettings = true; } @@ -2039,27 +2060,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; @@ -2196,6 +2197,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: @@ -2223,10 +2233,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"; @@ -2275,6 +2285,20 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) std::back_inserter(exclude_configs)); Elem e2(e1, tool); + bool isCSharp = (si.Source->GetLanguage() == "CSharp"); + if (isCSharp && exclude_configs.size() > 0) { + std::stringstream conditions; + bool firstConditionSet{ false }; + for (const auto& ci : include_configs) { + if (firstConditionSet) { + conditions << " Or "; + } + conditions << "('$(Configuration)|$(Platform)'=='" + + this->Configurations[ci] + "|" + this->Platform + "')"; + firstConditionSet = true; + } + e2.Attribute("Condition", conditions.str()); + } this->WriteSource(e2, si.Source); bool useNativeUnityBuild = false; @@ -2319,9 +2343,11 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) if (si.Source->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) { e2.Element("PrecompiledHeader", "NotUsing"); } - if (!exclude_configs.empty()) { + if (!isCSharp && !exclude_configs.empty()) { this->WriteExcludeFromBuild(e2, exclude_configs); } + + this->FinishWritingSource(e2, toolSettings); } } @@ -2330,6 +2356,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) { @@ -3340,8 +3392,6 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( // cmLinkLineDeviceComputer cmComputeLinkInformation& cli = *pcli; std::vector<std::string> libVec; - const std::string currentBinDir = - this->LocalGenerator->GetCurrentBinaryDirectory(); const auto& libs = cli.GetItems(); for (cmComputeLinkInformation::Item const& l : libs) { @@ -3377,9 +3427,9 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( } } - if (l.IsPath) { - std::string path = this->LocalGenerator->MaybeConvertToRelativePath( - currentBinDir, l.Value.Value); + if (l.IsPath == cmComputeLinkInformation::ItemIsPath::Yes) { + std::string path = + this->LocalGenerator->MaybeRelativeToCurBinDir(l.Value.Value); ConvertToWindowsSlash(path); if (!cmVS10IsTargetsFile(l.Value.Value)) { libVec.push_back(path); @@ -3507,8 +3557,6 @@ void cmVisualStudio10TargetGenerator::WriteNasmOptions( } Elem e2(e1, "NASM"); - std::vector<std::string> includes = - this->GetIncludes(configName, "ASM_NASM"); OptionsHelper nasmOptions(*(this->NasmOptions[configName]), e2); nasmOptions.OutputAdditionalIncludeDirectories("ASM_NASM"); nasmOptions.OutputFlagMap(); @@ -3930,12 +3978,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions( cmComputeLinkInformation& cli = *pcli; using ItemVector = cmComputeLinkInformation::ItemVector; const ItemVector& libs = cli.GetItems(); - std::string currentBinDir = - this->LocalGenerator->GetCurrentBinaryDirectory(); for (cmComputeLinkInformation::Item const& l : libs) { - if (l.IsPath && cmVS10IsTargetsFile(l.Value.Value)) { - std::string path = this->LocalGenerator->MaybeConvertToRelativePath( - currentBinDir, l.Value.Value); + if (l.IsPath == cmComputeLinkInformation::ItemIsPath::Yes && + cmVS10IsTargetsFile(l.Value.Value)) { + std::string path = + this->LocalGenerator->MaybeRelativeToCurBinDir(l.Value.Value); ConvertToWindowsSlash(path); this->AddTargetsFileAndConfigPair(path, config); } @@ -3975,8 +4022,6 @@ void cmVisualStudio10TargetGenerator::AddLibraries( { using ItemVector = cmComputeLinkInformation::ItemVector; ItemVector const& libs = cli.GetItems(); - std::string currentBinDir = - this->LocalGenerator->GetCurrentBinaryDirectory(); for (cmComputeLinkInformation::Item const& l : libs) { if (l.Target) { auto managedType = l.Target->GetManagedType(config); @@ -4018,9 +4063,9 @@ void cmVisualStudio10TargetGenerator::AddLibraries( } } - if (l.IsPath) { - std::string path = this->LocalGenerator->MaybeConvertToRelativePath( - currentBinDir, l.Value.Value); + if (l.IsPath == cmComputeLinkInformation::ItemIsPath::Yes) { + std::string path = + this->LocalGenerator->MaybeRelativeToCurBinDir(l.Value.Value); ConvertToWindowsSlash(path); if (cmVS10IsTargetsFile(l.Value.Value)) { vsTargetVec.push_back(path); @@ -4060,6 +4105,9 @@ void cmVisualStudio10TargetGenerator::WriteMidlOptions( if (this->ProjectType == csproj) { return; } + if (this->GeneratorTarget->GetType() > cmStateEnums::UTILITY) { + return; + } // This processes *any* of the .idl files specified in the project's file // list (and passed as the item metadata %(Filename) expressing the rule @@ -4174,7 +4222,10 @@ void cmVisualStudio10TargetGenerator::WriteEvent( comment += lg->ConstructComment(ccg); script += pre; pre = "\n"; - script += lg->ConstructScript(ccg); + cmLocalVisualStudioGenerator::IsManaged isManaged = (this->Managed) + ? cmLocalVisualStudioGenerator::managed + : cmLocalVisualStudioGenerator::unmanaged; + script += lg->ConstructScript(ccg, isManaged); stdPipesUTF8 = stdPipesUTF8 || cc.GetStdPipesUTF8(); } @@ -4237,11 +4288,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0) if (dt->IsCSharpOnly() || cmHasLiteralSuffix(path, "csproj")) { e2.Element("SkipGetTargetFrameworkProperties", "true"); } - // Don't reference targets that don't produce any output. - if (this->Configurations.empty() || - dt->GetManagedType(this->Configurations[0]) == - cmGeneratorTarget::ManagedType::Undefined) { + else if (this->Configurations.empty() || + dt->GetManagedType(this->Configurations[0]) == + cmGeneratorTarget::ManagedType::Undefined) { e2.Element("ReferenceOutputAssembly", "false"); e2.Element("CopyToOutputDirectory", "Never"); } @@ -5035,7 +5085,9 @@ std::string cmVisualStudio10TargetGenerator::GetCSharpSourceLink( { // For out of source files, we first check if a matching source group // for this file exists, otherwise we check if the path relative to current - // source- or binary-dir is used within the link and return that + // source- or binary-dir is used within the link and return that. + // In case of .cs files we can't do that automatically for files in the + // binary directory, because this leads to compilation errors. std::string link; std::string sourceGroupedFile; std::string const& fullFileName = source->GetFullPath(); @@ -5057,7 +5109,8 @@ std::string cmVisualStudio10TargetGenerator::GetCSharpSourceLink( link = sourceGroupedFile; } else if (cmHasPrefix(fullFileName, srcDir)) { link = fullFileName.substr(srcDir.length() + 1); - } else if (cmHasPrefix(fullFileName, binDir)) { + } else if (!cmHasSuffix(fullFileName, ".cs") && + cmHasPrefix(fullFileName, binDir)) { link = fullFileName.substr(binDir.length() + 1); } else if (cmProp l = source->GetProperty("VS_CSHARP_Link")) { link = *l; @@ -5080,7 +5133,9 @@ std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath( void cmVisualStudio10TargetGenerator::WriteStdOutEncodingUtf8(Elem& e1) { - if (this->GlobalGenerator->IsStdOutEncodingSupported()) { + if (this->GlobalGenerator->IsUtf8EncodingSupported()) { + e1.Element("UseUtf8Encoding", "Always"); + } else if (this->GlobalGenerator->IsStdOutEncodingSupported()) { e1.Element("StdOutEncoding", "UTF-8"); } } |