cmake-developer.7.rst 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. cmake-developer(7)
  2. ******************
  3. .. only:: html or latex
  4. .. contents::
  5. Introduction
  6. ============
  7. This manual is intended for reference by developers modifying the CMake
  8. source tree itself.
  9. Help
  10. ====
  11. Modules
  12. =======
  13. Note to authors of FindXxx.cmake files
  14. We would like all FindXxx.cmake files to produce consistent variable
  15. names.
  16. Please use the following consistent variable names for general use.
  17. Xxx_INCLUDE_DIRS
  18. The final set of include directories listed in one variable for use by client
  19. code. This should not be a cache entry.
  20. Xxx_LIBRARIES
  21. The libraries to link against to use Xxx. These should include full paths.
  22. This should not be a cache entry.
  23. Xxx_DEFINITIONS
  24. Definitions to use when compiling code that uses Xxx. This really shouldn't
  25. include options such as (-DHAS_JPEG)that a client source-code file uses to
  26. decide whether to #include <jpeg.h>
  27. Xxx_EXECUTABLE
  28. Where to find the Xxx tool.
  29. Xxx_Yyy_EXECUTABLE
  30. Where to find the Yyy tool that comes with Xxx.
  31. Xxx_LIBRARY_DIRS
  32. Optionally, the final set of library directories listed in one variable for
  33. use by client code. This should not be a cache entry.
  34. Xxx_ROOT_DIR
  35. Where to find the base directory of Xxx.
  36. Xxx_VERSION_Yy
  37. Expect Version Yy if true. Make sure at most one of these is ever true.
  38. Xxx_WRAP_Yy
  39. If False, do not try to use the relevant CMake wrapping command.
  40. Xxx_Yy_FOUND
  41. If False, optional Yy part of Xxx sytem is not available.
  42. Xxx_FOUND
  43. Set to false, or undefined, if we haven't found, or don't want to use Xxx.
  44. Xxx_NOT_FOUND_MESSAGE
  45. Should be set by config-files in the case that it has set Xxx_FOUND to FALSE.
  46. The contained message will be printed by the find_package() command and by
  47. find_package_handle_standard_args() to inform the user about the problem.
  48. Xxx_RUNTIME_LIBRARY_DIRS
  49. Optionally, the runtime library search path for use when running an
  50. executable linked to shared libraries. The list should be used by user code
  51. to create the PATH on windows or LD_LIBRARY_PATH on unix. This should not be
  52. a cache entry.
  53. Xxx_VERSION_STRING
  54. A human-readable string containing the version of the package found, if any.
  55. Xxx_VERSION_MAJOR
  56. The major version of the package found, if any.
  57. Xxx_VERSION_MINOR
  58. The minor version of the package found, if any.
  59. Xxx_VERSION_PATCH
  60. The patch version of the package found, if any.
  61. You do not have to provide all of the above variables. You should provide
  62. Xxx_FOUND under most circumstances. If Xxx is a library, then Xxx_LIBRARIES,
  63. should also be defined, and Xxx_INCLUDE_DIRS should usually be defined (I
  64. guess libm.a might be an exception)
  65. The following names should not usually be used in CMakeLists.txt files, but
  66. they may be usefully modified in users' CMake Caches to control stuff.
  67. Xxx_LIBRARY
  68. Name of Xxx Library. A User may set this and Xxx_INCLUDE_DIR to ignore to
  69. force non-use of Xxx.
  70. Xxx_Yy_LIBRARY
  71. Name of Yy library that is part of the Xxx system. It may or may not be
  72. required to use Xxx.
  73. Xxx_INCLUDE_DIR
  74. Where to find xxx.h, etc. (Xxx_INCLUDE_PATH was considered bad because a path
  75. includes an actual filename.)
  76. Xxx_Yy_INCLUDE_DIR
  77. Where to find xxx_yy.h, etc.
  78. For tidiness's sake, try to keep as many options as possible out of the cache,
  79. leaving at least one option which can be used to disable use of the module, or
  80. locate a not-found library (e.g. Xxx_ROOT_DIR). For the same reason, mark
  81. most cache options as advanced.
  82. If you need other commands to do special things then it should still begin
  83. with ``Xxx_``. This gives a sort of namespace effect and keeps things tidy for the
  84. user. You should put comments describing all the exported settings, plus
  85. descriptions of any the users can use to control stuff.
  86. You really should also provide backwards compatibility any old settings that
  87. were actually in use. Make sure you comment them as deprecated, so that
  88. no-one starts using them.
  89. To add a module to the CMake documentation, follow these steps:
  90. 1. Add file ``Help/module/FindXxx.rst`` containing just the line::
  91. .. cmake-module:: ../../Modules/FindXxx.cmake
  92. 2. Modify ``Help/manual/cmake-modules.7.rst`` to reference the module in the
  93. toctree directive as::
  94. /module/FindXxx
  95. Keep the toctree in sorted order!
  96. 3. Add to the top of ``Modules/FindXxx.cmake`` a #-comment of the form::
  97. #.rst:
  98. # FindXxx
  99. # -------
  100. #
  101. # ...reStructuredText documentation of module...
  102. Comment blocks starting with the line ``#.rst:`` may appear anywhere
  103. in the file.
  104. For example::
  105. #.rst:
  106. # FindXxx
  107. # -------
  108. #
  109. # This is a cool module.
  110. # This module does really cool stuff.
  111. # It can do even more than you think.
  112. #
  113. # It even needs two paragraphs to tell you about it.
  114. # And it defines the following variables:
  115. #
  116. # * VAR_COOL: this is great isn't it?
  117. # * VAR_REALLY_COOL: cool right?
  118. Test the documentation formatting by running cmake --help-module FindXxx,
  119. and ideally by enabling the SPHINX_HTML and SPHINX_MAN options to
  120. build the documentation. Edit the comments until generated documentation
  121. looks satisfactory. To have a .cmake file in this directory NOT show up in
  122. the modules documentation, simply leave out the ``Help/module/<module>.rst``
  123. file and the ``Help/manual/cmake-modules.7.rst`` toctree entry.
  124. After the documentation, leave a *BLANK* line, and then add a
  125. copyright and licence notice block like this one::
  126. #=============================================================================
  127. # Copyright 2009-2011 Your Name
  128. #
  129. # Distributed under the OSI-approved BSD License (the "License");
  130. # see accompanying file Copyright.txt for details.
  131. #
  132. # This software is distributed WITHOUT ANY WARRANTY; without even the
  133. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  134. # See the License for more information.
  135. #=============================================================================
  136. # (To distribute this file outside of CMake, substitute the full
  137. # License text for the above reference.)
  138. The layout of the notice block is strictly enforced by the ``ModuleNotices``
  139. test. Only the year range and name may be changed freely.
  140. A FindXxx.cmake module will typically be loaded by the command::
  141. FIND_PACKAGE(Xxx [major[.minor[.patch[.tweak]]]] [EXACT]
  142. [QUIET] [[REQUIRED|COMPONENTS] [components...]])
  143. If any version numbers are given to the command it will set the following
  144. variables before loading the module:
  145. Xxx_FIND_VERSION
  146. full requested version string
  147. Xxx_FIND_VERSION_MAJOR
  148. major version if requested, else 0
  149. Xxx_FIND_VERSION_MINOR
  150. minor version if requested, else 0
  151. Xxx_FIND_VERSION_PATCH
  152. patch version if requested, else 0
  153. Xxx_FIND_VERSION_TWEAK
  154. tweak version if requested, else 0
  155. Xxx_FIND_VERSION_COUNT
  156. number of version components, 0 to 4
  157. Xxx_FIND_VERSION_EXACT
  158. true if EXACT option was given
  159. If the find module supports versioning it should locate a version of
  160. the package that is compatible with the version requested. If a
  161. compatible version of the package cannot be found the module should
  162. not report success. The version of the package found should be stored
  163. in "Xxx_VERSION..." version variables documented by the module.
  164. If the QUIET option is given to the command it will set the variable
  165. Xxx_FIND_QUIETLY to true before loading the FindXxx.cmake module. If
  166. this variable is set the module should not complain about not being
  167. able to find the package. If the
  168. REQUIRED option is given to the command it will set the variable
  169. Xxx_FIND_REQUIRED to true before loading the FindXxx.cmake module. If
  170. this variable is set the module should issue a FATAL_ERROR if the
  171. package cannot be found.
  172. If neither the QUIET nor REQUIRED options are given then the
  173. FindXxx.cmake module should look for the package and complain without
  174. error if the module is not found.
  175. FIND_PACKAGE() will set the variable CMAKE_FIND_PACKAGE_NAME to
  176. contain the actual name of the package.
  177. A package can provide sub-components.
  178. Those components can be listed after the COMPONENTS (or REQUIRED) or
  179. OPTIONAL_COMPONENTS keywords. The set of all listed components will be
  180. specified in a Xxx_FIND_COMPONENTS variable.
  181. For each package-specific component, say Yyy, a variable Xxx_FIND_REQUIRED_Yyy
  182. will be set to true if it listed after COMPONENTS and it will be set to false
  183. if it was listed after OPTIONAL_COMPONENTS.
  184. Using those variables a FindXxx.cmake module and also a XxxConfig.cmake
  185. package configuration file can determine whether and which components have
  186. been requested, and whether they were requested as required or as optional.
  187. For each of the requested components a Xxx_Yyy_FOUND variable should be set
  188. accordingly.
  189. The per-package Xxx_FOUND variable should be only set to true if all requested
  190. required components have been found. A missing optional component should not
  191. keep the Xxx_FOUND variable from being set to true.
  192. If the package provides Xxx_INCLUDE_DIRS and Xxx_LIBRARIES variables, the
  193. include dirs and libraries for all components which were requested and which
  194. have been found should be added to those two variables.
  195. To get this behaviour you can use the FIND_PACKAGE_HANDLE_STANDARD_ARGS()
  196. macro, as an example see FindJPEG.cmake.
  197. For internal implementation, it's a generally accepted convention that
  198. variables starting with underscore are for temporary use only. (variable
  199. starting with an underscore are not intended as a reserved prefix).