Commit c700b624 authored by Robert Maynard's avatar Robert Maynard

Use strong types to express what level of build parallelism we want.

parent 89abbdd8
......@@ -255,7 +255,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
config = "Debug";
}
int retVal = cm.GetGlobalGenerator()->Build(
cmake::NO_BUILD_PARALLEL_LEVEL, this->SourceDir, this->BinaryDir,
make_SerialBuild(), this->SourceDir, this->BinaryDir,
this->BuildProject, { tar }, output, this->BuildMakeProgram, config,
!this->BuildNoClean, false, false, remainingTime);
out << output;
......
......@@ -893,7 +893,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
// actually do the try compile now that everything is setup
int res = this->Makefile->TryCompile(
sourceDirectory, this->BinaryDirectory, projectName, targetName,
this->SrcFileSignature, cmake::NO_BUILD_PARALLEL_LEVEL, &cmakeFlags,
this->SrcFileSignature, make_SerialBuild(), &cmakeFlags,
output);
if (erroroc) {
cmSystemTools::SetErrorOccured();
......
......@@ -57,18 +57,18 @@ std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalBorlandMakefileGenerator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int /*jobs*/, bool verbose,
const std::string& config, bool fast, cmParallelLevel, bool verbose,
std::vector<std::string> const& makeOptions)
{
return this->cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
makeProgram, projectName, projectDir, targetNames, config, fast,
cmake::NO_BUILD_PARALLEL_LEVEL, verbose, makeOptions);
make_SerialBuild(), verbose, makeOptions);
}
void cmGlobalBorlandMakefileGenerator::PrintBuildCommandAdvice(
std::ostream& os, int jobs) const
std::ostream& os, cmParallelLevel jobs) const
{
if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
if (!jobs.isSerial()) {
// Borland's make does not support parallel builds
// see http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Make
......@@ -80,5 +80,5 @@ void cmGlobalBorlandMakefileGenerator::PrintBuildCommandAdvice(
}
this->cmGlobalUnixMakefileGenerator3::PrintBuildCommandAdvice(
os, cmake::NO_BUILD_PARALLEL_LEVEL);
os, make_SerialBuild());
}
......@@ -49,11 +49,11 @@ protected:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
void PrintBuildCommandAdvice(std::ostream& os, int jobs) const override;
void PrintBuildCommandAdvice(std::ostream& os, cmParallelLevel jobs) const override;
};
#endif
......@@ -1741,7 +1741,7 @@ void cmGlobalGenerator::CheckTargetProperties()
}
}
int cmGlobalGenerator::TryCompile(int jobs, const std::string& srcdir,
int cmGlobalGenerator::TryCompile(cmParallelLevel jobs, const std::string& srcdir,
const std::string& bindir,
const std::string& projectName,
const std::string& target, bool fast,
......@@ -1779,7 +1779,7 @@ std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalGenerator::GenerateBuildCommand(
const std::string& /*unused*/, const std::string& /*unused*/,
const std::string& /*unused*/, std::vector<std::string> const& /*unused*/,
const std::string& /*unused*/, bool /*unused*/, int /*unused*/,
const std::string& /*unused*/, bool /*unused*/, cmParallelLevel /*unused*/,
bool /*unused*/, std::vector<std::string> const& /*unused*/)
{
GeneratedMakeCommand makeCommand;
......@@ -1788,14 +1788,14 @@ cmGlobalGenerator::GenerateBuildCommand(
}
void cmGlobalGenerator::PrintBuildCommandAdvice(std::ostream& /*os*/,
int /*jobs*/) const
cmParallelLevel /*jobs*/) const
{
// Subclasses override this method if they e.g want to give a warning that
// they do not support certain build command line options
}
int cmGlobalGenerator::Build(
int jobs, const std::string& /*unused*/, const std::string& bindir,
cmParallelLevel jobs, const std::string& /*unused*/, const std::string& bindir,
const std::string& projectName, const std::vector<std::string>& targets,
std::string& output, const std::string& makeCommandCSTR,
const std::string& config, bool clean, bool fast, bool verbose,
......
......@@ -21,6 +21,7 @@
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetDepend.h"
#include "cmParallelLevel.h"
#include "cm_codecvt.hxx"
#if defined(CMAKE_BUILD_WITH_CMAKE)
......@@ -191,7 +192,7 @@ public:
* Try running cmake and building a file. This is used for dynamically
* loaded commands, not as part of the usual build process.
*/
int TryCompile(int jobs, const std::string& srcdir,
int TryCompile(cmParallelLevel jobs, const std::string& srcdir,
const std::string& bindir, const std::string& projectName,
const std::string& targetName, bool fast, std::string& output,
cmMakefile* mf);
......@@ -203,7 +204,7 @@ public:
* done first.
*/
int Build(
int jobs, const std::string& srcdir, const std::string& bindir,
cmParallelLevel jobs, const std::string& srcdir, const std::string& bindir,
const std::string& projectName,
std::vector<std::string> const& targetNames, std::string& output,
const std::string& makeProgram, const std::string& config, bool clean,
......@@ -225,10 +226,10 @@ public:
virtual std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions = std::vector<std::string>());
virtual void PrintBuildCommandAdvice(std::ostream& os, int jobs) const;
virtual void PrintBuildCommandAdvice(std::ostream& os, cmParallelLevel jobs) const;
/** Generate a "cmake --build" call for a given target and config. */
std::string GenerateCMakeBuildCommand(const std::string& target,
......
......@@ -381,7 +381,7 @@ std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalGhsMultiGenerator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& /*config*/, bool /*fast*/, int jobs, bool /*verbose*/,
const std::string& /*config*/, bool /*fast*/, cmParallelLevel jobs, bool /*verbose*/,
std::vector<std::string> const& makeOptions)
{
GeneratedMakeCommand makeCommand = {};
......@@ -392,13 +392,12 @@ cmGlobalGhsMultiGenerator::GenerateBuildCommand(
}
makeCommand.Add(this->SelectMakeProgram(makeProgram, gbuild));
if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
if (!jobs.isSerial()) {
makeCommand.Add("-parallel");
if (jobs != cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
makeCommand.Add(std::to_string(jobs));
if(jobs.isUser()) {
makeCommand.Add(std::to_string(jobs.jobs));
}
}
makeCommand.Add(makeOptions.begin(), makeOptions.end());
/* determine which top-project file to use */
......
......@@ -101,7 +101,7 @@ protected:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
......
......@@ -58,7 +58,7 @@ std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalJOMMakefileGenerator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions)
{
std::vector<std::string> jomMakeOptions;
......@@ -72,8 +72,8 @@ cmGlobalJOMMakefileGenerator::GenerateBuildCommand(
// JOM does parallel builds by default, the -j is only needed if a specific
// number is given
// see https://github.com/qt-labs/jom/blob/v1.1.2/src/jomlib/options.cpp
if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
jobs = cmake::NO_BUILD_PARALLEL_LEVEL;
if (jobs.isDefaultParallel()) {
jobs = make_NocmParallelLevel();
}
return cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
......
......@@ -43,7 +43,7 @@ protected:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
......
......@@ -58,7 +58,7 @@ std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalNMakeMakefileGenerator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int /*jobs*/, bool verbose,
const std::string& config, bool fast, cmParallelLevel, bool verbose,
std::vector<std::string> const& makeOptions)
{
std::vector<std::string> nmakeMakeOptions;
......@@ -71,13 +71,13 @@ cmGlobalNMakeMakefileGenerator::GenerateBuildCommand(
return this->cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
makeProgram, projectName, projectDir, targetNames, config, fast,
cmake::NO_BUILD_PARALLEL_LEVEL, verbose, nmakeMakeOptions);
make_SerialBuild(), verbose, nmakeMakeOptions);
}
void cmGlobalNMakeMakefileGenerator::PrintBuildCommandAdvice(std::ostream& os,
int jobs) const
{
if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
if (!jobs.isSerial()) {
// nmake does not support parallel build level
// see https://msdn.microsoft.com/en-us/library/afyyse50.aspx
......@@ -89,5 +89,5 @@ void cmGlobalNMakeMakefileGenerator::PrintBuildCommandAdvice(std::ostream& os,
}
this->cmGlobalUnixMakefileGenerator3::PrintBuildCommandAdvice(
os, cmake::NO_BUILD_PARALLEL_LEVEL);
os, make_SerialBuild());
}
......@@ -48,11 +48,11 @@ protected:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
void PrintBuildCommandAdvice(std::ostream& os, int jobs) const override;
void PrintBuildCommandAdvice(std::ostream& os, cmParallelLevel jobs) const override;
private:
void PrintCompilerAdvice(std::ostream& os, std::string const& lang,
......
......@@ -682,7 +682,7 @@ cmGlobalNinjaGenerator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& /*projectName*/,
const std::string& /*projectDir*/,
std::vector<std::string> const& targetNames, const std::string& /*config*/,
bool /*fast*/, int jobs, bool verbose,
bool /*fast*/, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions)
{
GeneratedMakeCommand makeCommand;
......@@ -692,9 +692,8 @@ cmGlobalNinjaGenerator::GenerateBuildCommand(
makeCommand.Add("-v");
}
if ((jobs != cmake::NO_BUILD_PARALLEL_LEVEL) &&
(jobs != cmake::DEFAULT_BUILD_PARALLEL_LEVEL)) {
makeCommand.Add("-j", std::to_string(jobs));
if (jobs.isUser()) {
makeCommand.Add("-j", std::to_string(jobs.jobs));
}
makeCommand.Add(makeOptions.begin(), makeOptions.end());
......
......@@ -203,7 +203,7 @@ public:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
......
......@@ -499,7 +499,7 @@ cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
const std::string& makeProgram, const std::string& /*projectName*/,
const std::string& /*projectDir*/,
std::vector<std::string> const& targetNames, const std::string& /*config*/,
bool fast, int jobs, bool verbose,
bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions)
{
std::unique_ptr<cmMakefile> mfu;
......@@ -528,10 +528,10 @@ cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
}
makeCommand.Add(this->SelectMakeProgram(makeProgram));
if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
if (!jobs.isSerial()) {
makeCommand.Add("-j");
if (jobs != cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
makeCommand.Add(std::to_string(jobs));
if (jobs.isUser()) {
makeCommand.Add(std::to_string(jobs.jobs));
}
}
......
......@@ -130,7 +130,7 @@ public:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
......
......@@ -882,7 +882,7 @@ std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalVisualStudio10Generator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions)
{
std::vector<GeneratedMakeCommand> makeCommands;
......@@ -976,8 +976,8 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand(
makeCommand.Add(std::string("/p:VisualStudioVersion=") +
this->GetIDEVersion());
if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
if (!jobs.isSerial()) {
if (jobs.isDefaultParallel()) {
makeCommand.Add("/m");
} else {
makeCommand.Add(std::string("/m:") + std::to_string(jobs));
......
......@@ -25,7 +25,7 @@ public:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
......
......@@ -196,7 +196,7 @@ cmGlobalVisualStudio7Generator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& /*projectDir*/,
std::vector<std::string> const& targetNames, const std::string& config,
bool /*fast*/, int /*jobs*/, bool /*verbose*/,
bool /*fast*/, cmParallelLevel, bool /*verbose*/,
std::vector<std::string> const& makeOptions)
{
// Select the caller- or user-preferred make program, else devenv.
......
......@@ -55,7 +55,7 @@ public:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
......
......@@ -55,18 +55,18 @@ std::vector<cmGlobalGenerator::GeneratedMakeCommand>
cmGlobalWatcomWMakeGenerator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int /*jobs*/, bool verbose,
const std::string& config, bool fast, cmParallelLevel, bool verbose,
std::vector<std::string> const& makeOptions)
{
return this->cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
makeProgram, projectName, projectDir, targetNames, config, fast,
cmake::NO_BUILD_PARALLEL_LEVEL, verbose, makeOptions);
make_SerialBuild(), verbose, makeOptions);
}
void cmGlobalWatcomWMakeGenerator::PrintBuildCommandAdvice(std::ostream& os,
int jobs) const
{
if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
if (!jobs.isSerial()) {
// wmake does not support parallel build level
/* clang-format off */
......
......@@ -53,11 +53,11 @@ protected:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
void PrintBuildCommandAdvice(std::ostream& os, int jobs) const override;
void PrintBuildCommandAdvice(std::ostream& os, cmParallelLevel jobs) const override;
};
#endif
......@@ -339,7 +339,7 @@ cmGlobalXCodeGenerator::GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& /*projectDir*/,
std::vector<std::string> const& targetNames, const std::string& config,
bool /*fast*/, int jobs, bool /*verbose*/,
bool /*fast*/, cmParallelLevel jobs, bool /*verbose*/,
std::vector<std::string> const& makeOptions)
{
GeneratedMakeCommand makeCommand;
......@@ -374,10 +374,10 @@ cmGlobalXCodeGenerator::GenerateBuildCommand(
makeCommand.Add("-configuration", (config.empty() ? "Debug" : config));
if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
if (!jobs.isSerial()) {
makeCommand.Add("-jobs");
if (jobs != cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
makeCommand.Add(std::to_string(jobs));
if (jobs.isUser()) {
makeCommand.Add(std::to_string(jobs.jobs));
}
}
......
......@@ -69,7 +69,7 @@ public:
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,
const std::string& projectDir, std::vector<std::string> const& targetNames,
const std::string& config, bool fast, int jobs, bool verbose,
const std::string& config, bool fast, cmParallelLevel jobs, bool verbose,
std::vector<std::string> const& makeOptions =
std::vector<std::string>()) override;
......
......@@ -3396,7 +3396,7 @@ void cmMakefile::EnableLanguage(std::vector<std::string> const& lang,
int cmMakefile::TryCompile(const std::string& srcdir,
const std::string& bindir,
const std::string& projectName,
const std::string& targetName, bool fast, int jobs,
const std::string& targetName, bool fast, cmParallelLevel jobs,
const std::vector<std::string>* cmakeArgs,
std::string& output)
{
......
......@@ -25,6 +25,7 @@
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmTarget.h"
#include "cmParallelLevel.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
# include "cmSourceGroup.h"
......@@ -113,7 +114,7 @@ public:
*/
int TryCompile(const std::string& srcdir, const std::string& bindir,
const std::string& projectName, const std::string& targetName,
bool fast, int jobs,
bool fast, cmParallelLevel jobs,
const std::vector<std::string>* cmakeArgs,
std::string& output);
......
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef cmParallelLevel_h
#define cmParallelLevel_h
struct cmParallelLevel
{
enum struct Mode : std::int16_t { SERIAL, DEFAULT, USER };
constexpr bool isSerial() const{ return mode == Mode::SERIAL; }
constexpr bool isDefaultParallel() const { return mode == Mode::DEFAULT; }
constexpr bool isUser() const { return mode == Mode::USER; }
Mode mode;
std::int16_t jobs;
};
inline constexpr cmParallelLevel make_SerialBuild() { return cmParallelLevel{ cmParallelLevel::Mode::SERIAL, 1}; }
inline constexpr cmParallelLevel make_DefaultParallelBuild() { return cmParallelLevel{ cmParallelLevel::Mode::DEFAULT, -1}; }
inline constexpr cmParallelLevel make_UserParallelBuild(int jobs) { return cmParallelLevel{ cmParallelLevel::Mode::USER, static_cast<std::int16_t>(jobs)}; }
#endif
......@@ -2527,7 +2527,7 @@ cmMessenger* cmake::GetMessenger() const
return this->Messenger;
}
int cmake::Build(int jobs, const std::string& dir,
int cmake::Build(cmParallelLevel jobs, const std::string& dir,
const std::vector<std::string>& targets,
const std::string& config,
const std::vector<std::string>& nativeOptions, bool clean,
......
......@@ -19,6 +19,7 @@
#include "cmState.h"
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmParallelLevel.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
# include "cm_jsoncpp_value.h"
......@@ -110,9 +111,6 @@ public:
typedef std::map<std::string, cmInstalledFile> InstalledFilesMap;
static const int NO_BUILD_PARALLEL_LEVEL = -1;
static const int DEFAULT_BUILD_PARALLEL_LEVEL = 0;
/// Default constructor
cmake(Role role, cmState::Mode mode);
/// Destructor
......@@ -424,7 +422,7 @@ public:
cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
///! run the --build option
int Build(int jobs, const std::string& dir,
int Build(cmParallelLevel jobs, const std::string& dir,
const std::vector<std::string>& targets, const std::string& config,
const std::vector<std::string>& nativeOptions, bool clean,
bool verbose);
......
......@@ -378,8 +378,8 @@ int do_cmake(int ac, char const* const* av)
}
namespace {
int extract_job_number(int& index, char const* current, char const* next,
int len_of_flag)
cmParallelLevel 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);
......@@ -391,14 +391,14 @@ int extract_job_number(int& index, char const* current, char const* next,
int jobs = -1;
unsigned long numJobs = 0;
if (jobString.empty()) {
jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
return make_DefaultParallelBuild();
} 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;
return make_UserParallelBuild(jobs);
}
}
......@@ -408,7 +408,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;
auto parallelLevel = make_SerialBuild();
std::vector<std::string> targets;
std::string config = "Debug";
std::string dir;
......@@ -432,15 +432,15 @@ static int do_build(int ac, char const* const* av)
nativeOptions.emplace_back(av[i]);
} 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) {
parallelLevel = extract_job_number(i, av[i], nextArg, sizeof("-j") - 1);
if (parallelLevel.jobs < 0) {
dir.clear();
}
doing = DoingNone;
} 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) {
if (parallelLevel.jobs < 0) {
dir.clear();
}
doing = DoingNone;
......@@ -497,15 +497,15 @@ static int do_build(int ac, char const* const* av)
}
}
if (jobs == cmake::NO_BUILD_PARALLEL_LEVEL) {
if (jobs.isSerial()) {
std::string parallel;
if (cmSystemTools::GetEnv("CMAKE_BUILD_PARALLEL_LEVEL", parallel)) {
if (parallel.empty()) {
jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
jobs = make_DefaultParallelBuild()
} else {
unsigned long numJobs = 0;
if (cmSystemTools::StringToULong(parallel.c_str(), &numJobs)) {
jobs = int(numJobs);
jobs = make_UserParallelBuild(static_cast<int>(numJobs));
} else {
std::cerr << "'CMAKE_BUILD_PARALLEL_LEVEL' environment variable\n"
<< "invalid number '" << parallel << "' given.\n\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment