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 "cmLocalGenerator.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
|
2009-12-04 20:09:01 +03:00
|
|
|
//----------------------------------------------------------------------
|
2008-01-23 18:28:26 +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:
|
|
|
|
//
|
|
|
|
if(2 == args.size())
|
|
|
|
{
|
|
|
|
return this->TwoArgsSignature(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->MainSignature(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool cmBuildCommand
|
|
|
|
::MainSignature(std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
if(args.size() < 1)
|
|
|
|
{
|
|
|
|
this->SetError("requires at least one argument naming a CMake variable");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The cmake variable in which to store the result.
|
|
|
|
const char* variable = args[0].c_str();
|
|
|
|
|
|
|
|
// Parse remaining arguments.
|
|
|
|
const char* configuration = 0;
|
|
|
|
const char* project_name = 0;
|
2014-02-07 02:31:47 +04:00
|
|
|
std::string target;
|
2009-12-04 20:09:01 +03:00
|
|
|
enum Doing { DoingNone, DoingConfiguration, DoingProjectName, DoingTarget };
|
|
|
|
Doing doing = DoingNone;
|
|
|
|
for(unsigned int i=1; i < args.size(); ++i)
|
|
|
|
{
|
|
|
|
if(args[i] == "CONFIGURATION")
|
|
|
|
{
|
|
|
|
doing = DoingConfiguration;
|
|
|
|
}
|
|
|
|
else if(args[i] == "PROJECT_NAME")
|
|
|
|
{
|
|
|
|
doing = DoingProjectName;
|
|
|
|
}
|
|
|
|
else if(args[i] == "TARGET")
|
|
|
|
{
|
|
|
|
doing = DoingTarget;
|
|
|
|
}
|
|
|
|
else if(doing == DoingConfiguration)
|
|
|
|
{
|
|
|
|
doing = DoingNone;
|
|
|
|
configuration = args[i].c_str();
|
|
|
|
}
|
|
|
|
else if(doing == DoingProjectName)
|
|
|
|
{
|
|
|
|
doing = DoingNone;
|
|
|
|
project_name = args[i].c_str();
|
|
|
|
}
|
|
|
|
else if(doing == DoingTarget)
|
|
|
|
{
|
|
|
|
doing = DoingNone;
|
2014-02-07 02:31:47 +04:00
|
|
|
target = args[i];
|
2009-12-04 20:09:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
//
|
|
|
|
if(!configuration || !*configuration)
|
|
|
|
{
|
|
|
|
configuration = getenv("CMAKE_CONFIG_TYPE");
|
|
|
|
}
|
|
|
|
if(!configuration || !*configuration)
|
|
|
|
{
|
|
|
|
configuration = "Release";
|
|
|
|
}
|
|
|
|
|
2013-11-14 01:01:20 +04:00
|
|
|
if(project_name && *project_name)
|
2009-12-04 20:09:01 +03:00
|
|
|
{
|
2013-11-14 01:01:20 +04:00
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
|
|
|
|
"Ignoring PROJECT_NAME option because it has no effect.");
|
2009-12-04 20:09:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string makecommand = this->Makefile->GetLocalGenerator()
|
2013-11-14 01:01:20 +04:00
|
|
|
->GetGlobalGenerator()->GenerateCMakeBuildCommand(target, configuration,
|
2014-02-25 02:38:55 +04:00
|
|
|
"", true);
|
2009-12-04 20:09:01 +03:00
|
|
|
|
|
|
|
this->Makefile->AddDefinition(variable, makecommand.c_str());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool cmBuildCommand
|
|
|
|
::TwoArgsSignature(std::vector<std::string> const& args)
|
2001-05-04 19:34:59 +04: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;
|
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2001-05-04 19:34:59 +04:00
|
|
|
const char* define = args[0].c_str();
|
|
|
|
const char* cacheValue
|
2006-03-15 19:02:08 +03:00
|
|
|
= this->Makefile->GetDefinition(define);
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2006-07-09 21:18:15 +04:00
|
|
|
std::string configType = "Release";
|
|
|
|
const char* cfg = getenv("CMAKE_CONFIG_TYPE");
|
|
|
|
if ( cfg )
|
|
|
|
{
|
|
|
|
configType = cfg;
|
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2006-03-15 19:02:08 +03:00
|
|
|
std::string makecommand = this->Makefile->GetLocalGenerator()
|
2014-03-11 03:04:11 +04:00
|
|
|
->GetGlobalGenerator()->GenerateCMakeBuildCommand("", configType,
|
2014-02-25 02:38:55 +04:00
|
|
|
"", true);
|
2005-12-01 19:41:00 +03:00
|
|
|
|
2005-04-29 20:50:29 +04:00
|
|
|
if(cacheValue)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddCacheDefinition(define,
|
2001-08-08 19:54:46 +04:00
|
|
|
makecommand.c_str(),
|
|
|
|
"Command used to build entire project "
|
|
|
|
"from the command line.",
|
|
|
|
cmCacheManager::STRING);
|
2001-05-04 19:34:59 +04:00
|
|
|
return true;
|
|
|
|
}
|