diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeVersion.cmake | 2 | ||||
-rw-r--r-- | Source/cmExtraEclipseCDT4Generator.cxx | 7 | ||||
-rw-r--r-- | Source/cmFileCommand.cxx | 8 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 15 | ||||
-rw-r--r-- | Source/cmMakefileLibraryTargetGenerator.cxx | 13 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 26 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 4 | ||||
-rw-r--r-- | Source/cmTargetLinkLibrariesCommand.cxx | 11 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 892 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.h | 5 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 52 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.hxx.in | 5 | ||||
-rw-r--r-- | Source/kwsys/testDirectory.cxx | 33 | ||||
-rw-r--r-- | Source/kwsys/testSystemTools.cxx | 74 |
14 files changed, 642 insertions, 505 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index f669b7c..70ff631 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 11) -set(CMake_VERSION_PATCH 20180515) +set(CMake_VERSION_PATCH 20180524) #set(CMake_VERSION_RC 1) diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 258c9ca..e7279d9 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -1001,6 +1001,13 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const xml.EndElement(); // project xml.EndElement(); // storageModule + + // Append additional cproject contents without applying any XML formatting + if (const char* extraCProjectContents = + mf->GetState()->GetGlobalProperty("ECLIPSE_EXTRA_CPROJECT_CONTENTS")) { + fout << extraCProjectContents; + } + xml.EndElement(); // cproject } diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 6c1a869..1e47687 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -232,6 +232,14 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, } std::string message = cmJoin(cmMakeRange(i, args.end()), std::string()); file << message; + if (!file) { + std::string error = "write failed ("; + error += cmSystemTools::GetLastSystemError(); + error += "):\n "; + error += fileName; + this->SetError(error); + return false; + } file.close(); if (mode) { cmSystemTools::SetPermissions(fileName.c_str(), mode); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 799ae95..0c99ed4 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -4612,13 +4612,24 @@ bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind, // Select an output directory. if (const char* config_outdir = this->GetProperty(configProp)) { // Use the user-specified per-configuration output directory. - out = config_outdir; + cmGeneratorExpression ge; + std::unique_ptr<cmCompiledGeneratorExpression> cge = + ge.Parse(config_outdir); + out = cge->Evaluate(this->LocalGenerator, config); // Skip per-configuration subdirectory. conf.clear(); } else if (const char* outdir = this->GetProperty(propertyName)) { // Use the user-specified output directory. - out = outdir; + cmGeneratorExpression ge; + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir); + out = cge->Evaluate(this->LocalGenerator, config); + + // Skip per-configuration subdirectory if the value contained a + // generator expression. + if (out != outdir) { + conf.clear(); + } } if (out.empty()) { return false; diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 27fae04..c538992 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -5,6 +5,7 @@ #include <algorithm> #include <memory> // IWYU pragma: keep #include <sstream> +#include <stddef.h> #include <vector> #include "cmGeneratedFileStream.h" @@ -732,10 +733,14 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( // Archiving rules never use a response file. useResponseFileForObjects = false; - // Limit the length of individual object lists to less than the - // 32K command line length limit on Windows. We could make this a - // platform file variable but this should work everywhere. - archiveCommandLimit = 30000; + // Limit the length of individual object lists to less than half of + // the command line length limit (leaving half for other flags). + // This may result in several calls to the archiver. + if (size_t limit = cmSystemTools::CalculateCommandLineLengthLimit()) { + archiveCommandLimit = limit / 2; + } else { + archiveCommandLimit = 8000; + } } // Expand the rule variables. diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 94c5ee8..169b525 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1696,7 +1696,8 @@ void list_item_verbose(FILE* out, struct archive_entry* entry) fflush(out); } -long copy_data(struct archive* ar, struct archive* aw) +// Return 'true' on success +bool copy_data(struct archive* ar, struct archive* aw) { long r; const void* buff; @@ -1708,22 +1709,28 @@ long copy_data(struct archive* ar, struct archive* aw) #endif for (;;) { + // Return value: + // * ARCHIVE_OK - read succeed + // * ARCHIVE_EOF - no more data to read left r = archive_read_data_block(ar, &buff, &size, &offset); if (r == ARCHIVE_EOF) { - return (ARCHIVE_OK); + return true; } if (r != ARCHIVE_OK) { - return (r); + return false; } - r = archive_write_data_block(aw, buff, size, offset); - if (r != ARCHIVE_OK) { + // Return value: + // * >= ARCHIVE_OK - write succeed + // * < ARCHIVE_OK - write failed + const la_ssize_t w_size = archive_write_data_block(aw, buff, size, offset); + if (w_size < ARCHIVE_OK) { cmSystemTools::Message("archive_write_data_block()", archive_error_string(aw)); - return (r); + return false; } } #if !defined(__clang__) && !defined(__HP_aCC) - return r; /* this should not happen but it quiets some compilers */ + return false; /* this should not happen but it quiets some compilers */ #endif } @@ -1776,7 +1783,10 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract) r = archive_write_header(ext, entry); if (r == ARCHIVE_OK) { - copy_data(a, ext); + if (!copy_data(a, ext)) { + cmSystemTools::Error("Problem with copy_data"); + break; + } r = archive_write_finish_entry(ext); if (r != ARCHIVE_OK) { cmSystemTools::Error("Problem with archive_write_finish_entry(): ", diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index d17a85a..7dcba74 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -399,6 +399,10 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->SetPropertyDefault("JOB_POOL_COMPILE", nullptr); this->SetPropertyDefault("JOB_POOL_LINK", nullptr); } + + if (this->TargetTypeValue <= cmStateEnums::UTILITY) { + this->SetPropertyDefault("DOTNET_TARGET_FRAMEWORK_VERSION", nullptr); + } } cmGlobalGenerator* cmTarget::GetGlobalGenerator() const diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 699fff8..53f1213 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -364,7 +364,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, if (this->CurrentProcessingState != ProcessingKeywordLinkInterface && this->CurrentProcessingState != ProcessingPlainLinkInterface) { - // Assure that the target on the LHS was created in the current directory. + // Find target on the LHS locally cmTarget* t = this->Makefile->FindLocalNonAliasTarget(this->Target->GetName()); if (!t) { @@ -377,11 +377,18 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, } } } + + // If no local target has been found, find it in the global scope + if (!t) { + t = this->Makefile->GetGlobalGenerator()->FindTarget( + this->Target->GetName(), true); + } + if (!t) { std::ostringstream e; e << "Attempt to add link library \"" << lib << "\" to target \"" << this->Target->GetName() - << "\" which is not built in this directory."; + << "\" which does not exist or is an alias target."; this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); return false; } diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index fcea48b..99b8998 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -40,13 +40,13 @@ static std::string cmVS10EscapeAttr(std::string arg) struct cmVisualStudio10TargetGenerator::Elem { std::ostream& S; - int Indent; + const int Indent; bool HasElements = false; std::string Tag; - Elem(std::ostream& s, int i) + Elem(std::ostream& s) : S(s) - , Indent(i) + , Indent(0) { } Elem(const Elem&) = delete; @@ -94,15 +94,19 @@ struct cmVisualStudio10TargetGenerator::Elem { S << ">" << cmVS10EscapeXML(val) << "</" << this->Tag << ">\n"; } - void WriteEndTag(const std::string& tag) + void EndElement() { if (HasElements) { - this->WriteString("</") << tag << ">\n"; + this->WriteString("</") << this->Tag << ">"; + if (this->Indent > 0) { + this->S << '\n'; + } else { + // special case: don't print EOL at EOF + } } else { this->S << " />\n"; } } - void EndElement() { this->WriteEndTag(this->Tag); } void WritePlatformConfigTag(const char* tag, const std::string& cond, const std::string& content); @@ -234,7 +238,6 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->MSTools = !this->NsightTegra; this->Managed = false; this->TargetCompileAsWinRT = false; - this->BuildFileStream = 0; this->IsMissingFiles = false; this->DefaultArtifactDir = this->LocalGenerator->GetCurrentBinaryDirectory() + std::string("/") + @@ -246,13 +249,6 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() { - if (!this->BuildFileStream) { - return; - } - if (this->BuildFileStream->Close()) { - this->GlobalGenerator->FileReplacedDuringGenerate(this->PathToProjectFile); - } - delete this->BuildFileStream; } std::string cmVisualStudio10TargetGenerator::CalcCondition( @@ -310,12 +306,12 @@ void cmVisualStudio10TargetGenerator::Generate() this->GeneratorTarget->GetProperty("EXTERNAL_MSPROJECT")) { return; } - this->ProjectFileExtension = computeProjectFileExtension( + const std::string ProjectFileExtension = computeProjectFileExtension( this->GeneratorTarget, *this->Configurations.begin()); - if (this->ProjectFileExtension == ".vcxproj") { + if (ProjectFileExtension == ".vcxproj") { this->ProjectType = vcxproj; this->Managed = false; - } else if (this->ProjectFileExtension == ".csproj") { + } else if (ProjectFileExtension == ".csproj") { if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) { std::string message = "The C# target \"" + this->GeneratorTarget->GetName() + @@ -330,8 +326,8 @@ void cmVisualStudio10TargetGenerator::Generate() // Tell the global generator the name of the project file this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME", this->Name.c_str()); - this->GeneratorTarget->Target->SetProperty( - "GENERATOR_FILE_NAME_EXT", this->ProjectFileExtension.c_str()); + this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME_EXT", + ProjectFileExtension.c_str()); this->DotNetHintReferences.clear(); this->AdditionalUsingDirectories.clear(); if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) { @@ -363,340 +359,355 @@ void cmVisualStudio10TargetGenerator::Generate() std::string path = this->LocalGenerator->GetCurrentBinaryDirectory(); path += "/"; path += this->Name; - path += this->ProjectFileExtension; - this->BuildFileStream = new cmGeneratedFileStream(path.c_str()); - this->PathToProjectFile = path; - this->BuildFileStream->SetCopyIfDifferent(true); + path += ProjectFileExtension; + cmGeneratedFileStream BuildFileStream(path.c_str()); + const std::string PathToProjectFile = path; + BuildFileStream.SetCopyIfDifferent(true); // Write the encoding header into the file char magic[] = { char(0xEF), char(0xBB), char(0xBF) }; - this->BuildFileStream->write(magic, 3); - (*this->BuildFileStream) << "<?xml version=\"1.0\" encoding=\"" + - this->GlobalGenerator->Encoding() + "\"?>\n"; - - Elem e0(*this->BuildFileStream, 0); - e0.StartElement("Project"); - e0.Attribute("DefaultTargets", "Build"); - // get the tools version to use - const std::string toolsVer(this->GlobalGenerator->GetToolsVersion()); - e0.Attribute("ToolsVersion", toolsVer); - e0.Attribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003"); - e0.SetHasElements(); - - if (this->NsightTegra) { - Elem e1(e0, "PropertyGroup"); - e1.Attribute("Label", "NsightTegraProject"); - const unsigned int nsightTegraMajorVersion = this->NsightTegraVersion[0]; - const unsigned int nsightTegraMinorVersion = this->NsightTegraVersion[1]; - if (nsightTegraMajorVersion >= 2) { - if (nsightTegraMajorVersion > 3 || - (nsightTegraMajorVersion == 3 && nsightTegraMinorVersion >= 1)) { - e1.Element("NsightTegraProjectRevisionNumber", "11"); + BuildFileStream.write(magic, 3); + BuildFileStream << "<?xml version=\"1.0\" encoding=\"" + << this->GlobalGenerator->Encoding() << "\"?>" + << "\n"; + { + Elem e0(BuildFileStream); + e0.StartElement("Project"); + e0.Attribute("DefaultTargets", "Build"); + e0.Attribute("ToolsVersion", this->GlobalGenerator->GetToolsVersion()); + e0.Attribute("xmlns", + "http://schemas.microsoft.com/developer/msbuild/2003"); + + if (this->NsightTegra) { + Elem e1(e0, "PropertyGroup"); + e1.Attribute("Label", "NsightTegraProject"); + const unsigned int nsightTegraMajorVersion = this->NsightTegraVersion[0]; + const unsigned int nsightTegraMinorVersion = this->NsightTegraVersion[1]; + if (nsightTegraMajorVersion >= 2) { + if (nsightTegraMajorVersion > 3 || + (nsightTegraMajorVersion == 3 && nsightTegraMinorVersion >= 1)) { + e1.Element("NsightTegraProjectRevisionNumber", "11"); + } else { + // Nsight Tegra 2.0 uses project revision 9. + e1.Element("NsightTegraProjectRevisionNumber", "9"); + } + // Tell newer versions to upgrade silently when loading. + e1.Element("NsightTegraUpgradeOnceWithoutPrompt", "true"); } else { - // Nsight Tegra 2.0 uses project revision 9. - e1.Element("NsightTegraProjectRevisionNumber", "9"); + // Require Nsight Tegra 1.6 for JCompile support. + e1.Element("NsightTegraProjectRevisionNumber", "7"); } - // Tell newer versions to upgrade silently when loading. - e1.Element("NsightTegraUpgradeOnceWithoutPrompt", "true"); - } else { - // Require Nsight Tegra 1.6 for JCompile support. - e1.Element("NsightTegraProjectRevisionNumber", "7"); + e1.EndElement(); } - e1.EndElement(); - } - - if (const char* hostArch = - this->GlobalGenerator->GetPlatformToolsetHostArchitecture()) { - Elem e1(e0, "PropertyGroup"); - e1.Element("PreferredToolArchitecture", hostArch); - e1.EndElement(); - } - - if (this->ProjectType != csproj) { - this->WriteProjectConfigurations(e0); - } - - { - Elem e1(e0, "PropertyGroup"); - e1.Attribute("Label", "Globals"); - e1.Element("ProjectGuid", "{" + this->GUID + "}"); - if (this->MSTools && - this->GeneratorTarget->GetType() <= cmStateEnums::GLOBAL_TARGET) { - this->WriteApplicationTypeSettings(e1); - this->VerifyNecessaryFiles(); + if (const char* hostArch = + this->GlobalGenerator->GetPlatformToolsetHostArchitecture()) { + Elem e1(e0, "PropertyGroup"); + e1.Element("PreferredToolArchitecture", hostArch); + e1.EndElement(); } - const char* vsProjectTypes = - this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES"); - if (vsProjectTypes) { - std::string tagName = "ProjectTypes"; - if (this->ProjectType == csproj) { - tagName = "ProjectTypeGuids"; - } - e1.Element(tagName.c_str(), vsProjectTypes); + if (this->ProjectType != csproj) { + this->WriteProjectConfigurations(e0); } - const char* vsProjectName = - this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME"); - const char* vsLocalPath = - this->GeneratorTarget->GetProperty("VS_SCC_LOCALPATH"); - const char* vsProvider = - this->GeneratorTarget->GetProperty("VS_SCC_PROVIDER"); + { + Elem e1(e0, "PropertyGroup"); + e1.Attribute("Label", "Globals"); + e1.Element("ProjectGuid", "{" + this->GUID + "}"); - if (vsProjectName && vsLocalPath && vsProvider) { - e1.Element("SccProjectName", vsProjectName); - e1.Element("SccLocalPath", vsLocalPath); - e1.Element("SccProvider", vsProvider); + if (this->MSTools && + this->GeneratorTarget->GetType() <= cmStateEnums::GLOBAL_TARGET) { + this->WriteApplicationTypeSettings(e1); + this->VerifyNecessaryFiles(); + } - const char* vsAuxPath = - this->GeneratorTarget->GetProperty("VS_SCC_AUXPATH"); - if (vsAuxPath) { - e1.Element("SccAuxPath", vsAuxPath); + const char* vsProjectTypes = + this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES"); + if (vsProjectTypes) { + const char* tagName = "ProjectTypes"; + if (this->ProjectType == csproj) { + tagName = "ProjectTypeGuids"; + } + e1.Element(tagName, vsProjectTypes); } - } - if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) { - e1.Element("WinMDAssembly", "true"); - } + const char* vsProjectName = + this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME"); + const char* vsLocalPath = + this->GeneratorTarget->GetProperty("VS_SCC_LOCALPATH"); + const char* vsProvider = + this->GeneratorTarget->GetProperty("VS_SCC_PROVIDER"); + + if (vsProjectName && vsLocalPath && vsProvider) { + e1.Element("SccProjectName", vsProjectName); + e1.Element("SccLocalPath", vsLocalPath); + e1.Element("SccProvider", vsProvider); + + const char* vsAuxPath = + this->GeneratorTarget->GetProperty("VS_SCC_AUXPATH"); + if (vsAuxPath) { + e1.Element("SccAuxPath", vsAuxPath); + } + } - const char* vsGlobalKeyword = - this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD"); - if (!vsGlobalKeyword) { - e1.Element("Keyword", "Win32Proj"); - } else { - e1.Element("Keyword", vsGlobalKeyword); - } + if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) { + e1.Element("WinMDAssembly", "true"); + } - const char* vsGlobalRootNamespace = - this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE"); - if (vsGlobalRootNamespace) { - e1.Element("RootNamespace", vsGlobalRootNamespace); - } + const char* vsGlobalKeyword = + this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD"); + if (!vsGlobalKeyword) { + e1.Element("Keyword", "Win32Proj"); + } else { + e1.Element("Keyword", vsGlobalKeyword); + } - e1.Element("Platform", this->Platform); - const char* projLabel = - this->GeneratorTarget->GetProperty("PROJECT_LABEL"); - if (!projLabel) { - projLabel = this->Name.c_str(); - } - e1.Element("ProjectName", projLabel); - if (const char* targetFrameworkVersion = + const char* vsGlobalRootNamespace = + this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE"); + if (vsGlobalRootNamespace) { + e1.Element("RootNamespace", vsGlobalRootNamespace); + } + + e1.Element("Platform", this->Platform); + const char* projLabel = + this->GeneratorTarget->GetProperty("PROJECT_LABEL"); + if (!projLabel) { + projLabel = this->Name.c_str(); + } + e1.Element("ProjectName", projLabel); + { + // TODO: add deprecation warning for VS_* property? + const char* targetFrameworkVersion = this->GeneratorTarget->GetProperty( - "VS_DOTNET_TARGET_FRAMEWORK_VERSION")) { - e1.Element("TargetFrameworkVersion", targetFrameworkVersion); - } + "VS_DOTNET_TARGET_FRAMEWORK_VERSION"); + if (!targetFrameworkVersion) { + targetFrameworkVersion = this->GeneratorTarget->GetProperty( + "DOTNET_TARGET_FRAMEWORK_VERSION"); + } + if (targetFrameworkVersion) { + e1.Element("TargetFrameworkVersion", targetFrameworkVersion); + } + } - // Disable the project upgrade prompt that is displayed the first time a - // project using an older toolset version is opened in a newer version of - // the IDE (respected by VS 2013 and above). - if (this->GlobalGenerator->GetVersion() >= - cmGlobalVisualStudioGenerator::VS12) { - e1.Element("VCProjectUpgraderObjectName", "NoUpgrade"); - } + // Disable the project upgrade prompt that is displayed the first time a + // project using an older toolset version is opened in a newer version of + // the IDE (respected by VS 2013 and above). + if (this->GlobalGenerator->GetVersion() >= + cmGlobalVisualStudioGenerator::VS12) { + e1.Element("VCProjectUpgraderObjectName", "NoUpgrade"); + } - std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys(); - for (std::string const& keyIt : keys) { - static const char* prefix = "VS_GLOBAL_"; - if (keyIt.find(prefix) != 0) - continue; - std::string globalKey = keyIt.substr(strlen(prefix)); - // Skip invalid or separately-handled properties. - if (globalKey.empty() || globalKey == "PROJECT_TYPES" || - globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") { - continue; + std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys(); + for (std::string const& keyIt : keys) { + static const char* prefix = "VS_GLOBAL_"; + if (keyIt.find(prefix) != 0) + continue; + std::string globalKey = keyIt.substr(strlen(prefix)); + // Skip invalid or separately-handled properties. + if (globalKey.empty() || globalKey == "PROJECT_TYPES" || + globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") { + continue; + } + const char* value = this->GeneratorTarget->GetProperty(keyIt); + if (!value) + continue; + e1.Element(globalKey.c_str(), value); } - const char* value = this->GeneratorTarget->GetProperty(keyIt); - if (!value) - continue; - e1.Element(globalKey.c_str(), value); - } - if (this->Managed) { - std::string outputType; - switch (this->GeneratorTarget->GetType()) { - case cmStateEnums::OBJECT_LIBRARY: - case cmStateEnums::STATIC_LIBRARY: - case cmStateEnums::SHARED_LIBRARY: - outputType = "Library"; - break; - case cmStateEnums::MODULE_LIBRARY: - outputType = "Module"; - break; - case cmStateEnums::EXECUTABLE: - if (this->GeneratorTarget->Target->GetPropertyAsBool( - "WIN32_EXECUTABLE")) { - outputType = "WinExe"; - } else { - outputType = "Exe"; - } - break; - case cmStateEnums::UTILITY: - case cmStateEnums::GLOBAL_TARGET: - outputType = "Utility"; - break; - case cmStateEnums::UNKNOWN_LIBRARY: - case cmStateEnums::INTERFACE_LIBRARY: - break; + if (this->Managed) { + std::string outputType; + switch (this->GeneratorTarget->GetType()) { + case cmStateEnums::OBJECT_LIBRARY: + case cmStateEnums::STATIC_LIBRARY: + case cmStateEnums::SHARED_LIBRARY: + outputType = "Library"; + break; + case cmStateEnums::MODULE_LIBRARY: + outputType = "Module"; + break; + case cmStateEnums::EXECUTABLE: + if (this->GeneratorTarget->Target->GetPropertyAsBool( + "WIN32_EXECUTABLE")) { + outputType = "WinExe"; + } else { + outputType = "Exe"; + } + break; + case cmStateEnums::UTILITY: + case cmStateEnums::GLOBAL_TARGET: + outputType = "Utility"; + break; + case cmStateEnums::UNKNOWN_LIBRARY: + case cmStateEnums::INTERFACE_LIBRARY: + break; + } + e1.Element("OutputType", outputType); + e1.Element("AppDesignerFolder", "Properties"); } - e1.Element("OutputType", outputType); - e1.Element("AppDesignerFolder", "Properties"); - } - e1.EndElement(); - } + e1.EndElement(); + } - switch (this->ProjectType) { - case vcxproj: - Elem(e0, "Import") - .Attribute("Project", VS10_CXX_DEFAULT_PROPS) - .EndElement(); - break; - case csproj: - Elem(e0, "Import") - .Attribute("Project", VS10_CSharp_DEFAULT_PROPS) - .Attribute("Condition", "Exists('" VS10_CSharp_DEFAULT_PROPS "')") - .EndElement(); - break; - } + switch (this->ProjectType) { + case vcxproj: + Elem(e0, "Import") + .Attribute("Project", VS10_CXX_DEFAULT_PROPS) + .EndElement(); + break; + case csproj: + Elem(e0, "Import") + .Attribute("Project", VS10_CSharp_DEFAULT_PROPS) + .Attribute("Condition", "Exists('" VS10_CSharp_DEFAULT_PROPS "')") + .EndElement(); + break; + } - this->WriteProjectConfigurationValues(e0); + this->WriteProjectConfigurationValues(e0); - if (this->ProjectType == vcxproj) { - Elem(e0, "Import").Attribute("Project", VS10_CXX_PROPS).EndElement(); - } - { - Elem e1(e0, "ImportGroup"); - e1.Attribute("Label", "ExtensionSettings"); - e1.SetHasElements(); - - if (this->GlobalGenerator->IsCudaEnabled()) { - Elem(e1, "Import") - .Attribute("Project", "$(VCTargetsPath)\\BuildCustomizations\\CUDA " + - this->GlobalGenerator->GetPlatformToolsetCudaString() + - ".props") - .EndElement(); + if (this->ProjectType == vcxproj) { + Elem(e0, "Import").Attribute("Project", VS10_CXX_PROPS).EndElement(); } - if (this->GlobalGenerator->IsMasmEnabled()) { - Elem(e1, "Import") - .Attribute("Project", - "$(VCTargetsPath)\\BuildCustomizations\\masm.props") - .EndElement(); + { + Elem e1(e0, "ImportGroup"); + e1.Attribute("Label", "ExtensionSettings"); + e1.SetHasElements(); + + if (this->GlobalGenerator->IsCudaEnabled()) { + Elem(e1, "Import") + .Attribute( + "Project", "$(VCTargetsPath)\\BuildCustomizations\\CUDA " + + this->GlobalGenerator->GetPlatformToolsetCudaString() + ".props") + .EndElement(); + } + if (this->GlobalGenerator->IsMasmEnabled()) { + Elem(e1, "Import") + .Attribute("Project", + "$(VCTargetsPath)\\BuildCustomizations\\masm.props") + .EndElement(); + } + if (this->GlobalGenerator->IsNasmEnabled()) { + // Always search in the standard modules location. + std::string propsTemplate = + GetCMakeFilePath("Templates/MSBuild/nasm.props.in"); + + std::string propsLocal; + propsLocal += this->DefaultArtifactDir; + propsLocal += "\\nasm.props"; + ConvertToWindowsSlash(propsLocal); + this->Makefile->ConfigureFile(propsTemplate.c_str(), + propsLocal.c_str(), false, true, true); + Elem(e1, "Import").Attribute("Project", propsLocal).EndElement(); + } + e1.EndElement(); } - if (this->GlobalGenerator->IsNasmEnabled()) { - // Always search in the standard modules location. - std::string propsTemplate = - GetCMakeFilePath("Templates/MSBuild/nasm.props.in"); + { + Elem e1(e0, "ImportGroup"); + e1.Attribute("Label", "PropertySheets"); + std::string props; + switch (this->ProjectType) { + case vcxproj: + props = VS10_CXX_USER_PROPS; + break; + case csproj: + props = VS10_CSharp_USER_PROPS; + break; + } + if (const char* p = + this->GeneratorTarget->GetProperty("VS_USER_PROPS")) { + props = p; + } + if (!props.empty()) { + ConvertToWindowsSlash(props); + Elem(e1, "Import") + .Attribute("Project", props) + .Attribute("Condition", "exists('" + props + "')") + .Attribute("Label", "LocalAppDataPlatform") + .EndElement(); + } - std::string propsLocal; - propsLocal += this->DefaultArtifactDir; - propsLocal += "\\nasm.props"; - ConvertToWindowsSlash(propsLocal); - this->Makefile->ConfigureFile(propsTemplate.c_str(), propsLocal.c_str(), - false, true, true); - Elem(e1, "Import").Attribute("Project", propsLocal).EndElement(); + this->WritePlatformExtensions(e1); + e1.EndElement(); } - e1.EndElement(); - } - { - Elem e1(e0, "ImportGroup"); - e1.Attribute("Label", "PropertySheets"); - std::string props; + Elem(e0, "PropertyGroup").Attribute("Label", "UserMacros").EndElement(); + this->WriteWinRTPackageCertificateKeyFile(e0); + this->WritePathAndIncrementalLinkOptions(e0); + this->WriteItemDefinitionGroups(e0); + this->WriteCustomCommands(e0); + this->WriteAllSources(e0); + this->WriteDotNetReferences(e0); + this->WriteEmbeddedResourceGroup(e0); + this->WriteXamlFilesGroup(e0); + this->WriteWinRTReferences(e0); + this->WriteProjectReferences(e0); + this->WriteSDKReferences(e0); switch (this->ProjectType) { case vcxproj: - props = VS10_CXX_USER_PROPS; + Elem(e0, "Import").Attribute("Project", VS10_CXX_TARGETS).EndElement(); break; case csproj: - props = VS10_CSharp_USER_PROPS; + Elem(e0, "Import") + .Attribute("Project", VS10_CSharp_TARGETS) + .EndElement(); break; } - if (const char* p = this->GeneratorTarget->GetProperty("VS_USER_PROPS")) { - props = p; - } - if (!props.empty()) { - ConvertToWindowsSlash(props); - Elem(e1, "Import") - .Attribute("Project", props) - .Attribute("Condition", "exists('" + props + "')") - .Attribute("Label", "LocalAppDataPlatform") - .EndElement(); - } - - this->WritePlatformExtensions(e1); - e1.EndElement(); - } - Elem(e0, "PropertyGroup").Attribute("Label", "UserMacros").EndElement(); - this->WriteWinRTPackageCertificateKeyFile(e0); - this->WritePathAndIncrementalLinkOptions(e0); - this->WriteItemDefinitionGroups(e0); - this->WriteCustomCommands(e0); - this->WriteAllSources(e0); - this->WriteDotNetReferences(e0); - this->WriteEmbeddedResourceGroup(e0); - this->WriteXamlFilesGroup(e0); - this->WriteWinRTReferences(e0); - this->WriteProjectReferences(e0); - this->WriteSDKReferences(e0); - switch (this->ProjectType) { - case vcxproj: - Elem(e0, "Import").Attribute("Project", VS10_CXX_TARGETS).EndElement(); - break; - case csproj: - Elem(e0, "Import") - .Attribute("Project", VS10_CSharp_TARGETS) - .EndElement(); - break; - } - this->WriteTargetSpecificReferences(e0); - { - Elem e1(e0, "ImportGroup"); - e1.Attribute("Label", "ExtensionTargets"); - e1.SetHasElements(); - this->WriteTargetsFileReferences(e1); - if (this->GlobalGenerator->IsCudaEnabled()) { - Elem(e1, "Import") - .Attribute("Project", "$(VCTargetsPath)\\BuildCustomizations\\CUDA " + - this->GlobalGenerator->GetPlatformToolsetCudaString() + - ".targets") - .EndElement(); - } - if (this->GlobalGenerator->IsMasmEnabled()) { - Elem(e1, "Import") - .Attribute("Project", - "$(VCTargetsPath)\\BuildCustomizations\\masm.targets") - .EndElement(); - } - if (this->GlobalGenerator->IsNasmEnabled()) { - std::string nasmTargets = - GetCMakeFilePath("Templates/MSBuild/nasm.targets"); - Elem(e1, "Import").Attribute("Project", nasmTargets).EndElement(); - } - e1.EndElement(); - } - if (this->ProjectType == csproj) { - for (std::string const& i : this->Configurations) { - Elem e1(e0, "PropertyGroup"); - e1.Attribute("Condition", "'$(Configuration)' == '" + i + "'"); + this->WriteTargetSpecificReferences(e0); + { + Elem e1(e0, "ImportGroup"); + e1.Attribute("Label", "ExtensionTargets"); e1.SetHasElements(); - this->WriteEvents(e1, i); + this->WriteTargetsFileReferences(e1); + if (this->GlobalGenerator->IsCudaEnabled()) { + Elem(e1, "Import") + .Attribute("Project", + "$(VCTargetsPath)\\BuildCustomizations\\CUDA " + + this->GlobalGenerator->GetPlatformToolsetCudaString() + + ".targets") + .EndElement(); + } + if (this->GlobalGenerator->IsMasmEnabled()) { + Elem(e1, "Import") + .Attribute("Project", + "$(VCTargetsPath)\\BuildCustomizations\\masm.targets") + .EndElement(); + } + if (this->GlobalGenerator->IsNasmEnabled()) { + std::string nasmTargets = + GetCMakeFilePath("Templates/MSBuild/nasm.targets"); + Elem(e1, "Import").Attribute("Project", nasmTargets).EndElement(); + } e1.EndElement(); } - // make sure custom commands are executed before build (if necessary) - Elem e1(e0, "PropertyGroup"); - { - std::ostringstream oss; - oss << "\n"; - for (std::string const& i : this->CSharpCustomCommandNames) { - oss << " " << i << ";\n"; + if (this->ProjectType == csproj) { + for (std::string const& c : this->Configurations) { + Elem e1(e0, "PropertyGroup"); + e1.Attribute("Condition", "'$(Configuration)' == '" + c + "'"); + e1.SetHasElements(); + this->WriteEvents(e1, c); + e1.EndElement(); + } + // make sure custom commands are executed before build (if necessary) + { + Elem e1(e0, "PropertyGroup"); + std::ostringstream oss; + oss << "\n"; + for (std::string const& i : this->CSharpCustomCommandNames) { + oss << " " << i << ";\n"; + } + oss << " " + << "$(BuildDependsOn)\n"; + e1.Element("BuildDependsOn", oss.str()); + e1.EndElement(); } - oss << " " - << "$(BuildDependsOn)\n"; - e1.Element("BuildDependsOn", oss.str()); } - e1.EndElement(); + e0.EndElement(); + } + + if (BuildFileStream.Close()) { + this->GlobalGenerator->FileReplacedDuringGenerate(PathToProjectFile); } - e0.WriteString("</Project>"); + // The groups are stored in a separate file for VS 10 this->WriteGroups(); } @@ -833,7 +844,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0) std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h"; e2.Element("DependentUpon", hFileName); - for (std::string const& i : this->Configurations) { + for (std::string const& c : this->Configurations) { std::string s; if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE") || // Handle variant of VS_GLOBAL_<variable> for RootNamespace. @@ -841,7 +852,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0) s = "$(RootNamespace)."; } s += "%(Filename).resources"; - e2.WritePlatformConfigTag("LogicalName", CalcCondition(i), s); + e2.WritePlatformConfigTag("LogicalName", this->CalcCondition(c), s); } } else { std::string binDir = this->Makefile->GetCurrentBinaryDirectory(); @@ -911,8 +922,7 @@ void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup(Elem& e0) std::vector<cmSourceFile const*> xamlObjs; this->GeneratorTarget->GetXamlSources(xamlObjs, ""); if (!xamlObjs.empty()) { - Elem e1(e0); - e1.StartElement("ItemGroup"); + Elem e1(e0, "ItemGroup"); for (cmSourceFile const* oi : xamlObjs) { std::string obj = oi->GetFullPath(); const char* xamlType; @@ -1032,8 +1042,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurations(Elem& e0) void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0) { for (std::string const& c : this->Configurations) { - Elem e1(e0); - e1.StartElement("PropertyGroup"); + Elem e1(e0, "PropertyGroup"); e1.Attribute("Condition", this->CalcCondition(c)); e1.Attribute("Label", "Configuration"); @@ -1041,7 +1050,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0) std::string configType; if (const char* vsConfigurationType = this->GeneratorTarget->GetProperty("VS_CONFIGURATION_TYPE")) { - configType = cmVS10EscapeXML(vsConfigurationType); + configType = vsConfigurationType; } else { switch (this->GeneratorTarget->GetType()) { case cmStateEnums::SHARED_LIBRARY: @@ -1416,102 +1425,105 @@ void cmVisualStudio10TargetGenerator::WriteGroups() char magic[] = { char(0xEF), char(0xBB), char(0xBF) }; fout.write(magic, 3); - // get the tools version to use - const std::string toolsVer(this->GlobalGenerator->GetToolsVersion()); fout << "<?xml version=\"1.0\" encoding=\"" - << this->GlobalGenerator->Encoding() << "\"?>\n"; + << this->GlobalGenerator->Encoding() << "\"?>" + << "\n"; + { + Elem e0(fout); + e0.StartElement("Project"); + e0.Attribute("ToolsVersion", this->GlobalGenerator->GetToolsVersion()); + e0.Attribute("xmlns", + "http://schemas.microsoft.com/developer/msbuild/2003"); - Elem e0(fout, 0); - e0.StartElement("Project"); - e0.Attribute("ToolsVersion", toolsVer); - e0.Attribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003"); - e0.SetHasElements(); + for (auto const& ti : this->Tools) { + this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups); + } - for (auto const& ti : this->Tools) { - this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups); - } + // Added files are images and the manifest. + if (!this->AddedFiles.empty()) { + Elem e1(e0, "ItemGroup"); + e1.SetHasElements(); + for (std::string const& oi : this->AddedFiles) { + std::string fileName = + cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(oi)); + if (fileName == "wmappmanifest.xml") { + Elem e2(e1, "XML"); + e2.Attribute("Include", oi); + e2.Element("Filter", "Resource Files"); + e2.EndElement(); + } else if (cmSystemTools::GetFilenameExtension(fileName) == + ".appxmanifest") { + Elem e2(e1, "AppxManifest"); + e2.Attribute("Include", oi); + e2.Element("Filter", "Resource Files"); + e2.EndElement(); + } else if (cmSystemTools::GetFilenameExtension(fileName) == ".pfx") { + Elem e2(e1, "None"); + e2.Attribute("Include", oi); + e2.Element("Filter", "Resource Files"); + e2.EndElement(); + } else { + Elem e2(e1, "Image"); + e2.Attribute("Include", oi); + e2.Element("Filter", "Resource Files"); + e2.EndElement(); + } + } + e1.EndElement(); + } - // Added files are images and the manifest. - if (!this->AddedFiles.empty()) { - Elem e1(e0, "ItemGroup"); - e1.SetHasElements(); - for (std::string const& oi : this->AddedFiles) { - std::string fileName = - cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(oi)); - if (fileName == "wmappmanifest.xml") { - Elem e2(e1, "XML"); - e2.Attribute("Include", oi); - e2.Element("Filter", "Resource Files"); - e2.EndElement(); - } else if (cmSystemTools::GetFilenameExtension(fileName) == - ".appxmanifest") { - Elem e2(e1, "AppxManifest"); - e2.Attribute("Include", oi); - e2.Element("Filter", "Resource Files"); - e2.EndElement(); - } else if (cmSystemTools::GetFilenameExtension(fileName) == ".pfx") { - Elem e2(e1, "None"); - e2.Attribute("Include", oi); - e2.Element("Filter", "Resource Files"); - e2.EndElement(); - } else { - Elem e2(e1, "Image"); - e2.Attribute("Include", oi); + std::vector<cmSourceFile const*> resxObjs; + this->GeneratorTarget->GetResxSources(resxObjs, ""); + if (!resxObjs.empty()) { + Elem e1(e0, "ItemGroup"); + for (cmSourceFile const* oi : resxObjs) { + std::string obj = oi->GetFullPath(); + ConvertToWindowsSlash(obj); + Elem e2(e1, "EmbeddedResource"); + e2.Attribute("Include", obj); e2.Element("Filter", "Resource Files"); e2.EndElement(); } + e1.EndElement(); } - e1.EndElement(); - } + { + Elem e1(e0, "ItemGroup"); + e1.SetHasElements(); + std::vector<cmSourceGroup*> groupsVec(groupsUsed.begin(), + groupsUsed.end()); + std::sort(groupsVec.begin(), groupsVec.end(), + [](cmSourceGroup* l, cmSourceGroup* r) { + return l->GetFullName() < r->GetFullName(); + }); + for (cmSourceGroup* sg : groupsVec) { + std::string const& name = sg->GetFullName(); + if (!name.empty()) { + std::string guidName = "SG_Filter_" + name; + std::string guid = this->GlobalGenerator->GetGUID(guidName); + Elem e2(e1, "Filter"); + e2.Attribute("Include", name); + e2.Element("UniqueIdentifier", "{" + guid + "}"); + e2.EndElement(); + } + } - std::vector<cmSourceFile const*> resxObjs; - this->GeneratorTarget->GetResxSources(resxObjs, ""); - if (!resxObjs.empty()) { - Elem e1(e0, "ItemGroup"); - for (cmSourceFile const* oi : resxObjs) { - std::string obj = oi->GetFullPath(); - ConvertToWindowsSlash(obj); - Elem e2(e1, "EmbeddedResource"); - e2.Attribute("Include", obj); - e2.Element("Filter", "Resource Files"); - e2.EndElement(); - } - e1.EndElement(); - } + if (!resxObjs.empty() || !this->AddedFiles.empty()) { + std::string guidName = "SG_Filter_Resource Files"; + std::string guid = this->GlobalGenerator->GetGUID(guidName); + Elem e2(e1, "Filter"); + e2.Attribute("Include", "Resource Files"); + e2.Element("UniqueIdentifier", "{" + guid + "}"); + e2.Element("Extensions", + "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;" + "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms"); + e2.EndElement(); + } - Elem e1(e0, "ItemGroup"); - e1.SetHasElements(); - std::vector<cmSourceGroup*> groupsVec(groupsUsed.begin(), groupsUsed.end()); - std::sort(groupsVec.begin(), groupsVec.end(), - [](cmSourceGroup* l, cmSourceGroup* r) { - return l->GetFullName() < r->GetFullName(); - }); - for (cmSourceGroup* sg : groupsVec) { - std::string const& name = sg->GetFullName(); - if (!name.empty()) { - std::string guidName = "SG_Filter_" + name; - std::string guid = this->GlobalGenerator->GetGUID(guidName); - Elem e2(e1, "Filter"); - e2.Attribute("Include", name); - e2.Element("UniqueIdentifier", "{" + guid + "}"); - e2.EndElement(); + e1.EndElement(); } + e0.EndElement(); } - - if (!resxObjs.empty() || !this->AddedFiles.empty()) { - std::string guidName = "SG_Filter_Resource Files"; - std::string guid = this->GlobalGenerator->GetGUID(guidName); - Elem e2(e1, "Filter"); - e2.Attribute("Include", "Resource Files"); - e2.Element("UniqueIdentifier", "{" + guid + "}"); - e2.Element("Extensions", - "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;" - "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms"); - e2.EndElement(); - } - - e1.EndElement(); - e0.EndElement(); + fout << '\n'; if (fout.Close()) { this->GlobalGenerator->FileReplacedDuringGenerate(path); @@ -1866,7 +1878,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1, // write source file specific tags this->WriteCSharpSourceProperties(e2, sourceFileTags); } - e2.WriteEndTag(tool); + e2.EndElement(); } void cmVisualStudio10TargetGenerator::WriteSource(Elem& e2, @@ -1919,6 +1931,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) return; } Elem e1(e0, "ItemGroup"); + e1.SetHasElements(); std::vector<size_t> all_configs; for (size_t ci = 0; ci < this->Configurations.size(); ++ci) { @@ -2096,7 +2109,6 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( // for the first time we need a new line if there is something // produced here. if (!objectName.empty()) { - e2.SetHasElements(); if (lang == "CUDA") { e2.Element("CompileOut", "$(IntDir)/" + objectName); } else { @@ -2193,7 +2205,6 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } } if (this->IsXamlSource(source->GetFullPath())) { - e2.SetHasElements(); const std::string& fileName = source->GetFullPath(); std::string xamlFileName = fileName.substr(0, fileName.find_last_of(".")); e2.Element("DependentUpon", xamlFileName); @@ -2391,8 +2402,8 @@ std::vector<std::string> cmVisualStudio10TargetGenerator::GetIncludes( bool cmVisualStudio10TargetGenerator::ComputeClOptions() { - for (std::string const& i : this->Configurations) { - if (!this->ComputeClOptions(i)) { + for (std::string const& c : this->Configurations) { + if (!this->ComputeClOptions(c)) { return false; } } @@ -2658,8 +2669,8 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( bool cmVisualStudio10TargetGenerator::ComputeRcOptions() { - for (std::string const& i : this->Configurations) { - if (!this->ComputeRcOptions(i)) { + for (std::string const& c : this->Configurations) { + if (!this->ComputeRcOptions(c)) { return false; } } @@ -2716,8 +2727,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions() if (!this->GlobalGenerator->IsCudaEnabled()) { return true; } - for (std::string const& i : this->Configurations) { - if (!this->ComputeCudaOptions(i)) { + for (std::string const& c : this->Configurations) { + if (!this->ComputeCudaOptions(c)) { return false; } } @@ -2864,8 +2875,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions() if (!this->GlobalGenerator->IsCudaEnabled()) { return true; } - for (std::string const& i : this->Configurations) { - if (!this->ComputeCudaLinkOptions(i)) { + for (std::string const& c : this->Configurations) { + if (!this->ComputeCudaLinkOptions(c)) { return false; } } @@ -2932,8 +2943,8 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions() if (!this->GlobalGenerator->IsMasmEnabled()) { return true; } - for (std::string const& i : this->Configurations) { - if (!this->ComputeMasmOptions(i)) { + for (std::string const& c : this->Configurations) { + if (!this->ComputeMasmOptions(c)) { return false; } } @@ -2989,8 +3000,8 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions() if (!this->GlobalGenerator->IsNasmEnabled()) { return true; } - for (std::string const& i : this->Configurations) { - if (!this->ComputeNasmOptions(i)) { + for (std::string const& c : this->Configurations) { + if (!this->ComputeNasmOptions(c)) { return false; } } @@ -3121,8 +3132,8 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( } } - Elem e2(e1, "AntBuild"); // Tell MSBuild to launch Ant. + Elem e2(e1, "AntBuild"); { std::string antBuildPath = rootDir; ConvertToWindowsSlash(antBuildPath); @@ -3213,8 +3224,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions() if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE || this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY || this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) { - for (std::string const& i : this->Configurations) { - if (!this->ComputeLinkOptions(i)) { + for (std::string const& c : this->Configurations) { + if (!this->ComputeLinkOptions(c)) { return false; } } @@ -3448,8 +3459,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( bool cmVisualStudio10TargetGenerator::ComputeLibOptions() { if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) { - for (std::string const& i : this->Configurations) { - if (!this->ComputeLibOptions(i)) { + for (std::string const& c : this->Configurations) { + if (!this->ComputeLibOptions(c)) { return false; } } @@ -3626,10 +3637,10 @@ void cmVisualStudio10TargetGenerator::WriteMidlOptions( for (std::string const& i : includes) { oss << i << ";"; } + oss << "%(AdditionalIncludeDirectories)"; Elem e2(e1, "Midl"); - e2.Element("AdditionalIncludeDirectories", - oss.str() + "%(AdditionalIncludeDirectories)"); + e2.Element("AdditionalIncludeDirectories", oss.str()); e2.Element("OutputDirectory", "$(ProjectDir)/$(IntDir)"); e2.Element("HeaderFileName", "%(Filename).h"); e2.Element("TypeLibraryName", "%(Filename).tlb"); @@ -3643,36 +3654,36 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups(Elem& e0) if (this->ProjectType == csproj) { return; } - for (const auto& i : this->Configurations) { + for (const std::string& c : this->Configurations) { Elem e1(e0, "ItemDefinitionGroup"); - e1.Attribute("Condition", this->CalcCondition(i)); + e1.Attribute("Condition", this->CalcCondition(c)); // output cl compile flags <ClCompile></ClCompile> if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) { - this->WriteClOptions(e1, i); + this->WriteClOptions(e1, c); // output rc compile flags <ResourceCompile></ResourceCompile> - this->WriteRCOptions(e1, i); - this->WriteCudaOptions(e1, i); - this->WriteMasmOptions(e1, i); - this->WriteNasmOptions(e1, i); + this->WriteRCOptions(e1, c); + this->WriteCudaOptions(e1, c); + this->WriteMasmOptions(e1, c); + this->WriteNasmOptions(e1, c); } // output midl flags <Midl></Midl> - this->WriteMidlOptions(e1, i); + this->WriteMidlOptions(e1, c); // write events if (this->ProjectType != csproj) { - this->WriteEvents(e1, i); + this->WriteEvents(e1, c); } // output link flags <Link></Link> - this->WriteLinkOptions(e1, i); - this->WriteCudaLinkOptions(e1, i); + this->WriteLinkOptions(e1, c); + this->WriteCudaLinkOptions(e1, c); // output lib flags <Lib></Lib> - this->WriteLibOptions(e1, i); + this->WriteLibOptions(e1, c); // output manifest flags <Manifest></Manifest> - this->WriteManifestOptions(e1, i); + this->WriteManifestOptions(e1, c); if (this->NsightTegra && this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE && this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) { - this->WriteAntBuildOptions(e1, i); + this->WriteAntBuildOptions(e1, c); } e1.EndElement(); } @@ -3709,13 +3720,12 @@ void cmVisualStudio10TargetGenerator::WriteEvent( if (commands.empty()) { return; } - Elem e2(e1, name); cmLocalVisualStudio7Generator* lg = this->LocalGenerator; std::string script; const char* pre = ""; std::string comment; - for (cmCustomCommand const& i : commands) { - cmCustomCommandGenerator ccg(i, configName, this->LocalGenerator); + for (cmCustomCommand const& cc : commands) { + cmCustomCommandGenerator ccg(cc, configName, lg); if (!ccg.HasOnlyEmptyCommandLines()) { comment += pre; comment += lg->ConstructComment(ccg); @@ -3726,6 +3736,7 @@ void cmVisualStudio10TargetGenerator::WriteEvent( } comment = cmVS10EscapeComment(comment); if (this->ProjectType != csproj) { + Elem e2(e1, name); e2.Element("Message", comment); e2.Element("Command", script); e2.EndElement(); @@ -3739,7 +3750,7 @@ void cmVisualStudio10TargetGenerator::WriteEvent( oss << "echo " << comment << "\n"; } oss << script << "\n"; - e2.Content(oss.str()); + e1.Element(name, oss.str()); } } @@ -3752,8 +3763,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0) OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET); Elem e1(e0, "ItemGroup"); e1.SetHasElements(); - for (cmTargetDepend const& i : depends) { - cmGeneratorTarget const* dt = i; + for (cmGeneratorTarget const* dt : depends) { if (dt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 8c0b6ca..15e47b4 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -144,7 +144,7 @@ private: void WriteGroups(); void WriteProjectReferences(Elem& e0); void WriteApplicationTypeSettings(Elem& e1); - void OutputSourceSpecificFlags(Elem&, cmSourceFile const* source); + void OutputSourceSpecificFlags(Elem& e2, cmSourceFile const* source); void AddLibraries(const cmComputeLinkInformation& cli, std::vector<std::string>& libVec, std::vector<std::string>& vsTargetVec, @@ -186,8 +186,6 @@ private: OptionsMap NasmOptions; OptionsMap LinkOptions; std::string LangForClCompile; - std::string PathToProjectFile; - std::string ProjectFileExtension; enum VsProjectType { vcxproj, @@ -207,7 +205,6 @@ private: unsigned int NsightTegraVersion[4]; bool TargetCompileAsWinRT; cmGlobalVisualStudio10Generator* const GlobalGenerator; - cmGeneratedFileStream* BuildFileStream; cmLocalVisualStudio10Generator* const LocalGenerator; std::set<std::string> CSharpCustomCommandNames; bool IsMissingFiles; diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 52f509a..7743e4e 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -2282,7 +2282,9 @@ bool SystemTools::CopyADirectory(const std::string& source, const std::string& destination, bool always) { Directory dir; - dir.Load(source); + if (dir.Load(source) == 0) { + return false; + } size_t fileNum; if (!SystemTools::MakeDirectory(destination)) { return false; @@ -4030,23 +4032,16 @@ std::string SystemTools::MakeCidentifier(const std::string& s) return str; } -// Due to a buggy stream library on the HP and another on Mac OS X, we -// need this very carefully written version of getline. Returns true +// Convenience function around std::getline which removes a trailing carriage +// return and can truncate the buffer as needed. Returns true // if any data were read before the end-of-file was reached. bool SystemTools::GetLineFromStream(std::istream& is, std::string& line, bool* has_newline /* = 0 */, long sizeLimit /* = -1 */) { - const int bufferSize = 1024; - char buffer[bufferSize]; - bool haveData = false; - bool haveNewline = false; - // Start with an empty line. line = ""; - long leftToRead = sizeLimit; - // Early short circuit return if stream is no good. Just return // false and the empty line. (Probably means caller tried to // create a file stream with a non-existent file name...) @@ -4058,44 +4053,23 @@ bool SystemTools::GetLineFromStream(std::istream& is, std::string& line, return false; } - // If no characters are read from the stream, the end of file has - // been reached. Clear the fail bit just before reading. - while (!haveNewline && leftToRead != 0 && - (static_cast<void>(is.clear(is.rdstate() & ~std::ios::failbit)), - static_cast<void>(is.getline(buffer, bufferSize)), - is.gcount() > 0)) { - // We have read at least one byte. - haveData = true; - - // If newline character was read the gcount includes the character - // but the buffer does not: the end of line has been reached. - size_t length = strlen(buffer); - if (length < static_cast<size_t>(is.gcount())) { - haveNewline = true; - } - + std::getline(is, line); + bool haveData = !line.empty() || !is.eof(); + if (!line.empty()) { // Avoid storing a carriage return character. - if (length > 0 && buffer[length - 1] == '\r') { - buffer[length - 1] = 0; + if (*line.rbegin() == '\r') { + line.resize(line.size() - 1); } // if we read too much then truncate the buffer - if (leftToRead > 0) { - if (static_cast<long>(length) > leftToRead) { - buffer[leftToRead] = 0; - leftToRead = 0; - } else { - leftToRead -= static_cast<long>(length); - } + if (sizeLimit >= 0 && line.size() >= static_cast<size_t>(sizeLimit)) { + line.resize(sizeLimit); } - - // Append the data read to the line. - line.append(buffer); } // Return the results. if (has_newline) { - *has_newline = haveNewline; + *has_newline = !is.eof(); } return haveData; } diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index e79e3fc..3898e3a 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -523,9 +523,8 @@ public: static bool GetShortPath(const std::string& path, std::string& result); /** - * Read line from file. Make sure to get everything. Due to a buggy stream - * library on the HP and another on Mac OS X, we need this very carefully - * written version of getline. Returns true if any data were read before the + * Read line from file. Make sure to read a full line and truncates it if + * requested via sizeLimit. Returns true if any data were read before the * end-of-file was reached. If the has_newline argument is specified, it will * be true when the line read had a newline character. */ diff --git a/Source/kwsys/testDirectory.cxx b/Source/kwsys/testDirectory.cxx index 983f2c6..62a0986 100644 --- a/Source/kwsys/testDirectory.cxx +++ b/Source/kwsys/testDirectory.cxx @@ -73,7 +73,38 @@ int _doLongPathTest() return res; } +int _copyDirectoryTest() +{ + using namespace kwsys; + const std::string source(TEST_SYSTEMTOOLS_BINARY_DIR + "/directory_testing/copyDirectoryTestSrc"); + if (SystemTools::PathExists(source)) { + std::cerr << source << " shouldn't exist before test" << std::endl; + return 1; + } + const std::string destination(TEST_SYSTEMTOOLS_BINARY_DIR + "/directory_testing/copyDirectoryTestDst"); + if (SystemTools::PathExists(destination)) { + std::cerr << destination << " shouldn't exist before test" << std::endl; + return 2; + } + const bool copysuccess = SystemTools::CopyADirectory(source, destination); + const bool destinationexists = SystemTools::PathExists(destination); + if (copysuccess) { + std::cerr << "CopyADirectory should have returned false" << std::endl; + SystemTools::RemoveADirectory(destination); + return 3; + } + if (destinationexists) { + std::cerr << "CopyADirectory returned false, but destination directory" + << " has been created" << std::endl; + SystemTools::RemoveADirectory(destination); + return 4; + } + return 0; +} + int testDirectory(int, char* []) { - return _doLongPathTest(); + return _doLongPathTest() + _copyDirectoryTest(); } diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index a6d934b..8c928d4 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -912,6 +912,78 @@ static bool CheckGetLineFromStream() return ret; } +static bool CheckGetLineFromStreamLongLine() +{ + const std::string fileWithLongLine("longlines.txt"); + std::string firstLine, secondLine; + // First line: large buffer, containing a carriage return for some reason. + firstLine.assign(2050, ' '); + firstLine += "\rfirst"; + secondLine.assign(2050, 'y'); + secondLine += "second"; + + // Create file with long lines. + { + kwsys::ofstream out(fileWithLongLine.c_str(), std::ios::binary); + if (!out) { + std::cerr << "Problem opening for write: " << fileWithLongLine + << std::endl; + return false; + } + out << firstLine << "\r\n\n" << secondLine << "\n"; + } + + kwsys::ifstream file(fileWithLongLine.c_str(), std::ios::binary); + if (!file) { + std::cerr << "Problem opening: " << fileWithLongLine << std::endl; + return false; + } + + std::string line; + bool has_newline = false; + bool result; + + // Read first line. + result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1); + if (!result || line != firstLine) { + std::cerr << "First line does not match, expected " << firstLine.size() + << " characters, got " << line.size() << std::endl; + return false; + } + if (!has_newline) { + std::cerr << "Expected new line to be read from first line" << std::endl; + return false; + } + + // Read empty line. + has_newline = false; + result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1); + if (!result || !line.empty()) { + std::cerr << "Expected successful read with an empty line, got " + << line.size() << " characters" << std::endl; + return false; + } + if (!has_newline) { + std::cerr << "Expected new line to be read for an empty line" << std::endl; + return false; + } + + // Read second line. + has_newline = false; + result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1); + if (!result || line != secondLine) { + std::cerr << "Second line does not match, expected " << secondLine.size() + << " characters, got " << line.size() << std::endl; + return false; + } + if (!has_newline) { + std::cerr << "Expected new line to be read from second line" << std::endl; + return false; + } + + return true; +} + int testSystemTools(int, char* []) { bool res = true; @@ -951,6 +1023,8 @@ int testSystemTools(int, char* []) res &= CheckGetLineFromStream(); + res &= CheckGetLineFromStreamLongLine(); + res &= CheckGetFilenameName(); return res ? 0 : 1; |