diff options
63 files changed, 784 insertions, 1231 deletions
diff --git a/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst index ed321fc..ab2a023 100644 --- a/Help/command/add_custom_command.rst +++ b/Help/command/add_custom_command.rst @@ -68,9 +68,6 @@ The options are: order-only dependencies to ensure the byproducts will be available before their dependents build. - The ``BYPRODUCTS`` option is ignored on non-Ninja generators - except to mark byproducts ``GENERATED``. - ``COMMAND`` Specify the command-line(s) to execute at build time. If more than one ``COMMAND`` is specified they will be executed in order, @@ -111,6 +108,9 @@ The options are: an ``OUTPUT`` of another custom command in the same directory (``CMakeLists.txt`` file) CMake automatically brings the other custom command into the target in which this command is built. + A target-level dependency is added if any dependency is listed as + ``BYPRODUCTS`` of a target or any of its build events in the same + directory to ensure the byproducts will be available. If ``DEPENDS`` is not specified the command will run whenever the ``OUTPUT`` is missing; if the command does not actually create the ``OUTPUT`` then the rule will always run. diff --git a/Help/command/add_custom_target.rst b/Help/command/add_custom_target.rst index 08b9516..e74960c 100644 --- a/Help/command/add_custom_target.rst +++ b/Help/command/add_custom_target.rst @@ -49,9 +49,6 @@ The options are: order-only dependencies to ensure the byproducts will be available before their dependents build. - The ``BYPRODUCTS`` option is ignored on non-Ninja generators - except to mark byproducts ``GENERATED``. - ``COMMAND`` Specify the command-line(s) to execute at build time. If more than one ``COMMAND`` is specified they will be executed in order, @@ -86,6 +83,9 @@ The options are: :command:`add_custom_command` command calls in the same directory (``CMakeLists.txt`` file). They will be brought up to date when the target is built. + A target-level dependency is added if any dependency is a byproduct + of a target or any of its build events in the same directory to ensure + the byproducts will be available before this target is built. Use the :command:`add_dependencies` command to add dependencies on other targets. diff --git a/Help/cpack_gen/wix.rst b/Help/cpack_gen/wix.rst index dde4943..7fb5a12 100644 --- a/Help/cpack_gen/wix.rst +++ b/Help/cpack_gen/wix.rst @@ -95,6 +95,10 @@ Windows using WiX. If this variable is not set, it will be initialized with CPACK_PACKAGE_NAME + If this variable is set to ``.``, then application shortcuts will be + created directly in the start menu and the uninstaller shortcut will be + omitted. + .. variable:: CPACK_WIX_CULTURES Language(s) of the installer diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index fc86b56..2aef888 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 15) -set(CMake_VERSION_PATCH 20190912) +set(CMake_VERSION_PATCH 20190916) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index b0b2df2..f784832 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -537,9 +537,16 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() } } - bool emitUninstallShortcut = - emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) != - emittedShortcutTypes.end(); + bool emitUninstallShortcut = true; + const char* cpackWixProgramMenuFolder = + GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); + if (cpackWixProgramMenuFolder && + cm::string_view(cpackWixProgramMenuFolder) == ".") { + emitUninstallShortcut = false; + } else if (emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) == + emittedShortcutTypes.end()) { + emitUninstallShortcut = false; + } if (!CreateShortcuts(std::string(), "ProductFeature", globalShortcuts, emitUninstallShortcut, fileDefinitions, @@ -733,9 +740,16 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( { std::string directoryId; switch (type) { - case cmWIXShortcuts::START_MENU: - directoryId = "PROGRAM_MENU_FOLDER"; - break; + case cmWIXShortcuts::START_MENU: { + const char* cpackWixProgramMenuFolder = + GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); + if (cpackWixProgramMenuFolder && + cm::string_view(cpackWixProgramMenuFolder) == ".") { + directoryId = "ProgramMenuFolder"; + } else { + directoryId = "PROGRAM_MENU_FOLDER"; + } + } break; case cmWIXShortcuts::DESKTOP: directoryId = "DesktopFolder"; break; @@ -789,8 +803,13 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType( fileDefinitions); if (type == cmWIXShortcuts::START_MENU) { - fileDefinitions.EmitRemoveFolder("CM_REMOVE_PROGRAM_MENU_FOLDER" + - idSuffix); + const char* cpackWixProgramMenuFolder = + GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"); + if (cpackWixProgramMenuFolder && + cm::string_view(cpackWixProgramMenuFolder) != ".") { + fileDefinitions.EmitRemoveFolder("CM_REMOVE_PROGRAM_MENU_FOLDER" + + idSuffix); + } } if (emitUninstallShortcut) { diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx index 975dffb..0a83ca2 100644 --- a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx @@ -14,10 +14,12 @@ void cmWIXDirectoriesSourceWriter::EmitStartMenuFolder( BeginElement("Directory"); AddAttribute("Id", "ProgramMenuFolder"); - BeginElement("Directory"); - AddAttribute("Id", "PROGRAM_MENU_FOLDER"); - AddAttribute("Name", startMenuFolder); - EndElement("Directory"); + if (startMenuFolder != ".") { + BeginElement("Directory"); + AddAttribute("Id", "PROGRAM_MENU_FOLDER"); + AddAttribute("Name", startMenuFolder); + EndElement("Directory"); + } EndElement("Directory"); } diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index d2330e1..c91198c 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -4,7 +4,6 @@ #include <sstream> #include <unordered_set> -#include <utility> #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" @@ -13,7 +12,6 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" -#include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" @@ -51,7 +49,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, bool uses_terminal = false; bool command_expand_lists = false; std::string implicit_depends_lang; - cmCustomCommand::ImplicitDependsList implicit_depends; + cmImplicitDependsList implicit_depends; // Accumulate one command line at a time. cmCustomCommandLine currentLine; @@ -248,6 +246,8 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, // An implicit dependency starting point is also an // explicit dependency. std::string dep = copy; + // Upfront path conversion is correct because Genex + // are not supported. cmSystemTools::ConvertToUnixSlashes(dep); depends.push_back(dep); @@ -264,9 +264,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, target = copy; break; case doing_depends: { - std::string dep = copy; - cmSystemTools::ConvertToUnixSlashes(dep); - depends.push_back(std::move(dep)); + depends.push_back(copy); } break; case doing_outputs: outputs.push_back(filename); @@ -317,14 +315,9 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, // Check for an append request. if (append) { - // Lookup an existing command. - if (cmSourceFile* sf = mf.GetSourceFileWithOutput(output[0])) { - if (cmCustomCommand* cc = sf->GetCustomCommand()) { - cc->AppendCommands(commandLines); - cc->AppendDepends(depends); - cc->AppendImplicitDepends(implicit_depends); - return true; - } + if (mf.AppendCustomCommandToOutput(output[0], depends, implicit_depends, + commandLines)) { + return true; } // No command for this output exists. @@ -351,28 +344,10 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, job_pool, command_expand_lists); } else if (target.empty()) { // Target is empty, use the output. - mf.AddCustomCommandToOutput(output, byproducts, depends, main_dependency, - commandLines, comment, working.c_str(), false, - escapeOldStyle, uses_terminal, - command_expand_lists, depfile, job_pool); - - // Add implicit dependency scanning requests if any were given. - if (!implicit_depends.empty()) { - bool okay = false; - if (cmSourceFile* sf = mf.GetSourceFileWithOutput(output[0])) { - if (cmCustomCommand* cc = sf->GetCustomCommand()) { - okay = true; - cc->SetImplicitDepends(implicit_depends); - } - } - if (!okay) { - std::ostringstream e; - e << "could not locate source file with a custom command producing \"" - << output[0] << "\" even though this command tried to create it!"; - status.SetError(e.str()); - return false; - } - } + mf.AddCustomCommandToOutput( + output, byproducts, depends, main_dependency, implicit_depends, + commandLines, comment, working.c_str(), false, escapeOldStyle, + uses_terminal, command_expand_lists, depfile, job_pool); } else if (!byproducts.empty()) { status.SetError("BYPRODUCTS may not be specified with SOURCE signatures"); return false; diff --git a/Source/cmBuildCommand.cxx b/Source/cmBuildCommand.cxx index e9e1d49..49c9439 100644 --- a/Source/cmBuildCommand.cxx +++ b/Source/cmBuildCommand.cxx @@ -2,32 +2,21 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmBuildCommand.h" -#include <sstream> - +#include "cmExecutionStatus.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmStateTypes.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; - -bool cmBuildCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) -{ - // Support the legacy signature of the command: - // - if (2 == args.size()) { - return this->TwoArgsSignature(args); - } - - return this->MainSignature(args); -} +namespace { -bool cmBuildCommand::MainSignature(std::vector<std::string> const& args) +bool MainSignature(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("requires at least one argument naming a CMake variable"); + status.SetError("requires at least one argument naming a CMake variable"); return false; } @@ -63,9 +52,7 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args) doing = DoingNone; target = args[i]; } else { - std::ostringstream e; - e << "unknown argument \"" << args[i] << "\""; - this->SetError(e.str()); + status.SetError(cmStrCat("unknown argument \"", args[i], "\"")); return false; } } @@ -82,30 +69,32 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args) configuration = "Release"; } + cmMakefile& mf = status.GetMakefile(); if (!project_name.empty()) { - this->Makefile->IssueMessage( - MessageType::AUTHOR_WARNING, - "Ignoring PROJECT_NAME option because it has no effect."); + mf.IssueMessage(MessageType::AUTHOR_WARNING, + "Ignoring PROJECT_NAME option because it has no effect."); } - std::string makecommand = - this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand( - target, configuration, "", this->Makefile->IgnoreErrorsCMP0061()); + std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand( + target, configuration, "", mf.IgnoreErrorsCMP0061()); - this->Makefile->AddDefinition(variable, makecommand); + mf.AddDefinition(variable, makecommand); return true; } -bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args) +bool TwoArgsSignature(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with less than two arguments"); + status.SetError("called with less than two arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + std::string const& define = args[0]; - const char* cacheValue = this->Makefile->GetDefinition(define); + const char* cacheValue = mf.GetDefinition(define); std::string configType; if (!cmSystemTools::GetEnv("CMAKE_CONFIG_TYPE", configType) || @@ -113,16 +102,28 @@ bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args) configType = "Release"; } - std::string makecommand = - this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand( - "", configType, "", this->Makefile->IgnoreErrorsCMP0061()); + std::string makecommand = mf.GetGlobalGenerator()->GenerateCMakeBuildCommand( + "", configType, "", mf.IgnoreErrorsCMP0061()); if (cacheValue) { return true; } - this->Makefile->AddCacheDefinition(define, makecommand.c_str(), - "Command used to build entire project " - "from the command line.", - cmStateEnums::STRING); + mf.AddCacheDefinition(define, makecommand.c_str(), + "Command used to build entire project " + "from the command line.", + cmStateEnums::STRING); return true; } + +} // namespace + +bool cmBuildCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + // Support the legacy signature of the command: + if (args.size() == 2) { + return TwoArgsSignature(args, status); + } + + return MainSignature(args, status); +} diff --git a/Source/cmBuildCommand.h b/Source/cmBuildCommand.h index d373103..45aa71d 100644 --- a/Source/cmBuildCommand.h +++ b/Source/cmBuildCommand.h @@ -8,47 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmBuildCommand - * \brief build_command command - * - * cmBuildCommand implements the build_command CMake command - */ -class cmBuildCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmBuildCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - - /** - * The primary command signature with optional, KEYWORD-based args. - */ - virtual bool MainSignature(std::vector<std::string> const& args); - - /** - * Legacy "exactly 2 args required" signature. - */ - virtual bool TwoArgsSignature(std::vector<std::string> const& args); - -private: - bool IgnoreErrors() const; -}; +bool cmBuildCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index dfe130e..38fcf5b 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -222,41 +222,32 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("add_library", cmAddLibraryCommand); state->AddBuiltinCommand("add_subdirectory", cmAddSubDirectoryCommand); state->AddBuiltinCommand("add_test", cmAddTestCommand); - state->AddBuiltinCommand("build_command", cm::make_unique<cmBuildCommand>()); - state->AddBuiltinCommand("create_test_sourcelist", - cm::make_unique<cmCreateTestSourceList>()); - state->AddBuiltinCommand("define_property", - cm::make_unique<cmDefinePropertyCommand>()); - state->AddBuiltinCommand("enable_language", - cm::make_unique<cmEnableLanguageCommand>()); + state->AddBuiltinCommand("build_command", cmBuildCommand); + state->AddBuiltinCommand("create_test_sourcelist", cmCreateTestSourceList); + state->AddBuiltinCommand("define_property", cmDefinePropertyCommand); + state->AddBuiltinCommand("enable_language", cmEnableLanguageCommand); state->AddBuiltinCommand("enable_testing", cmEnableTestingCommand); state->AddBuiltinCommand("get_source_file_property", - cm::make_unique<cmGetSourceFilePropertyCommand>()); - state->AddBuiltinCommand("get_target_property", - cm::make_unique<cmGetTargetPropertyCommand>()); - state->AddBuiltinCommand("get_test_property", - cm::make_unique<cmGetTestPropertyCommand>()); + cmGetSourceFilePropertyCommand); + state->AddBuiltinCommand("get_target_property", cmGetTargetPropertyCommand); + state->AddBuiltinCommand("get_test_property", cmGetTestPropertyCommand); state->AddBuiltinCommand("include_directories", cm::make_unique<cmIncludeDirectoryCommand>()); - state->AddBuiltinCommand( - "include_regular_expression", - cm::make_unique<cmIncludeRegularExpressionCommand>()); + state->AddBuiltinCommand("include_regular_expression", + cmIncludeRegularExpressionCommand); state->AddBuiltinCommand("install", cm::make_unique<cmInstallCommand>()); - state->AddBuiltinCommand("install_files", - cm::make_unique<cmInstallFilesCommand>()); - state->AddBuiltinCommand("install_targets", - cm::make_unique<cmInstallTargetsCommand>()); + state->AddBuiltinCommand("install_files", cmInstallFilesCommand); + state->AddBuiltinCommand("install_targets", cmInstallTargetsCommand); state->AddBuiltinCommand("link_directories", cm::make_unique<cmLinkDirectoriesCommand>()); state->AddBuiltinCommand("project", cm::make_unique<cmProjectCommand>()); - state->AddBuiltinCommand( - "set_source_files_properties", - cm::make_unique<cmSetSourceFilesPropertiesCommand>()); + state->AddBuiltinCommand("set_source_files_properties", + cmSetSourceFilesPropertiesCommand); state->AddBuiltinCommand("set_target_properties", cm::make_unique<cmSetTargetPropertiesCommand>()); state->AddBuiltinCommand("set_tests_properties", - cm::make_unique<cmSetTestsPropertiesCommand>()); - state->AddBuiltinCommand("subdirs", cm::make_unique<cmSubdirCommand>()); + cmSetTestsPropertiesCommand); + state->AddBuiltinCommand("subdirs", cmSubdirCommand); state->AddBuiltinCommand( "target_compile_definitions", cm::make_unique<cmTargetCompileDefinitionsCommand>()); @@ -285,27 +276,21 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("aux_source_directory", cmAuxSourceDirectoryCommand); state->AddBuiltinCommand("export", cm::make_unique<cmExportCommand>()); - state->AddBuiltinCommand("fltk_wrap_ui", - cm::make_unique<cmFLTKWrapUICommand>()); - state->AddBuiltinCommand( - "include_external_msproject", - cm::make_unique<cmIncludeExternalMSProjectCommand>()); - state->AddBuiltinCommand("install_programs", - cm::make_unique<cmInstallProgramsCommand>()); + state->AddBuiltinCommand("fltk_wrap_ui", cmFLTKWrapUICommand); + state->AddBuiltinCommand("include_external_msproject", + cmIncludeExternalMSProjectCommand); + state->AddBuiltinCommand("install_programs", cmInstallProgramsCommand); state->AddBuiltinCommand("add_link_options", cmAddLinkOptionsCommand); - state->AddBuiltinCommand("link_libraries", - cm::make_unique<cmLinkLibrariesCommand>()); + state->AddBuiltinCommand("link_libraries", cmLinkLibrariesCommand); state->AddBuiltinCommand("target_link_options", cm::make_unique<cmTargetLinkOptionsCommand>()); state->AddBuiltinCommand("target_link_directories", cm::make_unique<cmTargetLinkDirectoriesCommand>()); state->AddBuiltinCommand("load_cache", cm::make_unique<cmLoadCacheCommand>()); - state->AddBuiltinCommand("qt_wrap_cpp", - cm::make_unique<cmQTWrapCPPCommand>()); - state->AddBuiltinCommand("qt_wrap_ui", cm::make_unique<cmQTWrapUICommand>()); - state->AddBuiltinCommand("remove_definitions", - cm::make_unique<cmRemoveDefinitionsCommand>()); + state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand); + state->AddBuiltinCommand("qt_wrap_ui", cmQTWrapUICommand); + state->AddBuiltinCommand("remove_definitions", cmRemoveDefinitionsCommand); state->AddBuiltinCommand("source_group", cm::make_unique<cmSourceGroupCommand>()); diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx index da23519..9d492ba 100644 --- a/Source/cmCreateTestSourceList.cxx +++ b/Source/cmCreateTestSourceList.cxx @@ -4,19 +4,17 @@ #include <algorithm> +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; - -// cmCreateTestSourceList -bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmCreateTestSourceList(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 3) { - this->SetError("called with wrong number of arguments."); + status.SetError("called with wrong number of arguments."); return false; } @@ -29,14 +27,14 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, if (*i == "EXTRA_INCLUDE") { ++i; if (i == args.end()) { - this->SetError("incorrect arguments to EXTRA_INCLUDE"); + status.SetError("incorrect arguments to EXTRA_INCLUDE"); return false; } extraInclude = cmStrCat("#include \"", *i, "\"\n"); } else if (*i == "FUNCTION") { ++i; if (i == args.end()) { - this->SetError("incorrect arguments to FUNCTION"); + status.SetError("incorrect arguments to FUNCTION"); return false; } function = cmStrCat(*i, "(&ac, &av);\n"); @@ -54,12 +52,12 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, // Name of the test driver // make sure they specified an extension if (cmSystemTools::GetFilenameExtension(*i).size() < 2) { - this->SetError( + status.SetError( "You must specify a file extension for the test driver file."); return false; } - std::string driver = - cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', *i); + cmMakefile& mf = status.GetMakefile(); + std::string driver = cmStrCat(mf.GetCurrentBinaryDirectory(), '/', *i); ++i; std::string configFile = cmSystemTools::GetCMakeRoot(); @@ -121,35 +119,32 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, numTests++; } if (!extraInclude.empty()) { - this->Makefile->AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES", - extraInclude); + mf.AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES", extraInclude); } if (!function.empty()) { - this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION", function); + mf.AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION", function); } - this->Makefile->AddDefinition("CMAKE_FORWARD_DECLARE_TESTS", - forwardDeclareCode); - this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES", - functionMapCode); + mf.AddDefinition("CMAKE_FORWARD_DECLARE_TESTS", forwardDeclareCode); + mf.AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES", functionMapCode); bool res = true; - if (!this->Makefile->ConfigureFile(configFile, driver, false, true, false)) { + if (!mf.ConfigureFile(configFile, driver, false, true, false)) { res = false; } // Construct the source list. std::string sourceListValue; { - cmSourceFile* sf = this->Makefile->GetOrCreateSource(driver); + cmSourceFile* sf = mf.GetOrCreateSource(driver); sf->SetProperty("ABSTRACT", "0"); sourceListValue = args[1]; } for (i = testsBegin; i != tests.end(); ++i) { - cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i); + cmSourceFile* sf = mf.GetOrCreateSource(*i); sf->SetProperty("ABSTRACT", "0"); sourceListValue += ";"; sourceListValue += *i; } - this->Makefile->AddDefinition(sourceList, sourceListValue); + mf.AddDefinition(sourceList, sourceListValue); return res; } diff --git a/Source/cmCreateTestSourceList.h b/Source/cmCreateTestSourceList.h index 5aa6af4..19503f4 100644 --- a/Source/cmCreateTestSourceList.h +++ b/Source/cmCreateTestSourceList.h @@ -8,34 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmCreateTestSourceList - * \brief Test driver generation command - * - */ - -class cmCreateTestSourceList : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmCreateTestSourceList>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmCreateTestSourceList(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 7402eeb..fc6718d 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -88,18 +88,17 @@ cmListFileBacktrace const& cmCustomCommand::GetBacktrace() const return this->Backtrace; } -cmCustomCommand::ImplicitDependsList const& -cmCustomCommand::GetImplicitDepends() const +cmImplicitDependsList const& cmCustomCommand::GetImplicitDepends() const { return this->ImplicitDepends; } -void cmCustomCommand::SetImplicitDepends(ImplicitDependsList const& l) +void cmCustomCommand::SetImplicitDepends(cmImplicitDependsList const& l) { this->ImplicitDepends = l; } -void cmCustomCommand::AppendImplicitDepends(ImplicitDependsList const& l) +void cmCustomCommand::AppendImplicitDepends(cmImplicitDependsList const& l) { cmAppend(this->ImplicitDepends, l); } diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 102b178..bb5a0ed 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -14,6 +14,11 @@ class cmMakefile; +class cmImplicitDependsList + : public std::vector<std::pair<std::string, std::string>> +{ +}; + /** \class cmCustomCommand * \brief A class to encapsulate a custom command * @@ -68,13 +73,9 @@ public: /** Backtrace of the command that created this custom command. */ cmListFileBacktrace const& GetBacktrace() const; - using ImplicitDependsPair = std::pair<std::string, std::string>; - class ImplicitDependsList : public std::vector<ImplicitDependsPair> - { - }; - void SetImplicitDepends(ImplicitDependsList const&); - void AppendImplicitDepends(ImplicitDependsList const&); - ImplicitDependsList const& GetImplicitDepends() const; + void SetImplicitDepends(cmImplicitDependsList const&); + void AppendImplicitDepends(cmImplicitDependsList const&); + cmImplicitDependsList const& GetImplicitDepends() const; /** Set/Get whether this custom command should be given access to the real console (if possible). */ @@ -99,7 +100,7 @@ private: std::vector<std::string> Depends; cmCustomCommandLines CommandLines; cmListFileBacktrace Backtrace; - ImplicitDependsList ImplicitDepends; + cmImplicitDependsList ImplicitDepends; std::string Comment; std::string WorkingDirectory; std::string Depfile; diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index ca2f210..2c0cbfd 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -58,6 +58,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, std::vector<std::string> result = cmExpandedList(cge->Evaluate(this->LG, this->Config)); for (std::string& it : result) { + cmSystemTools::ConvertToUnixSlashes(it); if (cmSystemTools::FileIsFullPath(it)) { it = cmSystemTools::CollapseFullPath(it); } diff --git a/Source/cmDefinePropertyCommand.cxx b/Source/cmDefinePropertyCommand.cxx index 86a83da..f4e4fda 100644 --- a/Source/cmDefinePropertyCommand.cxx +++ b/Source/cmDefinePropertyCommand.cxx @@ -2,19 +2,17 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmDefinePropertyCommand.h" -#include <sstream> - +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmProperty.h" #include "cmState.h" +#include "cmStringAlgorithms.h" -class cmExecutionStatus; - -bool cmDefinePropertyCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmDefinePropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } @@ -37,17 +35,17 @@ bool cmDefinePropertyCommand::InitialPass(std::vector<std::string> const& args, } else if (scope_arg == "CACHED_VARIABLE") { scope = cmProperty::CACHED_VARIABLE; } else { - std::ostringstream e; - e << "given invalid scope " << scope_arg << ". " - << "Valid scopes are " - << "GLOBAL, DIRECTORY, TARGET, SOURCE, " - << "TEST, VARIABLE, CACHED_VARIABLE."; - this->SetError(e.str()); + status.SetError(cmStrCat("given invalid scope ", scope_arg, + ". Valid scopes are GLOBAL, DIRECTORY, TARGET, " + "SOURCE, TEST, VARIABLE, CACHED_VARIABLE.")); return false; } // Parse remaining arguments. bool inherited = false; + std::string PropertyName; + std::string BriefDocs; + std::string FullDocs; enum Doing { DoingNone, @@ -68,39 +66,36 @@ bool cmDefinePropertyCommand::InitialPass(std::vector<std::string> const& args, inherited = true; } else if (doing == DoingProperty) { doing = DoingNone; - this->PropertyName = args[i]; + PropertyName = args[i]; } else if (doing == DoingBrief) { - this->BriefDocs += args[i]; + BriefDocs += args[i]; } else if (doing == DoingFull) { - this->FullDocs += args[i]; + FullDocs += args[i]; } else { - std::ostringstream e; - e << "given invalid argument \"" << args[i] << "\"."; - this->SetError(e.str()); + status.SetError(cmStrCat("given invalid argument \"", args[i], "\".")); return false; } } // Make sure a property name was found. - if (this->PropertyName.empty()) { - this->SetError("not given a PROPERTY <name> argument."); + if (PropertyName.empty()) { + status.SetError("not given a PROPERTY <name> argument."); return false; } // Make sure documentation was given. - if (this->BriefDocs.empty()) { - this->SetError("not given a BRIEF_DOCS <brief-doc> argument."); + if (BriefDocs.empty()) { + status.SetError("not given a BRIEF_DOCS <brief-doc> argument."); return false; } - if (this->FullDocs.empty()) { - this->SetError("not given a FULL_DOCS <full-doc> argument."); + if (FullDocs.empty()) { + status.SetError("not given a FULL_DOCS <full-doc> argument."); return false; } // Actually define the property. - this->Makefile->GetState()->DefineProperty( - this->PropertyName, scope, this->BriefDocs.c_str(), this->FullDocs.c_str(), - inherited); + status.GetMakefile().GetState()->DefineProperty( + PropertyName, scope, BriefDocs.c_str(), FullDocs.c_str(), inherited); return true; } diff --git a/Source/cmDefinePropertyCommand.h b/Source/cmDefinePropertyCommand.h index 36f97df..60dd76a 100644 --- a/Source/cmDefinePropertyCommand.h +++ b/Source/cmDefinePropertyCommand.h @@ -8,31 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmDefinePropertyCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmDefinePropertyCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -private: - std::string PropertyName; - std::string BriefDocs; - std::string FullDocs; -}; +bool cmDefinePropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmEnableLanguageCommand.cxx b/Source/cmEnableLanguageCommand.cxx index ddd26de..59522c0 100644 --- a/Source/cmEnableLanguageCommand.cxx +++ b/Source/cmEnableLanguageCommand.cxx @@ -2,20 +2,19 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmEnableLanguageCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" -class cmExecutionStatus; - -// cmEnableLanguageCommand -bool cmEnableLanguageCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmEnableLanguageCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { - bool optional = false; - std::vector<std::string> languages; if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + + bool optional = false; + std::vector<std::string> languages; for (std::string const& it : args) { if (it == "OPTIONAL") { optional = true; @@ -24,6 +23,6 @@ bool cmEnableLanguageCommand::InitialPass(std::vector<std::string> const& args, } } - this->Makefile->EnableLanguage(languages, optional); + status.GetMakefile().EnableLanguage(languages, optional); return true; } diff --git a/Source/cmEnableLanguageCommand.h b/Source/cmEnableLanguageCommand.h index dc43e34..1f8c4ce 100644 --- a/Source/cmEnableLanguageCommand.h +++ b/Source/cmEnableLanguageCommand.h @@ -8,37 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmEnableLanguageCommand - * \brief Specify the name for this build project. - * - * cmEnableLanguageCommand is used to specify a name for this build project. - * It is defined once per set of CMakeList.txt files (including - * all subdirectories). Currently it just sets the name of the workspace - * file for Microsoft Visual C++ - */ -class cmEnableLanguageCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmEnableLanguageCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmEnableLanguageCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index afeaf37..654714e 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -5,13 +5,13 @@ #include <cstddef> #include "cmCustomCommandLines.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; class cmTarget; static void FinalAction(cmMakefile& makefile, std::string const& name) @@ -30,39 +30,40 @@ static void FinalAction(cmMakefile& makefile, std::string const& name) } } -// cmFLTKWrapUICommand -bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmFLTKWrapUICommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // what is the current source dir - std::string cdir = this->Makefile->GetCurrentSourceDirectory(); + std::string cdir = mf.GetCurrentSourceDirectory(); std::string const& fluid_exe = - this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE"); + mf.GetRequiredDefinition("FLTK_FLUID_EXECUTABLE"); // Target that will use the generated files std::string const& target = args[0]; // get the list of GUI files from which .cxx and .h will be generated - std::string outputDirectory = this->Makefile->GetCurrentBinaryDirectory(); + std::string outputDirectory = mf.GetCurrentBinaryDirectory(); { // Some of the generated files are *.h so the directory "GUI" // where they are created have to be added to the include path std::vector<std::string> outputDirectories; outputDirectories.push_back(outputDirectory); - this->Makefile->AddIncludeDirectories(outputDirectories); + mf.AddIncludeDirectories(outputDirectories); } // List of produced files. std::vector<cmSourceFile*> generatedSourcesClasses; for (std::string const& arg : cmMakeRange(args).advance(1)) { - cmSourceFile* curr = this->Makefile->GetSource(arg); + cmSourceFile* curr = mf.GetSource(arg); // if we should use the source GUI // to generate .cxx and .h files if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE")) { @@ -91,14 +92,12 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, std::string no_main_dependency; const char* no_comment = nullptr; const char* no_working_dir = nullptr; - this->Makefile->AddCustomCommandToOutput( - cxxres, depends, no_main_dependency, commandLines, no_comment, - no_working_dir); - this->Makefile->AddCustomCommandToOutput( - hname, depends, no_main_dependency, commandLines, no_comment, - no_working_dir); - - cmSourceFile* sf = this->Makefile->GetSource(cxxres); + mf.AddCustomCommandToOutput(cxxres, depends, no_main_dependency, + commandLines, no_comment, no_working_dir); + mf.AddCustomCommandToOutput(hname, depends, no_main_dependency, + commandLines, no_comment, no_working_dir); + + cmSourceFile* sf = mf.GetSource(cxxres); sf->AddDepend(hname); sf->AddDepend(origname); generatedSourcesClasses.push_back(sf); @@ -116,9 +115,9 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, } std::string const varName = target + "_FLTK_UI_SRCS"; - this->Makefile->AddDefinition(varName, sourceListValue); + mf.AddDefinition(varName, sourceListValue); - this->Makefile->AddFinalAction( + mf.AddFinalAction( [target](cmMakefile& makefile) { FinalAction(makefile, target); }); return true; } diff --git a/Source/cmFLTKWrapUICommand.h b/Source/cmFLTKWrapUICommand.h index ea8d401..bb56dbd 100644 --- a/Source/cmFLTKWrapUICommand.h +++ b/Source/cmFLTKWrapUICommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmFLTKWrapUICommand - * \brief Create .h and .cxx files rules for FLTK user interfaces files - * - * cmFLTKWrapUICommand is used to create wrappers for FLTK classes into - * normal C++ - */ -class cmFLTKWrapUICommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmFLTKWrapUICommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmFLTKWrapUICommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index bc344ab..2ca5706 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -2599,7 +2599,7 @@ private: SourceEntry* CurrentEntry; std::queue<cmSourceFile*> SourceQueue; std::set<cmSourceFile*> SourcesQueued; - using NameMapType = std::map<std::string, cmSourceFile*>; + using NameMapType = std::map<std::string, cmSourcesWithOutput>; NameMapType NameMap; std::vector<std::string> NewSources; @@ -2705,19 +2705,30 @@ void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf) void cmTargetTraceDependencies::FollowName(std::string const& name) { - auto i = this->NameMap.find(name); - if (i == this->NameMap.end()) { + // Use lower bound with key comparison to not repeat the search for the + // insert position if the name could not be found (which is the common case). + auto i = this->NameMap.lower_bound(name); + if (i == this->NameMap.end() || i->first != name) { // Check if we know how to generate this file. - cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name); - NameMapType::value_type entry(name, sf); - i = this->NameMap.insert(entry).first; - } - if (cmSourceFile* sf = i->second) { - // Record the dependency we just followed. - if (this->CurrentEntry) { - this->CurrentEntry->Depends.push_back(sf); + cmSourcesWithOutput sources = this->Makefile->GetSourcesWithOutput(name); + i = this->NameMap.emplace_hint(i, name, sources); + } + if (cmTarget* t = i->second.Target) { + // The name is a byproduct of a utility target or a PRE_BUILD, PRE_LINK, or + // POST_BUILD command. + this->GeneratorTarget->Target->AddUtility(t->GetName()); + } + if (cmSourceFile* sf = i->second.Source) { + // For now only follow the dependency if the source file is not a + // byproduct. Semantics of byproducts in a non-Ninja context will have to + // be defined first. + if (!i->second.SourceIsByproduct) { + // Record the dependency we just followed. + if (this->CurrentEntry) { + this->CurrentEntry->Depends.push_back(sf); + } + this->QueueSource(sf); } - this->QueueSource(sf); } } diff --git a/Source/cmGetSourceFilePropertyCommand.cxx b/Source/cmGetSourceFilePropertyCommand.cxx index 5c1c8a5..eefdc6c 100644 --- a/Source/cmGetSourceFilePropertyCommand.cxx +++ b/Source/cmGetSourceFilePropertyCommand.cxx @@ -2,26 +2,25 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGetSourceFilePropertyCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmSourceFile.h" -class cmExecutionStatus; - -// cmSetSourceFilePropertyCommand -bool cmGetSourceFilePropertyCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmGetSourceFilePropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() != 3) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } std::string const& var = args[0]; std::string const& file = args[1]; - cmSourceFile* sf = this->Makefile->GetSource(file); + cmMakefile& mf = status.GetMakefile(); + cmSourceFile* sf = mf.GetSource(file); // for the location we must create a source file first if (!sf && args[2] == "LOCATION") { - sf = this->Makefile->CreateSource(file); + sf = mf.CreateSource(file); } if (sf) { const char* prop = nullptr; @@ -29,11 +28,11 @@ bool cmGetSourceFilePropertyCommand::InitialPass( prop = sf->GetPropertyForUser(args[2]); } if (prop) { - this->Makefile->AddDefinition(var, prop); + mf.AddDefinition(var, prop); return true; } } - this->Makefile->AddDefinition(var, "NOTFOUND"); + mf.AddDefinition(var, "NOTFOUND"); return true; } diff --git a/Source/cmGetSourceFilePropertyCommand.h b/Source/cmGetSourceFilePropertyCommand.h index 387a7f4..f0c319b 100644 --- a/Source/cmGetSourceFilePropertyCommand.h +++ b/Source/cmGetSourceFilePropertyCommand.h @@ -8,26 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmGetSourceFilePropertyCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmGetSourceFilePropertyCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmGetSourceFilePropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx index 07aaf02..7f5df9c 100644 --- a/Source/cmGetTargetPropertyCommand.cxx +++ b/Source/cmGetTargetPropertyCommand.cxx @@ -4,6 +4,7 @@ #include <sstream> +#include "cmExecutionStatus.h" #include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -11,32 +12,31 @@ #include "cmTarget.h" #include "cmTargetPropertyComputer.h" -class cmExecutionStatus; class cmMessenger; -// cmSetTargetPropertyCommand -bool cmGetTargetPropertyCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmGetTargetPropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() != 3) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } std::string const& var = args[0]; std::string const& targetName = args[1]; std::string prop; bool prop_exists = false; + cmMakefile& mf = status.GetMakefile(); - if (cmTarget* tgt = this->Makefile->FindTargetToUse(targetName)) { + if (cmTarget* tgt = mf.FindTargetToUse(targetName)) { if (args[2] == "ALIASED_TARGET") { - if (this->Makefile->IsAlias(targetName)) { + if (mf.IsAlias(targetName)) { prop = tgt->GetName(); prop_exists = true; } } else if (!args[2].empty()) { const char* prop_cstr = nullptr; - cmListFileBacktrace bt = this->Makefile->GetBacktrace(); - cmMessenger* messenger = this->Makefile->GetMessenger(); + cmListFileBacktrace bt = mf.GetBacktrace(); + cmMessenger* messenger = mf.GetMessenger(); if (cmTargetPropertyComputer::PassesWhitelist(tgt->GetType(), args[2], messenger, bt)) { prop_cstr = tgt->GetComputedProperty(args[2], messenger, bt); @@ -53,7 +53,7 @@ bool cmGetTargetPropertyCommand::InitialPass( bool issueMessage = false; std::ostringstream e; MessageType messageType = MessageType::AUTHOR_WARNING; - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0045)) { + switch (mf.GetPolicyStatus(cmPolicies::CMP0045)) { case cmPolicies::WARN: issueMessage = true; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0045) << "\n"; @@ -68,16 +68,16 @@ bool cmGetTargetPropertyCommand::InitialPass( if (issueMessage) { e << "get_target_property() called with non-existent target \"" << targetName << "\"."; - this->Makefile->IssueMessage(messageType, e.str()); + mf.IssueMessage(messageType, e.str()); if (messageType == MessageType::FATAL_ERROR) { return false; } } } if (prop_exists) { - this->Makefile->AddDefinition(var, prop); + mf.AddDefinition(var, prop); return true; } - this->Makefile->AddDefinition(var, var + "-NOTFOUND"); + mf.AddDefinition(var, var + "-NOTFOUND"); return true; } diff --git a/Source/cmGetTargetPropertyCommand.h b/Source/cmGetTargetPropertyCommand.h index 1a53195..c13078f 100644 --- a/Source/cmGetTargetPropertyCommand.h +++ b/Source/cmGetTargetPropertyCommand.h @@ -8,26 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmGetTargetPropertyCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmGetTargetPropertyCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmGetTargetPropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmGetTestPropertyCommand.cxx b/Source/cmGetTestPropertyCommand.cxx index 0b0d6eb..cf8c1d5 100644 --- a/Source/cmGetTestPropertyCommand.cxx +++ b/Source/cmGetTestPropertyCommand.cxx @@ -2,33 +2,32 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGetTestPropertyCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmTest.h" -class cmExecutionStatus; - -// cmGetTestPropertyCommand -bool cmGetTestPropertyCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmGetTestPropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 3) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } std::string const& testName = args[0]; std::string const& var = args[2]; - cmTest* test = this->Makefile->GetTest(testName); + cmMakefile& mf = status.GetMakefile(); + cmTest* test = mf.GetTest(testName); if (test) { const char* prop = nullptr; if (!args[1].empty()) { prop = test->GetProperty(args[1]); } if (prop) { - this->Makefile->AddDefinition(var, prop); + mf.AddDefinition(var, prop); return true; } } - this->Makefile->AddDefinition(var, "NOTFOUND"); + mf.AddDefinition(var, "NOTFOUND"); return true; } diff --git a/Source/cmGetTestPropertyCommand.h b/Source/cmGetTestPropertyCommand.h index a53a7f7..30beb8f 100644 --- a/Source/cmGetTestPropertyCommand.h +++ b/Source/cmGetTestPropertyCommand.h @@ -8,26 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmGetTestPropertyCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmGetTestPropertyCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmGetTestPropertyCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 5e60108..18ff9ac 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGlobalVisualStudio8Generator.h" +#include "cmCustomCommand.h" #include "cmDocumentationEntry.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" @@ -191,11 +192,13 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() // file as the main dependency because it would get // overwritten by the CreateVCProjBuildRule. // (this could be avoided with per-target source files) - std::string no_main_dependency; std::vector<std::string> no_byproducts; + std::string no_main_dependency; + cmImplicitDependsList no_implicit_depends; if (cmSourceFile* file = mf->AddCustomCommandToOutput( - stamps, no_byproducts, listFiles, no_main_dependency, commandLines, - "Checking Build System", no_working_directory, true, false)) { + stamps, no_byproducts, listFiles, no_main_dependency, + no_implicit_depends, commandLines, "Checking Build System", + no_working_directory, true, false)) { gt->AddSource(file->ResolveFullPath()); } else { cmSystemTools::Error("Error adding rule for " + stamps[0]); diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx index 93134ad..fa1e8bc 100644 --- a/Source/cmIncludeExternalMSProjectCommand.cxx +++ b/Source/cmIncludeExternalMSProjectCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmIncludeExternalMSProjectCommand.h" +#include "cmExecutionStatus.h" + #ifdef _WIN32 # include "cmGlobalGenerator.h" # include "cmMakefile.h" @@ -11,22 +13,20 @@ # include "cmake.h" #endif -class cmExecutionStatus; - -// cmIncludeExternalMSProjectCommand -bool cmIncludeExternalMSProjectCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmIncludeExternalMSProjectCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect " - "number of arguments"); + status.SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect " + "number of arguments"); return false; } + // only compile this for win32 to avoid coverage errors #ifdef _WIN32 - if (this->Makefile->GetDefinition("WIN32") || - this->Makefile->GetGlobalGenerator() - ->IsIncludeExternalMSProjectSupported()) { + cmMakefile& mf = status.GetMakefile(); + if (mf.GetDefinition("WIN32") || + mf.GetGlobalGenerator()->IsIncludeExternalMSProjectSupported()) { enum Doing { DoingNone, @@ -77,15 +77,15 @@ bool cmIncludeExternalMSProjectCommand::InitialPass( if (!customGuid.empty()) { std::string guidVariable = utility_name + "_GUID_CMAKE"; - this->Makefile->GetCMakeInstance()->AddCacheEntry( - guidVariable.c_str(), customGuid.c_str(), "Stored GUID", - cmStateEnums::INTERNAL); + mf.GetCMakeInstance()->AddCacheEntry(guidVariable.c_str(), + customGuid.c_str(), "Stored GUID", + cmStateEnums::INTERNAL); } // Create a target instance for this utility. - cmTarget* target = this->Makefile->AddNewTarget(cmStateEnums::UTILITY, - utility_name.c_str()); - if (this->Makefile->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { + cmTarget* target = + mf.AddNewTarget(cmStateEnums::UTILITY, utility_name.c_str()); + if (mf.GetPropertyAsBool("EXCLUDE_FROM_ALL")) { target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } diff --git a/Source/cmIncludeExternalMSProjectCommand.h b/Source/cmIncludeExternalMSProjectCommand.h index 9f76576..1013c44 100644 --- a/Source/cmIncludeExternalMSProjectCommand.h +++ b/Source/cmIncludeExternalMSProjectCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmIncludeExternalMSProjectCommand - * \brief Specify an external MS project file for inclusion in the workspace. - * - * cmIncludeExternalMSProjectCommand is used to specify an externally - * generated Microsoft project file for inclusion in the default workspace - * generated by CMake. - */ -class cmIncludeExternalMSProjectCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmIncludeExternalMSProjectCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmIncludeExternalMSProjectCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmIncludeRegularExpressionCommand.cxx b/Source/cmIncludeRegularExpressionCommand.cxx index 073c95f..655ebd6 100644 --- a/Source/cmIncludeRegularExpressionCommand.cxx +++ b/Source/cmIncludeRegularExpressionCommand.cxx @@ -2,22 +2,22 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmIncludeRegularExpressionCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" -class cmExecutionStatus; - -// cmIncludeRegularExpressionCommand -bool cmIncludeRegularExpressionCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmIncludeRegularExpressionCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { - if ((args.empty()) || (args.size() > 2)) { - this->SetError("called with incorrect number of arguments"); + if (args.empty() || args.size() > 2) { + status.SetError("called with incorrect number of arguments"); return false; } - this->Makefile->SetIncludeRegularExpression(args[0].c_str()); + + cmMakefile& mf = status.GetMakefile(); + mf.SetIncludeRegularExpression(args[0].c_str()); if (args.size() > 1) { - this->Makefile->SetComplainRegularExpression(args[1]); + mf.SetComplainRegularExpression(args[1]); } return true; diff --git a/Source/cmIncludeRegularExpressionCommand.h b/Source/cmIncludeRegularExpressionCommand.h index 1723c8b..ca152b0 100644 --- a/Source/cmIncludeRegularExpressionCommand.h +++ b/Source/cmIncludeRegularExpressionCommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmIncludeRegularExpressionCommand - * \brief Set the regular expression for following #includes. - * - * cmIncludeRegularExpressionCommand is used to specify the regular expression - * that determines whether to follow a #include file in dependency checking. - */ -class cmIncludeRegularExpressionCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmIncludeRegularExpressionCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmIncludeRegularExpressionCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmInstallExportAndroidMKGenerator.cxx b/Source/cmInstallExportAndroidMKGenerator.cxx deleted file mode 100644 index e8de029..0000000 --- a/Source/cmInstallExportAndroidMKGenerator.cxx +++ /dev/null @@ -1,134 +0,0 @@ - -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmInstallExportAndroidMKGenerator.h" - -#include <stdio.h> - -#include "cmExportInstallFileGenerator.h" -#include "cmExportSet.h" -#include "cmGeneratedFileStream.h" -#include "cmGlobalGenerator.h" -#include "cmInstallFilesGenerator.h" -#include "cmInstallTargetGenerator.h" -#include "cmLocalGenerator.h" -#include "cmMakefile.h" -#include "cmMessageType.h" - -cmInstallExportAndroidMKGenerator::cmInstallExportAndroidMKGenerator( - cmExportSet* exportSet, const char* destination, - const char* file_permissions, std::vector<std::string> const& configurations, - const char* component, MessageLevel message, bool exclude_from_all, - const char* filename, const char* name_space, bool exportOld) - : cmInstallExportGenerator(exportSet, destination, file_permissions, - configurations, component, message, - exclude_from_all, filename, name_space, exportOld) -{ -} - -cmInstallExportAndroidMKGenerator::~cmInstallExportAndroidMKGenerator() -{ -} - -bool cmInstallExportAndroidMKGenerator::Compute(cmLocalGenerator* lg) -{ - this->LocalGenerator = lg; - this->ExportSet->Compute(lg); - return true; -} - -void cmInstallExportAndroidMKGenerator::GenerateScript(std::ostream& os) -{ - // Skip empty sets. - if (ExportSet->GetTargetExports()->empty()) { - std::ostringstream e; - e << "INSTALL(EXPORT) given unknown export \"" << ExportSet->GetName() - << "\""; - cmSystemTools::Error(e.str()); - return; - } - - // Create the temporary directory in which to store the files. - this->ComputeTempDir(); - cmSystemTools::MakeDirectory(this->TempDir.c_str()); - - // Construct a temporary location for the file. - this->MainImportFile = cmStrCat(this->TempDir, '/', this->FileName); - - // Generate the import file for this export set. - this->EFGen->SetExportFile(this->MainImportFile.c_str()); - this->EFGen->SetNamespace(this->Namespace); - this->EFGen->SetExportOld(this->ExportOld); - if (this->ConfigurationTypes->empty()) { - if (!this->ConfigurationName.empty()) { - this->EFGen->AddConfiguration(this->ConfigurationName); - } else { - this->EFGen->AddConfiguration(""); - } - } else { - for (std::string const& config : this->ConfigurationTypes) { - this->EFGen->AddConfiguration(config); - } - } - this->EFGen->GenerateImportFile(); - - // Perform the main install script generation. - this->cmInstallGenerator::GenerateScript(os); -} - -void cmInstallExportAndroidMKGenerator::GenerateScriptConfigs( - std::ostream& os, Indent const& indent) -{ - // Create the main install rules first. - this->cmInstallGenerator::GenerateScriptConfigs(os, indent); - - // Now create a configuration-specific install rule for the import - // file of each configuration. - std::vector<std::string> files; - for (auto const& pair : this->EFGen->GetConfigImportFiles()) { - files.push_back(pair.second); - std::string config_test = this->CreateConfigTest(pair.first); - os << indent << "if(" << config_test << ")\n"; - this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files, - false, this->FilePermissions.c_str(), nullptr, - nullptr, nullptr, indent.Next()); - os << indent << "endif()\n"; - files.clear(); - } -} - -void cmInstallExportAndroidMKGenerator::GenerateScriptActions( - std::ostream& os, Indent const& indent) -{ - // Remove old per-configuration export files if the main changes. - std::string installedDir = - cmStrCat("$ENV{DESTDIR}", - this->ConvertToAbsoluteDestination(this->Destination), '/'); - std::string installedFile = cmStrCat(installedDir, this->FileName); - os << indent << "if(EXISTS \"" << installedFile << "\")\n"; - Indent indentN = indent.Next(); - Indent indentNN = indentN.Next(); - Indent indentNNN = indentNN.Next(); - /* clang-format off */ - os << indentN << "file(DIFFERENT EXPORT_FILE_CHANGED FILES\n" - << indentN << " \"" << installedFile << "\"\n" - << indentN << " \"" << this->MainImportFile << "\")\n"; - os << indentN << "if(EXPORT_FILE_CHANGED)\n"; - os << indentNN << "file(GLOB OLD_CONFIG_FILES \"" << installedDir - << this->EFGen->GetConfigImportFileGlob() << "\")\n"; - os << indentNN << "if(OLD_CONFIG_FILES)\n"; - os << indentNNN << "message(STATUS \"Old export file \\\"" << installedFile - << "\\\" will be replaced. Removing files [${OLD_CONFIG_FILES}].\")\n"; - os << indentNNN << "file(REMOVE ${OLD_CONFIG_FILES})\n"; - os << indentNN << "endif()\n"; - os << indentN << "endif()\n"; - os << indent << "endif()\n"; - /* clang-format on */ - - // Install the main export file. - std::vector<std::string> files; - files.push_back(this->MainImportFile); - this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files, - false, this->FilePermissions.c_str(), nullptr, nullptr, - nullptr, indent); -} diff --git a/Source/cmInstallExportAndroidMKGenerator.h b/Source/cmInstallExportAndroidMKGenerator.h deleted file mode 100644 index a92ff27..0000000 --- a/Source/cmInstallExportAndroidMKGenerator.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef cmInstallExportAndroidMKGenerator_h -#define cmInstallExportAndroidMKGenerator_h - -#include "cmInstallExportGenerator.h" - -class cmExportInstallFileGenerator; -class cmInstallFilesGenerator; -class cmInstallTargetGenerator; -class cmExportSet; -class cmMakefile; - -/** \class cmInstallExportAndroidMKGenerator - * \brief Generate rules for creating an export files. - */ -class cmInstallExportAndroidMKGenerator : public cmInstallExportGenerator -{ -public: - cmInstallExportAndroidMKGenerator( - cmExportSet* exportSet, const char* dest, const char* file_permissions, - const std::vector<std::string>& configurations, const char* component, - MessageLevel message, bool exclude_from_all, const char* filename, - const char* name_space, bool exportOld); - ~cmInstallExportAndroidMKGenerator(); - - bool Compute(cmLocalGenerator* lg) override; - -protected: - virtual void GenerateScript(std::ostream& os); - virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent); - virtual void GenerateScriptActions(std::ostream& os, Indent const& indent); - void GenerateImportFile(cmExportSet const* exportSet); - void GenerateImportFile(const char* config, cmExportSet const* exportSet); -}; - -#endif diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx index 4eb5f24..d623943 100644 --- a/Source/cmInstallFilesCommand.cxx +++ b/Source/cmInstallFilesCommand.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallFilesCommand.h" +#include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmInstallFilesGenerator.h" @@ -11,8 +12,6 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; - static std::string FindInstallSource(cmMakefile& makefile, const char* name); static void CreateInstallGenerator(cmMakefile& makefile, std::string const& dest, @@ -20,16 +19,18 @@ static void CreateInstallGenerator(cmMakefile& makefile, static void FinalAction(cmMakefile& makefile, std::string const& dest, std::vector<std::string> const& args); -bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmInstallFilesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Enable the install target. - this->Makefile->GetGlobalGenerator()->EnableInstallTarget(); + mf.GetGlobalGenerator()->EnableInstallTarget(); std::string const& dest = args[0]; @@ -37,18 +38,18 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args, std::vector<std::string> files; for (std::string const& arg : cmMakeRange(args).advance(2)) { // Find the source location for each file listed. - files.push_back(FindInstallSource(*this->Makefile, arg.c_str())); + files.push_back(FindInstallSource(mf, arg.c_str())); } - CreateInstallGenerator(*this->Makefile, dest, files); + CreateInstallGenerator(mf, dest, files); } else { std::vector<std::string> finalArgs(args.begin() + 1, args.end()); - this->Makefile->AddFinalAction([dest, finalArgs](cmMakefile& makefile) { + mf.AddFinalAction([dest, finalArgs](cmMakefile& makefile) { FinalAction(makefile, dest, finalArgs); }); } - this->Makefile->GetGlobalGenerator()->AddInstallComponent( - this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); + mf.GetGlobalGenerator()->AddInstallComponent( + mf.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); return true; } diff --git a/Source/cmInstallFilesCommand.h b/Source/cmInstallFilesCommand.h index f9b84fd..f4ebbde 100644 --- a/Source/cmInstallFilesCommand.h +++ b/Source/cmInstallFilesCommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmInstallFilesCommand - * \brief Specifies where to install some files - * - * cmInstallFilesCommand specifies the relative path where a list of - * files should be installed. - */ -class cmInstallFilesCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmInstallFilesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmInstallFilesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmInstallProgramsCommand.cxx b/Source/cmInstallProgramsCommand.cxx index 31a18b5..6bb4409 100644 --- a/Source/cmInstallProgramsCommand.cxx +++ b/Source/cmInstallProgramsCommand.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallProgramsCommand.h" +#include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmInstallFilesGenerator.h" @@ -10,30 +11,29 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; - static void FinalAction(cmMakefile& makefile, std::string const& dest, std::vector<std::string> const& args); static std::string FindInstallSource(cmMakefile& makefile, const char* name); -// cmExecutableCommand -bool cmInstallProgramsCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmInstallProgramsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Enable the install target. - this->Makefile->GetGlobalGenerator()->EnableInstallTarget(); + mf.GetGlobalGenerator()->EnableInstallTarget(); - this->Makefile->GetGlobalGenerator()->AddInstallComponent( - this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); + mf.GetGlobalGenerator()->AddInstallComponent( + mf.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); std::string const& dest = args[0]; std::vector<std::string> const finalArgs(args.begin() + 1, args.end()); - this->Makefile->AddFinalAction([dest, finalArgs](cmMakefile& makefile) { + mf.AddFinalAction([dest, finalArgs](cmMakefile& makefile) { FinalAction(makefile, dest, finalArgs); }); return true; diff --git a/Source/cmInstallProgramsCommand.h b/Source/cmInstallProgramsCommand.h index ccd621d..c567f3b 100644 --- a/Source/cmInstallProgramsCommand.h +++ b/Source/cmInstallProgramsCommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmInstallProgramsCommand - * \brief Specifies where to install some programs - * - * cmInstallProgramsCommand specifies the relative path where a list of - * programs should be installed. - */ -class cmInstallProgramsCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmInstallProgramsCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmInstallProgramsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmInstallTargetsCommand.cxx b/Source/cmInstallTargetsCommand.cxx index 30fd03d..44f23a5 100644 --- a/Source/cmInstallTargetsCommand.cxx +++ b/Source/cmInstallTargetsCommand.cxx @@ -5,25 +5,25 @@ #include <unordered_map> #include <utility> +#include "cmExecutionStatus.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmTarget.h" -class cmExecutionStatus; - -// cmExecutableCommand -bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmInstallTargetsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Enable the install target. - this->Makefile->GetGlobalGenerator()->EnableInstallTarget(); + mf.GetGlobalGenerator()->EnableInstallTarget(); - cmMakefile::cmTargetMap& tgts = this->Makefile->GetTargets(); + cmMakefile::cmTargetMap& tgts = mf.GetTargets(); auto s = args.begin(); ++s; std::string runtime_dir = "/bin"; @@ -31,8 +31,8 @@ bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args, if (*s == "RUNTIME_DIRECTORY") { ++s; if (s == args.end()) { - this->SetError("called with RUNTIME_DIRECTORY but no actual " - "directory"); + status.SetError("called with RUNTIME_DIRECTORY but no actual " + "directory"); return false; } @@ -45,14 +45,14 @@ bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args, ti->second.SetHaveInstallRule(true); } else { std::string str = "Cannot find target: \"" + *s + "\" to install."; - this->SetError(str); + status.SetError(str); return false; } } } - this->Makefile->GetGlobalGenerator()->AddInstallComponent( - this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); + mf.GetGlobalGenerator()->AddInstallComponent( + mf.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); return true; } diff --git a/Source/cmInstallTargetsCommand.h b/Source/cmInstallTargetsCommand.h index 55e69ba..0c5850c 100644 --- a/Source/cmInstallTargetsCommand.h +++ b/Source/cmInstallTargetsCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmInstallTargetsCommand - * \brief Specifies where to install some targets - * - * cmInstallTargetsCommand specifies the relative path where a list of - * targets should be installed. The targets can be executables or - * libraries. - */ -class cmInstallTargetsCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmInstallTargetsCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmInstallTargetsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmLinkLibrariesCommand.cxx b/Source/cmLinkLibrariesCommand.cxx index bf05310..cb63ceb 100644 --- a/Source/cmLinkLibrariesCommand.cxx +++ b/Source/cmLinkLibrariesCommand.cxx @@ -2,38 +2,37 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmLinkLibrariesCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" -class cmExecutionStatus; - -// cmLinkLibrariesCommand -bool cmLinkLibrariesCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmLinkLibrariesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { return true; } + cmMakefile& mf = status.GetMakefile(); // add libraries, note that there is an optional prefix // of debug and optimized than can be used for (auto i = args.begin(); i != args.end(); ++i) { if (*i == "debug") { ++i; if (i == args.end()) { - this->SetError("The \"debug\" argument must be followed by " - "a library"); + status.SetError("The \"debug\" argument must be followed by " + "a library"); return false; } - this->Makefile->AppendProperty("LINK_LIBRARIES", "debug"); + mf.AppendProperty("LINK_LIBRARIES", "debug"); } else if (*i == "optimized") { ++i; if (i == args.end()) { - this->SetError("The \"optimized\" argument must be followed by " - "a library"); + status.SetError("The \"optimized\" argument must be followed by " + "a library"); return false; } - this->Makefile->AppendProperty("LINK_LIBRARIES", "optimized"); + mf.AppendProperty("LINK_LIBRARIES", "optimized"); } - this->Makefile->AppendProperty("LINK_LIBRARIES", i->c_str()); + mf.AppendProperty("LINK_LIBRARIES", i->c_str()); } return true; diff --git a/Source/cmLinkLibrariesCommand.h b/Source/cmLinkLibrariesCommand.h index 484ab0a..3412251 100644 --- a/Source/cmLinkLibrariesCommand.h +++ b/Source/cmLinkLibrariesCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmLinkLibrariesCommand - * \brief Specify a list of libraries to link into executables. - * - * cmLinkLibrariesCommand is used to specify a list of libraries to link - * into executable(s) or shared objects. The names of the libraries - * should be those defined by the LIBRARY(library) command(s). - */ -class cmLinkLibrariesCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmLinkLibrariesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmLinkLibrariesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d73a285..88d03f9 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -908,12 +908,44 @@ void cmMakefile::AddCustomCommandToTarget( t.AddPostBuildCommand(cc); break; } + this->UpdateOutputToSourceMap(byproducts, &t); +} + +void cmMakefile::UpdateOutputToSourceMap( + std::vector<std::string> const& byproducts, cmTarget* target) +{ + for (std::string const& o : byproducts) { + this->UpdateOutputToSourceMap(o, target); + } +} + +void cmMakefile::UpdateOutputToSourceMap(std::string const& byproduct, + cmTarget* target) +{ + SourceEntry entry; + entry.Sources.Target = target; + + auto pr = this->OutputToSource.emplace(byproduct, entry); + if (!pr.second) { + SourceEntry& current = pr.first->second; + // Has the target already been set? + if (!current.Sources.Target) { + current.Sources.Target = target; + } else { + // Multiple custom commands/targets produce the same output (source file + // or target). See also comment in other UpdateOutputToSourceMap + // overload. + // + // TODO: Warn the user about this case. + } + } } cmSourceFile* cmMakefile::AddCustomCommandToOutput( const std::vector<std::string>& outputs, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, const std::string& main_dependency, + const cmImplicitDependsList& implicit_depends, const cmCustomCommandLines& commandLines, const char* comment, const char* workingDir, bool replace, bool escapeOldStyle, bool uses_terminal, bool command_expand_lists, const std::string& depfile, @@ -998,40 +1030,53 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( this, outputs, byproducts, depends2, commandLines, comment, workingDir); cc->SetEscapeOldStyle(escapeOldStyle); cc->SetEscapeAllowMakeVars(true); + cc->SetImplicitDepends(implicit_depends); cc->SetUsesTerminal(uses_terminal); cc->SetCommandExpandLists(command_expand_lists); cc->SetDepfile(depfile); cc->SetJobPool(job_pool); file->SetCustomCommand(cc); - this->UpdateOutputToSourceMap(outputs, file); + this->UpdateOutputToSourceMap(outputs, file, false); + this->UpdateOutputToSourceMap(byproducts, file, true); } return file; } void cmMakefile::UpdateOutputToSourceMap( - std::vector<std::string> const& outputs, cmSourceFile* source) + std::vector<std::string> const& outputs, cmSourceFile* source, + bool byproduct) { for (std::string const& o : outputs) { - this->UpdateOutputToSourceMap(o, source); + this->UpdateOutputToSourceMap(o, source, byproduct); } } void cmMakefile::UpdateOutputToSourceMap(std::string const& output, - cmSourceFile* source) -{ - auto i = this->OutputToSource.find(output); - if (i != this->OutputToSource.end()) { - // Multiple custom commands produce the same output but may - // be attached to a different source file (MAIN_DEPENDENCY). - // LinearGetSourceFileWithOutput would return the first one, - // so keep the mapping for the first one. - // - // TODO: Warn the user about this case. However, the VS 8 generator - // triggers it for separate generate.stamp rules in ZERO_CHECK and - // individual targets. - return; + cmSourceFile* source, bool byproduct) +{ + SourceEntry entry; + entry.Sources.Source = source; + entry.Sources.SourceIsByproduct = byproduct; + + auto pr = this->OutputToSource.emplace(output, entry); + if (!pr.second) { + SourceEntry& current = pr.first->second; + // Outputs take precedence over byproducts + if (!current.Sources.Source || + (current.Sources.SourceIsByproduct && !byproduct)) { + current.Sources.Source = source; + current.Sources.SourceIsByproduct = false; + } else { + // Multiple custom commands produce the same output but may + // be attached to a different source file (MAIN_DEPENDENCY). + // LinearGetSourceFileWithOutput would return the first one, + // so keep the mapping for the first one. + // + // TODO: Warn the user about this case. However, the VS 8 generator + // triggers it for separate generate.stamp rules in ZERO_CHECK and + // individual targets. + } } - this->OutputToSource[output] = source; } cmSourceFile* cmMakefile::AddCustomCommandToOutput( @@ -1044,10 +1089,11 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( std::vector<std::string> outputs; outputs.push_back(output); std::vector<std::string> no_byproducts; + cmImplicitDependsList no_implicit_depends; return this->AddCustomCommandToOutput( - outputs, no_byproducts, depends, main_dependency, commandLines, comment, - workingDir, replace, escapeOldStyle, uses_terminal, command_expand_lists, - depfile, job_pool); + outputs, no_byproducts, depends, main_dependency, no_implicit_depends, + commandLines, comment, workingDir, replace, escapeOldStyle, uses_terminal, + command_expand_lists, depfile, job_pool); } void cmMakefile::AddCustomCommandOldStyle( @@ -1108,6 +1154,23 @@ void cmMakefile::AddCustomCommandOldStyle( } } +bool cmMakefile::AppendCustomCommandToOutput( + const std::string& output, const std::vector<std::string>& depends, + const cmImplicitDependsList& implicit_depends, + const cmCustomCommandLines& commandLines) +{ + // Lookup an existing command. + if (cmSourceFile* sf = this->GetSourceFileWithOutput(output)) { + if (cmCustomCommand* cc = sf->GetCustomCommand()) { + cc->AppendCommands(commandLines); + cc->AppendDepends(depends); + cc->AppendImplicitDepends(implicit_depends); + return true; + } + } + return false; +} + cmTarget* cmMakefile::AddUtilityCommand( const std::string& utilityName, TargetOrigin origin, bool excludeFromAll, const std::vector<std::string>& depends, const char* workingDirectory, @@ -1181,11 +1244,12 @@ cmTarget* cmMakefile::AddUtilityCommand( std::vector<std::string> forced; forced.push_back(force); std::string no_main_dependency; + cmImplicitDependsList no_implicit_depends; bool no_replace = false; this->AddCustomCommandToOutput( - forced, byproducts, depends, no_main_dependency, commandLines, comment, - workingDirectory, no_replace, escapeOldStyle, uses_terminal, - command_expand_lists, /*depfile=*/"", job_pool); + forced, byproducts, depends, no_main_dependency, no_implicit_depends, + commandLines, comment, workingDirectory, no_replace, escapeOldStyle, + uses_terminal, command_expand_lists, /*depfile=*/"", job_pool); cmSourceFile* sf = target->AddSourceCMP0049(force); // The output is not actually created so mark it symbolic. @@ -1194,6 +1258,8 @@ cmTarget* cmMakefile::AddUtilityCommand( } else { cmSystemTools::Error("Could not get source file entry for " + force); } + + this->UpdateOutputToSourceMap(byproducts, target); } return target; } @@ -2007,52 +2073,126 @@ cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type, this->Targets .emplace(name, cmTarget(name, type, cmTarget::VisibilityNormal, this)) .first; + this->OrderedTargets.push_back(&it->second); this->GetGlobalGenerator()->IndexTarget(&it->second); this->GetStateSnapshot().GetDirectory().AddNormalTargetName(name); return &it->second; } +namespace { +bool AnyOutputMatches(const std::string& name, + const std::vector<std::string>& outputs) +{ + for (std::string const& output : outputs) { + std::string::size_type pos = output.rfind(name); + // If the output matches exactly + if (pos != std::string::npos && pos == output.size() - name.size() && + (pos == 0 || output[pos - 1] == '/')) { + return true; + } + } + return false; +} + +bool AnyTargetCommandOutputMatches( + const std::string& name, const std::vector<cmCustomCommand>& commands) +{ + for (cmCustomCommand const& command : commands) { + if (AnyOutputMatches(name, command.GetByproducts())) { + return true; + } + } + return false; +} +} + +cmTarget* cmMakefile::LinearGetTargetWithOutput(const std::string& name) const +{ + // We go through the ordered vector of targets to get reproducible results + // should multiple names match. + for (cmTarget* t : this->OrderedTargets) { + // Does the output of any command match the source file name? + if (AnyTargetCommandOutputMatches(name, t->GetPreBuildCommands())) { + return t; + } + if (AnyTargetCommandOutputMatches(name, t->GetPreLinkCommands())) { + return t; + } + if (AnyTargetCommandOutputMatches(name, t->GetPostBuildCommands())) { + return t; + } + } + return nullptr; +} + cmSourceFile* cmMakefile::LinearGetSourceFileWithOutput( - const std::string& name) const + const std::string& name, cmSourceOutputKind kind, bool& byproduct) const { - std::string out; + // Outputs take precedence over byproducts. + byproduct = false; + cmSourceFile* fallback = nullptr; - // look through all the source files that have custom commands - // and see if the custom command has the passed source file as an output + // Look through all the source files that have custom commands and see if the + // custom command has the passed source file as an output. for (cmSourceFile* src : this->SourceFiles) { - // does this source file have a custom command? + // Does this source file have a custom command? if (src->GetCustomCommand()) { // Does the output of the custom command match the source file name? - const std::vector<std::string>& outputs = - src->GetCustomCommand()->GetOutputs(); - for (std::string const& output : outputs) { - out = output; - std::string::size_type pos = out.rfind(name); - // If the output matches exactly - if (pos != std::string::npos && pos == out.size() - name.size() && - (pos == 0 || out[pos - 1] == '/')) { - return src; + if (AnyOutputMatches(name, src->GetCustomCommand()->GetOutputs())) { + // Return the first matching output. + return src; + } + if (kind == cmSourceOutputKind::OutputOrByproduct) { + if (AnyOutputMatches(name, src->GetCustomCommand()->GetByproducts())) { + // Do not return the source yet as there might be a matching output. + fallback = src; } } } } - // otherwise return NULL - return nullptr; + // Did we find a byproduct? + byproduct = fallback != nullptr; + return fallback; } -cmSourceFile* cmMakefile::GetSourceFileWithOutput( +cmSourcesWithOutput cmMakefile::GetSourcesWithOutput( const std::string& name) const { + // Linear search? Also see GetSourceFileWithOutput for detail. + if (!cmSystemTools::FileIsFullPath(name)) { + cmSourcesWithOutput sources; + sources.Target = this->LinearGetTargetWithOutput(name); + sources.Source = this->LinearGetSourceFileWithOutput( + name, cmSourceOutputKind::OutputOrByproduct, sources.SourceIsByproduct); + return sources; + } + // Otherwise we use an efficient lookup map. + auto o = this->OutputToSource.find(name); + if (o != this->OutputToSource.end()) { + return o->second.Sources; + } + return {}; +} + +cmSourceFile* cmMakefile::GetSourceFileWithOutput( + const std::string& name, cmSourceOutputKind kind) const +{ // If the queried path is not absolute we use the backward compatible // linear-time search for an output with a matching suffix. if (!cmSystemTools::FileIsFullPath(name)) { - return this->LinearGetSourceFileWithOutput(name); + bool byproduct = false; + return this->LinearGetSourceFileWithOutput(name, kind, byproduct); } // Otherwise we use an efficient lookup map. auto o = this->OutputToSource.find(name); - if (o != this->OutputToSource.end()) { - return (*o).second; + if (o != this->OutputToSource.end() && + (!o->second.Sources.SourceIsByproduct || + kind == cmSourceOutputKind::OutputOrByproduct)) { + // Source file could also be null pointer for example if we found the + // byproduct of a utility target or a PRE_BUILD, PRE_LINK, or POST_BUILD + // command of a target. + return o->second.Sources.Source; } return nullptr; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 252b855..1944879 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -42,6 +42,7 @@ class cmExportBuildFileGenerator; class cmFunctionBlocker; class cmGeneratorExpressionEvaluationFile; class cmGlobalGenerator; +class cmImplicitDependsList; class cmInstallGenerator; class cmMessenger; class cmSourceFile; @@ -51,6 +52,24 @@ class cmTestGenerator; class cmVariableWatch; class cmake; +/** Flag if byproducts shall also be considered. */ +enum class cmSourceOutputKind +{ + OutputOnly, + OutputOrByproduct +}; + +/** Target and source file which have a specific output. */ +struct cmSourcesWithOutput +{ + /** Target with byproduct. */ + cmTarget* Target = nullptr; + + /** Source file with output or byproduct. */ + cmSourceFile* Source = nullptr; + bool SourceIsByproduct = false; +}; + /** A type-safe wrapper for a string representing a directory id. */ class cmDirectoryId { @@ -166,6 +185,7 @@ public: const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, const std::string& main_dependency, + const cmImplicitDependsList& implicit_depends, const cmCustomCommandLines& commandLines, const char* comment, const char* workingDir, bool replace = false, bool escapeOldStyle = true, bool uses_terminal = false, bool command_expand_lists = false, @@ -183,6 +203,10 @@ public: const std::string& source, const cmCustomCommandLines& commandLines, const char* comment); + bool AppendCustomCommandToOutput( + const std::string& output, const std::vector<std::string>& depends, + const cmImplicitDependsList& implicit_depends, + const cmCustomCommandLines& commandLines); /** * Add a define flag to the build. @@ -687,10 +711,19 @@ public: } /** - * Is there a source file that has the provided source file as an output? - * if so then return it + * Return the target if the provided source name is a byproduct of a utility + * target or a PRE_BUILD, PRE_LINK, or POST_BUILD command. + * Return the source file which has the provided source name as output. */ - cmSourceFile* GetSourceFileWithOutput(const std::string& outName) const; + cmSourcesWithOutput GetSourcesWithOutput(const std::string& name) const; + + /** + * Is there a source file that has the provided source name as an output? + * If so then return it. + */ + cmSourceFile* GetSourceFileWithOutput( + const std::string& name, + cmSourceOutputKind kind = cmSourceOutputKind::OutputOnly) const; //! Add a new cmTest to the list of tests for this makefile. cmTest* CreateTest(const std::string& testName); @@ -914,6 +947,9 @@ protected: mutable cmTargetMap Targets; std::map<std::string, std::string> AliasTargets; + using TargetsVec = std::vector<cmTarget*>; + TargetsVec OrderedTargets; + using SourceFileVec = std::vector<cmSourceFile*>; SourceFileVec SourceFiles; @@ -1036,21 +1072,37 @@ private: cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); /** - * Old version of GetSourceFileWithOutput(const std::string&) kept for - * backward-compatibility. It implements a linear search and support - * relative file paths. It is used as a fall back by - * GetSourceFileWithOutput(const std::string&). + * See LinearGetSourceFileWithOutput for background information + */ + cmTarget* LinearGetTargetWithOutput(const std::string& name) const; + + /** + * Generalized old version of GetSourceFileWithOutput kept for + * backward-compatibility. It implements a linear search and supports + * relative file paths. It is used as a fall back by GetSourceFileWithOutput + * and GetSourcesWithOutput. */ - cmSourceFile* LinearGetSourceFileWithOutput(const std::string& cname) const; + cmSourceFile* LinearGetSourceFileWithOutput(const std::string& name, + cmSourceOutputKind kind, + bool& byproduct) const; + + struct SourceEntry + { + cmSourcesWithOutput Sources; + }; // A map for fast output to input look up. - using OutputToSourceMap = std::unordered_map<std::string, cmSourceFile*>; + using OutputToSourceMap = std::unordered_map<std::string, SourceEntry>; OutputToSourceMap OutputToSource; + void UpdateOutputToSourceMap(std::vector<std::string> const& byproducts, + cmTarget* target); + void UpdateOutputToSourceMap(std::string const& byproduct, cmTarget* target); + void UpdateOutputToSourceMap(std::vector<std::string> const& outputs, - cmSourceFile* source); - void UpdateOutputToSourceMap(std::string const& output, - cmSourceFile* source); + cmSourceFile* source, bool byproduct); + void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source, + bool byproduct); bool AddRequiredTargetCFeature(cmTarget* target, const std::string& feature, std::string* error = nullptr) const; diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index ba82813..1a5602b 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -2,45 +2,44 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmQTWrapCPPCommand.h" +#include <utility> + #include "cmCustomCommandLines.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -#include <utility> - -class cmExecutionStatus; - -// cmQTWrapCPPCommand -bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmQTWrapCPPCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 3) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Get the moc executable to run in the custom command. - std::string const& moc_exe = - this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE"); + std::string const& moc_exe = mf.GetRequiredDefinition("QT_MOC_EXECUTABLE"); // Get the variable holding the list of sources. std::string const& sourceList = args[1]; - std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList); + std::string sourceListValue = mf.GetSafeDefinition(sourceList); // Create a rule for all sources listed. for (std::string const& arg : cmMakeRange(args).advance(2)) { - cmSourceFile* curr = this->Makefile->GetSource(arg); + cmSourceFile* curr = mf.GetSource(arg); // if we should wrap the class if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) { // Compute the name of the file to generate. std::string srcName = cmSystemTools::GetFilenameWithoutLastExtension(arg); - std::string newName = cmStrCat( - this->Makefile->GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); - cmSourceFile* sf = this->Makefile->GetOrCreateSource(newName, true); + std::string newName = + cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); + cmSourceFile* sf = mf.GetOrCreateSource(newName, true); if (curr) { sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT")); } @@ -51,9 +50,9 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, hname = arg; } else { if (curr && curr->GetIsGenerated()) { - hname = this->Makefile->GetCurrentBinaryDirectory(); + hname = mf.GetCurrentBinaryDirectory(); } else { - hname = this->Makefile->GetCurrentSourceDirectory(); + hname = mf.GetCurrentSourceDirectory(); } hname += "/"; hname += arg; @@ -81,13 +80,13 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, std::string no_main_dependency; const char* no_working_dir = nullptr; - this->Makefile->AddCustomCommandToOutput( - newName, depends, no_main_dependency, commandLines, "Qt Wrapped File", - no_working_dir); + mf.AddCustomCommandToOutput(newName, depends, no_main_dependency, + commandLines, "Qt Wrapped File", + no_working_dir); } } // Store the final list of source files. - this->Makefile->AddDefinition(sourceList, sourceListValue); + mf.AddDefinition(sourceList, sourceListValue); return true; } diff --git a/Source/cmQTWrapCPPCommand.h b/Source/cmQTWrapCPPCommand.h index 88a2210..75fa180 100644 --- a/Source/cmQTWrapCPPCommand.h +++ b/Source/cmQTWrapCPPCommand.h @@ -8,35 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmQTWrapCPPCommand - * \brief Create moc file rules for Qt classes - * - * cmQTWrapCPPCommand is used to create wrappers for Qt classes into - * normal C++ - */ -class cmQTWrapCPPCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmQTWrapCPPCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmQTWrapCPPCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index 8bc914f..b7b5efa 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -2,52 +2,50 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmQTWrapUICommand.h" +#include <utility> + #include "cmCustomCommandLines.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -#include <utility> - -class cmExecutionStatus; - -// cmQTWrapUICommand -bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmQTWrapUICommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 4) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // Get the uic and moc executables to run in the custom commands. - std::string const& uic_exe = - this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE"); - std::string const& moc_exe = - this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE"); + std::string const& uic_exe = mf.GetRequiredDefinition("QT_UIC_EXECUTABLE"); + std::string const& moc_exe = mf.GetRequiredDefinition("QT_MOC_EXECUTABLE"); // Get the variable holding the list of sources. std::string const& headerList = args[1]; std::string const& sourceList = args[2]; - std::string headerListValue = this->Makefile->GetSafeDefinition(headerList); - std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList); + std::string headerListValue = mf.GetSafeDefinition(headerList); + std::string sourceListValue = mf.GetSafeDefinition(sourceList); // Create rules for all sources listed. for (std::string const& arg : cmMakeRange(args).advance(3)) { - cmSourceFile* curr = this->Makefile->GetSource(arg); + cmSourceFile* curr = mf.GetSource(arg); // if we should wrap the class if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) { // Compute the name of the files to generate. std::string srcName = cmSystemTools::GetFilenameWithoutLastExtension(arg); - std::string hName = cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), - '/', srcName, ".h"); - std::string cxxName = cmStrCat( - this->Makefile->GetCurrentBinaryDirectory(), '/', srcName, ".cxx"); - std::string mocName = cmStrCat( - this->Makefile->GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); + std::string hName = + cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".h"); + std::string cxxName = + cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".cxx"); + std::string mocName = + cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx"); // Compute the name of the ui file from which to generate others. std::string uiName; @@ -55,9 +53,9 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, uiName = arg; } else { if (curr && curr->GetIsGenerated()) { - uiName = this->Makefile->GetCurrentBinaryDirectory(); + uiName = mf.GetCurrentBinaryDirectory(); } else { - uiName = this->Makefile->GetCurrentSourceDirectory(); + uiName = mf.GetCurrentSourceDirectory(); } uiName += "/"; uiName += arg; @@ -109,25 +107,22 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, std::string no_main_dependency; const char* no_comment = nullptr; const char* no_working_dir = nullptr; - this->Makefile->AddCustomCommandToOutput( - hName, depends, no_main_dependency, hCommandLines, no_comment, - no_working_dir); + mf.AddCustomCommandToOutput(hName, depends, no_main_dependency, + hCommandLines, no_comment, no_working_dir); depends.push_back(hName); - this->Makefile->AddCustomCommandToOutput( - cxxName, depends, no_main_dependency, cxxCommandLines, no_comment, - no_working_dir); + mf.AddCustomCommandToOutput(cxxName, depends, no_main_dependency, + cxxCommandLines, no_comment, no_working_dir); depends.clear(); depends.push_back(hName); - this->Makefile->AddCustomCommandToOutput( - mocName, depends, no_main_dependency, mocCommandLines, no_comment, - no_working_dir); + mf.AddCustomCommandToOutput(mocName, depends, no_main_dependency, + mocCommandLines, no_comment, no_working_dir); } } // Store the final list of source files and headers. - this->Makefile->AddDefinition(sourceList, sourceListValue); - this->Makefile->AddDefinition(headerList, headerListValue); + mf.AddDefinition(sourceList, sourceListValue); + mf.AddDefinition(headerList, headerListValue); return true; } diff --git a/Source/cmQTWrapUICommand.h b/Source/cmQTWrapUICommand.h index 6a346d4..a17ef54 100644 --- a/Source/cmQTWrapUICommand.h +++ b/Source/cmQTWrapUICommand.h @@ -8,34 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmQTWrapUICommand - * \brief Create .h and .cxx files rules for Qt user interfaces files - * - * cmQTWrapUICommand is used to create wrappers for Qt classes into normal C++ - */ -class cmQTWrapUICommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmQTWrapUICommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmQTWrapUICommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index d6916b0..54304c3 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1166,10 +1166,12 @@ bool cmQtAutoGenInitializer::InitRccTargets() if (!this->Rcc.ExecutableTargetName.empty()) { ccDepends.push_back(this->Rcc.ExecutableTargetName); } - makefile->AddCustomCommandToOutput(ccOutput, ccByproducts, ccDepends, - /*main_dependency*/ std::string(), - commandLines, ccComment.c_str(), - this->Dir.Work.c_str()); + std::string no_main_dependency; + cmImplicitDependsList no_implicit_depends; + makefile->AddCustomCommandToOutput( + ccOutput, ccByproducts, ccDepends, no_main_dependency, + no_implicit_depends, commandLines, ccComment.c_str(), + this->Dir.Work.c_str()); } // Reconfigure when .qrc file changes makefile->AddCMakeDependFile(qrc.QrcFile); diff --git a/Source/cmRemoveDefinitionsCommand.cxx b/Source/cmRemoveDefinitionsCommand.cxx index 8d3f688..339ff9d 100644 --- a/Source/cmRemoveDefinitionsCommand.cxx +++ b/Source/cmRemoveDefinitionsCommand.cxx @@ -2,21 +2,15 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmRemoveDefinitionsCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" -class cmExecutionStatus; - -// cmRemoveDefinitionsCommand -bool cmRemoveDefinitionsCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmRemoveDefinitionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { - // it is OK to have no arguments - if (args.empty()) { - return true; - } - + cmMakefile& mf = status.GetMakefile(); for (std::string const& i : args) { - this->Makefile->RemoveDefineFlag(i); + mf.RemoveDefineFlag(i); } return true; } diff --git a/Source/cmRemoveDefinitionsCommand.h b/Source/cmRemoveDefinitionsCommand.h index 85d01d4..868416b 100644 --- a/Source/cmRemoveDefinitionsCommand.h +++ b/Source/cmRemoveDefinitionsCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmRemoveDefinitionsCommand - * \brief Specify a list of compiler defines - * - * cmRemoveDefinitionsCommand specifies a list of compiler defines. - * These defines will - * be removed from the compile command. - */ -class cmRemoveDefinitionsCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmRemoveDefinitionsCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmRemoveDefinitionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmSetSourceFilesPropertiesCommand.cxx b/Source/cmSetSourceFilesPropertiesCommand.cxx index 8e3217f..7ff604b 100644 --- a/Source/cmSetSourceFilesPropertiesCommand.cxx +++ b/Source/cmSetSourceFilesPropertiesCommand.cxx @@ -2,18 +2,23 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmSetSourceFilesPropertiesCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" -class cmExecutionStatus; +static bool RunCommand(cmMakefile* mf, + std::vector<std::string>::const_iterator filebeg, + std::vector<std::string>::const_iterator fileend, + std::vector<std::string>::const_iterator propbeg, + std::vector<std::string>::const_iterator propend, + std::string& errors); -// cmSetSourceFilesPropertiesCommand -bool cmSetSourceFilesPropertiesCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmSetSourceFilesPropertiesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.size() < 2) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } @@ -29,22 +34,24 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass( ++j; } + cmMakefile& mf = status.GetMakefile(); + // now call the worker function std::string errors; - bool ret = cmSetSourceFilesPropertiesCommand::RunCommand( - this->Makefile, args.begin(), args.begin() + numFiles, - args.begin() + numFiles, args.end(), errors); + bool ret = RunCommand(&mf, args.begin(), args.begin() + numFiles, + args.begin() + numFiles, args.end(), errors); if (!ret) { - this->SetError(errors); + status.SetError(errors); } return ret; } -bool cmSetSourceFilesPropertiesCommand::RunCommand( - cmMakefile* mf, std::vector<std::string>::const_iterator filebeg, - std::vector<std::string>::const_iterator fileend, - std::vector<std::string>::const_iterator propbeg, - std::vector<std::string>::const_iterator propend, std::string& errors) +static bool RunCommand(cmMakefile* mf, + std::vector<std::string>::const_iterator filebeg, + std::vector<std::string>::const_iterator fileend, + std::vector<std::string>::const_iterator propbeg, + std::vector<std::string>::const_iterator propend, + std::string& errors) { std::vector<std::string> propertyPairs; bool generated = false; diff --git a/Source/cmSetSourceFilesPropertiesCommand.h b/Source/cmSetSourceFilesPropertiesCommand.h index 6fd6c41..5eef785 100644 --- a/Source/cmSetSourceFilesPropertiesCommand.h +++ b/Source/cmSetSourceFilesPropertiesCommand.h @@ -8,34 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmMakefile; - -class cmSetSourceFilesPropertiesCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmSetSourceFilesPropertiesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - static bool RunCommand(cmMakefile* mf, - std::vector<std::string>::const_iterator filebeg, - std::vector<std::string>::const_iterator fileend, - std::vector<std::string>::const_iterator propbeg, - std::vector<std::string>::const_iterator propend, - std::string& errors); -}; +bool cmSetSourceFilesPropertiesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmSetTestsPropertiesCommand.cxx b/Source/cmSetTestsPropertiesCommand.cxx index ed909c6..de61eda 100644 --- a/Source/cmSetTestsPropertiesCommand.cxx +++ b/Source/cmSetTestsPropertiesCommand.cxx @@ -5,21 +5,25 @@ #include <iterator> #include "cmAlgorithms.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmStringAlgorithms.h" #include "cmTest.h" -class cmExecutionStatus; +static bool SetOneTest(const std::string& tname, + std::vector<std::string>& propertyPairs, cmMakefile* mf, + std::string& errors); -// cmSetTestsPropertiesCommand -bool cmSetTestsPropertiesCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } + cmMakefile& mf = status.GetMakefile(); + // first collect up the list of files std::vector<std::string> propertyPairs; int numFiles = 0; @@ -29,7 +33,7 @@ bool cmSetTestsPropertiesCommand::InitialPass( // now loop through the rest of the arguments, new style ++j; if (std::distance(j, args.end()) % 2 != 0) { - this->SetError("called with incorrect number of arguments."); + status.SetError("called with incorrect number of arguments."); return false; } cmAppend(propertyPairs, j, args.end()); @@ -38,8 +42,8 @@ bool cmSetTestsPropertiesCommand::InitialPass( numFiles++; } if (propertyPairs.empty()) { - this->SetError("called with illegal arguments, maybe " - "missing a PROPERTIES specifier?"); + status.SetError("called with illegal arguments, maybe " + "missing a PROPERTIES specifier?"); return false; } @@ -47,10 +51,9 @@ bool cmSetTestsPropertiesCommand::InitialPass( int i; for (i = 0; i < numFiles; ++i) { std::string errors; - bool ret = cmSetTestsPropertiesCommand::SetOneTest(args[i], propertyPairs, - this->Makefile, errors); + bool ret = SetOneTest(args[i], propertyPairs, &mf, errors); if (!ret) { - this->SetError(errors); + status.SetError(errors); return ret; } } @@ -58,9 +61,9 @@ bool cmSetTestsPropertiesCommand::InitialPass( return true; } -bool cmSetTestsPropertiesCommand::SetOneTest( - const std::string& tname, std::vector<std::string>& propertyPairs, - cmMakefile* mf, std::string& errors) +static bool SetOneTest(const std::string& tname, + std::vector<std::string>& propertyPairs, cmMakefile* mf, + std::string& errors) { if (cmTest* test = mf->GetTest(tname)) { // now loop through all the props and set them diff --git a/Source/cmSetTestsPropertiesCommand.h b/Source/cmSetTestsPropertiesCommand.h index d73e95a..4b75464 100644 --- a/Source/cmSetTestsPropertiesCommand.h +++ b/Source/cmSetTestsPropertiesCommand.h @@ -8,31 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmMakefile; - -class cmSetTestsPropertiesCommand : public cmCommand -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmSetTestsPropertiesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - static bool SetOneTest(const std::string& tname, - std::vector<std::string>& propertyPairs, - cmMakefile* mf, std::string& errors); -}; +bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmSubdirCommand.cxx b/Source/cmSubdirCommand.cxx index 07f8efe..2477d7a 100644 --- a/Source/cmSubdirCommand.cxx +++ b/Source/cmSubdirCommand.cxx @@ -2,22 +2,21 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmSubdirCommand.h" +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -class cmExecutionStatus; - -// cmSubdirCommand -bool cmSubdirCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmSubdirCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } bool res = true; bool excludeFromAll = false; + cmMakefile& mf = status.GetMakefile(); for (std::string const& i : args) { if (i == "EXCLUDE_FROM_ALL") { @@ -30,24 +29,21 @@ bool cmSubdirCommand::InitialPass(std::vector<std::string> const& args, } // if they specified a relative path then compute the full - std::string srcPath = - this->Makefile->GetCurrentSourceDirectory() + "/" + i; + std::string srcPath = mf.GetCurrentSourceDirectory() + "/" + i; if (cmSystemTools::FileIsDirectory(srcPath)) { - std::string binPath = - this->Makefile->GetCurrentBinaryDirectory() + "/" + i; - this->Makefile->AddSubDirectory(srcPath, binPath, excludeFromAll, false); + std::string binPath = mf.GetCurrentBinaryDirectory() + "/" + i; + mf.AddSubDirectory(srcPath, binPath, excludeFromAll, false); } // otherwise it is a full path else if (cmSystemTools::FileIsDirectory(i)) { // we must compute the binPath from the srcPath, we just take the last // element from the source path and use that - std::string binPath = this->Makefile->GetCurrentBinaryDirectory() + "/" + + std::string binPath = mf.GetCurrentBinaryDirectory() + "/" + cmSystemTools::GetFilenameName(i); - this->Makefile->AddSubDirectory(i, binPath, excludeFromAll, false); + mf.AddSubDirectory(i, binPath, excludeFromAll, false); } else { - std::string error = cmStrCat("Incorrect SUBDIRS command. Directory: ", i, - " does not exist."); - this->SetError(error); + status.SetError(cmStrCat("Incorrect SUBDIRS command. Directory: ", i, + " does not exist.")); res = false; } } diff --git a/Source/cmSubdirCommand.h b/Source/cmSubdirCommand.h index 3499c46..3254e84 100644 --- a/Source/cmSubdirCommand.h +++ b/Source/cmSubdirCommand.h @@ -8,36 +8,9 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmSubdirCommand - * \brief Specify a list of subdirectories to build. - * - * cmSubdirCommand specifies a list of subdirectories to process - * by CMake. For each subdirectory listed, CMake will descend - * into that subdirectory and process any CMakeLists.txt found. - */ -class cmSubdirCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmSubdirCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmSubdirCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Tests/CustomCommandByproducts/CMakeLists.txt b/Tests/CustomCommandByproducts/CMakeLists.txt index d0bf648..bfa69ce 100644 --- a/Tests/CustomCommandByproducts/CMakeLists.txt +++ b/Tests/CustomCommandByproducts/CMakeLists.txt @@ -28,6 +28,7 @@ add_custom_target(Producer3_4 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct3.c.in byproduct3.c BYPRODUCTS byproduct3.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct3.c.in ) # Generate a byproduct in a custom target POST_BUILD command. @@ -36,32 +37,36 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct4.c.in byproduct4.c BYPRODUCTS byproduct4.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct4.c.in ) -add_executable(ProducerExe ProducerExe.c) +add_executable(ProducerExe5_6_7 ProducerExe.c) # Generate a byproduct in an executable POST_BUILD command. add_custom_command( - TARGET ProducerExe POST_BUILD + TARGET ProducerExe5_6_7 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct5.c.in byproduct5.c BYPRODUCTS byproduct5.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct5.c.in ) # Generate a byproduct in an executable PRE_LINK command. add_custom_command( - TARGET ProducerExe PRE_LINK + TARGET ProducerExe5_6_7 PRE_LINK COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct6.c.in byproduct6.c BYPRODUCTS byproduct6.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct6.c.in ) # Generate a byproduct in an executable PRE_BUILD command. add_custom_command( - TARGET ProducerExe PRE_BUILD + TARGET ProducerExe5_6_7 PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/byproduct7.c.in byproduct7.c BYPRODUCTS byproduct7.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct7.c.in ) # Generate a byproduct in a custom command that consumes other byproducts. @@ -80,6 +85,25 @@ add_custom_command(OUTPUT timestamp8.txt ${CMAKE_CURRENT_SOURCE_DIR}/byproduct8.c.in ) +add_executable(ProducerExe9 ProducerExe.c) + +# Generate a byproduct in a custom target which depends on a byproduct of a +# POST_BUILD command (test if dependency of custom target Producer9 to +# ProducerExe9 is added). +add_custom_command( + TARGET ProducerExe9 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct9.c.in byproduct9a.c + BYPRODUCTS byproduct9a.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct9.c.in + ) +add_custom_target(Producer9 + COMMAND ${CMAKE_COMMAND} -E copy_if_different + byproduct9a.c byproduct9.c + BYPRODUCTS byproduct9.c + DEPENDS byproduct9a.c + ) + # Generate the library file of an imported target as a byproduct # of an external project. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) @@ -136,10 +160,13 @@ add_executable(CustomCommandByproducts byproduct6.c byproduct7.c byproduct8.c timestamp8.txt + byproduct9.c ) + +# Dependencies to byproducts of custom commands other than build events are not +# yet traced (see issue #19005). add_dependencies(CustomCommandByproducts Producer2) -add_dependencies(CustomCommandByproducts Producer3_4) -add_dependencies(CustomCommandByproducts ProducerExe) + target_link_libraries(CustomCommandByproducts ExternalLibrary) if(CMAKE_GENERATOR STREQUAL "Ninja") diff --git a/Tests/CustomCommandByproducts/CustomCommandByproducts.c b/Tests/CustomCommandByproducts/CustomCommandByproducts.c index 02ad7ea..0658d05 100644 --- a/Tests/CustomCommandByproducts/CustomCommandByproducts.c +++ b/Tests/CustomCommandByproducts/CustomCommandByproducts.c @@ -6,10 +6,11 @@ extern int byproduct5(void); extern int byproduct6(void); extern int byproduct7(void); extern int byproduct8(void); +extern int byproduct9(void); extern int ExternalLibrary(void); int main(void) { return (byproduct1() + byproduct2() + byproduct3() + byproduct4() + byproduct5() + byproduct6() + byproduct7() + byproduct8() + - ExternalLibrary() + 0); + byproduct9() + ExternalLibrary() + 0); } diff --git a/Tests/CustomCommandByproducts/byproduct9.c.in b/Tests/CustomCommandByproducts/byproduct9.c.in new file mode 100644 index 0000000..11eed2c --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct9.c.in @@ -0,0 +1 @@ +int byproduct9(void) { return 0; } diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt index 3ff2b85..9d51342 100644 --- a/Tests/GeneratorExpression/CMakeLists.txt +++ b/Tests/GeneratorExpression/CMakeLists.txt @@ -86,7 +86,7 @@ add_custom_target(check-part1 ALL -Dtest_colons_4=$<1:C:\\CMake> -Dtest_colons_5=$<1:C:/CMake> -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part1.cmake - COMMAND ${CMAKE_COMMAND} -E echo "check done (part 1 of 4)" + COMMAND ${CMAKE_COMMAND} -E echo "check done (part 1 of 5)" VERBATIM ) @@ -157,7 +157,7 @@ add_custom_target(check-part2 ALL -Dtest_arbitrary_content_comma_9=$<1:a,,b,,> -Dtest_arbitrary_content_comma_10=$<1:,,a,,b,,> -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part2.cmake - COMMAND ${CMAKE_COMMAND} -E echo "check done (part 2 of 4)" + COMMAND ${CMAKE_COMMAND} -E echo "check done (part 2 of 5)" VERBATIM ) @@ -251,7 +251,7 @@ add_custom_target(check-part3 ALL -Dequal22=$<EQUAL:10,-012> -Dequal23=$<EQUAL:-10,-012> -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part3.cmake - COMMAND ${CMAKE_COMMAND} -E echo "check done (part 3 of 4)" + COMMAND ${CMAKE_COMMAND} -E echo "check done (part 3 of 5)" VERBATIM ) @@ -277,7 +277,27 @@ add_custom_target(check-part4 ALL -DWIN32=${WIN32} -DCMAKE_GENERATOR=${CMAKE_GENERATOR} -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part4.cmake - COMMAND ${CMAKE_COMMAND} -E echo "check done (part 4 of 4)" + COMMAND ${CMAKE_COMMAND} -E echo "check done (part 4 of 5)" + VERBATIM + ) + +add_custom_target(check-part5 ALL + COMMAND ${CMAKE_COMMAND} -E echo "check done (part 5 of 5)" + DEPENDS check-part5.stamp + VERBATIM + ) + +add_custom_command( + OUTPUT check-part5.stamp + DEPENDS $<FILTER:file.foo.bar,EXCLUDE,\\.foo\\.bar$> + COMMAND ${CMAKE_COMMAND} -E sleep 0 + VERBATIM + ) +set_property(SOURCE check-part5.stamp PROPERTY SYMBOLIC 1) + +add_custom_command( + OUTPUT file.foo.bar + COMMAND ${CMAKE_COMMAND} -P check-part5.cmake VERBATIM ) diff --git a/Tests/GeneratorExpression/check-part5.cmake b/Tests/GeneratorExpression/check-part5.cmake new file mode 100644 index 0000000..77d1387 --- /dev/null +++ b/Tests/GeneratorExpression/check-part5.cmake @@ -0,0 +1 @@ +message(SEND_ERROR "$<FILTER:file.foo.bar,EXCLUDE,\\.foo\\.bar$> genex in DEPENDS argument of 'add_custom_command()' is not empty") |