cmFindPackageCommand.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmFindPackageCommand_h
  14. #define cmFindPackageCommand_h
  15. #include "cmCommand.h"
  16. /** \class cmFindPackageCommand
  17. * \brief Load settings from an external project.
  18. *
  19. * cmFindPackageCommand
  20. */
  21. class cmFindPackageCommand : public cmCommand
  22. {
  23. public:
  24. /**
  25. * This is a virtual constructor for the command.
  26. */
  27. virtual cmCommand* Clone()
  28. {
  29. return new cmFindPackageCommand;
  30. }
  31. /**
  32. * This is called when the command is first encountered in
  33. * the CMakeLists.txt file.
  34. */
  35. virtual bool InitialPass(std::vector<std::string> const& args);
  36. /**
  37. * This determines if the command is invoked when in script mode.
  38. */
  39. virtual bool IsScriptable() { return true; }
  40. /**
  41. * The name of the command as specified in CMakeList.txt.
  42. */
  43. virtual const char* GetName() { return "find_package";}
  44. /**
  45. * Succinct documentation.
  46. */
  47. virtual const char* GetTerseDocumentation()
  48. {
  49. return "Load settings for an external project.";
  50. }
  51. /**
  52. * More documentation.
  53. */
  54. virtual const char* GetFullDocumentation()
  55. {
  56. return
  57. " find_package(<name> [major.minor] [QUIET] [NO_MODULE]\n"
  58. " [[REQUIRED|COMPONENTS] [components...]])\n"
  59. "Finds and loads settings from an external project. <name>_FOUND will "
  60. "be set to indicate whether the package was found. Settings that "
  61. "can be used when <name>_FOUND is true are package-specific. The "
  62. "package is found through several steps. "
  63. "Directories listed in CMAKE_MODULE_PATH are searched for files called "
  64. "\"Find<name>.cmake\". If such a file is found, it is read and "
  65. "processed by CMake, and is responsible for finding the package. "
  66. "This first step may be skipped by using the NO_MODULE option. "
  67. "If no such file is found, it is expected that the package is another "
  68. "project built by CMake that has a \"<name>Config.cmake\" file. "
  69. "A cache entry called <name>_DIR is created and is expected to be set "
  70. "to the directory containing this file. If the file is found, it is "
  71. "read and processed by CMake to load the settings of the package. If "
  72. "<name>_DIR has not been set during a configure step, the command "
  73. "will generate an error describing the problem unless the QUIET "
  74. "argument is specified. If <name>_DIR has been set to a directory "
  75. "not containing a \"<name>Config.cmake\" file, an error is always "
  76. "generated. If REQUIRED is specified and the package is not found, "
  77. "a FATAL_ERROR is generated and the configure step stops executing. "
  78. "A package-specific list of components may be listed after the "
  79. "REQUIRED option, or after the COMPONENTS option if no REQUIRED "
  80. "option is given.";
  81. }
  82. cmTypeMacro(cmFindPackageCommand, cmCommand);
  83. private:
  84. void AppendSuccessInformation(bool quiet);
  85. void AppendToProperty(const char* propertyName);
  86. bool FindModule(bool& found, bool quiet, bool required);
  87. bool FindConfig();
  88. std::string SearchForConfig() const;
  89. bool ReadListFile(const char* f);
  90. cmStdString Name;
  91. cmStdString Variable;
  92. cmStdString Config;
  93. std::vector<cmStdString> Builds;
  94. std::vector<cmStdString> Prefixes;
  95. std::vector<cmStdString> Relatives;
  96. };
  97. #endif