diff options
Diffstat (limited to 'Source')
48 files changed, 699 insertions, 507 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 2835ee6..3b49f72 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -440,6 +440,8 @@ set(SRCS cmCreateTestSourceList.h cmDefinePropertyCommand.cxx cmDefinePropertyCommand.h + cmDisallowedCommand.cxx + cmDisallowedCommand.h cmEnableLanguageCommand.cxx cmEnableLanguageCommand.h cmEnableTestingCommand.cxx diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index a7a281d..a92cb20 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 8) -set(CMake_VERSION_PATCH 0) -set(CMake_VERSION_RC 1) +set(CMake_VERSION_PATCH 20170216) +#set(CMake_VERSION_RC 1) diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index 2bccf2e..39586de 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -437,8 +437,8 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() directoryDefinitions.AddAttribute("Name", "SourceDir"); size_t installRootSize = - directoryDefinitions.BeginInstallationPrefixDirectory( - GetProgramFilesFolderId(), installRoot); + directoryDefinitions.BeginInstallationPrefixDirectory(GetRootFolderId(), + installRoot); std::string fileDefinitionsFilename = this->CPackTopLevel + "/files.wxs"; @@ -570,16 +570,26 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() return this->Patch->CheckForUnappliedFragments(); } -std::string cmCPackWIXGenerator::GetProgramFilesFolderId() const +std::string cmCPackWIXGenerator::GetRootFolderId() const { if (cmSystemTools::IsOn(GetOption("CPACK_WIX_SKIP_PROGRAM_FOLDER"))) { return ""; } + + std::string result = "ProgramFiles<64>Folder"; + + const char* rootFolderId = GetOption("CPACK_WIX_ROOT_FOLDER_ID"); + if (rootFolderId) { + result = rootFolderId; + } + if (GetArchitecture() == "x86") { - return "ProgramFilesFolder"; + cmSystemTools::ReplaceString(result, "<64>", ""); } else { - return "ProgramFiles64Folder"; + cmSystemTools::ReplaceString(result, "<64>", "64"); } + + return result; } bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate() diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h index fc0994c..36647d8 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.h +++ b/Source/CPack/WiX/cmCPackWIXGenerator.h @@ -65,7 +65,7 @@ private: bool CreateWiXSourceFiles(); - std::string GetProgramFilesFolderId() const; + std::string GetRootFolderId() const; bool GenerateMainSourceFileFromTemplate(); diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index a989b12..2a67d47 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -123,8 +123,8 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, if (capureCMakeError) { this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR], "-1"); - const char* err = this->GetError(); - if (err && !cmSystemTools::FindLastString(err, "unknown error.")) { + std::string const err = this->GetName() + " " + this->GetError(); + if (!cmSystemTools::FindLastString(err.c_str(), "unknown error.")) { cmCTestLog(this->CTest, ERROR_MESSAGE, err << " error from command\n"); } // return success because failure is recorded in CAPTURE_CMAKE_ERROR diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 7c683ad..f5469e5 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -101,6 +101,12 @@ FwdIt cmRotate(FwdIt first, FwdIt middle, FwdIt last) return first; } +template <typename Container, typename Predicate> +void cmEraseIf(Container& cont, Predicate pred) +{ + cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end()); +} + namespace ContainerAlgorithms { template <typename T> diff --git a/Source/cmBuildNameCommand.cxx b/Source/cmBuildNameCommand.cxx index 1e1cd21..12b69a8 100644 --- a/Source/cmBuildNameCommand.cxx +++ b/Source/cmBuildNameCommand.cxx @@ -16,11 +16,6 @@ class cmExecutionStatus; bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) { - if (this->Disallowed( - cmPolicies::CMP0036, - "The build_name command should not be called; see CMP0036.")) { - return true; - } if (args.empty()) { this->SetError("called with incorrect number of arguments"); return false; diff --git a/Source/cmCommand.cxx b/Source/cmCommand.cxx index 181b412..d349c91 100644 --- a/Source/cmCommand.cxx +++ b/Source/cmCommand.cxx @@ -3,7 +3,6 @@ #include "cmCommand.h" #include "cmMakefile.h" -#include "cmake.h" class cmExecutionStatus; struct cmListFileArgument; @@ -23,32 +22,12 @@ bool cmCommand::InvokeInitialPass(const std::vector<cmListFileArgument>& args, const char* cmCommand::GetError() { if (this->Error.empty()) { - this->Error = this->GetName(); - this->Error += " unknown error."; + return "unknown error."; } return this->Error.c_str(); } void cmCommand::SetError(const std::string& e) { - this->Error = this->GetName(); - this->Error += " "; - this->Error += e; -} - -bool cmCommand::Disallowed(cmPolicies::PolicyID pol, const char* e) -{ - switch (this->Makefile->GetPolicyStatus(pol)) { - case cmPolicies::WARN: - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, - cmPolicies::GetPolicyWarning(pol)); - case cmPolicies::OLD: - return false; - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::NEW: - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e); - break; - } - return true; + this->Error = e; } diff --git a/Source/cmCommand.h b/Source/cmCommand.h index d9fd5a2..9107d85 100644 --- a/Source/cmCommand.h +++ b/Source/cmCommand.h @@ -7,9 +7,6 @@ #include <string> #include <vector> -#include "cmCommandArgumentsHelper.h" -#include "cmPolicies.h" - class cmExecutionStatus; class cmMakefile; struct cmListFileArgument; @@ -105,12 +102,12 @@ public: */ void SetError(const std::string& e); - /** Check if the command is disallowed by a policy. */ - bool Disallowed(cmPolicies::PolicyID pol, const char* e); +private: + cmCommand(cmCommand const&); // = delete; + cmCommand& operator=(cmCommand const&); // = delete; protected: cmMakefile* Makefile; - cmCommandArgumentsHelper Helper; private: std::string Error; diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 4c5b093..b58dc62 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -1,6 +1,7 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCommands.h" +#include "cmState.h" #include "cmAddCustomCommandCommand.h" #include "cmAddCustomTargetCommand.h" @@ -77,6 +78,7 @@ #include "cmAuxSourceDirectoryCommand.h" #include "cmBuildNameCommand.h" #include "cmCMakeHostSystemInformationCommand.h" +#include "cmDisallowedCommand.h" #include "cmExportCommand.h" #include "cmExportLibraryDependenciesCommand.h" #include "cmFLTKWrapUICommand.h" @@ -104,138 +106,162 @@ #include "cmWriteFileCommand.h" #endif -std::vector<cmCommand*> GetPredefinedCommands() +void GetScriptingCommands(cmState* state) { - std::vector<cmCommand*> commands; + state->AddCommand(new cmBreakCommand); + state->AddCommand(new cmCMakeMinimumRequired); + state->AddCommand(new cmCMakePolicyCommand); + state->AddCommand(new cmConfigureFileCommand); + state->AddCommand(new cmContinueCommand); + state->AddCommand(new cmExecProgramCommand); + state->AddCommand(new cmExecuteProcessCommand); + state->AddCommand(new cmFileCommand); + state->AddCommand(new cmFindFileCommand); + state->AddCommand(new cmFindLibraryCommand); + state->AddCommand(new cmFindPackageCommand); + state->AddCommand(new cmFindPathCommand); + state->AddCommand(new cmFindProgramCommand); + state->AddCommand(new cmForEachCommand); + state->AddCommand(new cmFunctionCommand); + state->AddCommand(new cmGetCMakePropertyCommand); + state->AddCommand(new cmGetDirectoryPropertyCommand); + state->AddCommand(new cmGetFilenameComponentCommand); + state->AddCommand(new cmGetPropertyCommand); + state->AddCommand(new cmIfCommand); + state->AddCommand(new cmIncludeCommand); + state->AddCommand(new cmListCommand); + state->AddCommand(new cmMacroCommand); + state->AddCommand(new cmMakeDirectoryCommand); + state->AddCommand(new cmMarkAsAdvancedCommand); + state->AddCommand(new cmMathCommand); + state->AddCommand(new cmMessageCommand); + state->AddCommand(new cmOptionCommand); + state->AddCommand(new cmParseArgumentsCommand); + state->AddCommand(new cmReturnCommand); + state->AddCommand(new cmSeparateArgumentsCommand); + state->AddCommand(new cmSetCommand); + state->AddCommand(new cmSetDirectoryPropertiesCommand); + state->AddCommand(new cmSetPropertyCommand); + state->AddCommand(new cmSiteNameCommand); + state->AddCommand(new cmStringCommand); + state->AddCommand(new cmUnsetCommand); + state->AddCommand(new cmWhileCommand); - commands.push_back(new cmAddCustomCommandCommand); - commands.push_back(new cmAddCustomTargetCommand); - commands.push_back(new cmAddDefinitionsCommand); - commands.push_back(new cmAddDependenciesCommand); - commands.push_back(new cmAddExecutableCommand); - commands.push_back(new cmAddLibraryCommand); - commands.push_back(new cmAddSubDirectoryCommand); - commands.push_back(new cmAddTestCommand); - commands.push_back(new cmBreakCommand); - commands.push_back(new cmBuildCommand); - commands.push_back(new cmCMakeMinimumRequired); - commands.push_back(new cmCMakePolicyCommand); - commands.push_back(new cmConfigureFileCommand); - commands.push_back(new cmContinueCommand); - commands.push_back(new cmCreateTestSourceList); - commands.push_back(new cmDefinePropertyCommand); - commands.push_back(new cmEnableLanguageCommand); - commands.push_back(new cmEnableTestingCommand); - commands.push_back(new cmExecProgramCommand); - commands.push_back(new cmExecuteProcessCommand); - commands.push_back(new cmFileCommand); - commands.push_back(new cmFindFileCommand); - commands.push_back(new cmFindLibraryCommand); - commands.push_back(new cmFindPackageCommand); - commands.push_back(new cmFindPathCommand); - commands.push_back(new cmFindProgramCommand); - commands.push_back(new cmForEachCommand); - commands.push_back(new cmFunctionCommand); - commands.push_back(new cmGetCMakePropertyCommand); - commands.push_back(new cmGetDirectoryPropertyCommand); - commands.push_back(new cmGetFilenameComponentCommand); - commands.push_back(new cmGetPropertyCommand); - commands.push_back(new cmGetSourceFilePropertyCommand); - commands.push_back(new cmGetTargetPropertyCommand); - commands.push_back(new cmGetTestPropertyCommand); - commands.push_back(new cmIfCommand); - commands.push_back(new cmIncludeCommand); - commands.push_back(new cmIncludeDirectoryCommand); - commands.push_back(new cmIncludeRegularExpressionCommand); - commands.push_back(new cmInstallCommand); - commands.push_back(new cmInstallFilesCommand); - commands.push_back(new cmInstallTargetsCommand); - commands.push_back(new cmLinkDirectoriesCommand); - commands.push_back(new cmListCommand); - commands.push_back(new cmMacroCommand); - commands.push_back(new cmMakeDirectoryCommand); - commands.push_back(new cmMarkAsAdvancedCommand); - commands.push_back(new cmMathCommand); - commands.push_back(new cmMessageCommand); - commands.push_back(new cmOptionCommand); - commands.push_back(new cmParseArgumentsCommand); - commands.push_back(new cmProjectCommand); - commands.push_back(new cmReturnCommand); - commands.push_back(new cmSeparateArgumentsCommand); - commands.push_back(new cmSetCommand); - commands.push_back(new cmSetDirectoryPropertiesCommand); - commands.push_back(new cmSetPropertyCommand); - commands.push_back(new cmSetSourceFilesPropertiesCommand); - commands.push_back(new cmSetTargetPropertiesCommand); - commands.push_back(new cmSetTestsPropertiesCommand); - commands.push_back(new cmSiteNameCommand); - commands.push_back(new cmStringCommand); - commands.push_back(new cmSubdirCommand); - commands.push_back(new cmTargetLinkLibrariesCommand); - commands.push_back(new cmTryCompileCommand); - commands.push_back(new cmTryRunCommand); - commands.push_back(new cmUnsetCommand); - commands.push_back(new cmWhileCommand); - - commands.push_back(new cmUnexpectedCommand( + state->AddCommand(new cmUnexpectedCommand( "else", "An ELSE command was found outside of a proper " "IF ENDIF structure. Or its arguments did not match " "the opening IF command.")); - commands.push_back(new cmUnexpectedCommand( + state->AddCommand(new cmUnexpectedCommand( "elseif", "An ELSEIF command was found outside of a proper " "IF ENDIF structure.")); - commands.push_back(new cmUnexpectedCommand( + state->AddCommand(new cmUnexpectedCommand( "endforeach", "An ENDFOREACH command was found outside of a proper " "FOREACH ENDFOREACH structure. Or its arguments did " "not match the opening FOREACH command.")); - commands.push_back(new cmUnexpectedCommand( + state->AddCommand(new cmUnexpectedCommand( "endfunction", "An ENDFUNCTION command was found outside of a proper " "FUNCTION ENDFUNCTION structure. Or its arguments did not " "match the opening FUNCTION command.")); - commands.push_back(new cmUnexpectedCommand( + state->AddCommand(new cmUnexpectedCommand( "endif", "An ENDIF command was found outside of a proper " "IF ENDIF structure. Or its arguments did not match " "the opening IF command.")); - commands.push_back(new cmUnexpectedCommand( + state->AddCommand(new cmUnexpectedCommand( "endmacro", "An ENDMACRO command was found outside of a proper " "MACRO ENDMACRO structure. Or its arguments did not " "match the opening MACRO command.")); - commands.push_back(new cmUnexpectedCommand( + state->AddCommand(new cmUnexpectedCommand( "endwhile", "An ENDWHILE command was found outside of a proper " "WHILE ENDWHILE structure. Or its arguments did not " "match the opening WHILE command.")); #if defined(CMAKE_BUILD_WITH_CMAKE) - commands.push_back(new cmAddCompileOptionsCommand); - commands.push_back(new cmAuxSourceDirectoryCommand); - commands.push_back(new cmBuildNameCommand); - commands.push_back(new cmCMakeHostSystemInformationCommand); - commands.push_back(new cmExportCommand); - commands.push_back(new cmExportLibraryDependenciesCommand); - commands.push_back(new cmFLTKWrapUICommand); - commands.push_back(new cmIncludeExternalMSProjectCommand); - commands.push_back(new cmInstallProgramsCommand); - commands.push_back(new cmLinkLibrariesCommand); - commands.push_back(new cmLoadCacheCommand); - commands.push_back(new cmLoadCommandCommand); - commands.push_back(new cmOutputRequiredFilesCommand); - commands.push_back(new cmQTWrapCPPCommand); - commands.push_back(new cmQTWrapUICommand); - commands.push_back(new cmRemoveCommand); - commands.push_back(new cmRemoveDefinitionsCommand); - commands.push_back(new cmSourceGroupCommand); - commands.push_back(new cmSubdirDependsCommand); - commands.push_back(new cmTargetCompileDefinitionsCommand); - commands.push_back(new cmTargetCompileFeaturesCommand); - commands.push_back(new cmTargetCompileOptionsCommand); - commands.push_back(new cmTargetIncludeDirectoriesCommand); - commands.push_back(new cmTargetSourcesCommand); - commands.push_back(new cmUseMangledMesaCommand); - commands.push_back(new cmUtilitySourceCommand); - commands.push_back(new cmVariableRequiresCommand); - commands.push_back(new cmVariableWatchCommand); - commands.push_back(new cmWriteFileCommand); + state->AddCommand(new cmCMakeHostSystemInformationCommand); + state->AddCommand(new cmRemoveCommand); + state->AddCommand(new cmVariableWatchCommand); + state->AddCommand(new cmWriteFileCommand); + + state->AddCommand(new cmDisallowedCommand( + new cmBuildNameCommand, cmPolicies::CMP0036, + "The build_name command should not be called; see CMP0036.")); + state->AddCommand(new cmDisallowedCommand( + new cmUseMangledMesaCommand, cmPolicies::CMP0030, + "The use_mangled_mesa command should not be called; see CMP0030.")); + #endif +} - return commands; +void GetProjectCommands(cmState* state) +{ + state->AddCommand(new cmAddCustomCommandCommand); + state->AddCommand(new cmAddCustomTargetCommand); + state->AddCommand(new cmAddDefinitionsCommand); + state->AddCommand(new cmAddDependenciesCommand); + state->AddCommand(new cmAddExecutableCommand); + state->AddCommand(new cmAddLibraryCommand); + state->AddCommand(new cmAddSubDirectoryCommand); + state->AddCommand(new cmAddTestCommand); + state->AddCommand(new cmBuildCommand); + state->AddCommand(new cmCreateTestSourceList); + state->AddCommand(new cmDefinePropertyCommand); + state->AddCommand(new cmEnableLanguageCommand); + state->AddCommand(new cmEnableTestingCommand); + state->AddCommand(new cmGetSourceFilePropertyCommand); + state->AddCommand(new cmGetTargetPropertyCommand); + state->AddCommand(new cmGetTestPropertyCommand); + state->AddCommand(new cmIncludeDirectoryCommand); + state->AddCommand(new cmIncludeRegularExpressionCommand); + state->AddCommand(new cmInstallCommand); + state->AddCommand(new cmInstallFilesCommand); + state->AddCommand(new cmInstallTargetsCommand); + state->AddCommand(new cmLinkDirectoriesCommand); + state->AddCommand(new cmProjectCommand); + state->AddCommand(new cmSetSourceFilesPropertiesCommand); + state->AddCommand(new cmSetTargetPropertiesCommand); + state->AddCommand(new cmSetTestsPropertiesCommand); + state->AddCommand(new cmSubdirCommand); + state->AddCommand(new cmTargetLinkLibrariesCommand); + state->AddCommand(new cmTryCompileCommand); + state->AddCommand(new cmTryRunCommand); + +#if defined(CMAKE_BUILD_WITH_CMAKE) + state->AddCommand(new cmAddCompileOptionsCommand); + state->AddCommand(new cmAuxSourceDirectoryCommand); + state->AddCommand(new cmExportCommand); + state->AddCommand(new cmFLTKWrapUICommand); + state->AddCommand(new cmIncludeExternalMSProjectCommand); + state->AddCommand(new cmInstallProgramsCommand); + state->AddCommand(new cmLinkLibrariesCommand); + state->AddCommand(new cmLoadCacheCommand); + state->AddCommand(new cmQTWrapCPPCommand); + state->AddCommand(new cmQTWrapUICommand); + state->AddCommand(new cmRemoveDefinitionsCommand); + state->AddCommand(new cmSourceGroupCommand); + state->AddCommand(new cmTargetCompileDefinitionsCommand); + state->AddCommand(new cmTargetCompileFeaturesCommand); + state->AddCommand(new cmTargetCompileOptionsCommand); + state->AddCommand(new cmTargetIncludeDirectoriesCommand); + state->AddCommand(new cmTargetSourcesCommand); + + state->AddCommand(new cmDisallowedCommand( + new cmExportLibraryDependenciesCommand, cmPolicies::CMP0033, + "The export_library_dependencies command should not be called; " + "see CMP0033.")); + state->AddCommand(new cmDisallowedCommand( + new cmLoadCommandCommand, cmPolicies::CMP0031, + "The load_command command should not be called; see CMP0031.")); + state->AddCommand(new cmDisallowedCommand( + new cmOutputRequiredFilesCommand, cmPolicies::CMP0032, + "The output_required_files command should not be called; " + "see CMP0032.")); + state->AddCommand(new cmDisallowedCommand( + new cmSubdirDependsCommand, cmPolicies::CMP0029, + "The subdir_depends command should not be called; see CMP0029.")); + state->AddCommand(new cmDisallowedCommand( + new cmUtilitySourceCommand, cmPolicies::CMP0034, + "The utility_source command should not be called; see CMP0034.")); + state->AddCommand(new cmDisallowedCommand( + new cmVariableRequiresCommand, cmPolicies::CMP0035, + "The variable_requires command should not be called; see CMP0035.")); +#endif } diff --git a/Source/cmCommands.h b/Source/cmCommands.h index 649dea6..7895ece 100644 --- a/Source/cmCommands.h +++ b/Source/cmCommands.h @@ -3,16 +3,14 @@ #ifndef cmCommands_h #define cmCommands_h -#include <cmConfigure.h> // IWYU pragma: keep +class cmState; -#include <vector> - -class cmCommand; /** - * Global function to return all compiled in commands. + * Global function to register all compiled in commands. * To add a new command edit cmCommands.cxx and add your command. * It is up to the caller to delete the commands created by this call. */ -std::vector<cmCommand*> GetPredefinedCommands(); +void GetScriptingCommands(cmState* state); +void GetProjectCommands(cmState* state); #endif diff --git a/Source/cmDisallowedCommand.cxx b/Source/cmDisallowedCommand.cxx new file mode 100644 index 0000000..ce1965d --- /dev/null +++ b/Source/cmDisallowedCommand.cxx @@ -0,0 +1,31 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmDisallowedCommand.h" + +#include "cmMakefile.h" +#include "cmake.h" + +class cmExecutionStatus; + +bool cmDisallowedCommand::InitialPass(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + switch (this->Makefile->GetPolicyStatus(this->Policy)) { + case cmPolicies::WARN: + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, + cmPolicies::GetPolicyWarning(this->Policy)); + break; + case cmPolicies::OLD: + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + this->Makefile->IssueMessage(cmake::FATAL_ERROR, this->Message); + return true; + } + + this->Command->SetMakefile(this->GetMakefile()); + bool const ret = this->Command->InitialPass(args, status); + this->SetError(this->Command->GetError()); + return ret; +} diff --git a/Source/cmDisallowedCommand.h b/Source/cmDisallowedCommand.h new file mode 100644 index 0000000..00b0183 --- /dev/null +++ b/Source/cmDisallowedCommand.h @@ -0,0 +1,57 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmDisallowedCommand_h +#define cmDisallowedCommand_h + +#include <cmConfigure.h> +#include <string> +#include <vector> + +#include "cmCommand.h" +#include "cmPolicies.h" + +class cmExecutionStatus; + +class cmDisallowedCommand : public cmCommand +{ +public: + cmDisallowedCommand(cmCommand* command, cmPolicies::PolicyID policy, + const char* message) + : Command(command) + , Policy(policy) + , Message(message) + { + } + + ~cmDisallowedCommand() CM_OVERRIDE { delete this->Command; } + + cmCommand* Clone() CM_OVERRIDE + { + return new cmDisallowedCommand(this->Command->Clone(), this->Policy, + this->Message); + } + + bool InitialPass(std::vector<std::string> const& args, + cmExecutionStatus& status) CM_OVERRIDE; + + void FinalPass() CM_OVERRIDE { this->Command->FinalPass(); } + + bool HasFinalPass() const CM_OVERRIDE + { + return this->Command->HasFinalPass(); + } + + bool IsScriptable() const CM_OVERRIDE + { + return this->Command->IsScriptable(); + } + + std::string GetName() const CM_OVERRIDE { return this->Command->GetName(); } + +private: + cmCommand* Command; + cmPolicies::PolicyID Policy; + const char* Message; +}; + +#endif diff --git a/Source/cmExportCommand.h b/Source/cmExportCommand.h index 99dac7d..a0224d0 100644 --- a/Source/cmExportCommand.h +++ b/Source/cmExportCommand.h @@ -41,6 +41,7 @@ public: std::string GetName() const CM_OVERRIDE { return "export"; } private: + cmCommandArgumentsHelper Helper; cmCommandArgumentGroup ArgumentGroup; cmCAStringVector Targets; cmCAEnabler Append; diff --git a/Source/cmExportLibraryDependenciesCommand.cxx b/Source/cmExportLibraryDependenciesCommand.cxx index ac4f040..e3fb412 100644 --- a/Source/cmExportLibraryDependenciesCommand.cxx +++ b/Source/cmExportLibraryDependenciesCommand.cxx @@ -23,12 +23,6 @@ class cmExecutionStatus; bool cmExportLibraryDependenciesCommand::InitialPass( std::vector<std::string> const& args, cmExecutionStatus&) { - if (this->Disallowed( - cmPolicies::CMP0033, - "The export_library_dependencies command should not be called; " - "see CMP0033.")) { - return true; - } if (args.empty()) { this->SetError("called with incorrect number of arguments"); return false; diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index e27615a..b1285ac 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -13,6 +13,7 @@ #include "cmVS10LibFlagTable.h" #include "cmVS10LinkFlagTable.h" #include "cmVS10MASMFlagTable.h" +#include "cmVS10NASMFlagTable.h" #include "cmVS10RCFlagTable.h" #include "cmVisualStudioSlnData.h" #include "cmVisualStudioSlnParser.h" @@ -113,6 +114,7 @@ cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator( this->DefaultLibFlagTable = cmVS10LibFlagTable; this->DefaultLinkFlagTable = cmVS10LinkFlagTable; this->DefaultMasmFlagTable = cmVS10MASMFlagTable; + this->DefaultNasmFlagTable = cmVS10NASMFlagTable; this->DefaultRcFlagTable = cmVS10RCFlagTable; this->Version = VS10; } @@ -180,24 +182,80 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset( bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset( std::string const& ts, cmMakefile* mf) { - if (ts.find_first_of(",=") != ts.npos) { - std::ostringstream e; - /* clang-format off */ - e << - "Generator\n" - " " << this->GetName() << "\n" - "does not recognize the toolset\n" - " " << ts << "\n" - "that was specified."; - /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); - return false; + std::vector<std::string> const fields = cmSystemTools::tokenize(ts, ","); + std::vector<std::string>::const_iterator fi = fields.begin(); + if (fi == fields.end()) { + return true; + } + + // The first field may be the VS platform toolset. + if (fi->find('=') == fi->npos) { + this->GeneratorToolset = *fi; + ++fi; + } + + std::set<std::string> handled; + + // The rest of the fields must be key=value pairs. + for (; fi != fields.end(); ++fi) { + std::string::size_type pos = fi->find('='); + if (pos == fi->npos) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "given toolset specification\n" + " " << ts << "\n" + "that contains a field after the first ',' with no '='." + ; + /* clang-format on */ + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } + std::string const key = fi->substr(0, pos); + std::string const value = fi->substr(pos + 1); + if (!handled.insert(key).second) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "given toolset specification\n" + " " << ts << "\n" + "that contains duplicate field key '" << key << "'." + ; + /* clang-format on */ + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } + if (!this->ProcessGeneratorToolsetField(key, value)) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "given toolset specification\n" + " " << ts << "\n" + "that contains invalid field '" << *fi << "'." + ; + /* clang-format on */ + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } } - this->GeneratorToolset = ts; return true; } +bool cmGlobalVisualStudio10Generator::ProcessGeneratorToolsetField( + std::string const& key, std::string const& value) +{ + static_cast<void>(key); + static_cast<void>(value); + return false; +} + bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf) { if (this->SystemName == "Windows") { @@ -354,6 +412,13 @@ void cmGlobalVisualStudio10Generator::Generate() void cmGlobalVisualStudio10Generator::EnableLanguage( std::vector<std::string> const& lang, cmMakefile* mf, bool optional) { + for (std::vector<std::string>::const_iterator it = lang.begin(); + it != lang.end(); ++it) { + if (*it == "ASM_NASM") { + this->NasmEnabled = true; + } + } + this->AddPlatformDefinitions(mf); cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional); } @@ -663,3 +728,8 @@ cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const return (table != CM_NULLPTR) ? table : this->DefaultMasmFlagTable; } + +cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const +{ + return this->DefaultNasmFlagTable; +} diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 5bfaf38..c5e4bcd 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -23,7 +23,6 @@ public: virtual bool SetSystemName(std::string const& s, cmMakefile* mf); virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf); virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf); - virtual bool ParseGeneratorToolset(std::string const& ts, cmMakefile* mf); virtual void GenerateBuildCommand( std::vector<std::string>& makeCommand, const std::string& makeProgram, @@ -96,6 +95,7 @@ public: cmIDEFlagTable const* GetLibFlagTable() const; cmIDEFlagTable const* GetLinkFlagTable() const; cmIDEFlagTable const* GetMasmFlagTable() const; + cmIDEFlagTable const* GetNasmFlagTable() const; protected: virtual void Generate(); @@ -105,6 +105,9 @@ protected: virtual bool InitializeWindowsPhone(cmMakefile* mf); virtual bool InitializeWindowsStore(cmMakefile* mf); + virtual bool ProcessGeneratorToolsetField(std::string const& key, + std::string const& value); + virtual std::string SelectWindowsCEToolset() const; virtual bool SelectWindowsPhoneToolset(std::string& toolset) const; virtual bool SelectWindowsStoreToolset(std::string& toolset) const; @@ -125,6 +128,7 @@ protected: cmIDEFlagTable const* DefaultLibFlagTable; cmIDEFlagTable const* DefaultLinkFlagTable; cmIDEFlagTable const* DefaultMasmFlagTable; + cmIDEFlagTable const* DefaultNasmFlagTable; cmIDEFlagTable const* DefaultRcFlagTable; bool SystemIsWindowsCE; bool SystemIsWindowsPhone; @@ -154,6 +158,8 @@ private: virtual std::string FindDevEnvCommand(); virtual std::string GetVSMakeProgram() { return this->GetMSBuildCommand(); } + bool ParseGeneratorToolset(std::string const& ts, cmMakefile* mf); + // We do not use the reload macros for VS >= 10. virtual std::string GetUserMacrosDirectory() { return ""; } }; diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx index 2656dcc..de62ff0 100644 --- a/Source/cmGlobalVisualStudio12Generator.cxx +++ b/Source/cmGlobalVisualStudio12Generator.cxx @@ -109,19 +109,15 @@ bool cmGlobalVisualStudio12Generator::MatchesGeneratorName( return false; } -bool cmGlobalVisualStudio12Generator::ParseGeneratorToolset( - std::string const& ts, cmMakefile* mf) +bool cmGlobalVisualStudio12Generator::ProcessGeneratorToolsetField( + std::string const& key, std::string const& value) { - std::string::size_type ts_end = ts.size(); - if (cmHasLiteralSuffix(ts, ",host=x64")) { + if (key == "host" && value == "x64") { this->GeneratorToolsetHostArchitecture = "x64"; - ts_end -= 9; - } else if (ts == "host=x64") { - this->GeneratorToolsetHostArchitecture = "x64"; - ts_end = 0; + return true; } - return this->cmGlobalVisualStudio11Generator::ParseGeneratorToolset( - ts.substr(0, ts_end), mf); + return this->cmGlobalVisualStudio11Generator::ProcessGeneratorToolsetField( + key, value); } bool cmGlobalVisualStudio12Generator::InitializeWindowsPhone(cmMakefile* mf) diff --git a/Source/cmGlobalVisualStudio12Generator.h b/Source/cmGlobalVisualStudio12Generator.h index 79efe52..3453628 100644 --- a/Source/cmGlobalVisualStudio12Generator.h +++ b/Source/cmGlobalVisualStudio12Generator.h @@ -31,8 +31,8 @@ public: // version number virtual const char* GetToolsVersion() { return "12.0"; } protected: - bool ParseGeneratorToolset(std::string const& ts, - cmMakefile* mf) CM_OVERRIDE; + bool ProcessGeneratorToolsetField(std::string const& key, + std::string const& value) CM_OVERRIDE; virtual bool InitializeWindowsPhone(cmMakefile* mf); virtual bool InitializeWindowsStore(cmMakefile* mf); diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 81c305c..d2ac36b 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -238,8 +238,7 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion() // Skip SDKs that do not contain <um/windows.h> because that indicates that // only the UCRT MSIs were installed for them. - sdks.erase(std::remove_if(sdks.begin(), sdks.end(), NoWindowsH()), - sdks.end()); + cmEraseIf(sdks, NoWindowsH()); if (!sdks.empty()) { // Only use the filename, which will be the SDK version. diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 602666e..65a0bde 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -47,6 +47,7 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator( this->IntelProjectVersion = 0; this->DevEnvCommandInitialized = false; this->MasmEnabled = false; + this->NasmEnabled = false; if (platformName.empty()) { this->DefaultPlatformName = "Win32"; diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 62194c3..1f96cc6 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -95,6 +95,7 @@ public: /** Is the Microsoft Assembler enabled? */ bool IsMasmEnabled() const { return this->MasmEnabled; } + bool IsNasmEnabled() const { return this->NasmEnabled; } // Encoding for Visual Studio files virtual std::string Encoding(); @@ -163,6 +164,7 @@ protected: std::string GeneratorPlatform; std::string DefaultPlatformName; bool MasmEnabled; + bool NasmEnabled; private: char* IntelProjectVersion; diff --git a/Source/cmIDEFlagTable.h b/Source/cmIDEFlagTable.h index 64ade76..152e293 100644 --- a/Source/cmIDEFlagTable.h +++ b/Source/cmIDEFlagTable.h @@ -24,6 +24,9 @@ struct cmIDEFlagTable // IgnoreDefaultLibraryNames) UserFollowing = (1 << 5), // expect value in following argument CaseInsensitive = (1 << 6), // flag may be any case + SpaceAppendable = (1 << 7), // a flag that if specified multiple times + // should have its value appended to the + // old value with spaces UserValueIgnored = UserValue | UserIgnored, UserValueRequired = UserValue | UserRequired diff --git a/Source/cmIDEOptions.cxx b/Source/cmIDEOptions.cxx index c6c0e05..1c0a99e 100644 --- a/Source/cmIDEOptions.cxx +++ b/Source/cmIDEOptions.cxx @@ -125,6 +125,8 @@ void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry, this->FlagMap[entry->IDEName] = entry->value; } else if (entry->special & cmIDEFlagTable::SemicolonAppendable) { this->FlagMap[entry->IDEName].push_back(new_value); + } else if (entry->special & cmIDEFlagTable::SpaceAppendable) { + this->FlagMap[entry->IDEName].append_with_space(new_value); } else { // Use the user-specified value. this->FlagMap[entry->IDEName] = new_value; @@ -172,6 +174,12 @@ void cmIDEOptions::AppendFlag(std::string const& flag, std::copy(value.begin(), value.end(), std::back_inserter(fv)); } +void cmIDEOptions::AppendFlagString(std::string const& flag, + std::string const& value) +{ + this->FlagMap[flag].append_with_space(value); +} + void cmIDEOptions::RemoveFlag(const char* flag) { this->FlagMap.erase(flag); diff --git a/Source/cmIDEOptions.h b/Source/cmIDEOptions.h index a0696e1..465cf2c 100644 --- a/Source/cmIDEOptions.h +++ b/Source/cmIDEOptions.h @@ -29,6 +29,7 @@ public: void AppendFlag(std::string const& flag, std::string const& value); void AppendFlag(std::string const& flag, std::vector<std::string> const& value); + void AppendFlagString(std::string const& flag, std::string const& value); void RemoveFlag(const char* flag); bool HasFlag(std::string const& flag) const; const char* GetFlag(const char* flag); @@ -57,15 +58,22 @@ protected: this->derived::operator=(r); return *this; } + FlagValue& append_with_space(std::string const& r) + { + this->resize(1); + std::string& l = this->operator[](0); + if (!l.empty()) { + l += " "; + } + l += r; + return *this; + } }; std::map<std::string, FlagValue> FlagMap; // Preprocessor definitions. std::vector<std::string> Defines; - // Unrecognized flags that get no special handling. - std::string FlagString; - bool DoingDefine; bool AllowDefine; bool AllowSlash; diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx index b6743f1..39e5684 100644 --- a/Source/cmLoadCommandCommand.cxx +++ b/Source/cmLoadCommandCommand.cxx @@ -174,11 +174,6 @@ cmLoadedCommand::~cmLoadedCommand() bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) { - if (this->Disallowed( - cmPolicies::CMP0031, - "The load_command command should not be called; see CMP0031.")) { - return true; - } if (args.empty()) { return true; } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 41a4caf..4388e75 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1864,10 +1864,7 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo( std::string binaryDir = this->GetState()->GetBinaryDirectory(); if (this->Makefile->IsOn("CMAKE_DEPENDS_IN_PROJECT_ONLY")) { const char* sourceDir = this->GetState()->GetSourceDirectory(); - std::vector<std::string>::iterator itr = - std::remove_if(includes.begin(), includes.end(), - ::NotInProjectDir(sourceDir, binaryDir)); - includes.erase(itr, includes.end()); + cmEraseIf(includes, ::NotInProjectDir(sourceDir, binaryDir)); } for (std::vector<std::string>::iterator i = includes.begin(); i != includes.end(); ++i) { diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 38dda04..6e976e1 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -787,7 +787,6 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( << this->ConvertToXMLOutputPath(modDir.c_str()) << "\\$(ConfigurationName)\"\n"; } - targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); fout << "\t\t\t\tAdditionalIncludeDirectories=\""; std::vector<std::string> includes; this->GetIncludeDirectories(includes, target, "C", configName); @@ -1090,7 +1089,6 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( if (!gg->NeedLinkLibraryDependencies(target)) { fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n"; } - linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " @@ -1176,7 +1174,6 @@ void cmLocalVisualStudio7Generator::OutputBuildTool( if (!gg->NeedLinkLibraryDependencies(target)) { fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n"; } - linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " @@ -1675,7 +1672,6 @@ bool cmLocalVisualStudio7Generator::WriteGroup( fileOptions.Parse(fc.CompileFlags.c_str()); fileOptions.AddDefines(fc.CompileDefs.c_str()); fileOptions.AddDefines(fc.CompileDefsConfig.c_str()); - fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n"); fileOptions.OutputFlagMap(fout, "\t\t\t\t\t"); fileOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t\t", "\n", ppLang); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index bfe46ae..bdaca97 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -281,7 +281,8 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, if (!invokeSucceeded || hadNestedError) { if (!hadNestedError) { // The command invocation requested that we report an error. - this->IssueMessage(cmake::FATAL_ERROR, pcmd->GetError()); + std::string const error = name + " " + pcmd->GetError(); + this->IssueMessage(cmake::FATAL_ERROR, error); } result = false; if (this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE) { @@ -653,21 +654,12 @@ void cmMakefile::FinalPass() // we don't want cmake to re-run if a configured file is created and deleted // during processing as that would make it a transient file that can't // influence the build process - - // remove_if will move all items that don't have a valid file name to the - // back of the vector - std::vector<std::string>::iterator new_output_files_end = std::remove_if( - this->OutputFiles.begin(), this->OutputFiles.end(), file_not_persistent()); - // we just have to erase all items at the back - this->OutputFiles.erase(new_output_files_end, this->OutputFiles.end()); + cmEraseIf(this->OutputFiles, file_not_persistent()); // if a configured file is used as input for another configured file, // and then deleted it will show up in the input list files so we // need to scan those too - std::vector<std::string>::iterator new_list_files_end = std::remove_if( - this->ListFiles.begin(), this->ListFiles.end(), file_not_persistent()); - - this->ListFiles.erase(new_list_files_end, this->ListFiles.end()); + cmEraseIf(this->ListFiles, file_not_persistent()); } // Generate the output file diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index b172478..9bf0ccd 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -260,12 +260,9 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile) rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), *i, vars); } - { - // If there is no ranlib the command will be ":". Skip it. - std::vector<std::string>::iterator newEnd = std::remove_if( - linkCmds.begin(), linkCmds.end(), cmNinjaRemoveNoOpCommands()); - linkCmds.erase(newEnd, linkCmds.end()); - } + + // If there is no ranlib the command will be ":". Skip it. + cmEraseIf(linkCmds, cmNinjaRemoveNoOpCommands()); std::string linkCmd = this->GetLocalGenerator()->BuildCommandLine(linkCmds); @@ -388,12 +385,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), *i, vars); } - { - // If there is no ranlib the command will be ":". Skip it. - std::vector<std::string>::iterator newEnd = std::remove_if( - linkCmds.begin(), linkCmds.end(), cmNinjaRemoveNoOpCommands()); - linkCmds.erase(newEnd, linkCmds.end()); - } + + // If there is no ranlib the command will be ":". Skip it. + cmEraseIf(linkCmds, cmNinjaRemoveNoOpCommands()); linkCmds.insert(linkCmds.begin(), "$PRE_LINK"); linkCmds.push_back("$POST_BUILD"); diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx index 7a17f2c..f120971 100644 --- a/Source/cmOutputRequiredFilesCommand.cxx +++ b/Source/cmOutputRequiredFilesCommand.cxx @@ -495,11 +495,6 @@ protected: bool cmOutputRequiredFilesCommand::InitialPass( std::vector<std::string> const& args, cmExecutionStatus&) { - if (this->Disallowed(cmPolicies::CMP0032, "The output_required_files " - "command should not be called; " - "see CMP0032.")) { - return true; - } if (args.size() != 2) { this->SetError("called with incorrect number of arguments"); return false; diff --git a/Source/cmSubdirDependsCommand.cxx b/Source/cmSubdirDependsCommand.cxx index 9259836..36e84d5 100644 --- a/Source/cmSubdirDependsCommand.cxx +++ b/Source/cmSubdirDependsCommand.cxx @@ -9,8 +9,5 @@ class cmExecutionStatus; bool cmSubdirDependsCommand::InitialPass(std::vector<std::string> const&, cmExecutionStatus&) { - this->Disallowed( - cmPolicies::CMP0029, - "The subdir_depends command should not be called; see CMP0029."); return true; } diff --git a/Source/cmUseMangledMesaCommand.cxx b/Source/cmUseMangledMesaCommand.cxx index 3e72d75..3d57f0e 100644 --- a/Source/cmUseMangledMesaCommand.cxx +++ b/Source/cmUseMangledMesaCommand.cxx @@ -13,11 +13,6 @@ class cmExecutionStatus; bool cmUseMangledMesaCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) { - if (this->Disallowed( - cmPolicies::CMP0030, - "The use_mangled_mesa command should not be called; see CMP0030.")) { - return true; - } // expected two arguments: // arguement one: the full path to gl_mangle.h // arguement two : directory for output of edited headers diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx index 3b78abe..9b24a74 100644 --- a/Source/cmUtilitySourceCommand.cxx +++ b/Source/cmUtilitySourceCommand.cxx @@ -16,11 +16,6 @@ class cmExecutionStatus; bool cmUtilitySourceCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) { - if (this->Disallowed( - cmPolicies::CMP0034, - "The utility_source command should not be called; see CMP0034.")) { - return true; - } if (args.size() < 3) { this->SetError("called with incorrect number of arguments"); return false; diff --git a/Source/cmVS10NASMFlagTable.h b/Source/cmVS10NASMFlagTable.h new file mode 100644 index 0000000..b91af92 --- /dev/null +++ b/Source/cmVS10NASMFlagTable.h @@ -0,0 +1,50 @@ +static cmVS7FlagTable cmVS10NASMFlagTable[] = { + + // Enum Properties + { "Outputswitch", "fwin32", "", "0", 0 }, + { "Outputswitch", "fwin", "", "0", 0 }, + { "Outputswitch", "fwin64", "", "1", 0 }, + { "Outputswitch", "felf", "", "2", 0 }, + { "Outputswitch", "felf32", "", "2", 0 }, + { "Outputswitch", "felf64", "", "3", 0 }, + + { "ErrorReportingFormat", "Xgnu", "", "-Xgnu GNU format: Default format", + 0 }, + { "ErrorReportingFormat", "Xvc", "", + "-Xvc Style used by Microsoft Visual C++", 0 }, + + // Bool Properties + { "TreatWarningsAsErrors", "Werror", "", "true", 0 }, + { "GenerateDebugInformation", "g", "", "true", 0 }, + { "floatunderflow", "w+float-underflow", "", "true", 0 }, + { "macrodefaults", "w-macro-defaults", "", "true", 0 }, + { "user", "w-user", "%warning directives (default on)", "true", 0 }, + { "floatoverflow", "w-float-overflow", "", "true", 0 }, + { "floatdenorm", "w+float-denorm", "", "true", 0 }, + { "numberoverflow", "w-number-overflow", "", "true", 0 }, + { "macroselfref", "w+macro-selfref", "", "true", 0 }, + { "floattoolong", "w-float-toolong", "", "true", 0 }, + { "orphanlabels", "w-orphan-labels", "", "true", 0 }, + { "tasmmode", "t", "", "true", 0 }, + + // Bool Properties With Argument + + // String List Properties + { "PreprocessorDefinitions", "D", "Preprocessor Definitions", "", + cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable }, + { "UndefinePreprocessorDefinitions", "U", + "Undefine Preprocessor Definitions", "", + cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable }, + { "IncludePaths", "I", "Include Paths", "", + cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable }, + { "AssembledCodeListingFile", "l", + "Generates an assembled code listing file.", "", + cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable }, + + // String Properties + // Skip [Inputs] - no command line Switch. + // Skip [CommandLineTemplate] - no command line Switch. + // Skip [ExecutionDescription] - no command line Switch. + // Skip [AdditionalOptions] - no command line Switch. + { 0, 0, 0, 0, 0 } +}; diff --git a/Source/cmVariableRequiresCommand.cxx b/Source/cmVariableRequiresCommand.cxx index 1eb1f20..bff6ec5 100644 --- a/Source/cmVariableRequiresCommand.cxx +++ b/Source/cmVariableRequiresCommand.cxx @@ -13,11 +13,6 @@ class cmExecutionStatus; bool cmVariableRequiresCommand::InitialPass( std::vector<std::string> const& args, cmExecutionStatus&) { - if (this->Disallowed( - cmPolicies::CMP0035, - "The variable_requires command should not be called; see CMP0035.")) { - return true; - } if (args.size() < 3) { this->SetError("called with incorrect number of arguments"); return false; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 2e6c19b..e3853ed 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -10,6 +10,7 @@ #include "cmLocalVisualStudio7Generator.h" #include "cmMakefile.h" #include "cmSourceFile.h" +#include "cmSystemTools.h" #include "cmVisualStudioGeneratorOptions.h" #include "windows.h" @@ -207,6 +208,9 @@ void cmVisualStudio10TargetGenerator::Generate() if (!this->ComputeMasmOptions()) { return; } + if (!this->ComputeNasmOptions()) { + return; + } if (!this->ComputeLinkOptions()) { return; } @@ -454,6 +458,21 @@ void cmVisualStudio10TargetGenerator::Generate() "BuildCustomizations\\masm.props\" />\n", 2); } + 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"; + this->ConvertToWindowsSlash(propsLocal); + this->Makefile->ConfigureFile(propsTemplate.c_str(), propsLocal.c_str(), + false, true, true); + std::string import = std::string("<Import Project=\"") + + cmVS10EscapeXML(propsLocal) + "\" />\n"; + this->WriteString(import.c_str(), 2); + } this->WriteString("</ImportGroup>\n", 1); this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1); { @@ -509,6 +528,13 @@ void cmVisualStudio10TargetGenerator::Generate() "BuildCustomizations\\masm.targets\" />\n", 2); } + if (this->GlobalGenerator->IsNasmEnabled()) { + std::string nasmTargets = + GetCMakeFilePath("Templates/MSBuild/nasm.targets"); + std::string import = "<Import Project=\""; + import += cmVS10EscapeXML(nasmTargets) + "\" />\n"; + this->WriteString(import.c_str(), 2); + } this->WriteString("</ImportGroup>\n", 1); if (csproj == this->ProjectType) { for (std::vector<std::string>::const_iterator i = @@ -1719,6 +1745,8 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() tool = "ClCompile"; } else if (lang == "ASM_MASM" && this->GlobalGenerator->IsMasmEnabled()) { tool = "MASM"; + } else if (lang == "ASM_NASM" && this->GlobalGenerator->IsNasmEnabled()) { + tool = "NASM"; } else if (lang == "RC") { tool = "ResourceCompile"; } else if (lang == "CSharp") { @@ -1911,7 +1939,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } clOptions.AddDefines(configDefines.c_str()); clOptions.SetConfiguration((*config).c_str()); - clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); + clOptions.PrependInheritedString("AdditionalOptions"); clOptions.OutputFlagMap(*this->BuildFileStream, " "); clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", "\n", lang); @@ -2265,7 +2293,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( return; } this->WriteString("<ClCompile>\n", 2); - clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); + clOptions.PrependInheritedString("AdditionalOptions"); clOptions.AppendFlag("AdditionalIncludeDirectories", includes); clOptions.AppendFlag("AdditionalIncludeDirectories", "%(AdditionalIncludeDirectories)"); @@ -2367,8 +2395,8 @@ void cmVisualStudio10TargetGenerator::WriteRCOptions( rcOptions.AppendFlag("AdditionalIncludeDirectories", includes); rcOptions.AppendFlag("AdditionalIncludeDirectories", "%(AdditionalIncludeDirectories)"); + rcOptions.PrependInheritedString("AdditionalOptions"); rcOptions.OutputFlagMap(*this->BuildFileStream, " "); - rcOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); this->WriteString("</ResourceCompile>\n", 2); } @@ -2425,12 +2453,77 @@ void cmVisualStudio10TargetGenerator::WriteMasmOptions( Options& masmOptions = *(this->MasmOptions[configName]); masmOptions.AppendFlag("IncludePaths", includes); masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)"); + masmOptions.PrependInheritedString("AdditionalOptions"); masmOptions.OutputFlagMap(*this->BuildFileStream, " "); - masmOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); this->WriteString("</MASM>\n", 2); } +bool cmVisualStudio10TargetGenerator::ComputeNasmOptions() +{ + if (!this->GlobalGenerator->IsNasmEnabled()) { + return true; + } + for (std::vector<std::string>::const_iterator i = + this->Configurations.begin(); + i != this->Configurations.end(); ++i) { + if (!this->ComputeNasmOptions(*i)) { + return false; + } + } + return true; +} + +bool cmVisualStudio10TargetGenerator::ComputeNasmOptions( + std::string const& configName) +{ + cmGlobalVisualStudio10Generator* gg = + static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator); + CM_AUTO_PTR<Options> pOptions(new Options( + this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable())); + Options& nasmOptions = *pOptions; + + std::string CONFIG = cmSystemTools::UpperCase(configName); + std::string configFlagsVar = std::string("CMAKE_ASM_NASM_FLAGS_") + CONFIG; + std::string flags = + std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_FLAGS")) + + std::string(" -f") + std::string(this->Makefile->GetSafeDefinition( + "CMAKE_ASM_NASM_OBJECT_FORMAT")) + + std::string(" ") + + std::string(this->Makefile->GetSafeDefinition(configFlagsVar)); + nasmOptions.Parse(flags.c_str()); + this->NasmOptions[configName] = pOptions.release(); + return true; +} + +void cmVisualStudio10TargetGenerator::WriteNasmOptions( + std::string const& configName, std::vector<std::string> includes) +{ + if (!this->GlobalGenerator->IsNasmEnabled()) { + return; + } + this->WriteString("<NASM>\n", 2); + + 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.OutputFlagMap(*this->BuildFileStream, " "); + nasmOptions.PrependInheritedString("AdditionalOptions"); + nasmOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", + "\n", "ASM_NASM"); + + // Preprocessor definitions and includes are shared with clOptions. + Options& clOptions = *(this->ClOptions[configName]); + clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ", + "\n", "ASM_NASM"); + + this->WriteString("</NASM>\n", 2); +} + void cmVisualStudio10TargetGenerator::WriteLibOptions( std::string const& config) { @@ -2449,7 +2542,7 @@ void cmVisualStudio10TargetGenerator::WriteLibOptions( this->LocalGenerator, cmVisualStudioGeneratorOptions::Linker, gg->GetLibFlagTable(), 0, this); libOptions.Parse(libflags.c_str()); - libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); + libOptions.PrependInheritedString("AdditionalOptions"); libOptions.OutputFlagMap(*this->BuildFileStream, " "); this->WriteString("</Lib>\n", 2); } @@ -2688,25 +2781,6 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( flags += " "; flags += flagsConfig; } - std::string standardLibsVar = "CMAKE_"; - standardLibsVar += linkLanguage; - standardLibsVar += "_STANDARD_LIBRARIES"; - std::string libs = - this->Makefile->GetSafeDefinition(standardLibsVar.c_str()); - // Remove trailing spaces from libs - std::string::size_type pos = libs.size() - 1; - if (!libs.empty()) { - while (libs[pos] == ' ') { - pos--; - } - } - if (pos != libs.size() - 1) { - libs = libs.substr(0, pos + 1); - } - // Replace spaces in libs with ; - std::replace(libs.begin(), libs.end(), ' ', ';'); - std::vector<std::string> libVec; - cmSystemTools::ExpandListArgument(libs, libVec); cmComputeLinkInformation* pcli = this->GeneratorTarget->GetLinkInformation(config.c_str()); @@ -2716,10 +2790,17 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( this->Name.c_str()); return false; } - // add the libraries for the target to libs string cmComputeLinkInformation& cli = *pcli; + + std::vector<std::string> libVec; std::vector<std::string> vsTargetVec; this->AddLibraries(cli, libVec, vsTargetVec); + std::string standardLibsVar = "CMAKE_"; + standardLibsVar += linkLanguage; + standardLibsVar += "_STANDARD_LIBRARIES"; + std::string const libs = + this->Makefile->GetSafeDefinition(standardLibsVar.c_str()); + cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec); linkOptions.AddFlag("AdditionalDependencies", libVec); // Populate TargetsFileAndConfigsVec @@ -2938,7 +3019,7 @@ void cmVisualStudio10TargetGenerator::WriteLinkOptions( Options& linkOptions = *(this->LinkOptions[config]); this->WriteString("<Link>\n", 2); - linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); + linkOptions.PrependInheritedString("AdditionalOptions"); linkOptions.OutputFlagMap(*this->BuildFileStream, " "); this->WriteString("</Link>\n", 2); @@ -3062,6 +3143,7 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups() // output rc compile flags <ResourceCompile></ResourceCompile> this->WriteRCOptions(*i, includes); this->WriteMasmOptions(*i, includes); + this->WriteNasmOptions(*i, includes); } // output midl flags <Midl></Midl> this->WriteMidlOptions(*i, includes); @@ -3988,3 +4070,14 @@ bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const CloseHandle(h); return true; } + +std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath( + const char* relativeFilePath) const +{ + // Always search in the standard modules location. + std::string path = cmSystemTools::GetCMakeRoot() + "/"; + path += relativeFilePath; + this->ConvertToWindowsSlash(path); + + return path; +} diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 45464c0..0ebb4e4 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -51,7 +51,7 @@ private: }; std::string ConvertPath(std::string const& path, bool forceRelative); - void ConvertToWindowsSlash(std::string& s); + static void ConvertToWindowsSlash(std::string& s); void WriteString(const char* line, int indentLevel); void WriteProjectConfigurations(); void WriteProjectConfigurationValues(); @@ -102,6 +102,11 @@ private: bool ComputeMasmOptions(std::string const& config); void WriteMasmOptions(std::string const& config, std::vector<std::string> const& includes); + bool ComputeNasmOptions(); + bool ComputeNasmOptions(std::string const& config); + void WriteNasmOptions(std::string const& config, + std::vector<std::string> includes); + bool ComputeLinkOptions(); bool ComputeLinkOptions(std::string const& config); bool ComputeLibOptions(); @@ -146,6 +151,7 @@ private: OptionsMap ClOptions; OptionsMap RcOptions; OptionsMap MasmOptions; + OptionsMap NasmOptions; OptionsMap LinkOptions; std::string PathToProjectFile; std::string ProjectFileExtension; @@ -177,6 +183,7 @@ private: typedef std::map<std::string, ToolSources> ToolSourceMap; ToolSourceMap Tools; + std::string GetCMakeFilePath(const char* name) const; }; #endif diff --git a/Source/cmVisualStudio10ToolsetOptions.cxx b/Source/cmVisualStudio10ToolsetOptions.cxx index afca216..0f15ec4 100644 --- a/Source/cmVisualStudio10ToolsetOptions.cxx +++ b/Source/cmVisualStudio10ToolsetOptions.cxx @@ -11,6 +11,7 @@ #include "cmVS10LibFlagTable.h" #include "cmVS10LinkFlagTable.h" #include "cmVS10MASMFlagTable.h" +#include "cmVS10NASMFlagTable.h" #include "cmVS10RCFlagTable.h" #include "cmVS11CLFlagTable.h" #include "cmVS11CSharpFlagTable.h" diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index c0913e6..dfe5ce6 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -211,6 +211,17 @@ void cmVisualStudioGeneratorOptions::ParseFinish() } } +void cmVisualStudioGeneratorOptions::PrependInheritedString( + std::string const& key) +{ + std::map<std::string, FlagValue>::iterator i = this->FlagMap.find(key); + if (i == this->FlagMap.end() || i->second.size() != 1) { + return; + } + std::string& value = i->second[0]; + value = "%(" + key + ") " + value; +} + void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag) { // Look for Intel Fortran flags that do not map well in the flag table. @@ -234,10 +245,10 @@ void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag) } // This option is not known. Store it in the output flags. - this->FlagString += " "; - this->FlagString += cmOutputConverter::EscapeWindowsShellArgument( + std::string const opts = cmOutputConverter::EscapeWindowsShellArgument( flag, cmOutputConverter::Shell_Flag_AllowMakeVariables | cmOutputConverter::Shell_Flag_VSIDE); + this->AppendFlagString("AdditionalOptions", opts); } void cmVisualStudioGeneratorOptions::SetConfiguration(const char* config) @@ -252,19 +263,19 @@ void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions( if (this->Defines.empty()) { return; } + const char* tag = "PreprocessorDefinitions"; if (this->Version >= cmGlobalVisualStudioGenerator::VS10) { // if there are configuration specific flags, then // use the configuration specific tag for PreprocessorDefinitions if (!this->Configuration.empty()) { fout << prefix; this->TargetGenerator->WritePlatformConfigTag( - "PreprocessorDefinitions", this->Configuration.c_str(), 0, 0, 0, - &fout); + tag, this->Configuration.c_str(), 0, 0, 0, &fout); } else { - fout << prefix << "<PreprocessorDefinitions>"; + fout << prefix << "<" << tag << ">"; } } else { - fout << prefix << "PreprocessorDefinitions=\""; + fout << prefix << tag << "=\""; } const char* sep = ""; for (std::vector<std::string>::const_iterator di = this->Defines.begin(); @@ -291,7 +302,7 @@ void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions( sep = ";"; } if (this->Version >= cmGlobalVisualStudioGenerator::VS10) { - fout << ";%(PreprocessorDefinitions)</PreprocessorDefinitions>" << suffix; + fout << ";%(" << tag << ")</" << tag << ">" << suffix; } else { fout << "\"" << suffix; } @@ -332,26 +343,3 @@ void cmVisualStudioGeneratorOptions::OutputFlagMap(std::ostream& fout, } } } - -void cmVisualStudioGeneratorOptions::OutputAdditionalOptions( - std::ostream& fout, const char* prefix, const char* suffix) -{ - if (!this->FlagString.empty()) { - if (this->Version >= cmGlobalVisualStudioGenerator::VS10) { - fout << prefix; - if (!this->Configuration.empty()) { - this->TargetGenerator->WritePlatformConfigTag( - "AdditionalOptions", this->Configuration.c_str(), 0, 0, 0, &fout); - } else { - fout << "<AdditionalOptions>"; - } - fout << "%(AdditionalOptions) " - << cmVisualStudio10GeneratorOptionsEscapeForXML(this->FlagString) - << "</AdditionalOptions>\n"; - } else { - fout << prefix << "AdditionalOptions=\""; - fout << cmVisualStudioGeneratorOptionsEscapeForXML(this->FlagString); - fout << "\"" << suffix; - } - } -} diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h index ab6b8cc..8c49470 100644 --- a/Source/cmVisualStudioGeneratorOptions.h +++ b/Source/cmVisualStudioGeneratorOptions.h @@ -27,6 +27,7 @@ public: Compiler, ResourceCompiler, MasmCompiler, + NasmCompiler, Linker, FortranCompiler, CSharpCompiler @@ -46,6 +47,8 @@ public: void Parse(const char* flags); void ParseFinish(); + void PrependInheritedString(std::string const& key); + // Fix the ExceptionHandling option to default to off. void FixExceptionHandlingDefault(); @@ -64,8 +67,6 @@ public: const char* suffix, const std::string& lang); void OutputFlagMap(std::ostream& fout, const char* indent); - void OutputAdditionalOptions(std::ostream& fout, const char* prefix, - const char* suffix); void SetConfiguration(const char* config); private: diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 6141f50..b2384cd 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -120,8 +120,6 @@ #include <string.h> #include <utility> -class cmCommand; - namespace { #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -179,7 +177,8 @@ cmake::cmake() this->AddDefaultGenerators(); this->AddDefaultExtraGenerators(); - this->AddDefaultCommands(); + this->AddScriptingCommands(); + this->AddProjectCommands(); // Make sure we can capture the build tool output. cmSystemTools::EnableVSConsoleOutput(); @@ -1654,13 +1653,14 @@ const char* cmake::GetCacheDefinition(const std::string& name) const return this->State->GetInitializedCacheValue(name); } -void cmake::AddDefaultCommands() +void cmake::AddScriptingCommands() { - std::vector<cmCommand*> const commands = GetPredefinedCommands(); - for (std::vector<cmCommand*>::const_iterator i = commands.begin(); - i != commands.end(); ++i) { - this->State->AddCommand(*i); - } + GetScriptingCommands(this->State); +} + +void cmake::AddProjectCommands() +{ + GetProjectCommands(this->State); } void cmake::AddDefaultGenerators() diff --git a/Source/cmake.h b/Source/cmake.h index 5347745..abb13ac 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -425,7 +425,8 @@ protected: typedef std::vector<cmExternalMakefileProjectGeneratorFactory*> RegisteredExtraGeneratorsVector; RegisteredExtraGeneratorsVector ExtraGenerators; - void AddDefaultCommands(); + void AddScriptingCommands(); + void AddProjectCommands(); void AddDefaultGenerators(); void AddDefaultExtraGenerators(); diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index d4fe8a7..de68118 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -946,7 +946,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) testConsoleBuf ) IF("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC" AND - NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0") + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "19.0.23506") set_property(SOURCE testConsoleBuf.cxx testConsoleBufChild.cxx PROPERTY COMPILE_FLAGS /utf-8) ENDIF() SET_PROPERTY(SOURCE testConsoleBuf.cxx APPEND PROPERTY COMPILE_DEFINITIONS diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index e01dcd7..86f7552 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -35,8 +35,13 @@ #include "SystemInformation.hxx.in" #endif +#include <algorithm> +#include <bitset> +#include <cassert> #include <fstream> #include <iostream> +#include <limits> +#include <set> #include <sstream> #include <string> #include <vector> @@ -394,7 +399,6 @@ public: bool SupportsMP; bool HasMMXPlus; bool HasSSEMMX; - bool SupportsHyperthreading; unsigned int LogicalProcessorsPerPhysical; int APIC_ID; CPUPowerManagement PowerManagement; @@ -463,10 +467,9 @@ protected: unsigned int NumberOfLogicalCPU; unsigned int NumberOfPhysicalCPU; - int CPUCount(); // For windows - unsigned char LogicalCPUPerPhysicalCPU(); + void CPUCountWindows(); // For windows unsigned char GetAPICId(); // For windows - bool IsHyperThreadingSupported(); + bool IsSMTSupported(); static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int); // For windows // For Linux and Cygwin, /proc/cpuinfo formats are slightly different @@ -1542,7 +1545,7 @@ void SystemInformationImplementation::RunCPUCheck() RetrieveProcessorSerialNumber(); } - this->CPUCount(); + this->CPUCountWindows(); #elif defined(__APPLE__) this->ParseSysCtl(); @@ -2090,16 +2093,10 @@ bool SystemInformationImplementation::RetrieveCPUFeatures() // Retrieve Intel specific extended features. if (this->ChipManufacturer == Intel) { - this->Features.ExtendedFeatures.SupportsHyperthreading = - ((cpuinfo[3] & 0x10000000) != - 0); // Intel specific: Hyperthreading --> Bit 28 - this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = - (this->Features.ExtendedFeatures.SupportsHyperthreading) - ? ((cpuinfo[1] & 0x00FF0000) >> 16) - : 1; - - if ((this->Features.ExtendedFeatures.SupportsHyperthreading) && - (this->Features.HasAPIC)) { + bool SupportsSMT = + ((cpuinfo[3] & 0x10000000) != 0); // Intel specific: SMT --> Bit 28 + + if ((SupportsSMT) && (this->Features.HasAPIC)) { // Retrieve APIC information if there is one present. this->Features.ExtendedFeatures.APIC_ID = ((cpuinfo[1] & 0xFF000000) >> 24); @@ -3401,7 +3398,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() fclose(fd); buffer.resize(fileSize - 2); // Number of logical CPUs (combination of multiple processors, multi-core - // and hyperthreading) + // and SMT) size_t pos = buffer.find("processor\t"); while (pos != buffer.npos) { this->NumberOfLogicalCPU++; @@ -3409,30 +3406,25 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() } #ifdef __linux - // Find the largest physical id. - int maxId = -1; + // Count sockets. + std::set<int> PhysicalIDs; std::string idc = this->ExtractValueFromCpuInfoFile(buffer, "physical id"); while (this->CurrentPositionInFile != buffer.npos) { int id = atoi(idc.c_str()); - if (id > maxId) { - maxId = id; - } + PhysicalIDs.insert(id); idc = this->ExtractValueFromCpuInfoFile(buffer, "physical id", this->CurrentPositionInFile + 1); } + uint64_t NumberOfSockets = PhysicalIDs.size(); + NumberOfSockets = std::max(NumberOfSockets, (uint64_t)1); // Physical ids returned by Linux don't distinguish cores. // We want to record the total number of cores in this->NumberOfPhysicalCPU // (checking only the first proc) - std::string cores = this->ExtractValueFromCpuInfoFile(buffer, "cpu cores"); - int numberOfCoresPerCPU = atoi(cores.c_str()); - if (maxId > 0) { - this->NumberOfPhysicalCPU = - static_cast<unsigned int>(numberOfCoresPerCPU * (maxId + 1)); - } else { - // Linux Sparc: get cpu count - this->NumberOfPhysicalCPU = - atoi(this->ExtractValueFromCpuInfoFile(buffer, "ncpus active").c_str()); - } + std::string Cores = this->ExtractValueFromCpuInfoFile(buffer, "cpu cores"); + unsigned int NumberOfCoresPerSocket = (unsigned int)atoi(Cores.c_str()); + NumberOfCoresPerSocket = std::max(NumberOfCoresPerSocket, 1u); + this->NumberOfPhysicalCPU = + NumberOfCoresPerSocket * (unsigned int)NumberOfSockets; #else // __CYGWIN__ // does not have "physical id" entries, neither "cpu cores" @@ -3447,7 +3439,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() if (this->NumberOfPhysicalCPU <= 0) { this->NumberOfPhysicalCPU = 1; } - // LogicalProcessorsPerPhysical>1 => hyperthreading. + // LogicalProcessorsPerPhysical>1 => SMT. this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = this->NumberOfLogicalCPU / this->NumberOfPhysicalCPU; @@ -4322,68 +4314,10 @@ void SystemInformationImplementation::DelayOverhead(unsigned int uiMS) (void)uiMS; } -/** Return the number of logical CPU per physical CPUs Works only for windows - */ -unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void) -{ -#ifdef __APPLE__ - size_t len = 4; - int cores_per_package = 0; - int err = sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, - &len, NULL, 0); - if (err != 0) { - return 1; // That name was not found, default to 1 - } - return static_cast<unsigned char>(cores_per_package); -#else - int Regs[4] = { 0, 0, 0, 0 }; -#if USE_CPUID - if (!this->IsHyperThreadingSupported()) { - return static_cast<unsigned char>(1); // HT not supported - } - call_cpuid(1, Regs); -#endif - return static_cast<unsigned char>((Regs[1] & NUM_LOGICAL_BITS) >> 16); -#endif -} - /** Works only for windows */ -bool SystemInformationImplementation::IsHyperThreadingSupported() +bool SystemInformationImplementation::IsSMTSupported() { - if (this->Features.ExtendedFeatures.SupportsHyperthreading) { - return true; - } - -#if USE_CPUID - int Regs[4] = { 0, 0, 0, 0 }, VendorId[4] = { 0, 0, 0, 0 }; - // Get vendor id string - if (!call_cpuid(0, VendorId)) { - return false; - } - // eax contains family processor type - // edx has info about the availability of hyper-Threading - if (!call_cpuid(1, Regs)) { - return false; - } - - if (((Regs[0] & FAMILY_ID) == PENTIUM4_ID) || (Regs[0] & EXT_FAMILY_ID)) { - if (VendorId[1] == 0x756e6547) // 'uneG' - { - if (VendorId[3] == 0x49656e69) // 'Ieni' - { - if (VendorId[2] == 0x6c65746e) // 'letn' - { - // Genuine Intel with hyper-Threading technology - this->Features.ExtendedFeatures.SupportsHyperthreading = - ((Regs[3] & HT_BIT) != 0); - return this->Features.ExtendedFeatures.SupportsHyperthreading; - } - } - } - } -#endif - - return 0; // Not genuine Intel processor + return this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical > 1; } /** Return the APIC Id. Works only for windows. */ @@ -4392,7 +4326,7 @@ unsigned char SystemInformationImplementation::GetAPICId() int Regs[4] = { 0, 0, 0, 0 }; #if USE_CPUID - if (!this->IsHyperThreadingSupported()) { + if (!this->IsSMTSupported()) { return static_cast<unsigned char>(-1); // HT not supported } // Logical processor = 1 call_cpuid(1, Regs); @@ -4402,102 +4336,46 @@ unsigned char SystemInformationImplementation::GetAPICId() } /** Count the number of CPUs. Works only on windows. */ -int SystemInformationImplementation::CPUCount() +void SystemInformationImplementation::CPUCountWindows() { #if defined(_WIN32) - unsigned char StatusFlag = 0; - SYSTEM_INFO info; - + std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> ProcInfo; this->NumberOfPhysicalCPU = 0; this->NumberOfLogicalCPU = 0; - info.dwNumberOfProcessors = 0; - GetSystemInfo(&info); - - // Number of physical processors in a non-Intel system - // or in a 32-bit Intel system with Hyper-Threading technology disabled - this->NumberOfPhysicalCPU = (unsigned char)info.dwNumberOfProcessors; - - if (this->IsHyperThreadingSupported()) { - unsigned char HT_Enabled = 0; - this->NumberOfLogicalCPU = this->LogicalCPUPerPhysicalCPU(); - if (this->NumberOfLogicalCPU >= - 1) // >1 Doesn't mean HT is enabled in the BIOS - { - HANDLE hCurrentProcessHandle; -#ifndef _WIN64 -#define DWORD_PTR DWORD -#endif - DWORD_PTR dwProcessAffinity; - DWORD_PTR dwSystemAffinity; - DWORD dwAffinityMask; - - // Calculate the appropriate shifts and mask based on the - // number of logical processors. - unsigned int i = 1; - unsigned char PHY_ID_MASK = 0xFF; - // unsigned char PHY_ID_SHIFT = 0; - - while (i < this->NumberOfLogicalCPU) { - i *= 2; - PHY_ID_MASK <<= 1; - // PHY_ID_SHIFT++; - } - hCurrentProcessHandle = GetCurrentProcess(); - GetProcessAffinityMask(hCurrentProcessHandle, &dwProcessAffinity, - &dwSystemAffinity); - - // Check if available process affinity mask is equal to the - // available system affinity mask - if (dwProcessAffinity != dwSystemAffinity) { - StatusFlag = HT_CANNOT_DETECT; - this->NumberOfPhysicalCPU = (unsigned char)-1; - return StatusFlag; - } - - dwAffinityMask = 1; - while (dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity) { - // Check if this CPU is available - if (dwAffinityMask & dwProcessAffinity) { - if (SetProcessAffinityMask(hCurrentProcessHandle, dwAffinityMask)) { - unsigned char APIC_ID, LOG_ID; - Sleep(0); // Give OS time to switch CPU - - APIC_ID = GetAPICId(); - LOG_ID = APIC_ID & ~PHY_ID_MASK; - - if (LOG_ID != 0) { - HT_Enabled = 1; - } - } - } - dwAffinityMask = dwAffinityMask << 1; - } - // Reset the processor affinity - SetProcessAffinityMask(hCurrentProcessHandle, dwProcessAffinity); + { + DWORD Length = 0; + DWORD rc = GetLogicalProcessorInformation(NULL, &Length); + assert(FALSE == rc); + (void)rc; // Silence unused variable warning in Borland C++ 5.81 + assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER); + ProcInfo.resize(Length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION)); + rc = GetLogicalProcessorInformation(&ProcInfo[0], &Length); + assert(rc != FALSE); + (void)rc; // Silence unused variable warning in Borland C++ 5.81 + } + + typedef std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION>::iterator + pinfoIt_t; + for (pinfoIt_t it = ProcInfo.begin(); it != ProcInfo.end(); ++it) { + SYSTEM_LOGICAL_PROCESSOR_INFORMATION PInfo = *it; + if (PInfo.Relationship != RelationProcessorCore) { + continue; + } - if (this->NumberOfLogicalCPU == - 1) // Normal P4 : HT is disabled in hardware - { - StatusFlag = HT_DISABLED; - } else { - if (HT_Enabled) { - // Total physical processors in a Hyper-Threading enabled system. - this->NumberOfPhysicalCPU /= (this->NumberOfLogicalCPU); - StatusFlag = HT_ENABLED; - } else { - StatusFlag = HT_SUPPORTED_NOT_ENABLED; - } - } + std::bitset<std::numeric_limits<ULONG_PTR>::digits> ProcMask( + (unsigned long long)PInfo.ProcessorMask); + unsigned int count = (unsigned int)ProcMask.count(); + if (count == 0) { // I think this should never happen, but just to be safe. + continue; } - } else { - // Processors do not have Hyper-Threading technology - StatusFlag = HT_NOT_CAPABLE; - this->NumberOfLogicalCPU = 1; + this->NumberOfPhysicalCPU++; + this->NumberOfLogicalCPU += (unsigned int)count; + this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = count; } - return StatusFlag; + this->NumberOfPhysicalCPU = std::max(1u, this->NumberOfPhysicalCPU); + this->NumberOfLogicalCPU = std::max(1u, this->NumberOfLogicalCPU); #else - return 0; #endif } @@ -4559,8 +4437,14 @@ bool SystemInformationImplementation::ParseSysCtl() sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len, NULL, 0); len = sizeof(this->NumberOfLogicalCPU); sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, NULL, 0); + + int cores_per_package = 0; + len = sizeof(cores_per_package); + err = sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, &len, + NULL, 0); + // That name was not found, default to 1 this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = - this->LogicalCPUPerPhysicalCPU(); + err != 0 ? 1 : static_cast<unsigned char>(cores_per_package); len = sizeof(value); sysctlbyname("hw.cpufrequency", &value, &len, NULL, 0); diff --git a/Source/kwsys/SystemInformation.hxx.in b/Source/kwsys/SystemInformation.hxx.in index 0fc1067..cc09393 100644 --- a/Source/kwsys/SystemInformation.hxx.in +++ b/Source/kwsys/SystemInformation.hxx.in @@ -67,7 +67,7 @@ public: bool Is64Bits(); - unsigned int GetNumberOfLogicalCPU(); // per physical cpu + unsigned int GetNumberOfLogicalCPU(); unsigned int GetNumberOfPhysicalCPU(); bool DoesCPUSupportCPUID(); diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 97dd4ae..8c82ec1 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -3067,6 +3067,28 @@ bool SystemTools::FileIsSymlink(const std::string& name) #endif } +bool SystemTools::FileIsFIFO(const std::string& name) +{ +#if defined(_WIN32) + HANDLE hFile = + CreateFileW(Encoding::ToWide(name).c_str(), GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (hFile == INVALID_HANDLE_VALUE) { + return false; + } + const DWORD type = GetFileType(hFile); + CloseHandle(hFile); + return type == FILE_TYPE_PIPE; +#else + struct stat fs; + if (lstat(name.c_str(), &fs) == 0) { + return S_ISFIFO(fs.st_mode); + } else { + return false; + } +#endif +} + #if defined(_WIN32) && !defined(__CYGWIN__) bool SystemTools::CreateSymlink(const std::string&, const std::string&) { diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index f3d06fe..7a5256b 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -654,6 +654,11 @@ public: static bool FileIsSymlink(const std::string& name); /** + * Return true if the file is a FIFO + */ + static bool FileIsFIFO(const std::string& name); + + /** * Return true if the file has a given signature (first set of bytes) */ static bool FileHasSignature(const char* filename, const char* signature, |