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-04-26 13:38:31 +00:00
|
|
|
#include "cmFindPathCommand.h"
|
|
|
|
|
2017-04-11 20:00:21 +00:00
|
|
|
#include "cmsys/Glob.hxx"
|
2016-10-25 18:35:04 +00:00
|
|
|
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmStateTypes.h"
|
2019-08-22 14:34:40 +00:00
|
|
|
#include "cmStringAlgorithms.h"
|
2016-10-19 19:59:14 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2016-10-25 18:35:04 +00:00
|
|
|
class cmExecutionStatus;
|
2006-03-02 18:30:22 +00:00
|
|
|
|
2019-09-10 19:44:48 +00:00
|
|
|
cmFindPathCommand::cmFindPathCommand(cmExecutionStatus& status)
|
|
|
|
: cmFindBase(status)
|
2006-03-02 18:30:22 +00:00
|
|
|
{
|
2007-12-15 01:46:15 +00:00
|
|
|
this->EnvironmentPath = "INCLUDE";
|
2006-03-02 18:30:22 +00:00
|
|
|
this->IncludeFileInPath = false;
|
2010-11-12 15:47:28 +00:00
|
|
|
}
|
|
|
|
|
2001-04-26 13:38:31 +00:00
|
|
|
// cmFindPathCommand
|
2019-09-10 19:44:48 +00:00
|
|
|
bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
|
2001-04-26 13:38:31 +00:00
|
|
|
{
|
2019-12-11 18:01:09 +00:00
|
|
|
this->DebugMode = ComputeIfDebugModeWanted();
|
2006-03-02 18:30:22 +00:00
|
|
|
this->VariableDocumentation = "Path to a file.";
|
|
|
|
this->CMakePathName = "INCLUDE";
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->ParseArguments(argsIn)) {
|
2001-04-26 13:38:31 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (this->AlreadyInCache) {
|
2006-07-18 19:21:26 +00:00
|
|
|
// If the user specifies the entry on the command line without a
|
|
|
|
// type we should add the type and docstring but keep the original
|
|
|
|
// value.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->AlreadyInCacheWithoutMetaInfo) {
|
2006-07-18 19:21:26 +00:00
|
|
|
this->Makefile->AddCacheDefinition(
|
2016-05-16 14:34:04 +00:00
|
|
|
this->VariableName, "", this->VariableDocumentation.c_str(),
|
2016-10-18 19:28:47 +00:00
|
|
|
(this->IncludeFileInPath ? cmStateEnums::FILEPATH
|
|
|
|
: cmStateEnums::PATH));
|
2001-04-26 13:38:31 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-06-09 15:58:29 +00:00
|
|
|
|
|
|
|
std::string result = this->FindHeader();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!result.empty()) {
|
|
|
|
this->Makefile->AddCacheDefinition(
|
|
|
|
this->VariableName, result.c_str(), this->VariableDocumentation.c_str(),
|
2016-10-18 19:28:47 +00:00
|
|
|
(this->IncludeFileInPath) ? cmStateEnums::FILEPATH : cmStateEnums::PATH);
|
2008-06-09 15:58:29 +00:00
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
this->Makefile->AddCacheDefinition(
|
|
|
|
this->VariableName, (this->VariableName + "-NOTFOUND").c_str(),
|
|
|
|
this->VariableDocumentation.c_str(),
|
2016-10-18 19:28:47 +00:00
|
|
|
(this->IncludeFileInPath) ? cmStateEnums::FILEPATH : cmStateEnums::PATH);
|
2001-04-26 13:38:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-09 15:58:29 +00:00
|
|
|
std::string cmFindPathCommand::FindHeader()
|
|
|
|
{
|
2019-12-11 18:01:09 +00:00
|
|
|
std::string debug_name = this->IncludeFileInPath ? "find_file" : "find_path";
|
|
|
|
cmFindBaseDebugState debug(debug_name, this);
|
2008-06-09 15:58:29 +00:00
|
|
|
std::string header;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->SearchFrameworkFirst || this->SearchFrameworkOnly) {
|
2019-12-11 18:01:09 +00:00
|
|
|
header = this->FindFrameworkHeader(debug);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (header.empty() && !this->SearchFrameworkOnly) {
|
2019-12-11 18:01:09 +00:00
|
|
|
header = this->FindNormalHeader(debug);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (header.empty() && this->SearchFrameworkLast) {
|
2019-12-11 18:01:09 +00:00
|
|
|
header = this->FindFrameworkHeader(debug);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2019-12-11 18:01:09 +00:00
|
|
|
|
2008-06-09 15:58:29 +00:00
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string cmFindPathCommand::FindHeaderInFramework(std::string const& file,
|
|
|
|
std::string const& dir)
|
2005-12-31 02:54:26 +00:00
|
|
|
{
|
2014-02-10 05:21:34 +00:00
|
|
|
std::string fileName = file;
|
|
|
|
std::string frameWorkName;
|
2016-12-10 13:49:22 +00:00
|
|
|
std::string::size_type pos = fileName.find('/');
|
2006-03-02 18:30:22 +00:00
|
|
|
// if there is a / in the name try to find the header as a framework
|
|
|
|
// For example bar/foo.h would look for:
|
|
|
|
// bar.framework/Headers/foo.h
|
2017-05-30 19:37:46 +00:00
|
|
|
if (pos != std::string::npos) {
|
2005-12-31 02:54:26 +00:00
|
|
|
// remove the name from the slash;
|
2016-05-16 14:34:04 +00:00
|
|
|
fileName = fileName.substr(pos + 1);
|
2005-12-31 02:54:26 +00:00
|
|
|
frameWorkName = file;
|
2012-08-13 17:42:58 +00:00
|
|
|
frameWorkName =
|
2016-05-16 14:34:04 +00:00
|
|
|
frameWorkName.substr(0, frameWorkName.size() - fileName.size() - 1);
|
2005-12-31 02:54:26 +00:00
|
|
|
// if the framework has a path in it then just use the filename
|
2017-05-30 19:37:46 +00:00
|
|
|
if (frameWorkName.find('/') != std::string::npos) {
|
2005-12-31 02:54:26 +00:00
|
|
|
fileName = file;
|
2017-09-15 23:26:49 +00:00
|
|
|
frameWorkName.clear();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!frameWorkName.empty()) {
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string fpath = cmStrCat(dir, frameWorkName, ".framework");
|
|
|
|
std::string intPath = cmStrCat(fpath, "/Headers/", fileName);
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(intPath)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->IncludeFileInPath) {
|
2006-03-02 18:30:22 +00:00
|
|
|
return intPath;
|
2005-12-31 02:54:26 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
return fpath;
|
2005-12-31 02:54:26 +00:00
|
|
|
}
|
2006-03-09 16:35:38 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-03-09 16:35:38 +00:00
|
|
|
// if it is not found yet or not a framework header, then do a glob search
|
2008-06-09 16:51:01 +00:00
|
|
|
// for all frameworks in the directory: dir/*.framework/Headers/<file>
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string glob = cmStrCat(dir, "*.framework/Headers/", file);
|
2006-03-21 17:54:31 +00:00
|
|
|
cmsys::Glob globIt;
|
2006-03-09 16:35:38 +00:00
|
|
|
globIt.FindFiles(glob);
|
|
|
|
std::vector<std::string> files = globIt.GetFiles();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!files.empty()) {
|
2014-10-15 12:54:05 +00:00
|
|
|
std::string fheader = cmSystemTools::CollapseFullPath(files[0]);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->IncludeFileInPath) {
|
2005-12-31 02:54:26 +00:00
|
|
|
return fheader;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2016-05-25 17:18:47 +00:00
|
|
|
fheader.resize(fheader.size() - file.size());
|
2006-03-09 16:35:38 +00:00
|
|
|
return fheader;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-03-02 18:30:22 +00:00
|
|
|
return "";
|
2005-12-31 02:54:26 +00:00
|
|
|
}
|
2006-03-02 18:30:22 +00:00
|
|
|
|
2019-12-11 18:01:09 +00:00
|
|
|
std::string cmFindPathCommand::FindNormalHeader(cmFindBaseDebugState& debug)
|
2008-06-09 15:58:29 +00:00
|
|
|
{
|
|
|
|
std::string tryPath;
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& n : this->Names) {
|
|
|
|
for (std::string const& sp : this->SearchPaths) {
|
2019-08-22 14:34:40 +00:00
|
|
|
tryPath = cmStrCat(sp, n);
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(tryPath)) {
|
2019-12-11 18:01:09 +00:00
|
|
|
debug.FoundAt(tryPath);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->IncludeFileInPath) {
|
2008-06-09 15:58:29 +00:00
|
|
|
return tryPath;
|
|
|
|
}
|
2017-09-11 10:40:26 +00:00
|
|
|
return sp;
|
2008-06-09 15:58:29 +00:00
|
|
|
}
|
2019-12-11 18:01:09 +00:00
|
|
|
debug.FailedAt(tryPath);
|
2008-06-09 15:58:29 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-06-09 15:58:29 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-12-11 18:01:09 +00:00
|
|
|
std::string cmFindPathCommand::FindFrameworkHeader(cmFindBaseDebugState& debug)
|
2008-06-09 15:58:29 +00:00
|
|
|
{
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& n : this->Names) {
|
|
|
|
for (std::string const& sp : this->SearchPaths) {
|
|
|
|
std::string fwPath = this->FindHeaderInFramework(n, sp);
|
2019-12-11 18:01:09 +00:00
|
|
|
fwPath.empty() ? debug.FailedAt(fwPath) : debug.FoundAt(fwPath);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!fwPath.empty()) {
|
2008-06-09 15:58:29 +00:00
|
|
|
return fwPath;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-06-09 15:58:29 +00:00
|
|
|
return "";
|
|
|
|
}
|
2019-09-10 19:44:48 +00:00
|
|
|
|
|
|
|
bool cmFindPath(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus& status)
|
|
|
|
{
|
|
|
|
return cmFindPathCommand(status).InitialPass(args);
|
|
|
|
}
|