2016-09-27 19:01:08 +00: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 15:30:18 +00:00
|
|
|
#include "cmUtilitySourceCommand.h"
|
|
|
|
|
2016-10-19 06:54:18 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmState.h"
|
2016-10-25 18:35:04 +00:00
|
|
|
#include "cmStateTypes.h"
|
2016-10-19 06:54:18 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
|
|
class cmExecutionStatus;
|
2016-10-18 19:28:49 +00:00
|
|
|
|
2001-03-08 15:30:18 +00:00
|
|
|
// cmUtilitySourceCommand
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmUtilitySourceCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2001-03-08 15:30:18 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() < 3) {
|
2001-03-08 15:30:18 +00:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-03-29 19:20:32 +00:00
|
|
|
|
2001-03-08 15:30:18 +00:00
|
|
|
std::vector<std::string>::const_iterator arg = args.begin();
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-03-08 15:30:18 +00:00
|
|
|
// The first argument is the cache entry name.
|
2017-05-24 20:18:28 +00:00
|
|
|
std::string const& cacheEntry = *arg++;
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* cacheValue = this->Makefile->GetDefinition(cacheEntry);
|
2005-07-27 20:37:44 +00: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 17:42:58 +00:00
|
|
|
const char* intDir =
|
2006-05-12 18:12:13 +00:00
|
|
|
this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
|
2007-08-10 19:02:38 +00:00
|
|
|
|
|
|
|
bool haveCacheValue = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING")) {
|
2017-08-22 21:42:36 +00:00
|
|
|
haveCacheValue = (cacheValue != nullptr);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!haveCacheValue) {
|
2007-08-10 19:02:38 +00: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 14:34:04 +00: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 19:02:38 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
|
|
|
cmState* state = this->Makefile->GetState();
|
|
|
|
haveCacheValue =
|
2017-08-22 21:42:36 +00:00
|
|
|
(cacheValue && (strstr(cacheValue, "(IntDir)") == nullptr ||
|
2016-05-16 14:34:04 +00:00
|
|
|
(intDir && strcmp(intDir, "$(IntDir)") == 0)) &&
|
|
|
|
(state->GetCacheMajorVersion() != 0 &&
|
|
|
|
state->GetCacheMinorVersion() != 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (haveCacheValue) {
|
2001-03-08 15:30:18 +00:00
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-03-08 15:30:18 +00:00
|
|
|
// The second argument is the utility's executable name, which will be
|
|
|
|
// needed later.
|
2017-05-24 20:18:28 +00:00
|
|
|
std::string const& utilityName = *arg++;
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-03-08 15:30:18 +00:00
|
|
|
// The third argument specifies the relative directory of the source
|
|
|
|
// of the utility.
|
2017-05-24 20:18:28 +00:00
|
|
|
std::string const& relativeSource = *arg++;
|
2015-04-16 19:17:41 +00:00
|
|
|
std::string utilitySource = this->Makefile->GetCurrentSourceDirectory();
|
2016-05-16 14:34:04 +00:00
|
|
|
utilitySource = utilitySource + "/" + relativeSource;
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-03-08 15:30:18 +00:00
|
|
|
// If the directory doesn't exist, the source has not been included.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmSystemTools::FileExists(utilitySource.c_str())) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-03-08 15:30:18 +00:00
|
|
|
// Make sure all the files exist in the source directory.
|
2016-05-16 14:34:04 +00:00
|
|
|
while (arg != args.end()) {
|
|
|
|
std::string file = utilitySource + "/" + *arg++;
|
|
|
|
if (!cmSystemTools::FileExists(file.c_str())) {
|
|
|
|
return true;
|
2001-03-08 15:30:18 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-03-09 15:53:32 +00:00
|
|
|
// The source exists.
|
2012-08-13 17:42:58 +00:00
|
|
|
std::string cmakeCFGout =
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
|
2015-04-16 19:33:09 +00:00
|
|
|
std::string utilityDirectory = this->Makefile->GetCurrentBinaryDirectory();
|
2001-06-07 18:52:29 +00:00
|
|
|
std::string exePath;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH")) {
|
2006-03-15 16:02:08 +00:00
|
|
|
exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!exePath.empty()) {
|
2001-06-07 18:52:29 +00:00
|
|
|
utilityDirectory = exePath;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
|
|
|
utilityDirectory += "/" + relativeSource;
|
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-03-09 15:53:32 +00:00
|
|
|
// Construct the cache entry for the executable's location.
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string utilityExecutable = utilityDirectory + "/" + cmakeCFGout + "/" +
|
|
|
|
utilityName + this->Makefile->GetDefinition("CMAKE_EXECUTABLE_SUFFIX");
|
2003-08-01 17:54:53 +00:00
|
|
|
|
|
|
|
// make sure we remove any /./ in the name
|
|
|
|
cmSystemTools::ReplaceString(utilityExecutable, "/./", "/");
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-03-08 15:30:18 +00:00
|
|
|
// Enter the value into the cache.
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Makefile->AddCacheDefinition(cacheEntry, utilityExecutable.c_str(),
|
|
|
|
"Path to an internal program.",
|
2016-10-18 19:28:47 +00:00
|
|
|
cmStateEnums::FILEPATH);
|
2001-06-07 18:52:29 +00: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 14:34:04 +00:00
|
|
|
this->Makefile->AddCacheDefinition(utilityExecutable, utilityName.c_str(),
|
|
|
|
"Executable to project name.",
|
2016-10-18 19:28:47 +00:00
|
|
|
cmStateEnums::INTERNAL);
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-03-08 15:30:18 +00:00
|
|
|
return true;
|
|
|
|
}
|