2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-05-04 19:34:59 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-05-04 19:34:59 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-05-04 19:34:59 +04:00
|
|
|
#include "cmBuildCommand.h"
|
|
|
|
|
2005-04-29 20:50:29 +04:00
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmBuildCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2009-12-04 20:09:01 +03:00
|
|
|
{
|
|
|
|
// Support the legacy signature of the command:
|
|
|
|
//
|
2016-05-16 17:34:04 +03:00
|
|
|
if (2 == args.size()) {
|
2009-12-04 20:09:01 +03:00
|
|
|
return this->TwoArgsSignature(args);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
|
|
|
return this->MainSignature(args);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmBuildCommand::MainSignature(std::vector<std::string> const& args)
|
2009-12-04 20:09:01 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() < 1) {
|
2009-12-04 20:09:01 +03:00
|
|
|
this->SetError("requires at least one argument naming a CMake variable");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
|
|
|
// The cmake variable in which to store the result.
|
|
|
|
const char* variable = args[0].c_str();
|
|
|
|
|
|
|
|
// Parse remaining arguments.
|
2016-07-08 00:54:05 +03:00
|
|
|
std::string configuration;
|
|
|
|
std::string project_name;
|
2014-02-07 02:31:47 +04:00
|
|
|
std::string target;
|
2016-05-16 17:34:04 +03:00
|
|
|
enum Doing
|
|
|
|
{
|
|
|
|
DoingNone,
|
|
|
|
DoingConfiguration,
|
|
|
|
DoingProjectName,
|
|
|
|
DoingTarget
|
|
|
|
};
|
2009-12-04 20:09:01 +03:00
|
|
|
Doing doing = DoingNone;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 1; i < args.size(); ++i) {
|
|
|
|
if (args[i] == "CONFIGURATION") {
|
2009-12-04 20:09:01 +03:00
|
|
|
doing = DoingConfiguration;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "PROJECT_NAME") {
|
2009-12-04 20:09:01 +03:00
|
|
|
doing = DoingProjectName;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "TARGET") {
|
2009-12-04 20:09:01 +03:00
|
|
|
doing = DoingTarget;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingConfiguration) {
|
2009-12-04 20:09:01 +03:00
|
|
|
doing = DoingNone;
|
2016-07-08 00:54:05 +03:00
|
|
|
configuration = args[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingProjectName) {
|
2009-12-04 20:09:01 +03:00
|
|
|
doing = DoingNone;
|
2016-07-08 00:54:05 +03:00
|
|
|
project_name = args[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingTarget) {
|
2009-12-04 20:09:01 +03:00
|
|
|
doing = DoingNone;
|
2014-02-07 02:31:47 +04:00
|
|
|
target = args[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2009-12-04 20:09:01 +03:00
|
|
|
e << "unknown argument \"" << args[i] << "\"";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2009-12-04 20:09:01 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2013-11-14 01:01:20 +04:00
|
|
|
// If null/empty CONFIGURATION argument, cmake --build uses 'Debug'
|
2009-12-04 20:09:01 +03: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-07-08 00:54:05 +03:00
|
|
|
if (configuration.empty()) {
|
|
|
|
cmSystemTools::GetEnv("CMAKE_CONFIG_TYPE", configuration);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-07-08 00:54:05 +03:00
|
|
|
if (configuration.empty()) {
|
2009-12-04 20:09:01 +03:00
|
|
|
configuration = "Release";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2016-07-08 00:54:05 +03:00
|
|
|
if (!project_name.empty()) {
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::AUTHOR_WARNING,
|
2013-11-14 01:01:20 +04:00
|
|
|
"Ignoring PROJECT_NAME option because it has no effect.");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string makecommand =
|
|
|
|
this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand(
|
2016-07-08 00:54:05 +03:00
|
|
|
target, configuration.c_str(), "",
|
|
|
|
this->Makefile->IgnoreErrorsCMP0061());
|
2009-12-04 20:09:01 +03:00
|
|
|
|
|
|
|
this->Makefile->AddDefinition(variable, makecommand.c_str());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args)
|
2001-05-04 19:34:59 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() < 2) {
|
2009-12-04 20:09:01 +03:00
|
|
|
this->SetError("called with less than two arguments");
|
2001-05-04 19:34:59 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2001-05-04 19:34:59 +04:00
|
|
|
const char* define = args[0].c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cacheValue = this->Makefile->GetDefinition(define);
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2016-07-08 00:54:05 +03:00
|
|
|
std::string configType;
|
|
|
|
if (!cmSystemTools::GetEnv("CMAKE_CONFIG_TYPE", configType) ||
|
|
|
|
configType.empty()) {
|
|
|
|
configType = "Release";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string makecommand =
|
|
|
|
this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand(
|
|
|
|
"", configType, "", this->Makefile->IgnoreErrorsCMP0061());
|
2005-12-01 19:41:00 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cacheValue) {
|
2005-04-29 20:50:29 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
this->Makefile->AddCacheDefinition(define, makecommand.c_str(),
|
|
|
|
"Command used to build entire project "
|
|
|
|
"from the command line.",
|
|
|
|
cmState::STRING);
|
2001-05-04 19:34:59 +04:00
|
|
|
return true;
|
|
|
|
}
|