summaryrefslogtreecommitdiffstats
path: root/Source/cmakemain.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-01-23 13:15:29 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-01-23 13:15:36 (GMT)
commitc1247d861a42fa79e7ca4cc9a793b1fa1f012dce (patch)
tree29ac3c5421837467a8ce8e3bc195c2ae5d4fef06 /Source/cmakemain.cxx
parent877eed30c7f3fa873b36ec3654c00c50a3977425 (diff)
parentf2fca92686fb360c433d06452700d90dcf62c9fa (diff)
downloadCMake-c1247d861a42fa79e7ca4cc9a793b1fa1f012dce.zip
CMake-c1247d861a42fa79e7ca4cc9a793b1fa1f012dce.tar.gz
CMake-c1247d861a42fa79e7ca4cc9a793b1fa1f012dce.tar.bz2
Merge topic 'cmake_build_jobs_supports_no_space'
f2fca92686 cmake: --build supports '-jN' e463133cd2 Tests: Remove unused files from RunCMake.CommandLine test Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2819
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r--Source/cmakemain.cxx55
1 files changed, 36 insertions, 19 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 10655d5..0c25498 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -358,6 +358,31 @@ int do_cmake(int ac, char const* const* av)
return 0;
}
+namespace {
+int extract_job_number(int& index, char const* current, char const* next,
+ int len_of_flag)
+{
+ std::string command(current);
+ std::string jobString = command.substr(len_of_flag);
+ if (jobString.empty() && next && isdigit(next[0])) {
+ ++index; // skip parsing the job number
+ jobString = std::string(next);
+ }
+
+ int jobs = -1;
+ unsigned long numJobs = 0;
+ if (jobString.empty()) {
+ jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
+ } else if (cmSystemTools::StringToULong(jobString.c_str(), &numJobs)) {
+ jobs = int(numJobs);
+ } else {
+ std::cerr << "'" << command.substr(0, len_of_flag) << "' invalid number '"
+ << jobString << "' given.\n\n";
+ }
+ return jobs;
+}
+}
+
static int do_build(int ac, char const* const* av)
{
#ifndef CMAKE_BUILD_WITH_CMAKE
@@ -375,7 +400,6 @@ static int do_build(int ac, char const* const* av)
enum Doing
{
DoingNone,
- DoingJobs,
DoingDir,
DoingTarget,
DoingConfig,
@@ -385,12 +409,17 @@ static int do_build(int ac, char const* const* av)
for (int i = 2; i < ac; ++i) {
if (doing == DoingNative) {
nativeOptions.emplace_back(av[i]);
- } else if ((strcmp(av[i], "-j") == 0) ||
- (strcmp(av[i], "--parallel") == 0)) {
- jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
- /* does the next argument start with a number? */
- if ((i + 1 < ac) && (isdigit(*av[i + 1]))) {
- doing = DoingJobs;
+ } else if (cmHasLiteralPrefix(av[i], "-j")) {
+ const char* nextArg = ((i + 1 < ac) ? av[i + 1] : nullptr);
+ jobs = extract_job_number(i, av[i], nextArg, sizeof("-j") - 1);
+ if (jobs < 0) {
+ dir.clear();
+ }
+ } else if (cmHasLiteralPrefix(av[i], "--parallel")) {
+ const char* nextArg = ((i + 1 < ac) ? av[i + 1] : nullptr);
+ jobs = extract_job_number(i, av[i], nextArg, sizeof("--parallel") - 1);
+ if (jobs < 0) {
+ dir.clear();
}
} else if (strcmp(av[i], "--target") == 0) {
if (!hasTarget) {
@@ -412,18 +441,6 @@ static int do_build(int ac, char const* const* av)
doing = DoingNative;
} else {
switch (doing) {
- case DoingJobs: {
- unsigned long numJobs = 0;
- if (cmSystemTools::StringToULong(av[i], &numJobs)) {
- jobs = int(numJobs);
- doing = DoingNone;
- } else {
- std::cerr << "'" << av[i - 1] << "' invalid number '" << av[i]
- << "' given.\n\n";
- dir.clear();
- break;
- }
- } break;
case DoingDir:
dir = cmSystemTools::CollapseFullPath(av[i]);
doing = DoingNone;