2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-01-11 22:55:47 +03: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-01-11 22:55:47 +03: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-01-18 19:20:24 +03:00
|
|
|
#include "cmProjectCommand.h"
|
2001-01-05 19:41:20 +03:00
|
|
|
|
2001-01-18 19:20:24 +03:00
|
|
|
// cmProjectCommand
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2016-09-16 00:59:29 +03:00
|
|
|
if (args.empty()) {
|
2001-01-05 19:41:20 +03:00
|
|
|
this->SetError("PROJECT called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-08-02 11:57:31 +03:00
|
|
|
this->Makefile->SetProjectName(args[0]);
|
2001-02-15 21:30:13 +03:00
|
|
|
|
|
|
|
std::string bindir = args[0];
|
|
|
|
bindir += "_BINARY_DIR";
|
|
|
|
std::string srcdir = args[0];
|
|
|
|
srcdir += "_SOURCE_DIR";
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddCacheDefinition(
|
|
|
|
bindir, this->Makefile->GetCurrentBinaryDirectory(),
|
|
|
|
"Value Computed by CMake", cmState::STATIC);
|
|
|
|
this->Makefile->AddCacheDefinition(
|
|
|
|
srcdir, this->Makefile->GetCurrentSourceDirectory(),
|
|
|
|
"Value Computed by CMake", cmState::STATIC);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-05-23 18:01:10 +04:00
|
|
|
bindir = "PROJECT_BINARY_DIR";
|
|
|
|
srcdir = "PROJECT_SOURCE_DIR";
|
|
|
|
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(bindir,
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->GetCurrentBinaryDirectory());
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(srcdir,
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->GetCurrentSourceDirectory());
|
2001-05-23 18:01:10 +04:00
|
|
|
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddDefinition("PROJECT_NAME", args[0].c_str());
|
2001-10-17 23:11:02 +04:00
|
|
|
|
2005-02-22 23:31:02 +03:00
|
|
|
// Set the CMAKE_PROJECT_NAME variable to be the highest-level
|
2011-12-16 06:56:34 +04:00
|
|
|
// project name in the tree. If there are two project commands
|
|
|
|
// in the same CMakeLists.txt file, and it is the top level
|
|
|
|
// CMakeLists.txt file, then go with the last one, so that
|
|
|
|
// CMAKE_PROJECT_NAME will match PROJECT_NAME, and cmake --build
|
|
|
|
// will work.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME") ||
|
|
|
|
(this->Makefile->IsRootMakefile())) {
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", args[0].c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddCacheDefinition("CMAKE_PROJECT_NAME", args[0].c_str(),
|
|
|
|
"Value Computed by CMake",
|
|
|
|
cmState::STATIC);
|
|
|
|
}
|
2005-02-22 23:31:02 +03:00
|
|
|
|
2014-01-29 18:28:01 +04:00
|
|
|
bool haveVersion = false;
|
2014-01-29 18:28:01 +04:00
|
|
|
bool haveLanguages = false;
|
2014-01-29 18:28:01 +04:00
|
|
|
std::string version;
|
2004-08-27 16:41:07 +04:00
|
|
|
std::vector<std::string> languages;
|
2016-05-16 17:34:04 +03:00
|
|
|
enum Doing
|
|
|
|
{
|
|
|
|
DoingLanguages,
|
|
|
|
DoingVersion
|
|
|
|
};
|
2014-01-29 18:28:01 +04:00
|
|
|
Doing doing = DoingLanguages;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 1; i < args.size(); ++i) {
|
|
|
|
if (args[i] == "LANGUAGES") {
|
|
|
|
if (haveLanguages) {
|
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR, "LANGUAGES may be specified at most once.");
|
2014-01-29 18:28:01 +04:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-29 18:28:01 +04:00
|
|
|
haveLanguages = true;
|
2014-01-29 18:28:01 +04:00
|
|
|
doing = DoingLanguages;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "VERSION") {
|
|
|
|
if (haveVersion) {
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR,
|
|
|
|
"VERSION may be specified at most once.");
|
2014-01-29 18:28:01 +04:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-29 18:28:01 +04:00
|
|
|
haveVersion = true;
|
|
|
|
doing = DoingVersion;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingVersion) {
|
2014-01-29 18:28:01 +04:00
|
|
|
doing = DoingLanguages;
|
|
|
|
version = args[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
} else // doing == DoingLanguages
|
|
|
|
{
|
2004-08-27 16:41:07 +04:00
|
|
|
languages.push_back(args[i]);
|
2002-04-03 00:43:23 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-29 18:28:01 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (haveVersion && !haveLanguages && !languages.empty()) {
|
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR,
|
|
|
|
"project with VERSION must use LANGUAGES before language names.");
|
2014-01-29 18:28:01 +04:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (haveLanguages && languages.empty()) {
|
2014-01-29 18:28:01 +04:00
|
|
|
languages.push_back("NONE");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-29 18:28:01 +04:00
|
|
|
|
2014-01-29 18:28:01 +04:00
|
|
|
cmPolicies::PolicyStatus cmp0048 =
|
|
|
|
this->Makefile->GetPolicyStatus(cmPolicies::CMP0048);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (haveVersion) {
|
2014-01-29 18:28:01 +04:00
|
|
|
// Set project VERSION variables to given values
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmp0048 == cmPolicies::OLD || cmp0048 == cmPolicies::WARN) {
|
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR,
|
|
|
|
"VERSION not allowed unless CMP0048 is set to NEW");
|
2014-01-29 18:28:01 +04:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-29 18:28:01 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmsys::RegularExpression vx(
|
|
|
|
"^([0-9]+(\\.[0-9]+(\\.[0-9]+(\\.[0-9]+)?)?)?)?$");
|
|
|
|
if (!vx.find(version)) {
|
2014-01-29 18:28:01 +04:00
|
|
|
std::string e = "VERSION \"" + version + "\" format invalid.";
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e);
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-29 18:28:01 +04:00
|
|
|
|
|
|
|
std::string vs;
|
|
|
|
const char* sep = "";
|
|
|
|
char vb[4][64];
|
2016-05-16 17:34:04 +03:00
|
|
|
unsigned int v[4] = { 0, 0, 0, 0 };
|
|
|
|
int vc =
|
|
|
|
sscanf(version.c_str(), "%u.%u.%u.%u", &v[0], &v[1], &v[2], &v[3]);
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (i < vc) {
|
2014-01-29 18:28:01 +04:00
|
|
|
sprintf(vb[i], "%u", v[i]);
|
|
|
|
vs += sep;
|
|
|
|
vs += vb[i];
|
|
|
|
sep = ".";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-01-29 18:28:01 +04:00
|
|
|
vb[i][0] = 0;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-29 18:28:01 +04:00
|
|
|
|
|
|
|
std::string vv;
|
|
|
|
vv = args[0] + "_VERSION";
|
|
|
|
this->Makefile->AddDefinition("PROJECT_VERSION", vs.c_str());
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(vv, vs.c_str());
|
2014-01-29 18:28:01 +04:00
|
|
|
vv = args[0] + "_VERSION_MAJOR";
|
|
|
|
this->Makefile->AddDefinition("PROJECT_VERSION_MAJOR", vb[0]);
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(vv, vb[0]);
|
2014-01-29 18:28:01 +04:00
|
|
|
vv = args[0] + "_VERSION_MINOR";
|
|
|
|
this->Makefile->AddDefinition("PROJECT_VERSION_MINOR", vb[1]);
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(vv, vb[1]);
|
2014-01-29 18:28:01 +04:00
|
|
|
vv = args[0] + "_VERSION_PATCH";
|
|
|
|
this->Makefile->AddDefinition("PROJECT_VERSION_PATCH", vb[2]);
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(vv, vb[2]);
|
2014-01-29 18:28:01 +04:00
|
|
|
vv = args[0] + "_VERSION_TWEAK";
|
|
|
|
this->Makefile->AddDefinition("PROJECT_VERSION_TWEAK", vb[3]);
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(vv, vb[3]);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmp0048 != cmPolicies::OLD) {
|
2014-01-29 18:28:01 +04:00
|
|
|
// Set project VERSION variables to empty
|
|
|
|
std::vector<std::string> vv;
|
|
|
|
vv.push_back("PROJECT_VERSION");
|
|
|
|
vv.push_back("PROJECT_VERSION_MAJOR");
|
|
|
|
vv.push_back("PROJECT_VERSION_MINOR");
|
|
|
|
vv.push_back("PROJECT_VERSION_PATCH");
|
|
|
|
vv.push_back("PROJECT_VERSION_TWEAK");
|
|
|
|
vv.push_back(args[0] + "_VERSION");
|
|
|
|
vv.push_back(args[0] + "_VERSION_MAJOR");
|
|
|
|
vv.push_back(args[0] + "_VERSION_MINOR");
|
|
|
|
vv.push_back(args[0] + "_VERSION_PATCH");
|
|
|
|
vv.push_back(args[0] + "_VERSION_TWEAK");
|
|
|
|
std::string vw;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = vv.begin(); i != vv.end();
|
|
|
|
++i) {
|
2014-03-11 03:04:11 +04:00
|
|
|
const char* v = this->Makefile->GetDefinition(*i);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (v && *v) {
|
|
|
|
if (cmp0048 == cmPolicies::WARN) {
|
2014-01-29 18:28:01 +04:00
|
|
|
vw += "\n ";
|
|
|
|
vw += *i;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(*i, "");
|
2014-01-29 18:28:01 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!vw.empty()) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream w;
|
2015-05-03 11:12:10 +03:00
|
|
|
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0048)
|
2014-01-29 18:28:01 +04:00
|
|
|
<< "\nThe following variable(s) would be set to empty:" << vw;
|
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-29 18:28:01 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (languages.empty()) {
|
2004-08-26 22:55:55 +04:00
|
|
|
// if no language is specified do c and c++
|
2004-08-27 16:41:07 +04:00
|
|
|
languages.push_back("C");
|
|
|
|
languages.push_back("CXX");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-28 17:09:26 +04:00
|
|
|
this->Makefile->EnableLanguage(languages, false);
|
2012-02-17 21:41:39 +04:00
|
|
|
std::string extraInclude = "CMAKE_PROJECT_" + args[0] + "_INCLUDE";
|
2014-03-11 03:04:11 +04:00
|
|
|
const char* include = this->Makefile->GetDefinition(extraInclude);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (include) {
|
|
|
|
bool readit = this->Makefile->ReadDependentFile(include);
|
|
|
|
if (!readit && !cmSystemTools::GetFatalErrorOccured()) {
|
|
|
|
std::string m = "could not find file:\n"
|
|
|
|
" ";
|
2012-02-17 21:41:39 +04:00
|
|
|
m += include;
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(m);
|
2012-02-17 21:41:39 +04:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-01-05 19:41:20 +03:00
|
|
|
return true;
|
|
|
|
}
|