2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2001-03-08 18:30:18 +03:00
|
|
|
#include "cmUtilitySourceCommand.h"
|
|
|
|
|
|
|
|
// cmUtilitySourceCommand
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmUtilitySourceCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2001-03-08 18:30:18 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Disallowed(
|
|
|
|
cmPolicies::CMP0034,
|
|
|
|
"The utility_source command should not be called; see CMP0034.")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (args.size() < 3) {
|
2001-03-08 18:30:18 +03:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2002-03-29 22:20:32 +03:00
|
|
|
|
2001-03-08 18:30:18 +03:00
|
|
|
std::vector<std::string>::const_iterator arg = args.begin();
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-03-08 18:30:18 +03:00
|
|
|
// The first argument is the cache entry name.
|
|
|
|
std::string cacheEntry = *arg++;
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cacheValue = this->Makefile->GetDefinition(cacheEntry);
|
2005-07-28 00:37:44 +04:00
|
|
|
// If it exists already and appears up to date then we are done. If
|
|
|
|
// the string contains "(IntDir)" but that is not the
|
|
|
|
// CMAKE_CFG_INTDIR setting then the value is out of date.
|
2012-08-13 21:42:58 +04:00
|
|
|
const char* intDir =
|
2006-05-12 22:12:13 +04:00
|
|
|
this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
|
2007-08-10 23:02:38 +04:00
|
|
|
|
|
|
|
bool haveCacheValue = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING")) {
|
2016-06-27 23:44:16 +03:00
|
|
|
haveCacheValue = (cacheValue != CM_NULLPTR);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!haveCacheValue) {
|
2007-08-10 23:02:38 +04:00
|
|
|
std::string msg = "UTILITY_SOURCE is used in cross compiling mode for ";
|
|
|
|
msg += cacheEntry;
|
|
|
|
msg += ". If your intention is to run this executable, you need to "
|
2016-05-16 17:34:04 +03:00
|
|
|
"preload the cache with the full path to a version of that "
|
|
|
|
"program, which runs on this build machine.";
|
|
|
|
cmSystemTools::Message(msg.c_str(), "Warning");
|
2007-08-10 23:02:38 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
cmState* state = this->Makefile->GetState();
|
|
|
|
haveCacheValue =
|
2016-06-27 23:44:16 +03:00
|
|
|
(cacheValue && (strstr(cacheValue, "(IntDir)") == CM_NULLPTR ||
|
2016-05-16 17:34:04 +03:00
|
|
|
(intDir && strcmp(intDir, "$(IntDir)") == 0)) &&
|
|
|
|
(state->GetCacheMajorVersion() != 0 &&
|
|
|
|
state->GetCacheMinorVersion() != 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (haveCacheValue) {
|
2001-03-08 18:30:18 +03:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-03-08 18:30:18 +03:00
|
|
|
// The second argument is the utility's executable name, which will be
|
|
|
|
// needed later.
|
|
|
|
std::string utilityName = *arg++;
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-03-08 18:30:18 +03:00
|
|
|
// The third argument specifies the relative directory of the source
|
|
|
|
// of the utility.
|
|
|
|
std::string relativeSource = *arg++;
|
2015-04-16 22:17:41 +03:00
|
|
|
std::string utilitySource = this->Makefile->GetCurrentSourceDirectory();
|
2016-05-16 17:34:04 +03:00
|
|
|
utilitySource = utilitySource + "/" + relativeSource;
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-03-08 18:30:18 +03:00
|
|
|
// If the directory doesn't exist, the source has not been included.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(utilitySource.c_str())) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-03-08 18:30:18 +03:00
|
|
|
// Make sure all the files exist in the source directory.
|
2016-05-16 17:34:04 +03:00
|
|
|
while (arg != args.end()) {
|
|
|
|
std::string file = utilitySource + "/" + *arg++;
|
|
|
|
if (!cmSystemTools::FileExists(file.c_str())) {
|
|
|
|
return true;
|
2001-03-08 18:30:18 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-03-09 18:53:32 +03:00
|
|
|
// The source exists.
|
2012-08-13 21:42:58 +04:00
|
|
|
std::string cmakeCFGout =
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
|
2015-04-16 22:33:09 +03:00
|
|
|
std::string utilityDirectory = this->Makefile->GetCurrentBinaryDirectory();
|
2001-06-07 22:52:29 +04:00
|
|
|
std::string exePath;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH")) {
|
2006-03-15 19:02:08 +03:00
|
|
|
exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!exePath.empty()) {
|
2001-06-07 22:52:29 +04:00
|
|
|
utilityDirectory = exePath;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
utilityDirectory += "/" + relativeSource;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-03-09 18:53:32 +03:00
|
|
|
// Construct the cache entry for the executable's location.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string utilityExecutable = utilityDirectory + "/" + cmakeCFGout + "/" +
|
|
|
|
utilityName + this->Makefile->GetDefinition("CMAKE_EXECUTABLE_SUFFIX");
|
2003-08-01 21:54:53 +04:00
|
|
|
|
|
|
|
// make sure we remove any /./ in the name
|
|
|
|
cmSystemTools::ReplaceString(utilityExecutable, "/./", "/");
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-03-08 18:30:18 +03:00
|
|
|
// Enter the value into the cache.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddCacheDefinition(cacheEntry, utilityExecutable.c_str(),
|
|
|
|
"Path to an internal program.",
|
|
|
|
cmState::FILEPATH);
|
2001-06-07 22:52:29 +04:00
|
|
|
// add a value into the cache that maps from the
|
|
|
|
// full path to the name of the project
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(utilityExecutable);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddCacheDefinition(utilityExecutable, utilityName.c_str(),
|
|
|
|
"Executable to project name.",
|
|
|
|
cmState::INTERNAL);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-03-08 18:30:18 +03:00
|
|
|
return true;
|
|
|
|
}
|