summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-07-26 14:19:36 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-07-26 14:19:46 (GMT)
commit5a164f1649d1ed76a0864dc43acced58c8534982 (patch)
tree767fb6c009cf56dddbb79d28fa2c543376de2404 /Source
parent06839c419f7f3ebfde8109bfbcb8c5b15696a055 (diff)
parent3825d6ec981d20ee55b12aed8cc8f94ab1afc88f (diff)
downloadCMake-5a164f1649d1ed76a0864dc43acced58c8534982.zip
CMake-5a164f1649d1ed76a0864dc43acced58c8534982.tar.gz
CMake-5a164f1649d1ed76a0864dc43acced58c8534982.tar.bz2
Merge topic 'jobserver-fix'
3825d6ec98 add_custom_{command,target}: Teach JOB_SERVER_AWARE about WORKING_DIRECTORY Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !8644
Diffstat (limited to 'Source')
-rw-r--r--Source/cmAddCustomCommandCommand.cxx10
-rw-r--r--Source/cmAddCustomTargetCommand.cxx20
-rw-r--r--Source/cmCustomCommand.cxx10
-rw-r--r--Source/cmCustomCommand.h6
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx9
5 files changed, 32 insertions, 23 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx
index 044b5df..b1589ff 100644
--- a/Source/cmAddCustomCommandCommand.cxx
+++ b/Source/cmAddCustomCommandCommand.cxx
@@ -334,15 +334,6 @@ 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);
@@ -353,6 +344,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
cc->SetUsesTerminal(uses_terminal);
cc->SetDepfile(depfile);
cc->SetJobPool(job_pool);
+ cc->SetJobserverAware(cmIsOn(job_server_aware));
cc->SetCommandExpandLists(command_expand_lists);
cc->SetDependsExplicitOnly(depends_explicit_only);
if (source.empty() && output.empty()) {
diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx
index 6339062..711eaa5 100644
--- a/Source/cmAddCustomTargetCommand.cxx
+++ b/Source/cmAddCustomTargetCommand.cxx
@@ -55,7 +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;
+ std::string job_server_aware;
// Keep track of parser state.
enum tdoing
@@ -67,7 +67,7 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args,
doing_comment,
doing_source,
doing_job_pool,
- doing_JOB_SERVER_AWARE,
+ doing_job_server_aware,
doing_nothing
};
tdoing doing = doing_command;
@@ -106,7 +106,7 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args,
} else if (copy == "JOB_POOL") {
doing = doing_job_pool;
} else if (copy == "JOB_SERVER_AWARE") {
- doing = doing_JOB_SERVER_AWARE;
+ doing = doing_job_server_aware;
} else if (copy == "COMMAND") {
doing = doing_command;
@@ -153,8 +153,8 @@ 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;
+ case doing_job_server_aware:
+ job_server_aware = copy;
break;
default:
status.SetError("Wrong syntax. Unknown type of argument.");
@@ -220,15 +220,6 @@ 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());
@@ -240,6 +231,7 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args,
cc->SetUsesTerminal(uses_terminal);
cc->SetCommandExpandLists(command_expand_lists);
cc->SetJobPool(job_pool);
+ cc->SetJobserverAware(cmIsOn(job_server_aware));
cmTarget* target =
mf.AddUtilityCommand(targetName, excludeFromAll, std::move(cc));
diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx
index e12cf70..9958e4d 100644
--- a/Source/cmCustomCommand.cxx
+++ b/Source/cmCustomCommand.cxx
@@ -194,6 +194,16 @@ void cmCustomCommand::SetJobPool(const std::string& job_pool)
this->JobPool = job_pool;
}
+bool cmCustomCommand::GetJobserverAware() const
+{
+ return this->JobserverAware;
+}
+
+void cmCustomCommand::SetJobserverAware(bool b)
+{
+ this->JobserverAware = b;
+}
+
#define DEFINE_CC_POLICY_ACCESSOR(P) \
cmPolicies::PolicyStatus cmCustomCommand::Get##P##Status() const \
{ \
diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h
index 1e68dbf..167e601 100644
--- a/Source/cmCustomCommand.h
+++ b/Source/cmCustomCommand.h
@@ -115,6 +115,11 @@ public:
const std::string& GetJobPool() const;
void SetJobPool(const std::string& job_pool);
+ /** Set/Get whether this custom command should be given access to the
+ jobserver (if possible). */
+ bool GetJobserverAware() const;
+ void SetJobserverAware(bool b);
+
#define DECLARE_CC_POLICY_ACCESSOR(P) \
cmPolicies::PolicyStatus Get##P##Status() const;
CM_FOR_EACH_CUSTOM_COMMAND_POLICY(DECLARE_CC_POLICY_ACCESSOR)
@@ -139,6 +144,7 @@ private:
std::string WorkingDirectory;
std::string Depfile;
std::string JobPool;
+ bool JobserverAware = false;
bool HaveComment = false;
bool EscapeAllowMakeVars = false;
bool EscapeOldStyle = true;
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index 3c6b303..e26a6ea 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -1080,6 +1080,15 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
// Setup the proper working directory for the commands.
this->CreateCDCommand(commands1, dir, relative);
+ cmGlobalUnixMakefileGenerator3* gg =
+ static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
+
+ // Prefix the commands with the jobserver prefix "+"
+ if (ccg.GetCC().GetJobserverAware() && gg->IsGNUMakeJobServerAware()) {
+ std::transform(commands1.begin(), commands1.end(), commands1.begin(),
+ [](std::string const& cmd) { return cmStrCat("+", cmd); });
+ }
+
// push back the custom commands
cm::append(commands, commands1);
}