summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-10-26 09:55:40 -0400
committerAlexander Neundorf <neundorf@kde.org>2007-10-26 09:55:40 -0400
commit0398d8ad38c5a00aba7286fd511c15bad55f2987 (patch)
tree71a2886e9fd9f9ca732d10eae5b7956e621e387a
parent480b97a8e2f825f31e378025bce666d5bafc45ca (diff)
downloadcmake-0398d8ad38c5a00aba7286fd511c15bad55f2987.tar.gz
ENH: add support for CMAKE_FIND_PREFIX_PATH as discussed with Brad.
CMAKE_FIND_PREFIX_PATH is both an environment variable and a cmake variable, which is a list of base directories where FIND_PATH, FIND_FILE, FIND_PROGRAM and FIND_LIBRARY will search in the respective subdirectories Alex
-rw-r--r--Source/cmFindBase.cxx55
-rw-r--r--Source/cmFindBase.h2
-rw-r--r--Source/cmFindLibraryCommand.cxx2
-rw-r--r--Source/cmFindPathCommand.cxx2
-rw-r--r--Source/cmFindProgramCommand.cxx2
-rw-r--r--Tests/FindPackageTest/CMakeLists.txt12
-rw-r--r--Tests/FindPackageTest/include/foo.h1
7 files changed, 74 insertions, 2 deletions
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index b95cb899bf..00927f4eb5 100644
--- a/Source/cmFindBase.cxx
+++ b/Source/cmFindBase.cxx
@@ -83,6 +83,7 @@ cmFindBase::cmFindBase()
"1. Search cmake specific environment variables. This "
"can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.\n"
""
+ " CMAKE_FIND_PREFIX_PATH/XXX_SUBDIR\n"
" CMAKE_FRAMEWORK_PATH\n"
" CMAKE_APPBUNDLE_PATH\n"
" CMAKE_XXX_PATH\n"
@@ -92,6 +93,7 @@ cmFindBase::cmFindBase()
"-DVAR=value. This can be skipped if NO_CMAKE_PATH "
"is passed.\n"
""
+ " CMAKE_FIND_PREFIX_PATH/XXX_SUBDIR\n"
" CMAKE_FRAMEWORK_PATH\n"
" CMAKE_APPBUNDLE_PATH\n"
" CMAKE_XXX_PATH\n"
@@ -546,10 +548,15 @@ void cmFindBase::HandleCMakeFindRootPath()
void cmFindBase::AddEnvironmentVariables()
{
+ std::vector<std::string> paths;
+
+ std::vector<std::string> prefixPaths;
+ cmSystemTools::GetPath(prefixPaths, "CMAKE_FIND_PREFIX_PATH");
+ this->AddFindPrefix(paths, prefixPaths);
+
std::string var = "CMAKE_";
var += this->CMakePathName;
var += "_PATH";
- std::vector<std::string> paths;
cmSystemTools::GetPath(paths, var.c_str());
if(this->SearchAppBundleLast)
{
@@ -559,7 +566,42 @@ void cmFindBase::AddEnvironmentVariables()
{
cmSystemTools::GetPath(paths, "CMAKE_FRAMEWORK_PATH");
}
- this->AddPaths(paths);
+ 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 dirWithSubdir = it->c_str();
+ dirWithSubdir += subdir;
+ dest.push_back(dirWithSubdir);
+ if (subdir == "/bin")
+ {
+ dirWithSubdir = it->c_str();
+ dirWithSubdir += "/sbin";
+ dest.push_back(dirWithSubdir);
+ }
+ }
}
void cmFindBase::AddFrameWorkPaths()
@@ -644,6 +686,15 @@ void cmFindBase::AddCMakeVariables()
var += this->CMakePathName;
var += "_PATH";
std::vector<std::string> paths;
+
+ if(const char* prefixPath =
+ this->Makefile->GetDefinition("CMAKE_FIND_PREFIX_PATH"))
+ {
+ std::vector<std::string> prefixPaths;
+ cmSystemTools::ExpandListArgument(prefixPath, prefixPaths);
+ this->AddFindPrefix(paths, prefixPaths);
+ }
+
if(const char* path = this->Makefile->GetDefinition(var.c_str()))
{
cmSystemTools::ExpandListArgument(path, paths);
diff --git a/Source/cmFindBase.h b/Source/cmFindBase.h
index 547576d36b..5efbe2ad14 100644
--- a/Source/cmFindBase.h
+++ b/Source/cmFindBase.h
@@ -53,6 +53,8 @@ protected:
void AddFrameWorkPaths();
void AddAppBundlePaths();
void AddEnvironmentVariables();
+ void AddFindPrefix(std::vector<std::string>& dest,
+ const std::vector<std::string>& src);
void AddCMakeVariables();
void AddSystemEnvironmentVariables();
void AddCMakeSystemVariables();
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx
index 797122190d..208ed02a54 100644
--- a/Source/cmFindLibraryCommand.cxx
+++ b/Source/cmFindLibraryCommand.cxx
@@ -33,6 +33,8 @@ cmFindLibraryCommand::cmFindLibraryCommand()
cmSystemTools::ReplaceString(this->GenericDocumentation,
"SEARCH_XXX", "library");
cmSystemTools::ReplaceString(this->GenericDocumentation,
+ "XXX_SUBDIR", "lib");
+ cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_LIBRARY");
diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx
index 1210b3bdd1..80d0b102c7 100644
--- a/Source/cmFindPathCommand.cxx
+++ b/Source/cmFindPathCommand.cxx
@@ -37,6 +37,8 @@ cmFindPathCommand::cmFindPathCommand()
cmSystemTools::ReplaceString(this->GenericDocumentation,
"SEARCH_XXX", "file in a directory");
cmSystemTools::ReplaceString(this->GenericDocumentation,
+ "XXX_SUBDIR", "include");
+ cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_INCLUDE");
diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx
index f1b8135288..fb563e285c 100644
--- a/Source/cmFindProgramCommand.cxx
+++ b/Source/cmFindProgramCommand.cxx
@@ -38,6 +38,8 @@ cmFindProgramCommand::cmFindProgramCommand()
cmSystemTools::ReplaceString(this->GenericDocumentation,
"SEARCH_XXX", "program");
cmSystemTools::ReplaceString(this->GenericDocumentation,
+ "XXX_SUBDIR", "[s]bin");
+ cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
"CMAKE_FIND_ROOT_PATH_MODE_PROGRAM");
}
diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt
index 6f1a7e5fc0..a58408c7e5 100644
--- a/Tests/FindPackageTest/CMakeLists.txt
+++ b/Tests/FindPackageTest/CMakeLists.txt
@@ -10,3 +10,15 @@ FIND_PACKAGE(NotAPackage QUIET)
FIND_PACKAGE(VTK QUIET)
ADD_EXECUTABLE(FindPackageTest FindPackageTest.cxx)
+
+# test behaviour of cmFindBase wrt. the CMAKE_FIND_PREFIX_PATH variable
+# foo.h should be found in ${CMAKE_CURRENT_SOURCE_DIR}/include:
+
+SET(CMAKE_FIND_PREFIX_PATH /blub /blah "${CMAKE_CURRENT_SOURCE_DIR}")
+FIND_PATH(FOO_DIR foo.h)
+
+IF(NOT FOO_DIR)
+ MESSAGE(FATAL_ERROR "Did not find foo.h which is in ${CMAKE_CURRENT_SOURCE_DIR}/include
+ CMAKE_FIND_PREFIX_PATH = ${CMAKE_FIND_PREFIX_PATH}")
+ENDIF(NOT FOO_DIR)
+
diff --git a/Tests/FindPackageTest/include/foo.h b/Tests/FindPackageTest/include/foo.h
new file mode 100644
index 0000000000..2392aee71d
--- /dev/null
+++ b/Tests/FindPackageTest/include/foo.h
@@ -0,0 +1 @@
+/* empty header file */