CMake/Source/cmFindBase.cxx

596 lines
18 KiB
C++
Raw Normal View History

2006-02-28 00:38:22 +03:00
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmFindBase.h"
cmFindBase::cmFindBase()
{
cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
"FIND_ARGS_XXX", "<VAR> NAMES name");
2006-02-28 00:38:22 +03:00
this->AlreadyInCache = false;
this->AlreadyInCacheWithoutMetaInfo = false;
2006-03-02 21:30:22 +03:00
this->GenericDocumentation =
" FIND_XXX(<VAR> name1 path1 path2 ...)\n"
2006-03-02 21:43:39 +03:00
"This is the short-hand signature for the command that "
2006-03-02 21:30:22 +03:00
"is sufficient in many cases. It is the same "
"as FIND_XXX(<VAR> name1 PATHS path2 path2 ...)\n"
2006-03-02 21:30:22 +03:00
" FIND_XXX(\n"
2008-01-10 06:09:19 +03:00
" <VAR>\n"
" name | NAMES name1 [name2 ...]\n"
" PATHS path1 [path2 ... ENV var]\n"
2006-03-02 21:30:22 +03:00
" [PATH_SUFFIXES suffix1 [suffix2 ...]]\n"
" [DOC \"cache documentation string\"]\n"
" [NO_DEFAULT_PATH]\n"
" [NO_CMAKE_ENVIRONMENT_PATH]\n"
" [NO_CMAKE_PATH]\n"
" [NO_SYSTEM_ENVIRONMENT_PATH]\n"
" [NO_CMAKE_SYSTEM_PATH]\n"
" [CMAKE_FIND_ROOT_PATH_BOTH |\n"
" ONLY_CMAKE_FIND_ROOT_PATH |\n"
" NO_CMAKE_FIND_ROOT_PATH]\n"
2006-03-02 21:30:22 +03:00
" )\n"
""
"This command is used to find a SEARCH_XXX_DESC. "
"A cache entry named by <VAR> is created to store the result "
"of this command. "
"If the SEARCH_XXX is found the result is stored in the variable "
"and the search will not be repeated unless the variable is cleared. "
"If nothing is found, the result will be "
"<VAR>-NOTFOUND, and the search will be attempted again the "
"next time FIND_XXX is invoked with the same variable. "
"The name of the SEARCH_XXX that "
2006-03-02 21:30:22 +03:00
"is searched for is specified by the names listed "
"after the NAMES argument. Additional search locations "
"can be specified after the PATHS argument. If ENV var is "
"found in the PATHS section the environment variable var "
"will be read and converted from a system environment variable to "
"a cmake style list of paths. For example ENV PATH would be a way "
"to list the system path variable. The argument "
2006-03-02 21:30:22 +03:00
"after DOC will be used for the documentation string in "
"the cache. PATH_SUFFIXES can be used to give sub directories "
2006-03-02 21:43:39 +03:00
"that will be appended to the search paths.\n"
"If NO_DEFAULT_PATH is specified, then no additional paths are "
"added to the search. "
"If NO_DEFAULT_PATH is not specified, the search process is as follows:\n"
"1. Search cmake specific environment variables. This "
"can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.\n"
2006-03-02 21:30:22 +03:00
""
" <prefix>/XXX_SUBDIR for each <prefix> in CMAKE_PREFIX_PATH\n"
2006-03-02 21:30:22 +03:00
" CMAKE_XXX_PATH\n"
" CMAKE_XXX_MAC_PATH\n"
2006-03-02 21:30:22 +03:00
"2. Search cmake variables with the same names as "
"the cmake specific environment variables. These "
"are intended to be used on the command line with a "
"-DVAR=value. This can be skipped if NO_CMAKE_PATH "
"is passed.\n"
2006-03-02 21:30:22 +03:00
""
" <prefix>/XXX_SUBDIR for each <prefix> in CMAKE_PREFIX_PATH\n"
2006-03-02 21:30:22 +03:00
" CMAKE_XXX_PATH\n"
" CMAKE_XXX_MAC_PATH\n"
2006-03-02 21:30:22 +03:00
"3. Search the standard system environment variables. "
"This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.\n"
2006-03-02 21:30:22 +03:00
" PATH\n"
" XXX_SYSTEM\n" // replace with "", LIB, or INCLUDE
"4. Search cmake variables defined in the Platform files "
"for the current system. This can be skipped if NO_CMAKE_SYSTEM_PATH "
"is passed.\n"
" <prefix>/XXX_SUBDIR for each <prefix> in CMAKE_SYSTEM_PREFIX_PATH\n"
2006-03-02 21:30:22 +03:00
" CMAKE_SYSTEM_XXX_PATH\n"
" CMAKE_SYSTEM_XXX_MAC_PATH\n"
2006-03-02 21:30:22 +03:00
"5. Search the paths specified after PATHS or in the short-hand version "
"of the command.\n"
;
this->GenericDocumentation += this->GenericDocumentationMacPolicy;
this->GenericDocumentation += this->GenericDocumentationRootPath;
this->GenericDocumentation += this->GenericDocumentationPathsOrder;
2006-02-28 00:38:22 +03:00
}
2006-03-02 21:30:22 +03:00
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;
}
// CMake versions below 2.3 did not search all these extra
// locations. Preserve compatibility unless a modern argument is
// passed.
bool compatibility = false;
const char* versionValue =
this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
int major = 0;
int minor = 0;
if(versionValue && sscanf(versionValue, "%d.%d", &major, &minor) != 2)
{
versionValue = 0;
}
if(versionValue && (major < 2 || major == 2 && minor < 3))
{
compatibility = true;
}
2006-02-28 00:38:22 +03:00
// copy argsIn into args so it can be modified,
// in the process extract the DOC "documentation"
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;
}
}
}
}
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
std::vector<std::string> userPaths;
std::string doc;
bool doingNames = true; // assume it starts with a name
2006-02-28 00:38:22 +03:00
bool doingPaths = false;
bool doingPathSuf = false;
bool newStyle = false;
2006-02-28 00:38:22 +03:00
for (unsigned int j = 1; j < args.size(); ++j)
{
if(args[j] == "NAMES")
{
doingNames = true;
newStyle = true;
doingPathSuf = false;
doingPaths = false;
}
else if (args[j] == "PATHS")
{
doingPaths = true;
newStyle = true;
doingNames = false;
doingPathSuf = false;
}
else if (args[j] == "PATH_SUFFIXES")
{
compatibility = false;
2006-02-28 00:38:22 +03:00
doingPathSuf = true;
newStyle = true;
doingNames = false;
doingPaths = false;
}
else if (args[j] == "NO_SYSTEM_PATH")
2006-02-28 00:38:22 +03:00
{
2006-03-10 19:12:53 +03:00
doingPaths = false;
doingPathSuf = false;
doingNames = false;
this->NoDefaultPath = true;
2006-02-28 00:38:22 +03:00
}
else if (this->CheckCommonArgument(args[j]))
{
compatibility = false;
doingPaths = false;
doingPathSuf = false;
doingNames = false;
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
else
{
if(doingNames)
{
this->Names.push_back(args[j]);
}
else if(doingPaths)
{
userPaths.push_back(args[j]);
}
else if(doingPathSuf)
{
this->AddPathSuffix(args[j]);
2006-02-28 00:38:22 +03:00
}
}
}
// Now that arguments have been parsed check the compatibility
// setting. If we need to be compatible with CMake 2.2 and earlier
// do not add the CMake system paths. It is safe to add the CMake
// environment paths and system environment paths because that
// existed in 2.2. It is safe to add the CMake user variable paths
// because the user or project has explicitly set them.
if(compatibility)
{
this->NoCMakeSystemPath = true;
}
2006-02-28 00:38:22 +03:00
if(this->VariableDocumentation.size() == 0)
{
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 ";
2006-02-28 00:38:22 +03:00
if(this->Names.size() == 0)
{
this->VariableDocumentation += "the (unknown) library be found";
}
else if(this->Names.size() == 1)
{
2006-05-10 23:46:45 +04:00
this->VariableDocumentation += "the "
+ this->Names[0] + " library be found";
2006-02-28 00:38:22 +03:00
}
else
{
this->VariableDocumentation += "one of the " + this->Names[0];
for (unsigned int j = 1; j < this->Names.size() - 1; ++j)
{
this->VariableDocumentation += ", " + this->Names[j];
}
2006-05-10 23:46:45 +04:00
this->VariableDocumentation += " or "
+ 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)
{
this->Names.clear(); // clear out any values in Names
2006-02-28 00:38:22 +03:00
this->Names.push_back(args[1]);
for(unsigned int j = 2; j < args.size(); ++j)
{
userPaths.push_back(args[j]);
}
}
this->ExpandPaths(userPaths);
// Handle search root stuff.
this->RerootPaths(this->SearchPaths);
2006-02-28 00:38:22 +03:00
return true;
}
void cmFindBase::ExpandPaths(std::vector<std::string> userPaths)
{
// if NO Default paths was not specified add the
// standard search paths.
if(!this->NoDefaultPath)
2006-02-28 00:38:22 +03:00
{
if(this->SearchFrameworkFirst || this->SearchFrameworkOnly)
{
this->AddFrameWorkPaths();
}
if(this->SearchAppBundleFirst || this->SearchAppBundleOnly)
{
this->AddAppBundlePaths();
}
2006-05-10 23:46:45 +04:00
if(!this->NoCMakeEnvironmentPath &&
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
{
// Add CMAKE_*_PATH environment variables
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->AddEnvironmentVariables();
}
2006-05-10 23:46:45 +04:00
if(!this->NoCMakePath &&
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
{
// 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
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->AddCMakeVariables();
}
2006-05-10 23:46:45 +04:00
if(!this->NoSystemEnvironmentPath &&
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
{
// add System environment PATH and (LIB or INCLUDE)
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->AddSystemEnvironmentVariables();
}
2006-05-10 23:46:45 +04:00
if(!this->NoCMakeSystemPath &&
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
{
// Add CMAKE_SYSTEM_*_PATH variables which are defined in platform files
this->AddCMakeSystemVariables();
}
if(this->SearchAppBundleLast)
{
this->AddAppBundlePaths();
}
if(this->SearchFrameworkLast)
{
this->AddFrameWorkPaths();
}
2006-02-28 00:38:22 +03:00
}
std::vector<std::string> paths;
2006-02-28 00:38:22 +03:00
// add the paths specified in the FIND_* call
for(unsigned int i =0; i < userPaths.size(); ++i)
{
paths.push_back(userPaths[i]);
2006-02-28 00:38:22 +03:00
}
this->AddPaths(paths);
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
void cmFindBase::AddEnvironmentVariables()
2006-02-28 00:38:22 +03:00
{
std::vector<std::string> paths;
std::vector<std::string> prefixPaths;
cmSystemTools::GetPath(prefixPaths, "CMAKE_PREFIX_PATH");
this->AddFindPrefix(paths, prefixPaths);
2006-02-28 00:38:22 +03:00
std::string var = "CMAKE_";
var += this->CMakePathName;
var += "_PATH";
cmSystemTools::GetPath(paths, var.c_str());
this->AddPaths(paths);
}
void cmFindBase::AddFindPrefix(std::vector<std::string>& dest,
const std::vector<std::string>& src)
{
// default for programs
std::string subdir = "bin";
if (this->CMakePathName == "INCLUDE")
{
subdir = "include";
}
else if (this->CMakePathName == "LIBRARY")
{
subdir = "lib";
}
else if (this->CMakePathName == "FRAMEWORK")
{
subdir = ""; // ? what to do for frameworks ?
}
for (std::vector<std::string>::const_iterator it = src.begin();
it != src.end();
++it)
{
std::string dir = it->c_str();
if(!subdir.empty() && !dir.empty() && dir[dir.size()-1] != '/')
{
dir += "/";
}
dest.push_back(dir + subdir);
if (subdir == "bin")
{
dest.push_back(dir + "sbin");
}
if(!subdir.empty())
{
dest.push_back(*it);
}
}
2006-02-28 00:38:22 +03:00
}
void cmFindBase::AddFrameWorkPaths()
{
std::vector<std::string> paths;
this->GetFrameworkPaths(paths);
this->AddPaths(paths);
}
void cmFindBase::AddPaths(std::vector<std::string> & paths)
{
// add suffixes and clean up paths
this->ExpandRegistryAndCleanPath(paths);
// add the paths to the search paths
this->SearchPaths.insert(this->SearchPaths.end(),
paths.begin(),
paths.end());
}
void cmFindBase::AddAppBundlePaths()
{
std::vector<std::string> paths;
this->GetAppBundlePaths(paths);
this->AddPaths(paths);
}
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
void cmFindBase::AddCMakeVariables()
{
2006-02-28 00:38:22 +03:00
std::string var = "CMAKE_";
var += this->CMakePathName;
var += "_PATH";
std::vector<std::string> paths;
if(const char* prefixPath =
this->Makefile->GetDefinition("CMAKE_PREFIX_PATH"))
{
std::vector<std::string> prefixPaths;
cmSystemTools::ExpandListArgument(prefixPath, prefixPaths);
this->AddFindPrefix(paths, prefixPaths);
}
2006-03-15 19:02:08 +03:00
if(const char* path = this->Makefile->GetDefinition(var.c_str()))
2006-02-28 00:38:22 +03:00
{
cmSystemTools::ExpandListArgument(path, paths);
2006-02-28 00:38:22 +03:00
}
this->AddPaths(paths);
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
void cmFindBase::AddSystemEnvironmentVariables()
2006-02-28 00:38:22 +03:00
{
// Add LIB or INCLUDE
std::vector<std::string> paths;
2006-02-28 00:38:22 +03:00
if(this->EnvironmentPath.size())
{
cmSystemTools::GetPath(paths, this->EnvironmentPath.c_str());
2006-02-28 00:38:22 +03:00
}
// Add PATH
cmSystemTools::GetPath(paths);
this->AddPaths(paths);
2006-02-28 00:38:22 +03:00
}
void cmFindBase::AddCMakeSystemVariables()
{
std::string var = "CMAKE_SYSTEM_";
var += this->CMakePathName;
var += "_PATH";
std::vector<std::string> paths;
if(const char* prefixPath =
this->Makefile->GetDefinition("CMAKE_SYSTEM_PREFIX_PATH"))
{
std::vector<std::string> prefixPaths;
cmSystemTools::ExpandListArgument(prefixPath, prefixPaths);
this->AddFindPrefix(paths, prefixPaths);
}
2006-03-15 19:02:08 +03:00
if(const char* path = this->Makefile->GetDefinition(var.c_str()))
2006-02-28 00:38:22 +03:00
{
cmSystemTools::ExpandListArgument(path, paths);
2006-02-28 00:38:22 +03:00
}
this->AddPaths(paths);
2006-02-28 00:38:22 +03:00
}
void cmFindBase::ExpandRegistryAndCleanPath(std::vector<std::string>& paths)
2006-02-28 00:38:22 +03:00
{
std::vector<std::string> finalPath;
std::vector<std::string>::iterator i;
// glob and expand registry stuff from paths and put
// into finalPath
for(i = paths.begin();
i != paths.end(); ++i)
2006-02-28 00:38:22 +03:00
{
cmSystemTools::ExpandRegistryValues(*i);
cmSystemTools::GlobDirs(i->c_str(), finalPath);
}
// clear the path
paths.clear();
// convert all paths to unix slashes and add search path suffixes
// if there are any
2006-02-28 00:38:22 +03:00
for(i = finalPath.begin();
i != finalPath.end(); ++i)
{
cmSystemTools::ConvertToUnixSlashes(*i);
// copy each finalPath combined with SearchPathSuffixes
// to the SearchPaths ivar
2006-05-10 23:46:45 +04:00
for(std::vector<std::string>::iterator j =
this->SearchPathSuffixes.begin();
2006-02-28 00:38:22 +03:00
j != this->SearchPathSuffixes.end(); ++j)
{
std::string p = *i + std::string("/") + *j;
// add to all paths because the search path may be modified
// later with lib being replaced for lib64 which may exist
paths.push_back(p);
2006-02-28 00:38:22 +03:00
}
}
// now put the path without the path suffixes in the SearchPaths
for(i = finalPath.begin();
i != finalPath.end(); ++i)
{
// put all search paths in because it may later be replaced
// by lib64 stuff fixes bug 4009
paths.push_back(*i);
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";
2006-05-10 23:46:45 +04:00
std::cerr << "VariableDocumentation "
<< this->VariableDocumentation << "\n";
std::cerr << "NoDefaultPath " << this->NoDefaultPath << "\n";
2006-05-10 23:46:45 +04:00
std::cerr << "NoCMakeEnvironmentPath "
<< this->NoCMakeEnvironmentPath << "\n";
std::cerr << "NoCMakePath " << this->NoCMakePath << "\n";
2006-05-10 23:46:45 +04:00
std::cerr << "NoSystemEnvironmentPath "
<< 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(unsigned int i =0; i < this->SearchPaths.size(); ++i)
{
std::cerr << "[" << this->SearchPaths[i] << "]\n";
}
}
bool cmFindBase::CheckForVariableInCache()
{
if(const char* cacheValue =
this->Makefile->GetDefinition(this->VariableName.c_str()))
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;
}