cmake/Source/cmBuildCommand.cxx

129 lines
3.6 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmBuildCommand.h"
2017-04-14 19:02:05 +02:00
#include <sstream>
#include "cmGlobalGenerator.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmake.h"
class cmExecutionStatus;
2016-07-09 11:21:54 +02:00
bool cmBuildCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
2010-03-17 14:00:29 +02:00
{
// Support the legacy signature of the command:
//
2016-07-09 11:21:54 +02:00
if (2 == args.size()) {
2010-03-17 14:00:29 +02:00
return this->TwoArgsSignature(args);
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
return this->MainSignature(args);
}
2016-07-09 11:21:54 +02:00
bool cmBuildCommand::MainSignature(std::vector<std::string> const& args)
2010-03-17 14:00:29 +02:00
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
2010-03-17 14:00:29 +02:00
this->SetError("requires at least one argument naming a CMake variable");
return false;
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
// The cmake variable in which to store the result.
2017-07-20 19:35:53 +02:00
std::string const& variable = args[0];
2010-03-17 14:00:29 +02:00
// Parse remaining arguments.
2016-10-30 18:24:19 +01:00
std::string configuration;
std::string project_name;
2015-04-27 22:25:09 +02:00
std::string target;
2016-07-09 11:21:54 +02:00
enum Doing
{
DoingNone,
DoingConfiguration,
DoingProjectName,
DoingTarget
};
2010-03-17 14:00:29 +02:00
Doing doing = DoingNone;
2016-07-09 11:21:54 +02:00
for (unsigned int i = 1; i < args.size(); ++i) {
if (args[i] == "CONFIGURATION") {
2010-03-17 14:00:29 +02:00
doing = DoingConfiguration;
2016-07-09 11:21:54 +02:00
} else if (args[i] == "PROJECT_NAME") {
2010-03-17 14:00:29 +02:00
doing = DoingProjectName;
2016-07-09 11:21:54 +02:00
} else if (args[i] == "TARGET") {
2010-03-17 14:00:29 +02:00
doing = DoingTarget;
2016-07-09 11:21:54 +02:00
} else if (doing == DoingConfiguration) {
2010-03-17 14:00:29 +02:00
doing = DoingNone;
2016-10-30 18:24:19 +01:00
configuration = args[i];
2016-07-09 11:21:54 +02:00
} else if (doing == DoingProjectName) {
2010-03-17 14:00:29 +02:00
doing = DoingNone;
2016-10-30 18:24:19 +01:00
project_name = args[i];
2016-07-09 11:21:54 +02:00
} else if (doing == DoingTarget) {
2010-03-17 14:00:29 +02:00
doing = DoingNone;
2015-04-27 22:25:09 +02:00
target = args[i];
2016-07-09 11:21:54 +02:00
} else {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2010-03-17 14:00:29 +02:00
e << "unknown argument \"" << args[i] << "\"";
2015-04-27 22:25:09 +02:00
this->SetError(e.str());
2010-03-17 14:00:29 +02:00
return false;
}
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
2014-08-03 19:52:23 +02:00
// If null/empty CONFIGURATION argument, cmake --build uses 'Debug'
2010-03-17 14:00:29 +02:00
// in the currently implemented multi-configuration global generators...
// so we put this code here to end up with the same default configuration
// as the original 2-arg build_command signature:
//
2016-10-30 18:24:19 +01:00
if (configuration.empty()) {
cmSystemTools::GetEnv("CMAKE_CONFIG_TYPE", configuration);
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
if (configuration.empty()) {
2010-03-17 14:00:29 +02:00
configuration = "Release";
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
2016-10-30 18:24:19 +01:00
if (!project_name.empty()) {
2016-07-09 11:21:54 +02:00
this->Makefile->IssueMessage(
cmake::AUTHOR_WARNING,
2014-08-03 19:52:23 +02:00
"Ignoring PROJECT_NAME option because it has no effect.");
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
2016-07-09 11:21:54 +02:00
std::string makecommand =
this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand(
2017-04-14 19:02:05 +02:00
target, configuration, "", this->Makefile->IgnoreErrorsCMP0061());
2010-03-17 14:00:29 +02:00
this->Makefile->AddDefinition(variable, makecommand.c_str());
return true;
}
2016-07-09 11:21:54 +02:00
bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 2) {
2010-03-17 14:00:29 +02:00
this->SetError("called with less than two arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
2017-07-20 19:35:53 +02:00
std::string const& define = args[0];
2016-07-09 11:21:54 +02:00
const char* cacheValue = this->Makefile->GetDefinition(define);
2010-03-17 14:00:29 +02:00
2016-10-30 18:24:19 +01:00
std::string configType;
if (!cmSystemTools::GetEnv("CMAKE_CONFIG_TYPE", configType) ||
configType.empty()) {
configType = "Release";
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
2016-07-09 11:21:54 +02:00
std::string makecommand =
this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand(
"", configType, "", this->Makefile->IgnoreErrorsCMP0061());
2016-07-09 11:21:54 +02:00
if (cacheValue) {
return true;
2016-07-09 11:21:54 +02:00
}
this->Makefile->AddCacheDefinition(define, makecommand.c_str(),
"Command used to build entire project "
"from the command line.",
2017-04-14 19:02:05 +02:00
cmStateEnums::STRING);
return true;
}