diff options
author | Chris Mahoney <chris.mahoney@kitware.com> | 2023-06-05 19:59:13 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-07-19 14:45:33 (GMT) |
commit | 95941fd99020bb2345869ed393abde1a44529837 (patch) | |
tree | 4e809b9c121ce0e5745c1030d6a7c62b1c09bf2e /Source | |
parent | af9489a4f2858db0bf666c29f99dd332426f5ca1 (diff) | |
download | CMake-95941fd99020bb2345869ed393abde1a44529837.zip CMake-95941fd99020bb2345869ed393abde1a44529837.tar.gz CMake-95941fd99020bb2345869ed393abde1a44529837.tar.bz2 |
add_custom_{target,command}: Add argument JOB_SERVER_AWARE
Issue: #16273
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAddCustomCommandCommand.cxx | 19 | ||||
-rw-r--r-- | Source/cmAddCustomTargetCommand.cxx | 17 | ||||
-rw-r--r-- | Source/cmGlobalBorlandMakefileGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmGlobalJOMMakefileGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmGlobalNMakeMakefileGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmGlobalUnixMakefileGenerator3.h | 2 | ||||
-rw-r--r-- | Source/cmGlobalWatcomWMakeGenerator.h | 2 |
8 files changed, 48 insertions, 0 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index b1398db..044b5df 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -19,6 +19,7 @@ #include "cmPolicies.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" +#include "cmValue.h" bool cmAddCustomCommandCommand(std::vector<std::string> const& args, cmExecutionStatus& status) @@ -39,6 +40,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, std::string working; std::string depfile; std::string job_pool; + std::string job_server_aware; std::string comment_buffer; const char* comment = nullptr; std::vector<std::string> depends; @@ -78,6 +80,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, doing_working_directory, doing_depfile, doing_job_pool, + doing_job_server_aware, doing_nothing }; @@ -95,6 +98,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, MAKE_STATIC_KEYWORD(DEPFILE); MAKE_STATIC_KEYWORD(IMPLICIT_DEPENDS); MAKE_STATIC_KEYWORD(JOB_POOL); + MAKE_STATIC_KEYWORD(JOB_SERVER_AWARE); MAKE_STATIC_KEYWORD(MAIN_DEPENDENCY); MAKE_STATIC_KEYWORD(OUTPUT); MAKE_STATIC_KEYWORD(OUTPUTS); @@ -126,6 +130,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, keyPRE_BUILD, keyPRE_LINK, keySOURCE, + keyJOB_SERVER_AWARE, keyTARGET, keyUSES_TERMINAL, keyVERBATIM, @@ -190,6 +195,8 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, } } else if (copy == keyJOB_POOL) { doing = doing_job_pool; + } else if (copy == keyJOB_SERVER_AWARE) { + doing = doing_job_server_aware; } } else { std::string filename; @@ -226,6 +233,9 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, case doing_job_pool: job_pool = copy; break; + case doing_job_server_aware: + job_server_aware = copy; + break; case doing_working_directory: working = copy; break; @@ -324,6 +334,15 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, return false; } + // If using a GNU Make generator and `JOB_SERVER_AWARE` is set then + // prefix all commands with '+'. + if (cmIsOn(job_server_aware) && + mf.GetGlobalGenerator()->IsGNUMakeJobServerAware()) { + for (auto& commandLine : commandLines) { + commandLine.insert(commandLine.begin(), "+"); + } + } + // Choose which mode of the command to use. auto cc = cm::make_unique<cmCustomCommand>(); cc->SetByproducts(byproducts); diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index a246d06..6339062 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -17,6 +17,7 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" +#include "cmValue.h" bool cmAddCustomTargetCommand(std::vector<std::string> const& args, cmExecutionStatus& status) @@ -54,6 +55,7 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args, const char* comment = nullptr; std::vector<std::string> sources; std::string job_pool; + std::string JOB_SERVER_AWARE; // Keep track of parser state. enum tdoing @@ -65,6 +67,7 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args, doing_comment, doing_source, doing_job_pool, + doing_JOB_SERVER_AWARE, doing_nothing }; tdoing doing = doing_command; @@ -102,6 +105,8 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args, doing = doing_comment; } else if (copy == "JOB_POOL") { doing = doing_job_pool; + } else if (copy == "JOB_SERVER_AWARE") { + doing = doing_JOB_SERVER_AWARE; } else if (copy == "COMMAND") { doing = doing_command; @@ -148,6 +153,9 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args, case doing_job_pool: job_pool = copy; break; + case doing_JOB_SERVER_AWARE: + JOB_SERVER_AWARE = copy; + break; default: status.SetError("Wrong syntax. Unknown type of argument."); return false; @@ -212,6 +220,15 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args, return false; } + // If using a GNU Make generator and `JOB_SERVER_AWARE` is set then + // prefix all commands with '+'. + if (cmIsOn(JOB_SERVER_AWARE) && + mf.GetGlobalGenerator()->IsGNUMakeJobServerAware()) { + for (auto& commandLine : commandLines) { + commandLine.insert(commandLine.begin(), "+"); + } + } + // Add the utility target to the makefile. auto cc = cm::make_unique<cmCustomCommand>(); cc->SetWorkingDirectory(working_directory.c_str()); diff --git a/Source/cmGlobalBorlandMakefileGenerator.h b/Source/cmGlobalBorlandMakefileGenerator.h index 049d6ba..a2adbd0 100644 --- a/Source/cmGlobalBorlandMakefileGenerator.h +++ b/Source/cmGlobalBorlandMakefileGenerator.h @@ -54,6 +54,8 @@ public: bool AllowDeleteOnError() const override { return false; } bool CanEscapeOctothorpe() const override { return true; } + bool IsGNUMakeJobServerAware() const override { return false; } + protected: std::vector<GeneratedMakeCommand> GenerateBuildCommand( const std::string& makeProgram, const std::string& projectName, diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 9aefaff..0e40813 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -161,6 +161,8 @@ public: virtual bool CheckCxxModuleSupport() { return false; } + virtual bool IsGNUMakeJobServerAware() const { return false; } + bool Compute(); virtual void AddExtraIDETargets() {} diff --git a/Source/cmGlobalJOMMakefileGenerator.h b/Source/cmGlobalJOMMakefileGenerator.h index 5e74875..cd3ed33 100644 --- a/Source/cmGlobalJOMMakefileGenerator.h +++ b/Source/cmGlobalJOMMakefileGenerator.h @@ -47,6 +47,8 @@ public: void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*, bool optional) override; + bool IsGNUMakeJobServerAware() const override { return false; } + protected: std::vector<GeneratedMakeCommand> GenerateBuildCommand( const std::string& makeProgram, const std::string& projectName, diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h index 436ebca..167889c 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.h +++ b/Source/cmGlobalNMakeMakefileGenerator.h @@ -53,6 +53,8 @@ public: void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*, bool optional) override; + bool IsGNUMakeJobServerAware() const override { return false; } + protected: std::vector<GeneratedMakeCommand> GenerateBuildCommand( const std::string& makeProgram, const std::string& projectName, diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 760679a..ee78351 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -120,6 +120,8 @@ public: void Configure() override; + bool IsGNUMakeJobServerAware() const override { return true; } + /** * Generate the all required files for building this project/tree. This * basically creates a series of LocalGenerators for each directory and diff --git a/Source/cmGlobalWatcomWMakeGenerator.h b/Source/cmGlobalWatcomWMakeGenerator.h index 5579120..8b24679 100644 --- a/Source/cmGlobalWatcomWMakeGenerator.h +++ b/Source/cmGlobalWatcomWMakeGenerator.h @@ -53,6 +53,8 @@ public: bool AllowNotParallel() const override { return false; } bool AllowDeleteOnError() const override { return false; } + bool IsGNUMakeJobServerAware() const override { return false; } + protected: std::vector<GeneratedMakeCommand> GenerateBuildCommand( const std::string& makeProgram, const std::string& projectName, |