summaryrefslogtreecommitdiffstats
path: root/Source/cmakemain.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r--Source/cmakemain.cxx50
1 files changed, 49 insertions, 1 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index b185a1b..9c9f65c 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -22,6 +22,8 @@
#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
#include "cmsys/ConsoleBuf.hxx"
#endif
+
+#include <ctype.h>
#include <iostream>
#include <string.h>
#include <string>
@@ -49,6 +51,12 @@ static const char* cmDocumentationUsageNote[][2] = {
#define CMAKE_BUILD_OPTIONS \
" <dir> = Project binary directory to be built.\n" \
+ " -j [<jobs>] --parallel [<jobs>] = Build in parallel using\n" \
+ " the given number of jobs. If <jobs> is omitted\n" \
+ " the native build tool's default number is used.\n" \
+ " The CMAKE_BUILD_PARALLEL_LEVEL environment variable\n" \
+ " specifies a default parallel level when this option\n" \
+ " is not given.\n" \
" --target <tgt> = Build <tgt> instead of default targets.\n" \
" May only be specified once.\n" \
" --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \
@@ -338,6 +346,7 @@ static int do_build(int ac, char const* const* av)
std::cerr << "This cmake does not support --build\n";
return -1;
#else
+ int jobs = cmake::NO_BUILD_PARALLEL_LEVEL;
std::string target;
std::string config = "Debug";
std::string dir;
@@ -348,6 +357,7 @@ static int do_build(int ac, char const* const* av)
enum Doing
{
DoingNone,
+ DoingJobs,
DoingDir,
DoingTarget,
DoingConfig,
@@ -357,6 +367,13 @@ static int do_build(int ac, char const* const* av)
for (int i = 2; i < ac; ++i) {
if (doing == DoingNative) {
nativeOptions.push_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 (strcmp(av[i], "--target") == 0) {
if (!hasTarget) {
doing = DoingTarget;
@@ -377,6 +394,18 @@ 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;
@@ -396,6 +425,25 @@ static int do_build(int ac, char const* const* av)
}
}
}
+
+ if (jobs == cmake::NO_BUILD_PARALLEL_LEVEL) {
+ std::string parallel;
+ if (cmSystemTools::GetEnv("CMAKE_BUILD_PARALLEL_LEVEL", parallel)) {
+ if (parallel.empty()) {
+ jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
+ } else {
+ unsigned long numJobs = 0;
+ if (cmSystemTools::StringToULong(parallel.c_str(), &numJobs)) {
+ jobs = int(numJobs);
+ } else {
+ std::cerr << "'CMAKE_BUILD_PARALLEL_LEVEL' environment variable\n"
+ << "invalid number '" << parallel << "' given.\n\n";
+ dir.clear();
+ }
+ }
+ }
+ }
+
if (dir.empty()) {
/* clang-format off */
std::cerr <<
@@ -410,7 +458,7 @@ static int do_build(int ac, char const* const* av)
cmake cm(cmake::RoleInternal);
cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm);
cm.SetProgressCallback(cmakemainProgressCallback, &cm);
- return cm.Build(dir, target, config, nativeOptions, clean);
+ return cm.Build(jobs, dir, target, config, nativeOptions, clean);
#endif
}