diff options
author | Marc Chevrier <marc.chevrier@sap.com> | 2017-12-19 15:03:41 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@sap.com> | 2018-01-23 09:25:03 (GMT) |
commit | 3073bd1f3deecaaf090202075382e372a3b3656a (patch) | |
tree | b7d4e16f8e35e2f617b7453decf4fb4e58df109e /Source/cmVisualStudio10TargetGenerator.cxx | |
parent | 78b1c2e09ee5005d75e31c68c1c7b112e4b36d90 (diff) | |
download | CMake-3073bd1f3deecaaf090202075382e372a3b3656a.zip CMake-3073bd1f3deecaaf090202075382e372a3b3656a.tar.gz CMake-3073bd1f3deecaaf090202075382e372a3b3656a.tar.bz2 |
VisualStudio generators: refactoring
Uniformize include directories handling.
Fix memory leaks in class cmVisualStudio10TargetGenerator:
OptionsMap uses now std::unique_ptr.
Diffstat (limited to 'Source/cmVisualStudio10TargetGenerator.cxx')
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 95 |
1 files changed, 41 insertions, 54 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 122ba4e..c3a77e2 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -114,22 +114,6 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() { - for (OptionsMap::iterator i = this->ClOptions.begin(); - i != this->ClOptions.end(); ++i) { - delete i->second; - } - for (OptionsMap::iterator i = this->LinkOptions.begin(); - i != this->LinkOptions.end(); ++i) { - delete i->second; - } - for (OptionsMap::iterator i = this->CudaOptions.begin(); - i != this->CudaOptions.end(); ++i) { - delete i->second; - } - for (OptionsMap::iterator i = this->CudaLinkOptions.begin(); - i != this->CudaLinkOptions.end(); ++i) { - delete i->second; - } if (!this->BuildFileStream) { return; } @@ -2156,10 +2140,6 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } clOptions.Parse(expandedOptions.c_str()); } - if (clOptions.HasFlag("AdditionalIncludeDirectories")) { - clOptions.AppendFlag("AdditionalIncludeDirectories", - "%(AdditionalIncludeDirectories)"); - } if (clOptions.HasFlag("DisableSpecificWarnings")) { clOptions.AppendFlag("DisableSpecificWarnings", "%(DisableSpecificWarnings)"); @@ -2173,6 +2153,8 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( clOptions.SetConfiguration(config.c_str()); clOptions.PrependInheritedString("AdditionalOptions"); clOptions.OutputFlagMap(*this->BuildFileStream, " "); + clOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", lang); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", lang); } @@ -2465,6 +2447,13 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( break; } clOptions.AddDefines(targetDefines); + + // Get includes for this target + if (!this->LangForClCompile.empty()) { + clOptions.AddIncludes( + this->GetIncludes(configName, this->LangForClCompile)); + } + if (this->MSTools) { clOptions.SetVerboseMakefile( this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")); @@ -2516,7 +2505,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( } } - this->ClOptions[configName] = pOptions.release(); + this->ClOptions[configName] = std::move(pOptions); return true; } @@ -2529,14 +2518,9 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( } this->WriteString("<ClCompile>\n", 2); clOptions.PrependInheritedString("AdditionalOptions"); - if (!this->LangForClCompile.empty()) { - std::vector<std::string> const includes = - this->GetIncludes(configName, this->LangForClCompile); - clOptions.AppendFlag("AdditionalIncludeDirectories", includes); - } - clOptions.AppendFlag("AdditionalIncludeDirectories", - "%(AdditionalIncludeDirectories)"); clOptions.OutputFlagMap(*this->BuildFileStream, " "); + clOptions.OutputAdditionalIncludeDirectories( + *this->BuildFileStream, " ", "\n", this->LangForClCompile); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", this->LangForClCompile); @@ -2614,7 +2598,10 @@ bool cmVisualStudio10TargetGenerator::ComputeRcOptions( Options& clOptions = *(this->ClOptions[configName]); rcOptions.AddDefines(clOptions.GetDefines()); - this->RcOptions[configName] = pOptions.release(); + // Get includes for this target + rcOptions.AddIncludes(this->GetIncludes(configName, "RC")); + + this->RcOptions[configName] = std::move(pOptions); return true; } @@ -2629,11 +2616,8 @@ void cmVisualStudio10TargetGenerator::WriteRCOptions( Options& rcOptions = *(this->RcOptions[configName]); rcOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", "RC"); - std::vector<std::string> const includes = - this->GetIncludes(configName, "RC"); - rcOptions.AppendFlag("AdditionalIncludeDirectories", includes); - rcOptions.AppendFlag("AdditionalIncludeDirectories", - "%(AdditionalIncludeDirectories)"); + rcOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", "RC"); rcOptions.PrependInheritedString("AdditionalOptions"); rcOptions.OutputFlagMap(*this->BuildFileStream, " "); @@ -2747,7 +2731,10 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( cudaOptions.AddDefine(exportMacro); } - this->CudaOptions[configName] = pOptions.release(); + // Get includes for this target + cudaOptions.AddIncludes(this->GetIncludes(configName, "CUDA")); + + this->CudaOptions[configName] = std::move(pOptions); return true; } @@ -2760,10 +2747,8 @@ void cmVisualStudio10TargetGenerator::WriteCudaOptions( this->WriteString("<CudaCompile>\n", 2); Options& cudaOptions = *(this->CudaOptions[configName]); - std::vector<std::string> const includes = - this->GetIncludes(configName, "CUDA"); - cudaOptions.AppendFlag("Include", includes); - cudaOptions.AppendFlag("Include", "%(Include)"); + cudaOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", "CUDA"); cudaOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", "CUDA"); cudaOptions.PrependInheritedString("AdditionalOptions"); @@ -2820,7 +2805,7 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( "-Wno-deprecated-gpu-targets"); } - this->CudaLinkOptions[configName] = pOptions.release(); + this->CudaLinkOptions[configName] = std::move(pOptions); return true; } @@ -2871,7 +2856,11 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions( std::string(this->Makefile->GetSafeDefinition(configFlagsVar)); masmOptions.Parse(flags.c_str()); - this->MasmOptions[configName] = pOptions.release(); + + // Get includes for this target + masmOptions.AddIncludes(this->GetIncludes(configName, "ASM_MASM")); + + this->MasmOptions[configName] = std::move(pOptions); return true; } @@ -2889,10 +2878,8 @@ void cmVisualStudio10TargetGenerator::WriteMasmOptions( "\n", "ASM_MASM"); Options& masmOptions = *(this->MasmOptions[configName]); - std::vector<std::string> const includes = - this->GetIncludes(configName, "ASM_MASM"); - masmOptions.AppendFlag("IncludePaths", includes); - masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)"); + masmOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", "ASM_MASM"); masmOptions.PrependInheritedString("AdditionalOptions"); masmOptions.OutputFlagMap(*this->BuildFileStream, " "); @@ -2930,7 +2917,11 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions( std::string(" ") + std::string(this->Makefile->GetSafeDefinition(configFlagsVar)); nasmOptions.Parse(flags.c_str()); - this->NasmOptions[configName] = pOptions.release(); + + // Get includes for this target + nasmOptions.AddIncludes(this->GetIncludes(configName, "ASM_NASM")); + + this->NasmOptions[configName] = std::move(pOptions); return true; } @@ -2945,12 +2936,8 @@ void cmVisualStudio10TargetGenerator::WriteNasmOptions( std::vector<std::string> includes = this->GetIncludes(configName, "ASM_NASM"); Options& nasmOptions = *(this->NasmOptions[configName]); - for (size_t i = 0; i < includes.size(); i++) { - includes[i] += "\\"; - } - - nasmOptions.AppendFlag("IncludePaths", includes); - nasmOptions.AppendFlag("IncludePaths", "%(IncludePaths)"); + nasmOptions.OutputAdditionalIncludeDirectories(*this->BuildFileStream, + " ", "\n", "ASM_NASM"); nasmOptions.OutputFlagMap(*this->BuildFileStream, " "); nasmOptions.PrependInheritedString("AdditionalOptions"); nasmOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", @@ -3376,7 +3363,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( } } - this->LinkOptions[config] = pOptions.release(); + this->LinkOptions[config] = std::move(pOptions); return true; } @@ -3542,7 +3529,7 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups() if (this->ProjectType == csproj) { return; } - for (std::string const& i : this->Configurations) { + for (const auto& i : this->Configurations) { this->WritePlatformConfigTag("ItemDefinitionGroup", i, 1); *this->BuildFileStream << "\n"; // output cl compile flags <ClCompile></ClCompile> |