diff options
-rw-r--r-- | Help/manual/cmake-commands.7.rst | 133 | ||||
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestHandlerCommand.cxx | 4 | ||||
-rw-r--r-- | Source/cmBuildNameCommand.cxx | 5 | ||||
-rw-r--r-- | Source/cmCommand.cxx | 25 | ||||
-rw-r--r-- | Source/cmCommand.h | 9 | ||||
-rw-r--r-- | Source/cmCommands.cxx | 242 | ||||
-rw-r--r-- | Source/cmCommands.h | 10 | ||||
-rw-r--r-- | Source/cmDisallowedCommand.cxx | 31 | ||||
-rw-r--r-- | Source/cmDisallowedCommand.h | 50 | ||||
-rw-r--r-- | Source/cmExportCommand.h | 1 | ||||
-rw-r--r-- | Source/cmExportLibraryDependenciesCommand.cxx | 6 | ||||
-rw-r--r-- | Source/cmLoadCommandCommand.cxx | 5 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 3 | ||||
-rw-r--r-- | Source/cmOutputRequiredFilesCommand.cxx | 5 | ||||
-rw-r--r-- | Source/cmSubdirDependsCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmUseMangledMesaCommand.cxx | 5 | ||||
-rw-r--r-- | Source/cmUtilitySourceCommand.cxx | 5 | ||||
-rw-r--r-- | Source/cmVariableRequiresCommand.cxx | 5 | ||||
-rw-r--r-- | Source/cmake.cxx | 18 | ||||
-rw-r--r-- | Source/cmake.h | 3 |
21 files changed, 313 insertions, 257 deletions
diff --git a/Help/manual/cmake-commands.7.rst b/Help/manual/cmake-commands.7.rst index d0c2986..611c989 100644 --- a/Help/manual/cmake-commands.7.rst +++ b/Help/manual/cmake-commands.7.rst @@ -7,91 +7,103 @@ cmake-commands(7) .. contents:: -Normal Commands -=============== +Scripting Commands +================== -These commands may be used freely in CMake projects. +These commands are always available. .. toctree:: :maxdepth: 1 - /command/add_compile_options - /command/add_custom_command - /command/add_custom_target - /command/add_definitions - /command/add_dependencies - /command/add_executable - /command/add_library - /command/add_subdirectory - /command/add_test - /command/aux_source_directory /command/break - /command/build_command /command/cmake_host_system_information /command/cmake_minimum_required /command/cmake_parse_arguments /command/cmake_policy /command/configure_file /command/continue - /command/create_test_sourcelist - /command/define_property /command/elseif /command/else - /command/enable_language - /command/enable_testing /command/endforeach /command/endfunction /command/endif /command/endmacro /command/endwhile /command/execute_process - /command/export /command/file /command/find_file /command/find_library /command/find_package /command/find_path /command/find_program - /command/fltk_wrap_ui /command/foreach /command/function /command/get_cmake_property /command/get_directory_property /command/get_filename_component /command/get_property + /command/if + /command/include + /command/list + /command/macro + /command/mark_as_advanced + /command/math + /command/message + /command/option + /command/return + /command/separate_arguments + /command/set_directory_properties + /command/set_property + /command/set + /command/site_name + /command/string + /command/unset + /command/variable_watch + /command/while + +Project Commands +================ + +These commands are available only in CMake projects. + +.. toctree:: + :maxdepth: 1 + + /command/add_compile_options + /command/add_custom_command + /command/add_custom_target + /command/add_definitions + /command/add_dependencies + /command/add_executable + /command/add_library + /command/add_subdirectory + /command/add_test + /command/aux_source_directory + /command/build_command + /command/create_test_sourcelist + /command/define_property + /command/enable_language + /command/enable_testing + /command/export + /command/fltk_wrap_ui /command/get_source_file_property /command/get_target_property /command/get_test_property - /command/if /command/include_directories /command/include_external_msproject /command/include_regular_expression - /command/include /command/install /command/link_directories /command/link_libraries - /command/list /command/load_cache - /command/macro - /command/mark_as_advanced - /command/math - /command/message - /command/option /command/project /command/qt_wrap_cpp /command/qt_wrap_ui /command/remove_definitions - /command/return - /command/separate_arguments - /command/set_directory_properties - /command/set_property - /command/set /command/set_source_files_properties /command/set_target_properties /command/set_tests_properties - /command/site_name /command/source_group - /command/string /command/target_compile_definitions /command/target_compile_features /command/target_compile_options @@ -100,9 +112,30 @@ These commands may be used freely in CMake projects. /command/target_sources /command/try_compile /command/try_run - /command/unset - /command/variable_watch - /command/while + +.. _`CTest Commands`: + +CTest Commands +============== + +These commands are available only in CTest scripts. + +.. toctree:: + :maxdepth: 1 + + /command/ctest_build + /command/ctest_configure + /command/ctest_coverage + /command/ctest_empty_binary_directory + /command/ctest_memcheck + /command/ctest_read_custom_files + /command/ctest_run_script + /command/ctest_sleep + /command/ctest_start + /command/ctest_submit + /command/ctest_test + /command/ctest_update + /command/ctest_upload Deprecated Commands =================== @@ -129,27 +162,3 @@ versions of CMake. Do not use them in new code. /command/utility_source /command/variable_requires /command/write_file - -.. _`CTest Commands`: - -CTest Commands -============== - -These commands are available only in ctest scripts. - -.. toctree:: - :maxdepth: 1 - - /command/ctest_build - /command/ctest_configure - /command/ctest_coverage - /command/ctest_empty_binary_directory - /command/ctest_memcheck - /command/ctest_read_custom_files - /command/ctest_run_script - /command/ctest_sleep - /command/ctest_start - /command/ctest_submit - /command/ctest_test - /command/ctest_update - /command/ctest_upload 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/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/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..9cf5e6f --- /dev/null +++ b/Source/cmDisallowedCommand.h @@ -0,0 +1,50 @@ +/* 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; + + 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/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/cmMakefile.cxx b/Source/cmMakefile.cxx index 618f694..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) { 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/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/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(); |