diff options
Diffstat (limited to 'Source/cmVisualStudio10TargetGenerator.cxx')
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 428 |
1 files changed, 281 insertions, 147 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 7a90176..d28905a 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -19,9 +19,10 @@ #include "windows.h" #include <iterator> -#include <memory> // IWYU pragma: keep #include <set> +#include <cm/memory> + static void ConvertToWindowsSlash(std::string& s); static std::string cmVS10EscapeXML(std::string arg) @@ -120,7 +121,7 @@ struct cmVisualStudio10TargetGenerator::Elem class cmVS10GeneratorOptions : public cmVisualStudioGeneratorOptions { public: - typedef cmVisualStudio10TargetGenerator::Elem Elem; + using Elem = cmVisualStudio10TargetGenerator::Elem; cmVS10GeneratorOptions(cmLocalVisualStudioGenerator* lg, Tool tool, cmVS7FlagTable const* table, cmVisualStudio10TargetGenerator* g = nullptr) @@ -248,6 +249,9 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() == this->Makefile->GetCurrentBinaryDirectory()); + + this->LocalGenerator->AddUnityBuild(target, ""); + this->LocalGenerator->AddPchDependencies(target, ""); } cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() @@ -363,10 +367,9 @@ void cmVisualStudio10TargetGenerator::Generate() return; } } - std::string path = this->LocalGenerator->GetCurrentBinaryDirectory(); - path += "/"; - path += this->Name; - path += ProjectFileExtension; + std::string path = + cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/', + this->Name, ProjectFileExtension); cmGeneratedFileStream BuildFileStream(path); const std::string PathToProjectFile = path; BuildFileStream.SetCopyIfDifferent(true); @@ -505,6 +508,11 @@ void cmVisualStudio10TargetGenerator::Generate() if (targetFrameworkVersion) { e1.Element("TargetFrameworkVersion", targetFrameworkVersion); } + if (this->ProjectType == vcxproj && + this->GlobalGenerator->TargetsWindowsCE()) { + e1.Element("EnableRedirectPlatform", "true"); + e1.Element("RedirectPlatformValue", this->Platform); + } if (this->ProjectType == csproj && this->GlobalGenerator->TargetsWindowsCE()) { const char* targetFrameworkId = this->GeneratorTarget->GetProperty( @@ -520,6 +528,13 @@ void cmVisualStudio10TargetGenerator::Generate() } e1.Element("TargetFrameworkTargetsVersion", targetFrameworkVer); } + if (!this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString() + .empty()) { + e1.Element( + "CudaToolkitCustomDir", + this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString() + + "nvcc"); + } } // Disable the project upgrade prompt that is displayed the first time a @@ -606,10 +621,17 @@ void cmVisualStudio10TargetGenerator::Generate() e1.SetHasElements(); if (this->GlobalGenerator->IsCudaEnabled()) { + auto customDir = + this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString(); + std::string cudaPath = customDir.empty() + ? "$(VCTargetsPath)\\BuildCustomizations\\" + : customDir + + "CUDAVisualStudioIntegration\\extras\\" + "visual_studio_integration\\MSBuildExtensions\\"; Elem(e1, "Import") .Attribute("Project", - "$(VCTargetsPath)\\BuildCustomizations\\CUDA " + - this->GlobalGenerator->GetPlatformToolsetCudaString() + + std::move(cudaPath) + "CUDA " + + this->GlobalGenerator->GetPlatformToolsetCuda() + ".props"); } if (this->GlobalGenerator->IsMasmEnabled()) { @@ -622,9 +644,8 @@ void cmVisualStudio10TargetGenerator::Generate() std::string propsTemplate = GetCMakeFilePath("Templates/MSBuild/nasm.props.in"); - std::string propsLocal; - propsLocal += this->DefaultArtifactDir; - propsLocal += "\\nasm.props"; + std::string propsLocal = + cmStrCat(this->DefaultArtifactDir, "\\nasm.props"); ConvertToWindowsSlash(propsLocal); this->Makefile->ConfigureFile(propsTemplate, propsLocal, false, true, true); @@ -692,10 +713,17 @@ void cmVisualStudio10TargetGenerator::Generate() e1.SetHasElements(); this->WriteTargetsFileReferences(e1); if (this->GlobalGenerator->IsCudaEnabled()) { + auto customDir = + this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString(); + std::string cudaPath = customDir.empty() + ? "$(VCTargetsPath)\\BuildCustomizations\\" + : customDir + + "CUDAVisualStudioIntegration\\extras\\" + "visual_studio_integration\\MSBuildExtensions\\"; Elem(e1, "Import") .Attribute("Project", - "$(VCTargetsPath)\\BuildCustomizations\\CUDA " + - this->GlobalGenerator->GetPlatformToolsetCudaString() + + std::move(cudaPath) + "CUDA " + + this->GlobalGenerator->GetPlatformToolsetCuda() + ".targets"); } if (this->GlobalGenerator->IsMasmEnabled()) { @@ -744,7 +772,7 @@ void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0) std::vector<std::string> packageReferences; if (const char* vsPackageReferences = this->GeneratorTarget->GetProperty("VS_PACKAGE_REFERENCES")) { - cmSystemTools::ExpandListArgument(vsPackageReferences, packageReferences); + cmExpandList(vsPackageReferences, packageReferences); } if (!packageReferences.empty()) { Elem e1(e0, "ItemGroup"); @@ -771,14 +799,14 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences(Elem& e0) std::vector<std::string> references; if (const char* vsDotNetReferences = this->GeneratorTarget->GetProperty("VS_DOTNET_REFERENCES")) { - cmSystemTools::ExpandListArgument(vsDotNetReferences, references); + cmExpandList(vsDotNetReferences, references); } cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); - for (auto const& i : props) { + for (auto const& i : props.GetList()) { if (i.first.find("VS_DOTNET_REFERENCE_") == 0) { std::string name = i.first.substr(20); if (!name.empty()) { - std::string path = i.second.GetValue(); + std::string path = i.second; if (!cmsys::SystemTools::FileIsFullPath(path)) { path = this->Makefile->GetCurrentSourceDirectory() + "/" + path; } @@ -832,7 +860,7 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReference( const char* privateReference = "True"; if (const char* value = this->GeneratorTarget->GetProperty( "VS_DOTNET_REFERENCES_COPY_LOCAL")) { - if (cmSystemTools::IsOff(value)) { + if (cmIsOff(value)) { privateReference = "False"; } } @@ -847,8 +875,8 @@ void cmVisualStudio10TargetGenerator::WriteImports(Elem& e0) const char* imports = this->GeneratorTarget->Target->GetProperty("VS_PROJECT_IMPORT"); if (imports) { - std::vector<std::string> argsSplit; - cmSystemTools::ExpandListArgument(std::string(imports), argsSplit, false); + std::vector<std::string> argsSplit = + cmExpandedList(std::string(imports), false); for (auto& path : argsSplit) { if (!cmsys::SystemTools::FileIsFullPath(path)) { path = this->Makefile->GetCurrentSourceDirectory() + "/" + path; @@ -867,13 +895,13 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags( static const std::string refpropPrefix = "VS_DOTNET_REFERENCEPROP_"; static const std::string refpropInfix = "_TAG_"; const std::string refPropFullPrefix = refpropPrefix + ref + refpropInfix; - typedef std::map<std::string, std::string> CustomTags; + using CustomTags = std::map<std::string, std::string>; CustomTags tags; cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); - for (const auto& i : props) { + for (const auto& i : props.GetList()) { if (i.first.find(refPropFullPrefix) == 0) { std::string refTag = i.first.substr(refPropFullPrefix.length()); - std::string refVal = i.second.GetValue(); + std::string refVal = i.second; if (!refTag.empty() && !refVal.empty()) { tags[refTag] = refVal; } @@ -967,12 +995,12 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0) } } const cmPropertyMap& props = oi->GetProperties(); - for (const auto& p : props) { + for (const std::string& p : props.GetKeys()) { static const std::string propNamePrefix = "VS_CSHARP_"; - if (p.first.find(propNamePrefix) == 0) { - std::string tagName = p.first.substr(propNamePrefix.length()); + if (p.find(propNamePrefix) == 0) { + std::string tagName = p.substr(propNamePrefix.length()); if (!tagName.empty()) { - std::string value = props.GetPropertyValue(p.first); + std::string value = props.GetPropertyValue(p); if (!value.empty()) { e2.Element(tagName.c_str(), value); } @@ -1068,7 +1096,7 @@ void cmVisualStudio10TargetGenerator::WriteWinRTReferences(Elem& e0) std::vector<std::string> references; if (const char* vsWinRTReferences = this->GeneratorTarget->GetProperty("VS_WINRT_REFERENCES")) { - cmSystemTools::ExpandListArgument(vsWinRTReferences, references); + cmExpandList(vsWinRTReferences, references); } if (this->GlobalGenerator->TargetsWindowsPhone() && @@ -1111,7 +1139,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0) std::string configType; if (const char* vsConfigurationType = this->GeneratorTarget->GetProperty("VS_CONFIGURATION_TYPE")) { - configType = vsConfigurationType; + configType = cmGeneratorExpression::Evaluate(vsConfigurationType, + this->LocalGenerator, c); } else { switch (this->GeneratorTarget->GetType()) { case cmStateEnums::SHARED_LIBRARY: @@ -1266,8 +1295,8 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged( e1.Element("PlatformToolset", toolset); } - std::string postfixName = cmSystemTools::UpperCase(config); - postfixName += "_POSTFIX"; + std::string postfixName = + cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX"); std::string assemblyName = this->GeneratorTarget->GetOutputName( config, cmStateEnums::RuntimeBinaryArtifact); if (const char* postfix = this->GeneratorTarget->GetProperty(postfixName)) { @@ -1372,9 +1401,8 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( // preventing dependent rebuilds. this->ForceOld(sourcePath); } else { - std::string error = "Could not create file: ["; - error += sourcePath; - error += "] "; + std::string error = + cmStrCat("Could not create file: [", sourcePath, "] "); cmSystemTools::Error(error + cmSystemTools::GetLastSystemError()); } } @@ -1557,11 +1585,9 @@ void cmVisualStudio10TargetGenerator::WriteGroups() this->AddMissingSourceGroups(groupsUsed, sourceGroups); // Write out group file - std::string path = this->LocalGenerator->GetCurrentBinaryDirectory(); - path += "/"; - path += this->Name; - path += computeProjectFileExtension(this->GeneratorTarget); - path += ".filters"; + std::string path = cmStrCat( + this->LocalGenerator->GetCurrentBinaryDirectory(), '/', this->Name, + computeProjectFileExtension(this->GeneratorTarget), ".filters"); cmGeneratedFileStream fout(path); fout.SetCopyIfDifferent(true); char magic[] = { char(0xEF), char(0xBB), char(0xBF) }; @@ -1956,11 +1982,11 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1, const std::string& enableDebug = cge->Evaluate(this->LocalGenerator, this->Configurations[i]); if (!enableDebug.empty()) { - e2.WritePlatformConfigTag( - "EnableDebuggingInformation", - "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] + - "|" + this->Platform + "'", - cmSystemTools::IsOn(enableDebug) ? "true" : "false"); + e2.WritePlatformConfigTag("EnableDebuggingInformation", + "'$(Configuration)|$(Platform)'=='" + + this->Configurations[i] + "|" + + this->Platform + "'", + cmIsOn(enableDebug) ? "true" : "false"); } } } @@ -1977,7 +2003,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1, "DisableOptimizations", "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] + "|" + this->Platform + "'", - (cmSystemTools::IsOn(disableOptimizations) ? "true" : "false")); + (cmIsOn(disableOptimizations) ? "true" : "false")); } } } @@ -2057,6 +2083,17 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) if (this->GeneratorTarget->GetType() > cmStateEnums::UTILITY) { return; } + + const bool haveUnityBuild = + this->GeneratorTarget->GetPropertyAsBool("UNITY_BUILD"); + + if (haveUnityBuild && + this->GlobalGenerator->GetVersion() >= + cmGlobalVisualStudioGenerator::VS15) { + Elem e1(e0, "PropertyGroup"); + e1.Element("EnableUnitySupport", "true"); + } + Elem e1(e0, "ItemGroup"); e1.SetHasElements(); @@ -2155,9 +2192,51 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) Elem e2(e1, tool); this->WriteSource(e2, si.Source); + + bool useNativeUnityBuild = false; + if (haveUnityBuild && + this->GlobalGenerator->GetVersion() >= + cmGlobalVisualStudioGenerator::VS15) { + // Magic value taken from cmGlobalVisualStudioVersionedGenerator.cxx + static const std::string vs15 = "141"; + std::string toolset = + this->GlobalGenerator->GetPlatformToolsetString(); + cmSystemTools::ReplaceString(toolset, "v", ""); + + if (toolset.empty() || + cmSystemTools::VersionCompareGreaterEq(toolset, vs15)) { + useNativeUnityBuild = true; + } + } + + if (haveUnityBuild && strcmp(tool, "ClCompile") == 0 && + si.Source->GetProperty("UNITY_SOURCE_FILE")) { + if (useNativeUnityBuild) { + e2.Attribute( + "IncludeInUnityFile", + si.Source->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION") + ? "false" + : "true"); + e2.Attribute("CustomUnityFile", "true"); + + std::string unityDir = cmSystemTools::GetFilenamePath( + si.Source->GetProperty("UNITY_SOURCE_FILE")); + e2.Attribute("UnityFilesDirectory", unityDir); + } else { + // Visual Studio versions prior to 2017 do not know about unity + // builds, thus we exclude the files alredy part of unity sources. + if (!si.Source->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION")) { + exclude_configs = si.Configs; + } + } + } + if (si.Kind == cmGeneratorTarget::SourceKindObjectSource) { this->OutputSourceSpecificFlags(e2, si.Source); } + if (si.Source->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) { + e2.Element("PrecompiledHeader", "NotUsing"); + } if (!exclude_configs.empty()) { this->WriteExcludeFromBuild(e2, exclude_configs); } @@ -2242,8 +2321,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( for (std::string const& config : this->Configurations) { std::string configUpper = cmSystemTools::UpperCase(config); std::string configDefines = defines; - std::string defPropName = "COMPILE_DEFINITIONS_"; - defPropName += configUpper; + std::string defPropName = cmStrCat("COMPILE_DEFINITIONS_", configUpper); if (const char* ccdefs = sf.GetProperty(defPropName)) { if (!configDefines.empty()) { configDefines += ";"; @@ -2334,7 +2412,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } if (this->ProjectType == csproj) { std::string f = source->GetFullPath(); - typedef std::map<std::string, std::string> CsPropMap; + using CsPropMap = std::map<std::string, std::string>; CsPropMap sourceFileTags; // set <Link> tag if necessary std::string link; @@ -2381,49 +2459,32 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions( if (ttype <= cmStateEnums::UTILITY) { if (const char* workingDir = this->GeneratorTarget->GetProperty( "VS_DEBUGGER_WORKING_DIRECTORY")) { - cmGeneratorExpression ge; - std::unique_ptr<cmCompiledGeneratorExpression> cge = - ge.Parse(workingDir); - std::string genWorkingDir = - cge->Evaluate(this->LocalGenerator, config); - + std::string genWorkingDir = cmGeneratorExpression::Evaluate( + workingDir, this->LocalGenerator, config); e1.WritePlatformConfigTag("LocalDebuggerWorkingDirectory", cond, genWorkingDir); } if (const char* environment = this->GeneratorTarget->GetProperty("VS_DEBUGGER_ENVIRONMENT")) { - cmGeneratorExpression ge; - std::unique_ptr<cmCompiledGeneratorExpression> cge = - ge.Parse(environment); - std::string genEnvironment = - cge->Evaluate(this->LocalGenerator, config); - + std::string genEnvironment = cmGeneratorExpression::Evaluate( + environment, this->LocalGenerator, config); e1.WritePlatformConfigTag("LocalDebuggerEnvironment", cond, genEnvironment); } if (const char* debuggerCommand = this->GeneratorTarget->GetProperty("VS_DEBUGGER_COMMAND")) { - - cmGeneratorExpression ge; - std::unique_ptr<cmCompiledGeneratorExpression> cge = - ge.Parse(debuggerCommand); - std::string genDebuggerCommand = - cge->Evaluate(this->LocalGenerator, config); - + std::string genDebuggerCommand = cmGeneratorExpression::Evaluate( + debuggerCommand, this->LocalGenerator, config); e1.WritePlatformConfigTag("LocalDebuggerCommand", cond, genDebuggerCommand); } if (const char* commandArguments = this->GeneratorTarget->GetProperty( "VS_DEBUGGER_COMMAND_ARGUMENTS")) { - cmGeneratorExpression ge; - std::unique_ptr<cmCompiledGeneratorExpression> cge = - ge.Parse(commandArguments); - std::string genCommandArguments = - cge->Evaluate(this->LocalGenerator, config); - + std::string genCommandArguments = cmGeneratorExpression::Evaluate( + commandArguments, this->LocalGenerator, config); e1.WritePlatformConfigTag("LocalDebuggerCommandArguments", cond, genCommandArguments); } @@ -2433,17 +2494,14 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions( e1.WritePlatformConfigTag( "IntDir", cond, "$(Platform)\\$(Configuration)\\$(ProjectName)\\"); } else { - std::string intermediateDir = - this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); - intermediateDir += "/"; - intermediateDir += config; - intermediateDir += "/"; + std::string intermediateDir = cmStrCat( + this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), '/', + config, '/'); std::string outDir; std::string targetNameFull; if (ttype == cmStateEnums::OBJECT_LIBRARY) { outDir = intermediateDir; - targetNameFull = this->GeneratorTarget->GetName(); - targetNameFull += ".lib"; + targetNameFull = cmStrCat(this->GeneratorTarget->GetName(), ".lib"); } else { outDir = this->GeneratorTarget->GetDirectory(config) + "/"; targetNameFull = this->GeneratorTarget->GetFullName(config); @@ -2611,8 +2669,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( std::string langForClCompile; if (this->ProjectType == csproj) { langForClCompile = "CSharp"; - } else if (std::find(cm::cbegin(clLangs), cm::cend(clLangs), linkLanguage) != - cm::cend(clLangs)) { + } else if (cmContains(clLangs, linkLanguage)) { langForClCompile = linkLanguage; } else { std::set<std::string> languages; @@ -2644,6 +2701,13 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( this->IPOEnabledConfigurations.insert(configName); } + // Precompile Headers + std::string pchHeader = + this->GeneratorTarget->GetPchHeader(configName, linkLanguage); + if (this->MSTools && vcxproj == this->ProjectType && pchHeader.empty()) { + clOptions.AddFlag("PrecompiledHeader", "NotUsing"); + } + // Get preprocessor definitions for this directory. std::string defineFlags = this->Makefile->GetDefineFlags(); if (this->MSTools) { @@ -2659,7 +2723,6 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( // replace this setting with "true" below. clOptions.AddFlag("UseFullPaths", "false"); } - clOptions.AddFlag("PrecompiledHeader", "NotUsing"); clOptions.AddFlag("AssemblerListingLocation", "$(IntDir)"); } } @@ -2724,9 +2787,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( } // Add a definition for the configuration name. - std::string configDefine = "CMAKE_INTDIR=\""; - configDefine += configName; - configDefine += "\""; + std::string configDefine = cmStrCat("CMAKE_INTDIR=\"", configName, '"'); clOptions.AddDefine(configDefine); if (const std::string* exportMacro = this->GeneratorTarget->GetExportMacro()) { @@ -2751,7 +2812,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( } } if (const char* winRT = clOptions.GetFlag("CompileAsWinRT")) { - if (cmSystemTools::IsOn(winRT)) { + if (cmIsOn(winRT)) { this->TargetCompileAsWinRT = true; } } @@ -3021,9 +3082,7 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( cudaOptions.AddDefines(targetDefines); // Add a definition for the configuration name. - std::string configDefine = "CMAKE_INTDIR=\""; - configDefine += configName; - configDefine += "\""; + std::string configDefine = cmStrCat("CMAKE_INTDIR=\"", configName, '"'); cudaOptions.AddDefine(configDefine); if (const std::string* exportMacro = this->GeneratorTarget->GetExportMacro()) { @@ -3088,6 +3147,82 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( "-Wno-deprecated-gpu-targets"); } + // For static libraries that have device linking enabled compute + // the libraries + if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY && + doDeviceLinking) { + cmComputeLinkInformation* pcli = + this->GeneratorTarget->GetLinkInformation(configName); + if (!pcli) { + cmSystemTools::Error( + "CMake can not compute cmComputeLinkInformation for target: " + + this->Name); + return false; + } + + // Would like to use: + // cmLinkLineDeviceComputer computer(this->LocalGenerator, + // this->LocalGenerator->GetStateSnapshot().GetDirectory()); + // std::string computed_libs = computer.ComputeLinkLibraries(cli, + // std::string{}); but it outputs in "<libA> <libB>" format instead of + // "<libA>;<libB>" + // Note: + // Any modification of this algorithm should be reflected also in + // 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) { + + if (l.Target) { + auto managedType = l.Target->GetManagedType(configName); + // Do not allow C# targets to be added to the LIB listing. LIB files + // are used for linking C++ dependencies. C# libraries do not have lib + // files. Instead, they compile down to C# reference libraries (DLL + // files). The + // `<ProjectReference>` elements added to the vcxproj are enough for + // the IDE to deduce the DLL file required by other C# projects that + // need its reference library. + if (managedType == cmGeneratorTarget::ManagedType::Managed) { + continue; + } + const auto type = l.Target->GetType(); + + bool skip = false; + switch (type) { + case cmStateEnums::SHARED_LIBRARY: + case cmStateEnums::MODULE_LIBRARY: + case cmStateEnums::INTERFACE_LIBRARY: + skip = true; + break; + case cmStateEnums::STATIC_LIBRARY: + skip = l.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS"); + break; + default: + break; + } + if (skip) { + continue; + } + } + + if (l.IsPath) { + std::string path = this->LocalGenerator->MaybeConvertToRelativePath( + currentBinDir, l.Value); + ConvertToWindowsSlash(path); + if (!cmVS10IsTargetsFile(l.Value)) { + libVec.push_back(path); + } + } else { + libVec.push_back(l.Value); + } + } + + cudaLinkOptions.AddFlag("AdditionalDependencies", libVec); + } + this->CudaLinkOptions[configName] = std::move(pOptions); return true; } @@ -3264,15 +3399,32 @@ void cmVisualStudio10TargetGenerator::WriteManifestOptions( std::vector<cmSourceFile const*> manifest_srcs; this->GeneratorTarget->GetManifests(manifest_srcs, config); - if (!manifest_srcs.empty()) { - std::ostringstream oss; - for (cmSourceFile const* mi : manifest_srcs) { - std::string m = this->ConvertPath(mi->GetFullPath(), false); - ConvertToWindowsSlash(m); - oss << m << ";"; - } + + const char* dpiAware = this->GeneratorTarget->GetProperty("VS_DPI_AWARE"); + + if (!manifest_srcs.empty() || dpiAware) { Elem e2(e1, "Manifest"); - e2.Element("AdditionalManifestFiles", oss.str()); + if (!manifest_srcs.empty()) { + std::ostringstream oss; + for (cmSourceFile const* mi : manifest_srcs) { + std::string m = this->ConvertPath(mi->GetFullPath(), false); + ConvertToWindowsSlash(m); + oss << m << ";"; + } + e2.Element("AdditionalManifestFiles", oss.str()); + } + if (dpiAware) { + if (!strcmp(dpiAware, "PerMonitor")) { + e2.Element("EnableDpiAwareness", "PerMonitorHighDPIAware"); + } else if (cmIsOn(dpiAware)) { + e2.Element("EnableDpiAwareness", "true"); + } else if (cmIsOff(dpiAware)) { + e2.Element("EnableDpiAwareness", "false"); + } else { + cmSystemTools::Error("Bad parameter for VS_DPI_AWARE: " + + std::string(dpiAware)); + } + } } } @@ -3322,22 +3474,16 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( if (const char* nativeLibDirectoriesExpression = this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) { - cmGeneratorExpression ge; - std::unique_ptr<cmCompiledGeneratorExpression> cge = - ge.Parse(nativeLibDirectoriesExpression); - std::string nativeLibDirs = - cge->Evaluate(this->LocalGenerator, configName); + std::string nativeLibDirs = cmGeneratorExpression::Evaluate( + nativeLibDirectoriesExpression, this->LocalGenerator, configName); e2.Element("NativeLibDirectories", nativeLibDirs); } if (const char* nativeLibDependenciesExpression = this->GeneratorTarget->GetProperty( "ANDROID_NATIVE_LIB_DEPENDENCIES")) { - cmGeneratorExpression ge; - std::unique_ptr<cmCompiledGeneratorExpression> cge = - ge.Parse(nativeLibDependenciesExpression); - std::string nativeLibDeps = - cge->Evaluate(this->LocalGenerator, configName); + std::string nativeLibDeps = cmGeneratorExpression::Evaluate( + nativeLibDependenciesExpression, this->LocalGenerator, configName); e2.Element("NativeLibDependencies", nativeLibDeps); } @@ -3348,11 +3494,8 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( if (const char* jarDirectoriesExpression = this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) { - cmGeneratorExpression ge; - std::unique_ptr<cmCompiledGeneratorExpression> cge = - ge.Parse(jarDirectoriesExpression); - std::string jarDirectories = - cge->Evaluate(this->LocalGenerator, configName); + std::string jarDirectories = cmGeneratorExpression::Evaluate( + jarDirectoriesExpression, this->LocalGenerator, configName); e2.Element("JarDirectories", jarDirectories); } @@ -3421,9 +3564,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( linkType = "EXE"; } std::string flags; - std::string linkFlagVarBase = "CMAKE_"; - linkFlagVarBase += linkType; - linkFlagVarBase += "_LINKER_FLAGS"; + std::string linkFlagVarBase = cmStrCat("CMAKE_", linkType, "_LINKER_FLAGS"); flags += " "; flags += this->Makefile->GetRequiredDefinition(linkFlagVarBase); std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG; @@ -3435,8 +3576,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( flags += " "; flags += targetLinkFlags; } - std::string flagsProp = "LINK_FLAGS_"; - flagsProp += CONFIG; + std::string flagsProp = cmStrCat("LINK_FLAGS_", CONFIG); if (const char* flagsConfig = this->GeneratorTarget->GetProperty(flagsProp)) { flags += " "; @@ -3461,8 +3601,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( std::vector<std::string> libVec; std::vector<std::string> vsTargetVec; this->AddLibraries(cli, libVec, vsTargetVec, config); - if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(), - "CUDA") != linkClosure->Languages.end() && + if (cmContains(linkClosure->Languages, "CUDA") && this->CudaOptions[config] != nullptr) { switch (this->CudaOptions[config]->GetCudaRuntime()) { case cmVisualStudioGeneratorOptions::CudaRuntimeStatic: @@ -3477,9 +3616,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( break; } } - std::string standardLibsVar = "CMAKE_"; - standardLibsVar += linkLanguage; - standardLibsVar += "_STANDARD_LIBRARIES"; + std::string standardLibsVar = + cmStrCat("CMAKE_", linkLanguage, "_STANDARD_LIBRARIES"); std::string const& libs = this->Makefile->GetSafeDefinition(standardLibsVar); cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec); linkOptions.AddFlag("AdditionalDependencies", libVec); @@ -3543,13 +3681,12 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( linkOptions.AddFlag("GenerateDebugInformation", "false"); - std::string pdb = this->GeneratorTarget->GetPDBDirectory(config); - pdb += "/"; - pdb += targetNames.PDB; - std::string imLib = this->GeneratorTarget->GetDirectory( - config, cmStateEnums::ImportLibraryArtifact); - imLib += "/"; - imLib += targetNames.ImportLibrary; + std::string pdb = cmStrCat(this->GeneratorTarget->GetPDBDirectory(config), + '/', targetNames.PDB); + std::string imLib = + cmStrCat(this->GeneratorTarget->GetDirectory( + config, cmStateEnums::ImportLibraryArtifact), + '/', targetNames.ImportLibrary); linkOptions.AddFlag("ImportLibrary", imLib); linkOptions.AddFlag("ProgramDataBaseFile", pdb); @@ -3639,7 +3776,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions( } cmComputeLinkInformation& cli = *pcli; - typedef cmComputeLinkInformation::ItemVector ItemVector; + using ItemVector = cmComputeLinkInformation::ItemVector; const ItemVector& libs = cli.GetItems(); std::string currentBinDir = this->LocalGenerator->GetCurrentBinaryDirectory(); @@ -3684,7 +3821,7 @@ void cmVisualStudio10TargetGenerator::AddLibraries( const cmComputeLinkInformation& cli, std::vector<std::string>& libVec, std::vector<std::string>& vsTargetVec, const std::string& config) { - typedef cmComputeLinkInformation::ItemVector ItemVector; + using ItemVector = cmComputeLinkInformation::ItemVector; ItemVector const& libs = cli.GetItems(); std::string currentBinDir = this->LocalGenerator->GetCurrentBinaryDirectory(); @@ -3749,8 +3886,7 @@ void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair( { for (TargetsFileAndConfigs& i : this->TargetsFileAndConfigsVec) { if (cmSystemTools::ComparePath(targetsFile, i.File)) { - if (std::find(i.Configs.begin(), i.Configs.end(), config) == - i.Configs.end()) { + if (!cmContains(i.Configs, config)) { i.Configs.push_back(config); } return; @@ -3911,8 +4047,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0) { cmGlobalGenerator::TargetDependSet const& unordered = this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget); - typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet - OrderedTargetDependSet; + using OrderedTargetDependSet = + cmGlobalVisualStudioGenerator::OrderedTargetDependSet; OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET); Elem e1(e0, "ItemGroup"); e1.SetHasElements(); @@ -3932,10 +4068,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0) if (p) { path = p; } else { - path = lg->GetCurrentBinaryDirectory(); - path += "/"; - path += dt->GetName(); - path += computeProjectFileExtension(dt); + path = cmStrCat(lg->GetCurrentBinaryDirectory(), '/', dt->GetName(), + computeProjectFileExtension(dt)); } ConvertToWindowsSlash(path); Elem e2(e1, "ProjectReference"); @@ -4018,7 +4152,7 @@ void cmVisualStudio10TargetGenerator::WriteSDKReferences(Elem& e0) std::unique_ptr<Elem> spe1; if (const char* vsSDKReferences = this->GeneratorTarget->GetProperty("VS_SDK_REFERENCES")) { - cmSystemTools::ExpandListArgument(vsSDKReferences, sdkReferences); + cmExpandList(vsSDKReferences, sdkReferences); spe1 = cm::make_unique<Elem>(e0, "ItemGroup"); for (std::string const& ri : sdkReferences) { Elem(*spe1, "SDKReference").Attribute("Include", ri); @@ -4693,12 +4827,12 @@ void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties( { if (this->ProjectType == csproj) { const cmPropertyMap& props = sf->GetProperties(); - for (auto const& p : props) { + for (const std::string& p : props.GetKeys()) { static const std::string propNamePrefix = "VS_CSHARP_"; - if (p.first.find(propNamePrefix) == 0) { - std::string tagName = p.first.substr(propNamePrefix.length()); + if (p.find(propNamePrefix) == 0) { + std::string tagName = p.substr(propNamePrefix.length()); if (!tagName.empty()) { - const std::string val = props.GetPropertyValue(p.first); + const std::string val = props.GetPropertyValue(p); if (!val.empty()) { tags[tagName] = val; } else { @@ -4742,8 +4876,8 @@ std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath( const char* relativeFilePath) const { // Always search in the standard modules location. - std::string path = cmSystemTools::GetCMakeRoot() + "/"; - path += relativeFilePath; + std::string path = + cmStrCat(cmSystemTools::GetCMakeRoot(), '/', relativeFilePath); ConvertToWindowsSlash(path); return path; |