.
. RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .rstReportMargin post:
.. . RE indent \\n[an-margin]
old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1 new: \\n[rst2man-indent\\n[rst2man-indent-level]]
..
CMake Domain directives Directives defined in the \%CMake Domain for defining CMake documentation objects are printed in command-line help output as if the lines were normal paragraph text with interpretation.
CMake Domain interpreted text roles Interpreted text roles defined in the \%CMake Domain for cross-referencing CMake documentation objects are replaced by their link text in command-line help output. Other roles are printed literally and not processed.
code-block directive Add a literal code block without interpretation. The command-line help processor prints the block content without the leading directive line and with common indentation replaced by one space.
include directive Include another document source file. The command-line help processor prints the included document inline with the referencing document.
literal block after :: A paragraph ending in :: followed by a blank line treats the following indented block as literal text without interpretation. The command-line help processor prints the :: literally and prints the block content with common indentation replaced by one space.
note directive Call out a side note. The command-line help processor prints the block content as if the lines were normal paragraph text with interpretation.
parsed-literal directive Add a literal block with markup interpretation. The command-line help processor prints the block content without the leading directive line and with common indentation replaced by one space.
productionlist directive Render context-free grammar productions. The command-line help processor prints the block content as if the lines were normal paragraph text with interpretation.
replace directive Define a |substitution| replacement. The command-line help processor requires a substitution replacement to be defined before it is referenced.
|substitution| reference Reference a substitution replacement previously defined by the replace directive. The command-line help processor performs the substitution and replaces all newlines in the replacement text with spaces.
toctree directive Include other document sources in the Table-of-Contents document tree. The command-line help processor prints the referenced documents inline as part of the referencing document. NINDENT Inline markup constructs not listed above are printed literally in the command-line help output. We prefer to use inline markup constructs that look correct in source form, so avoid use of \e-escapes in favor of inline literals when possible. Explicit markup blocks not matching directives listed above are removed from command-line help output. Do not use them, except for plain .. comments that are removed by Sphinx too. Note that nested indentation of blocks is not recognized by the command-line help processor. Therefore: NDENT 0.0
command A CMake language command.
generator A CMake native build system generator. See the cmake(1) command-line tool\(aqs -G option.
manual A CMake manual page, like this \%cmake-developer(7) manual.
module A CMake module. See the cmake-modules(7) manual and the include() command.
policy A CMake policy. See the cmake-policies(7) manual and the cmake_policy() command.
prop_cache, prop_dir, prop_gbl, prop_sf, prop_inst, prop_test, prop_tgt A CMake cache, directory, global, source file, installed file, test, or target property, respectively. See the cmake-properties(7) manual and the set_property() command.
variable A CMake language variable. See the cmake-variables(7) manual and the set() command. NINDENT Documentation objects in the CMake Domain come from two sources. First, the CMake extension to Sphinx transforms every document named with the form Help/<type>/<file-name>.rst to a domain object with type <type>. The object name is extracted from the document title, which is expected to be of the form: NDENT 0.0 NDENT 3.5
<object-name> -------------NINDENT NINDENT and to appear at or near the top of the .rst file before any other lines starting in a letter, digit, or <. If no such title appears literally in the .rst file, the object name is the <file-name>. If a title does appear, it is expected that <file-name> is equal to <object-name> with any < and > characters removed. Second, the CMake Domain provides directives to define objects inside other documents: NDENT 0.0 NDENT 3.5
.. command:: <command-name> This indented block documents <command-name>. .. variable:: <variable-name> This indented block documents <variable-name>.NINDENT NINDENT Object types for which no directive is available must be defined using the first approach above.
:type:\(ganame\(ga :type:\(gatext <name>\(gaNINDENT NINDENT where type is the domain object type and name is the domain object name. In the first form the link text will be name (or name() if the type is command) and in the second form the link text will be the explicit text. For example, the code: NDENT 0.0 NDENT 3.5
* The :command:\(galist\(ga command. * The :command:\(galist(APPEND)\(ga sub-command. * The :command:\(galist() command <list>\(ga. * The :command:\(galist(APPEND) sub-command <list>\(ga. * The :variable:\(gaCMAKE_VERSION\(ga variable. * The :prop_tgt:\(gaOUTPUT_NAME_<CONFIG>\(ga target property.NINDENT NINDENT produces: NDENT 0.0
Title Text ----------NINDENT NINDENT Capitalize the first letter of each non-minor word in the title. The section header underline character hierarchy is NDENT 0.0
... preceding paragraph. Normal Libraries ^^^^^^^^^^^^^^^^ :: add_library(<lib> ...) This signature is used for ...NINDENT NINDENT Signatures of commands should wrap optional parts with square brackets, and should mark list of optional arguments with an ellipsis (...). Elements of the signature which are specified by the user should be specified with angle brackets, and may be referred to in prose using inline-literal syntax.
If \(ga\(gaWIN32\(ga\(ga is used with :command:\(gaadd_executable\(ga, the :prop_tgt:\(gaWIN32_EXECUTABLE\(ga target property is enabled. That command creates the file \(ga\(ga<name>.exe\(ga\(ga on Windows.NINDENT NINDENT
This command creates an :ref:\(gaImported Target <Imported Targets>\(ga.NINDENT NINDENT instead of: NDENT 0.0 NDENT 3.5
This command creates an :prop_tgt:\(gaIMPORTED\(ga target.NINDENT NINDENT The latter should be used only when referring specifically to the property. References to manual sections are not automatically created by creating a section, but code such as: NDENT 0.0 NDENT 3.5
.. _\(gaImported Targets\(ga:NINDENT NINDENT creates a suitable anchor. Use an anchor name which matches the name of the corresponding section. Refer to the anchor using a cross-reference with specified text. Imported Targets need the IMPORTED term marked up with care in particular because the term may refer to a command keyword (IMPORTED), a target property (IMPORTED), or a concept (Imported Targets). Where a property, command or variable is related conceptually to others, by for example, being related to the buildsystem description, generator expressions or Qt, each relevant property, command or variable should link to the primary manual, which provides high-level information. Only particular information relating to the command should be in the documentation of the command.
Set the :prop_tgt:\(gaAUTOMOC\(ga target property to \(ga\(gaON\(ga\(ga.NINDENT NINDENT Instead of NDENT 0.0 NDENT 3.5
Set the target property :prop_tgt:\(gaAUTOMOC\(ga to \(ga\(gaON\(ga\(ga.NINDENT NINDENT The policy directive is an exception, and the type us usually referred to before the link: NDENT 0.0 NDENT 3.5
If policy :prop_tgt:\(gaCMP0022\(ga is set to \(ga\(gaNEW\(ga\(ga the behavior is ...NINDENT NINDENT However, markup self-references with inline-literal syntax. For example, within the add_executable() command documentation, use NDENT 0.0 NDENT 3.5
\(ga\(gaadd_executable\(ga\(gaNINDENT NINDENT not NDENT 0.0 NDENT 3.5
:command:\(gaadd_executable\(gaNINDENT NINDENT which is used elsewhere.
/module/<module-name>NINDENT NINDENT Then add the module document file Help/module/<module-name>.rst containing just the line: NDENT 0.0 NDENT 3.5
.. cmake-module:: ../../Modules/<module-name>.cmakeNINDENT NINDENT The cmake-module directive will scan the module file to extract reStructuredText markup from comment blocks that start in .rst:. Add to the top of Modules/<module-name>.cmake a Line Comment block of the form: NDENT 0.0 NDENT 3.5
#.rst: # <module-name> # ------------- # # <reStructuredText documentation of module>NINDENT NINDENT or a Bracket Comment of the form: NDENT 0.0 NDENT 3.5
#[[.rst: <module-name> ------------- <reStructuredText documentation of module> #]]NINDENT NINDENT Any number of = may be used in the opening and closing brackets as long as they match. Content on the line containing the closing bracket is excluded if and only if the line starts in #. Additional such .rst: comments may appear anywhere in the module file. All such comments must start with # in the first column. For example, a Modules/Findxxx.cmake module may contain: NDENT 0.0 NDENT 3.5
#.rst: # FindXxx # ------- # # This is a cool module. # This module does really cool stuff. # It can do even more than you think. # # It even needs two paragraphs to tell you about it. # And it defines the following variables: # # * VAR_COOL: this is great isn\(aqt it? # * VAR_REALLY_COOL: cool right? <code> #[========================================[.rst: .. command:: xxx_do_something This command does something for Xxx:: xxx_do_something(some arguments) #]========================================] macro(xxx_do_something) <code> endmacro()NINDENT NINDENT After the top documentation block, leave a BLANK line, and then add a copyright and licence notice block like this one (change only the year range and name) NDENT 0.0 NDENT 3.5
#============================================================================= # Copyright 2009-2011 Your Name # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.)NINDENT NINDENT Test the documentation formatting by running cmake --help-module <module-name>, and also by enabling the SPHINX_HTML and SPHINX_MAN options to build the documentation. Edit the comments until generated documentation looks satisfactory. To have a .cmake file in this directory NOT show up in the modules documentation, simply leave out the Help/module/<module-name>.rst file and the Help/manual/cmake-modules.7.rst toctree entry.
find_package(Foo [major[.minor[.patch[.tweak]]]] [EXACT] [QUIET] [REQUIRED] [[COMPONENTS] [components...]] [OPTIONAL_COMPONENTS components...] [NO_POLICY_SCOPE])NINDENT NINDENT See the find_package() documentation for details on what variables are set for the find module. Most of these are dealt with by using FindPackageHandleStandardArgs. Briefly, the module should only locate versions of the package compatible with the requested version, as described by the Foo_FIND_VERSION family of variables. If Foo_FIND_QUIETLY is set to true, it should avoid printing messages, including anything complaining about the package not being found. If Foo_FIND_REQUIRED is set to true, the module should issue a FATAL_ERROR if the package cannot be found. If neither are set to true, it should print a non-fatal message if it cannot find the package. Packages that find multiple semi-independent parts (like bundles of libraries) should search for the components listed in Foo_FIND_COMPONENTS if it is set , and only set Foo_FOUND to true if for each searched-for component <c> that was not found, Foo_FIND_REQUIRED_<c> is not set to true. The HANDLE_COMPONENTS argument of find_package_handle_standard_args() can be used to implement this. If Foo_FIND_COMPONENTS is not set, which modules are searched for and required is up to the find module, but should be documented. For internal implementation, it is a generally accepted convention that variables starting with underscore are for temporary use only. Like all modules, find modules should be properly documented. To add a module to the CMake documentation, follow the steps in the \%Module Documentation section above.
Xxx_INCLUDE_DIRS The final set of include directories listed in one variable for use by client code. This should not be a cache entry.
Xxx_LIBRARIES The libraries to link against to use Xxx. These should include full paths. This should not be a cache entry.
Xxx_DEFINITIONS Definitions to use when compiling code that uses Xxx. This really shouldn\(aqt include options such as -DHAS_JPEG that a client source-code file uses to decide whether to #include <jpeg.h>
Xxx_EXECUTABLE Where to find the Xxx tool.
Xxx_Yyy_EXECUTABLE Where to find the Yyy tool that comes with Xxx.
Xxx_LIBRARY_DIRS Optionally, the final set of library directories listed in one variable for use by client code. This should not be a cache entry.
Xxx_ROOT_DIR Where to find the base directory of Xxx.
Xxx_VERSION_Yy Expect Version Yy if true. Make sure at most one of these is ever true.
Xxx_WRAP_Yy If False, do not try to use the relevant CMake wrapping command.
Xxx_Yy_FOUND If False, optional Yy part of Xxx sytem is not available.
Xxx_FOUND Set to false, or undefined, if we haven\(aqt found, or don\(aqt want to use Xxx.
Xxx_NOT_FOUND_MESSAGE Should be set by config-files in the case that it has set Xxx_FOUND to FALSE. The contained message will be printed by the find_package() command and by find_package_handle_standard_args() to inform the user about the problem.
Xxx_RUNTIME_LIBRARY_DIRS Optionally, the runtime library search path for use when running an executable linked to shared libraries. The list should be used by user code to create the PATH on windows or LD_LIBRARY_PATH on UNIX. This should not be a cache entry.
Xxx_VERSION The full version string of the package found, if any. Note that many existing modules provide Xxx_VERSION_STRING instead.
Xxx_VERSION_MAJOR The major version of the package found, if any.
Xxx_VERSION_MINOR The minor version of the package found, if any.
Xxx_VERSION_PATCH The patch version of the package found, if any. NINDENT The following names should not usually be used in CMakeLists.txt files, but are typically cache variables for users to edit and control the behaviour of find modules (like entering the path to a library manually) NDENT 0.0
Xxx_LIBRARY The path of the Xxx library (as used with find_library(), for example).
Xxx_Yy_LIBRARY The path of the Yy library that is part of the Xxx system. It may or may not be required to use Xxx.
Xxx_INCLUDE_DIR Where to find headers for using the Xxx library.
Xxx_Yy_INCLUDE_DIR Where to find headers for using the Yy library of the Xxx system. NINDENT To prevent users being overwhelmed with settings to configure, try to keep as many options as possible out of the cache, leaving at least one option which can be used to disable use of the module, or locate a not-found library (e.g. Xxx_ROOT_DIR). For the same reason, mark most cache options as advanced. For packages which provide both debug and release binaries, it is common to create cache variables with a _LIBRARY_<CONFIG> suffix, such as Foo_LIBRARY_RELEASE and Foo_LIBRARY_DEBUG. While these are the standard variable names, you should provide backwards compatibility for any old names that were actually in use. Make sure you comment them as deprecated, so that no-one starts using them.
#.rst: # FindFoo # ------- # # Finds the Foo library #NINDENT NINDENT More description may be required for some packages. If there are caveats or other details users of the module should be aware of, you can add further paragraphs below this. Then you need to document what variables and imported targets are set by the module, such as NDENT 0.0 NDENT 3.5
# This will define the following variables:: # # Foo_FOUND - True if the system has the Foo library # Foo_VERSION - The version of the Foo library which was found # # and the following imported targets:: # # Foo::Foo - The Foo libraryNINDENT NINDENT If the package provides any macros, they should be listed here, but can be documented where they are defined. See the \%Module Documentation section above for more details. After the documentation, leave a blank line, and then add a copyright and licence notice block NDENT 0.0 NDENT 3.5
#============================================================================= # Copyright 2009-2011 Your Name # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.)NINDENT NINDENT Now the actual libraries and so on have to be found. The code here will obviously vary from module to module (dealing with that, after all, is the point of find modules), but there tends to be a common pattern for libraries. First, we try to use pkg-config to find the library. Note that we cannot rely on this, as it may not be available, but it provides a good starting point. NDENT 0.0 NDENT 3.5
find_package(PkgConfig) pkg_check_modules(PC_Foo QUIET Foo)NINDENT NINDENT This should define some variables starting PC_Foo_ that contain the information from the Foo.pc file. Now we need to find the libraries and include files; we use the information from pkg-config to provide hints to CMake about where to look. NDENT 0.0 NDENT 3.5
find_path(Foo_INCLUDE_DIR NAMES foo.h PATHS ${PC_Foo_INCLUDE_DIRS} PATH_SUFFIXES Foo ) find_library(Foo_LIBRARY NAMES foo PATHS ${PC_Foo_LIBRARY_DIRS} )NINDENT NINDENT If you have a good way of getting the version (from a header file, for example), you can use that information to set Foo_VERSION (although note that find modules have traditionally used Foo_VERSION_STRING, so you may want to set both). Otherwise, attempt to use the information from pkg-config NDENT 0.0 NDENT 3.5
set(Foo_VERSION ${PC_Foo_VERSION})NINDENT NINDENT Now we can use FindPackageHandleStandardArgs to do most of the rest of the work for us NDENT 0.0 NDENT 3.5
include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Foo FOUND_VAR Foo_FOUND REQUIRED_VARS Foo_LIBRARY Foo_INCLUDE_DIR VERSION_VAR Foo_VERSION )NINDENT NINDENT This will check that the REQUIRED_VARS contain values (that do not end in -NOTFOUND) and set Foo_FOUND appropriately. It will also cache those values. If Foo_VERSION is set, and a required version was passed to find_package(), it will check the requested version against the one in Foo_VERSION. It will also print messages as appropriate; note that if the package was found, it will print the contents of the first required variable to indicate where it was found. At this point, we have to provide a way for users of the find module to link to the library or libraries that were found. There are two approaches, as discussed in the \%Find Modules section above. The traditional variable approach looks like NDENT 0.0 NDENT 3.5
if(Foo_FOUND) set(Foo_LIBRARIES ${Foo_LIBRARY}) set(Foo_INCLUDE_DIRS ${Foo_INCLUDE_DIR}) set(Foo_DEFINITIONS ${PC_Foo_CFLAGS_OTHER}) endif()NINDENT NINDENT If more than one library was found, all of them should be included in these variables (see the \%Standard Variable Names section for more information). When providing imported targets, these should be namespaced (hence the Foo:: prefix); CMake will recognize that values passed to target_link_libraries() that contain :: in their name are supposed to be imported targets (rather than just library names), and will produce appropriate diagnostic messages if that target does not exist (see policy CMP0028). NDENT 0.0 NDENT 3.5
if(Foo_FOUND AND NOT TARGET Foo::Foo) add_library(Foo::Foo UNKNOWN IMPORTED) set_target_properties(Foo::Foo PROPERTIES IMPORTED_LOCATION "${Foo_LIBRARY}" INTERFACE_COMPILE_OPTIONS "${PC_Foo_CFLAGS_OTHER}" INTERFACE_INCLUDE_DIRECTORIES "${Foo_INCLUDE_DIR}" ) endif()NINDENT NINDENT One thing to note about this is that the INTERFACE_INCLUDE_DIRECTORIES and similar properties should only contain information about the target itself, and not any of its dependencies. Instead, those dependencies should also be targets, and CMake should be told that they are dependencies of this target. CMake will then combine all the necessary information automatically. The type of the IMPORTED target created in the add_library() command can always be specified as UNKNOWN type. This simplifies the code in cases where static or shared variants may be found, and CMake will determine the type by inspecting the files. If the library is available with multiple configurations, the IMPORTED_CONFIGURATIONS target property should also be populated: NDENT 0.0 NDENT 3.5
if(Foo_FOUND) if (NOT TARGET Foo::Foo) add_library(Foo::Foo UNKNOWN IMPORTED) endif() if (Foo_LIBRARY_RELEASE) set_property(TARGET Foo::Foo APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE ) set_target_properties(Foo::Foo PROPERTIES IMPORTED_LOCATION_RELEASE "${Foo_LIBRARY_RELEASE}" ) endif() if (Foo_LIBRARY_DEBUG) set_property(TARGET Foo::Foo APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG ) set_target_properties(Foo::Foo PROPERTIES IMPORTED_LOCATION_DEBUG "${Foo_LIBRARY_DEBUG}" ) endif() set_target_properties(Foo::Foo PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Foo_CFLAGS_OTHER}" INTERFACE_INCLUDE_DIRECTORIES "${Foo_INCLUDE_DIR}" ) endif()NINDENT NINDENT The RELEASE variant should be listed first in the property so that that variant is chosen if the user uses a configuration which is not an exact match for any listed IMPORTED_CONFIGURATIONS. Most of the cache variables should be hidden in the ccmake interface unless the user explicitly asks to edit them. NDENT 0.0 NDENT 3.5
mark_as_advanced( Foo_INCLUDE_DIR Foo_LIBRARY )NINDENT NINDENT If this module replaces an older version, you should set compatibility variables to cause the least disruption possible. NDENT 0.0 NDENT 3.5
# compatibility variables set(Foo_VERSION_STRING ${Foo_VERSION})NINDENT NINDENT
.