Commit b424df91 authored by Brad King's avatar Brad King

ENH: Major improvements to the FIND_PACKAGE command. See bug #3659.

  - Use CMAKE_PREFIX_PATH and CMAKE_SYSTEM_PREFIX_PATH among other means
    to locate package configuration files.
  - Create cmFindCommon as base for cmFindBase and cmFindPackageCommand
  - Move common functionality up to cmFindCommon
  - Improve documentation of FIND_* commands.
  - Fix FIND_* commands to not add framework/app paths in wrong place.
parent 491d5d01
......@@ -42,6 +42,7 @@
#include "cmExecProgramCommand.cxx"
#include "cmExternalMakefileProjectGenerator.cxx"
#include "cmFindBase.cxx"
#include "cmFindCommon.cxx"
#include "cmFileCommand.cxx"
#include "cmFindFileCommand.cxx"
#include "cmFindLibraryCommand.cxx"
......
This diff is collapsed.
......@@ -17,15 +17,15 @@
#ifndef cmFindBase_h
#define cmFindBase_h
#include "cmCommand.h"
#include "cmFindCommon.h"
/** \class cmFindBase
* \brief Define a command to search for an executable program.
* \brief Base class for most FIND_XXX commands.
*
* cmFindBase is a parent class for cmFindProgramCommand, cmFindPathCommand,
* and cmFindLibraryCommand, cmFindFile
* and cmFindLibraryCommand, cmFindFileCommand
*/
class cmFindBase : public cmCommand
class cmFindBase : public cmFindCommon
{
public:
cmFindBase();
......@@ -34,20 +34,15 @@ public:
* the CMakeLists.txt file.
*/
virtual bool ParseArguments(std::vector<std::string> const& args);
cmTypeMacro(cmFindBase, cmCommand);
cmTypeMacro(cmFindBase, cmFindCommon);
virtual const char* GetFullDocumentation()
{return this->GenericDocumentation.c_str();}
enum RootPathMode { RootPathModeBoth,
RootPathModeOnlyRootPath,
RootPathModeNoRootPath };
protected:
void PrintFindStuff();
void ExpandPaths(std::vector<std::string> userPaths);
void HandleCMakeFindRootPath();
// add to the SearchPaths
void AddPaths(std::vector<std::string>& paths);
void AddFrameWorkPaths();
......@@ -70,29 +65,12 @@ protected:
cmStdString VariableName;
std::vector<std::string> Names;
std::vector<std::string> SearchPaths;
std::vector<std::string> SearchPathSuffixes;
// CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM
cmStdString CMakePathName;
cmStdString EnvironmentPath; // LIB,INCLUDE
bool AlreadyInCache;
bool AlreadyInCacheWithoutMetaInfo;
bool NoDefaultPath;
bool NoCMakePath;
bool NoCMakeEnvironmentPath;
bool NoSystemEnvironmentPath;
bool NoCMakeSystemPath;
RootPathMode FindRootPathMode;
bool SearchFrameworkFirst;
bool SearchFrameworkOnly;
bool SearchFrameworkLast;
bool SearchAppBundleFirst;
bool SearchAppBundleOnly;
bool SearchAppBundleLast;
};
......
This diff is collapsed.
/*=========================================================================
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.
=========================================================================*/
#ifndef cmFindCommon_h
#define cmFindCommon_h
#include "cmCommand.h"
/** \class cmFindCommon
* \brief Base class for FIND_XXX implementations.
*
* cmFindCommon is a parent class for cmFindBase,
* cmFindProgramCommand, cmFindPathCommand, cmFindLibraryCommand,
* cmFindFileCommand, and cmFindPackageCommand.
*/
class cmFindCommon : public cmCommand
{
public:
cmFindCommon();
~cmFindCommon();
cmTypeMacro(cmFindCommon, cmCommand);
protected:
enum RootPathMode { RootPathModeBoth,
RootPathModeOnlyRootPath,
RootPathModeNoRootPath };
enum PathType { FullPath, CMakePath, EnvPath };
/** Place a set of search paths under the search roots. */
void RerootPaths(std::vector<std::string>& paths);
/** Compute the current default root path mode. */
void SelectDefaultRootPathMode();
/** Compute the current default bundle/framework search policy. */
void SelectDefaultMacMode();
cmStdString CMakePathName;
RootPathMode FindRootPathMode;
bool CheckCommonArgument(std::string const& arg);
void AddPathSuffix(std::string const& arg);
void GetAppBundlePaths(std::vector<std::string>& paths);
void GetFrameworkPaths(std::vector<std::string>& paths);
void AddCMakePath(std::vector<std::string>& out_paths,
const char* variable, std::set<cmStdString>* emmitted = 0);
void AddEnvPath(std::vector<std::string>& out_paths,
const char* variable, std::set<cmStdString>* emmitted = 0);
void AddPathsInternal(std::vector<std::string>& out_paths,
std::vector<std::string> const& in_paths,
PathType pathType,
std::set<cmStdString>* emmitted = 0);
void AddPathInternal(std::vector<std::string>& out_paths,
std::string const& in_path,
PathType pathType,
std::set<cmStdString>* emmitted = 0);
bool NoDefaultPath;
bool NoCMakePath;
bool NoCMakeEnvironmentPath;
bool NoSystemEnvironmentPath;
bool NoCMakeSystemPath;
std::vector<std::string> SearchPathSuffixes;
std::string GenericDocumentationMacPolicy;
std::string GenericDocumentationRootPath;
std::string GenericDocumentationPathsOrder;
bool SearchFrameworkFirst;
bool SearchFrameworkOnly;
bool SearchFrameworkLast;
bool SearchAppBundleFirst;
bool SearchAppBundleOnly;
bool SearchAppBundleLast;
};
#endif
......@@ -23,6 +23,12 @@ cmFindLibraryCommand::cmFindLibraryCommand()
"FIND_XXX", "find_library");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_XXX_PATH", "CMAKE_LIBRARY_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_XXX_MAC_PATH",
"CMAKE_FRAMEWORK_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_SYSTEM_XXX_MAC_PATH",
"CMAKE_SYSTEM_FRAMEWORK_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"XXX_SYSTEM", "LIB");
cmSystemTools::ReplaceString(this->GenericDocumentation,
......
This diff is collapsed.
......@@ -17,16 +17,20 @@
#ifndef cmFindPackageCommand_h
#define cmFindPackageCommand_h
#include "cmCommand.h"
#include "cmFindCommon.h"
class cmFindPackageFileList;
/** \class cmFindPackageCommand
* \brief Load settings from an external project.
*
* cmFindPackageCommand
*/
class cmFindPackageCommand : public cmCommand
class cmFindPackageCommand : public cmFindCommon
{
public:
cmFindPackageCommand();
/**
* This is a virtual constructor for the command.
*/
......@@ -62,51 +66,45 @@ public:
/**
* More documentation.
*/
virtual const char* GetFullDocumentation()
{
return
" find_package(<name> [major.minor] [QUIET] [NO_MODULE]\n"
" [[REQUIRED|COMPONENTS] [components...]])\n"
"Finds and loads settings from an external project. <name>_FOUND will "
"be set to indicate whether the package was found. Settings that "
"can be used when <name>_FOUND is true are package-specific. The "
"package is found through several steps. "
"Directories listed in CMAKE_MODULE_PATH are searched for files called "
"\"Find<name>.cmake\". If such a file is found, it is read and "
"processed by CMake, and is responsible for finding the package. "
"This first step may be skipped by using the NO_MODULE option. "
"If no such file is found, it is expected that the package is another "
"project built by CMake that has a \"<name>Config.cmake\" file. "
"A cache entry called <name>_DIR is created and is expected to be set "
"to the directory containing this file. If the file is found, it is "
"read and processed by CMake to load the settings of the package. If "
"<name>_DIR has not been set during a configure step, the command "
"will generate an error describing the problem unless the QUIET "
"argument is specified. If <name>_DIR has been set to a directory "
"not containing a \"<name>Config.cmake\" file, an error is always "
"generated. If REQUIRED is specified and the package is not found, "
"a FATAL_ERROR is generated and the configure step stops executing. "
"A package-specific list of components may be listed after the "
"REQUIRED option, or after the COMPONENTS option if no REQUIRED "
"option is given.";
}
virtual const char* GetFullDocumentation();
cmTypeMacro(cmFindPackageCommand, cmCommand);
cmTypeMacro(cmFindPackageCommand, cmFindCommon);
private:
void AppendSuccessInformation(bool quiet);
void AppendSuccessInformation();
void AppendToProperty(const char* propertyName);
bool FindModule(bool& found, bool quiet, bool required);
bool FindConfig();
std::string SearchForConfig() const;
bool FindModule(bool& found);
bool HandlePackageMode();
void FindConfig();
bool FindPrefixedConfig();
bool FindFrameworkConfig();
bool FindAppBundleConfig();
bool ReadListFile(const char* f);
void AddUserPath(std::string const& p);
void ComputePrefixes();
bool SearchDirectory(std::string const& dir);
bool CheckDirectory(std::string const& dir);
bool FindConfigFile(std::string const& dir, std::string& file);
bool SearchPrefix(std::string const& prefix);
bool SearchFrameworkPrefix(std::string const& prefix_in);
bool SearchAppBundlePrefix(std::string const& prefix_in);
friend class cmFindPackageFileList;
std::string CommandDocumentation;
cmStdString Name;
cmStdString Variable;
cmStdString Config;
std::vector<cmStdString> Builds;
std::vector<cmStdString> Prefixes;
std::vector<cmStdString> Relatives;
cmStdString FileFound;
bool Quiet;
bool Required;
bool Compatibility_1_6;
bool NoModule;
bool NoBuilds;
bool DebugMode;
std::vector<std::string> Names;
std::vector<std::string> Configs;
std::vector<std::string> Prefixes;
std::vector<std::string> UserPaths;
};
#endif
......@@ -27,6 +27,12 @@ cmFindPathCommand::cmFindPathCommand()
"FIND_XXX", "find_path");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_XXX_PATH", "CMAKE_INCLUDE_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_XXX_MAC_PATH",
"CMAKE_FRAMEWORK_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_SYSTEM_XXX_MAC_PATH",
"CMAKE_SYSTEM_FRAMEWORK_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"XXX_SYSTEM", "INCLUDE");
cmSystemTools::ReplaceString(this->GenericDocumentation,
......
......@@ -28,6 +28,12 @@ cmFindProgramCommand::cmFindProgramCommand()
"FIND_XXX", "find_program");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_XXX_PATH", "CMAKE_PROGRAM_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_XXX_MAC_PATH",
"CMAKE_APPBUNDLE_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"CMAKE_SYSTEM_XXX_MAC_PATH",
"CMAKE_SYSTEM_APPBUNDLE_PATH");
cmSystemTools::ReplaceString(this->GenericDocumentation,
"XXX_SYSTEM", "");
cmSystemTools::ReplaceString(this->GenericDocumentation,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment