CMake/Source/cmFindBase.cxx

404 lines
11 KiB
C++
Raw Normal View History

/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
2006-02-28 00:38:22 +03:00
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
2006-02-28 00:38:22 +03: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.
============================================================================*/
2006-02-28 00:38:22 +03:00
#include "cmFindBase.h"
2006-02-28 00:38:22 +03:00
cmFindBase::cmFindBase()
{
this->AlreadyInCache = false;
this->AlreadyInCacheWithoutMetaInfo = false;
this->NamesPerDir = false;
this->NamesPerDirAllowed = false;
}
//----------------------------------------------------------------------------
2006-02-28 00:38:22 +03:00
bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
{
if(argsIn.size() < 2 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
2006-02-28 00:38:22 +03:00
// copy argsIn into args so it can be modified,
// in the process extract the DOC "documentation"
2006-02-28 00:38:22 +03:00
size_t size = argsIn.size();
std::vector<std::string> args;
bool foundDoc = false;
for(unsigned int j = 0; j < size; ++j)
{
if(foundDoc || argsIn[j] != "DOC" )
{
if(argsIn[j] == "ENV")
{
if(j+1 < size)
{
j++;
cmSystemTools::GetPath(args, argsIn[j].c_str());
}
}
else
{
args.push_back(argsIn[j]);
}
2006-02-28 00:38:22 +03:00
}
else
{
if(j+1 < size)
{
foundDoc = true;
this->VariableDocumentation = argsIn[j+1];
j++;
if(j >= size)
{
break;
}
}
}
}
if(args.size() < 2 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
2006-02-28 00:38:22 +03:00
this->VariableName = args[0];
if(this->CheckForVariableInCache())
{
this->AlreadyInCache = true;
return true;
}
this->AlreadyInCache = false;
// Find the current root path mode.
this->SelectDefaultRootPathMode();
// Find the current bundle/framework search policy.
this->SelectDefaultMacMode();
ENH: merge CMake-CrossCompileBasic to HEAD -add a RESULT_VARIABLE to INCLUDE() -add CMAKE_TOOLCHAIN_FILE for specifiying your (potentially crosscompiling) toolchain -have TRY_RUN() complain if you try to use it in crosscompiling mode (which were compiled but cannot run on this system) -use CMAKE_EXECUTABLE_SUFFIX in TRY_RUN(), probably TRY_RUN won't be able to run the executables if they have a different suffix because they are probably crosscompiled, but nevertheless it should be able to find them -make several cmake variables presettable by the user: CMAKE_C/CXX_COMPILER, CMAKE_C/CXX_OUTPUT_EXTENSION, CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_INFO_FILE -support prefix for GNU toolchains (arm-elf-gcc, arm-elf-ar, arm-elf-strip etc.) -move ranlib on OSX from the file command to a command in executed in cmake_install.cmake -add support for stripping during install in cmake_install.cmake -split out cl.cmake from Windows-cl.cmake, first (very incomplete) step to support MS crosscompiling tools -remove stdio.h from the simple C program which checks if the compiler works, since this may not exist for some embedded platforms -create a new CMakeFindBinUtils.cmake which collects the search fro ar, ranlib, strip, ld, link, install_name_tool and other tools like these -add support for CMAKE_FIND_ROOT_PATH for all FIND_XXX commands, which is a list of directories which will be prepended to all search directories, right now as a cmake variable, turning it into a global cmake property may need some more work -remove cmTestTestHandler::TryExecutable(), it's unused -split cmFileCommand::HandleInstall() into slightly smaller functions Alex
2007-05-17 21:20:44 +04:00
2006-02-28 00:38:22 +03:00
bool newStyle = false;
enum Doing { DoingNone, DoingNames, DoingPaths, DoingPathSuffixes,
DoingHints };
Doing doing = DoingNames; // assume it starts with a name
2006-02-28 00:38:22 +03:00
for (unsigned int j = 1; j < args.size(); ++j)
{
if(args[j] == "NAMES")
{
doing = DoingNames;
2006-02-28 00:38:22 +03:00
newStyle = true;
}
else if (args[j] == "PATHS")
{
doing = DoingPaths;
newStyle = true;
}
else if (args[j] == "HINTS")
{
doing = DoingHints;
2006-02-28 00:38:22 +03:00
newStyle = true;
}
else if (args[j] == "PATH_SUFFIXES")
{
doing = DoingPathSuffixes;
2006-02-28 00:38:22 +03:00
newStyle = true;
}
else if (args[j] == "NAMES_PER_DIR")
{
doing = DoingNone;
if(this->NamesPerDirAllowed)
{
this->NamesPerDir = true;
}
else
{
this->SetError("does not support NAMES_PER_DIR");
return false;
}
}
else if (args[j] == "NO_SYSTEM_PATH")
2006-02-28 00:38:22 +03:00
{
doing = DoingNone;
this->NoDefaultPath = true;
2006-02-28 00:38:22 +03:00
}
else if (this->CheckCommonArgument(args[j]))
{
doing = DoingNone;
// Some common arguments were accidentally supported by CMake
// 2.4 and 2.6.0 in the short-hand form of the command, so we
// must support it even though it is not documented.
ENH: merge CMake-CrossCompileBasic to HEAD -add a RESULT_VARIABLE to INCLUDE() -add CMAKE_TOOLCHAIN_FILE for specifiying your (potentially crosscompiling) toolchain -have TRY_RUN() complain if you try to use it in crosscompiling mode (which were compiled but cannot run on this system) -use CMAKE_EXECUTABLE_SUFFIX in TRY_RUN(), probably TRY_RUN won't be able to run the executables if they have a different suffix because they are probably crosscompiled, but nevertheless it should be able to find them -make several cmake variables presettable by the user: CMAKE_C/CXX_COMPILER, CMAKE_C/CXX_OUTPUT_EXTENSION, CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_INFO_FILE -support prefix for GNU toolchains (arm-elf-gcc, arm-elf-ar, arm-elf-strip etc.) -move ranlib on OSX from the file command to a command in executed in cmake_install.cmake -add support for stripping during install in cmake_install.cmake -split out cl.cmake from Windows-cl.cmake, first (very incomplete) step to support MS crosscompiling tools -remove stdio.h from the simple C program which checks if the compiler works, since this may not exist for some embedded platforms -create a new CMakeFindBinUtils.cmake which collects the search fro ar, ranlib, strip, ld, link, install_name_tool and other tools like these -add support for CMAKE_FIND_ROOT_PATH for all FIND_XXX commands, which is a list of directories which will be prepended to all search directories, right now as a cmake variable, turning it into a global cmake property may need some more work -remove cmTestTestHandler::TryExecutable(), it's unused -split cmFileCommand::HandleInstall() into slightly smaller functions Alex
2007-05-17 21:20:44 +04:00
}
else if(doing == DoingNames)
2006-02-28 00:38:22 +03:00
{
this->Names.push_back(args[j]);
}
else if(doing == DoingPaths)
{
this->UserGuessArgs.push_back(args[j]);
}
else if(doing == DoingHints)
{
this->UserHintsArgs.push_back(args[j]);
}
else if(doing == DoingPathSuffixes)
{
this->AddPathSuffix(args[j]);
2006-02-28 00:38:22 +03:00
}
}
if(this->VariableDocumentation.empty())
2006-02-28 00:38:22 +03:00
{
ENH: merge CMake-CrossCompileBasic to HEAD -add a RESULT_VARIABLE to INCLUDE() -add CMAKE_TOOLCHAIN_FILE for specifiying your (potentially crosscompiling) toolchain -have TRY_RUN() complain if you try to use it in crosscompiling mode (which were compiled but cannot run on this system) -use CMAKE_EXECUTABLE_SUFFIX in TRY_RUN(), probably TRY_RUN won't be able to run the executables if they have a different suffix because they are probably crosscompiled, but nevertheless it should be able to find them -make several cmake variables presettable by the user: CMAKE_C/CXX_COMPILER, CMAKE_C/CXX_OUTPUT_EXTENSION, CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_INFO_FILE -support prefix for GNU toolchains (arm-elf-gcc, arm-elf-ar, arm-elf-strip etc.) -move ranlib on OSX from the file command to a command in executed in cmake_install.cmake -add support for stripping during install in cmake_install.cmake -split out cl.cmake from Windows-cl.cmake, first (very incomplete) step to support MS crosscompiling tools -remove stdio.h from the simple C program which checks if the compiler works, since this may not exist for some embedded platforms -create a new CMakeFindBinUtils.cmake which collects the search fro ar, ranlib, strip, ld, link, install_name_tool and other tools like these -add support for CMAKE_FIND_ROOT_PATH for all FIND_XXX commands, which is a list of directories which will be prepended to all search directories, right now as a cmake variable, turning it into a global cmake property may need some more work -remove cmTestTestHandler::TryExecutable(), it's unused -split cmFileCommand::HandleInstall() into slightly smaller functions Alex
2007-05-17 21:20:44 +04:00
this->VariableDocumentation = "Where can ";
if(this->Names.empty())
2006-02-28 00:38:22 +03:00
{
this->VariableDocumentation += "the (unknown) library be found";
}
else if(this->Names.size() == 1)
{
this->VariableDocumentation += "the "
2006-05-10 23:46:45 +04:00
+ this->Names[0] + " library be found";
2006-02-28 00:38:22 +03:00
}
else
{
this->VariableDocumentation += "one of the ";
this->VariableDocumentation += cmJoin(cmRange(this->Names).retreat(1),
", ");
this->VariableDocumentation += " or "
2006-05-10 23:46:45 +04:00
+ this->Names[this->Names.size() - 1] + " libraries be found";
2006-02-28 00:38:22 +03:00
}
}
// look for old style
// FIND_*(VAR name path1 path2 ...)
if(!newStyle)
{
// All the short-hand arguments have been recorded as names.
std::vector<std::string> shortArgs = this->Names;
this->Names.clear(); // clear out any values in Names
this->Names.push_back(shortArgs[0]);
this->UserGuessArgs.insert(this->UserGuessArgs.end(),
shortArgs.begin() + 1, shortArgs.end());
2006-02-28 00:38:22 +03:00
}
this->ExpandPaths();
this->ComputeFinalPaths();
2006-02-28 00:38:22 +03:00
return true;
}
void cmFindBase::ExpandPaths()
2006-02-28 00:38:22 +03:00
{
if(!this->NoDefaultPath)
{
if(!this->NoCMakePath)
{
this->FillCMakeVariablePath();
}
if(!this->NoCMakeEnvironmentPath)
{
this->FillCMakeEnvironmentPath();
}
if(!this->NoSystemEnvironmentPath)
{
this->FillSystemEnvironmentPath();
}
if(!this->NoCMakeSystemPath)
{
this->FillCMakeSystemVariablePath();
}
}
this->FillUserHintsPath();
this->FillUserGuessPath();
}
//----------------------------------------------------------------------------
void cmFindBase::FillCMakeEnvironmentPath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::CMakeEnvironment];
// Add CMAKE_*_PATH environment variables
std::string var = "CMAKE_";
var += this->CMakePathName;
var += "_PATH";
paths.AddEnvPrefixPath("CMAKE_PREFIX_PATH");
paths.AddEnvPath(var);
if(this->CMakePathName == "PROGRAM")
2006-02-28 00:38:22 +03:00
{
paths.AddEnvPath("CMAKE_APPBUNDLE_PATH");
}
else
{
paths.AddEnvPath("CMAKE_FRAMEWORK_PATH");
2006-02-28 00:38:22 +03:00
}
paths.AddSuffixes(this->SearchPathSuffixes);
2006-02-28 00:38:22 +03:00
}
//----------------------------------------------------------------------------
void cmFindBase::FillCMakeVariablePath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::CMake];
// Add CMake varibles of the same name as the previous environment
// varibles CMAKE_*_PATH to be used most of the time with -D
// command line options
std::string var = "CMAKE_";
var += this->CMakePathName;
var += "_PATH";
paths.AddCMakePrefixPath("CMAKE_PREFIX_PATH");
paths.AddCMakePath(var);
if(this->CMakePathName == "PROGRAM")
{
paths.AddCMakePath("CMAKE_APPBUNDLE_PATH");
}
else
{
paths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
}
paths.AddSuffixes(this->SearchPathSuffixes);
2006-02-28 00:38:22 +03:00
}
//----------------------------------------------------------------------------
void cmFindBase::FillSystemEnvironmentPath()
2006-02-28 00:38:22 +03:00
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::SystemEnvironment];
// Add LIB or INCLUDE
if(!this->EnvironmentPath.empty())
{
paths.AddEnvPath(this->EnvironmentPath);
}
// Add PATH
paths.AddEnvPath("PATH");
paths.AddSuffixes(this->SearchPathSuffixes);
}
//----------------------------------------------------------------------------
void cmFindBase::FillCMakeSystemVariablePath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::CMakeSystem];
std::string var = "CMAKE_SYSTEM_";
var += this->CMakePathName;
var += "_PATH";
paths.AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH");
paths.AddCMakePath(var);
if(this->CMakePathName == "PROGRAM")
2006-02-28 00:38:22 +03:00
{
paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
}
else
{
paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
2006-02-28 00:38:22 +03:00
}
paths.AddSuffixes(this->SearchPathSuffixes);
}
//----------------------------------------------------------------------------
void cmFindBase::FillUserHintsPath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::Hints];
for(std::vector<std::string>::const_iterator p = this->UserHintsArgs.begin();
p != this->UserHintsArgs.end(); ++p)
{
paths.AddUserPath(*p);
}
paths.AddSuffixes(this->SearchPathSuffixes);
}
//----------------------------------------------------------------------------
void cmFindBase::FillUserGuessPath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::Guess];
for(std::vector<std::string>::const_iterator p = this->UserGuessArgs.begin();
p != this->UserGuessArgs.end(); ++p)
2006-02-28 00:38:22 +03:00
{
paths.AddUserPath(*p);
2006-02-28 00:38:22 +03:00
}
paths.AddSuffixes(this->SearchPathSuffixes);
2006-02-28 00:38:22 +03:00
}
//----------------------------------------------------------------------------
2006-02-28 00:38:22 +03:00
void cmFindBase::PrintFindStuff()
{
std::cerr << "SearchFrameworkLast: " << this->SearchFrameworkLast << "\n";
std::cerr << "SearchFrameworkOnly: " << this->SearchFrameworkOnly << "\n";
std::cerr << "SearchFrameworkFirst: " << this->SearchFrameworkFirst << "\n";
std::cerr << "SearchAppBundleLast: " << this->SearchAppBundleLast << "\n";
std::cerr << "SearchAppBundleOnly: " << this->SearchAppBundleOnly << "\n";
std::cerr << "SearchAppBundleFirst: " << this->SearchAppBundleFirst << "\n";
2006-02-28 00:38:22 +03:00
std::cerr << "VariableName " << this->VariableName << "\n";
std::cerr << "VariableDocumentation "
2006-05-10 23:46:45 +04:00
<< this->VariableDocumentation << "\n";
std::cerr << "NoDefaultPath " << this->NoDefaultPath << "\n";
std::cerr << "NoCMakeEnvironmentPath "
2006-05-10 23:46:45 +04:00
<< this->NoCMakeEnvironmentPath << "\n";
std::cerr << "NoCMakePath " << this->NoCMakePath << "\n";
std::cerr << "NoSystemEnvironmentPath "
2006-05-10 23:46:45 +04:00
<< this->NoSystemEnvironmentPath << "\n";
std::cerr << "NoCMakeSystemPath " << this->NoCMakeSystemPath << "\n";
2006-02-28 00:38:22 +03:00
std::cerr << "EnvironmentPath " << this->EnvironmentPath << "\n";
std::cerr << "CMakePathName " << this->CMakePathName << "\n";
std::cerr << "Names ";
for(unsigned int i =0; i < this->Names.size(); ++i)
{
std::cerr << this->Names[i] << " ";
}
std::cerr << "\n";
std::cerr << "\n";
std::cerr << "SearchPathSuffixes ";
for(unsigned int i =0; i < this->SearchPathSuffixes.size(); ++i)
{
std::cerr << this->SearchPathSuffixes[i] << "\n";
}
std::cerr << "\n";
std::cerr << "SearchPaths\n";
for(std::vector<std::string>::const_iterator i = this->SearchPaths.begin();
i != this->SearchPaths.end(); ++i)
2006-02-28 00:38:22 +03:00
{
std::cerr << "[" << *i << "]\n";
2006-02-28 00:38:22 +03:00
}
}
bool cmFindBase::CheckForVariableInCache()
{
if(const char* cacheValue =
this->Makefile->GetDefinition(this->VariableName))
2006-02-28 00:38:22 +03:00
{
cmCacheManager::CacheIterator it =
2006-05-10 23:46:45 +04:00
this->Makefile->GetCacheManager()->
GetCacheIterator(this->VariableName.c_str());
bool found = !cmSystemTools::IsNOTFOUND(cacheValue);
bool cached = !it.IsAtEnd();
if(found)
{
// 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. Tell the subclass implementations to do
// this.
if(cached && it.GetType() == cmCacheManager::UNINITIALIZED)
{
this->AlreadyInCacheWithoutMetaInfo = true;
}
return true;
}
else if(cached)
2006-02-28 00:38:22 +03:00
{
const char* hs = it.GetProperty("HELPSTRING");
this->VariableDocumentation = hs?hs:"(none)";
}
}
return false;
}