Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/ide-integration/index.rst.txt +161 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/importing-exporting/index.rst.txt +772 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/A Basic Starting Point.rst.txt +460 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding Export Configuration.rst.txt +140 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding Generator Expressions.rst.txt +168 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding Support for a Testing Dashboard.rst.txt +110 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding System Introspection.rst.txt +163 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding Usage Requirements for a Library.rst.txt +323 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding a Custom Command and Generated File.rst.txt +103 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding a Library.rst.txt +455 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Installing and Testing.rst.txt +311 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Packaging Debug and Release.rst.txt +86 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Packaging an Installer.rst.txt +62 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Selecting Static or Shared Libraries.rst.txt +50 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/index.rst.txt +44 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/user-interaction/index.rst.txt +772 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/using-dependencies/index.rst.txt +419 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/ADVANCED.rst.txt +8 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/HELPSTRING.rst.txt +7 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/MODIFIED.rst.txt +7 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/STRINGS.rst.txt +9 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/TYPE.rst.txt +21 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/VALUE.rst.txt +7 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst.txt +21 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOGEN_SOURCE_GROUP.rst.txt +18 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst.txt +9 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOMOC_SOURCE_GROUP.rst.txt +9 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst.txt +11 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTORCC_SOURCE_GROUP.rst.txt +9 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOUIC_SOURCE_GROUP.rst.txt +9 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/CMAKE_CUDA_KNOWN_FEATURES.rst.txt +44 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst.txt +367 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst.txt +57 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/CMAKE_ROLE.rst.txt +22 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/DEBUG_CONFIGURATIONS.rst.txt +13 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/DISABLED_FEATURES.rst.txt +11 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ECLIPSE_EXTRA_CPROJECT_CONTENTS.rst.txt +14 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ECLIPSE_EXTRA_NATURES.rst.txt +10 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ENABLED_FEATURES.rst.txt +11 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ENABLED_LANGUAGES.rst.txt +6 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/FIND_LIBRARY_USE_LIB32_PATHS.rst.txt +14 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS.rst.txt +12 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/FIND_LIBRARY_USE_LIBX32_PATHS.rst.txt +14 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING.rst.txt +10 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/GENERATOR_IS_MULTI_CONFIG.rst.txt +15 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/GLOBAL_DEPENDS_DEBUG_MODE.rst.txt +8 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/GLOBAL_DEPENDS_NO_CYCLES.rst.txt +10 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/IN_TRY_COMPILE.rst.txt +7 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/JOB_POOLS.rst.txt +31 -0
- toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/PACKAGES_FOUND.rst.txt +7 -0
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/ide-integration/index.rst.txt
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
IDE Integration Guide
|
| 2 |
+
*********************
|
| 3 |
+
|
| 4 |
+
.. only:: html
|
| 5 |
+
|
| 6 |
+
.. contents::
|
| 7 |
+
|
| 8 |
+
Introduction
|
| 9 |
+
============
|
| 10 |
+
|
| 11 |
+
Integrated development environments (IDEs) may want to integrate with CMake to
|
| 12 |
+
improve the development experience for CMake users. This document lays out the
|
| 13 |
+
recommended best practices for such integration.
|
| 14 |
+
|
| 15 |
+
Bundling
|
| 16 |
+
========
|
| 17 |
+
|
| 18 |
+
Many IDE vendors will want to bundle a copy of CMake with their IDE. IDEs that
|
| 19 |
+
bundle CMake should present the user with the option of using an external CMake
|
| 20 |
+
installation instead of the bundled one, in case the bundled copy becomes
|
| 21 |
+
outdated and the user wants to use a newer version.
|
| 22 |
+
|
| 23 |
+
While IDE vendors may be tempted to bundle different versions of CMake with
|
| 24 |
+
their application, such practice is not recommended. CMake has strong
|
| 25 |
+
guarantees of backwards compatibility, and there is no reason not to use a
|
| 26 |
+
newer version of CMake than what a project requires, or indeed, the very latest
|
| 27 |
+
version. Therefore, it is recommended that IDE vendors that bundle CMake with
|
| 28 |
+
their application always include the very latest patch version of CMake
|
| 29 |
+
available at the time of release.
|
| 30 |
+
|
| 31 |
+
As a suggestion, IDEs may also ship a copy of the Ninja buildsystem alongside
|
| 32 |
+
CMake. Ninja is highly performant and well-supported on all platforms that
|
| 33 |
+
support CMake. IDEs that bundle Ninja should use Ninja 1.10 or later, which
|
| 34 |
+
contains features needed to support Fortran builds.
|
| 35 |
+
|
| 36 |
+
Presets
|
| 37 |
+
=======
|
| 38 |
+
|
| 39 |
+
CMake supports a file format called ``CMakePresets.json``, and its
|
| 40 |
+
user-specific counterpart, ``CMakeUserPresets.json``. This file contains
|
| 41 |
+
information on the various configure presets that a user may want. Each preset
|
| 42 |
+
may have a different compiler, build flags, etc. The details of this format are
|
| 43 |
+
explained in the :manual:`cmake(1)` manual.
|
| 44 |
+
|
| 45 |
+
IDE vendors are encouraged to read and evaluate this file the same way CMake
|
| 46 |
+
does, and present the user with the presets listed in the file. Users should be
|
| 47 |
+
able to see (and possibly edit) the CMake cache variables, environment
|
| 48 |
+
variables, and command line options that are defined for a given preset. The
|
| 49 |
+
IDE should then construct the list of appropriate :manual:`cmake(1)` command
|
| 50 |
+
line arguments based on these settings, rather than using the
|
| 51 |
+
:option:`--preset= <cmake --preset>` option directly. The
|
| 52 |
+
:option:`--preset= <cmake --preset>` option is intended only as a convenient
|
| 53 |
+
frontend for command line users, and should not be used by the IDE.
|
| 54 |
+
|
| 55 |
+
For example, if a preset named ``ninja`` specifies ``Ninja`` as the generator
|
| 56 |
+
and ``${sourceDir}/build`` as the build directory, instead of running:
|
| 57 |
+
|
| 58 |
+
.. code-block:: console
|
| 59 |
+
|
| 60 |
+
cmake -S /path/to/source --preset=ninja
|
| 61 |
+
|
| 62 |
+
the IDE should instead calculate the settings of the ``ninja`` preset, and then
|
| 63 |
+
run:
|
| 64 |
+
|
| 65 |
+
.. code-block:: console
|
| 66 |
+
|
| 67 |
+
cmake -S /path/to/source -B /path/to/source/build -G Ninja
|
| 68 |
+
|
| 69 |
+
In cases where a preset contains lots of cache variables, and passing all of
|
| 70 |
+
them as :option:`-D <cmake -D>` flags would cause the command line length limit
|
| 71 |
+
of the platform to be exceeded, the IDE should instead construct a temporary
|
| 72 |
+
cache script and pass it with the :option:`-C <cmake -C>` flag.
|
| 73 |
+
|
| 74 |
+
While reading, parsing, and evaluating the contents of ``CMakePresets.json`` is
|
| 75 |
+
straightforward, it is not trivial. In addition to the documentation, IDE
|
| 76 |
+
vendors may also wish to refer to the CMake source code and test cases for a
|
| 77 |
+
better understanding of how to implement the format.
|
| 78 |
+
:download:`This file <../../manual/presets/schema.json>` provides a
|
| 79 |
+
machine-readable JSON schema for the ``CMakePresets.json`` format that IDE
|
| 80 |
+
vendors may find useful for validation and providing editing assistance.
|
| 81 |
+
|
| 82 |
+
Configuring
|
| 83 |
+
===========
|
| 84 |
+
|
| 85 |
+
IDEs that invoke :manual:`cmake(1)` to run the configure step may wish to
|
| 86 |
+
receive information about the artifacts that the build will produce, as well
|
| 87 |
+
as the include directories, compile definitions, etc. used to build the
|
| 88 |
+
artifacts. Such information can be obtained by using the
|
| 89 |
+
:manual:`File API <cmake-file-api(7)>`. The manual page for the File API
|
| 90 |
+
contains more information about the API and how to invoke it.
|
| 91 |
+
:manual:`Server mode <cmake-server(7)>` was removed as of CMake 3.20 and
|
| 92 |
+
should not be used on CMake 3.14 or later.
|
| 93 |
+
|
| 94 |
+
IDEs should avoid creating more build trees than necessary, and only create
|
| 95 |
+
multiple build trees if the user wishes to switch to a different compiler,
|
| 96 |
+
use different compile flags, etc. In particular, IDEs should NOT create
|
| 97 |
+
multiple single-config build trees which all have the same properties except
|
| 98 |
+
for a differing :variable:`CMAKE_BUILD_TYPE`, effectively creating a
|
| 99 |
+
multi-config environment. Instead, the :generator:`Ninja Multi-Config`
|
| 100 |
+
generator, in conjunction with the :manual:`File API <cmake-file-api(7)>` to
|
| 101 |
+
get the list of build configurations, should be used for this purpose.
|
| 102 |
+
|
| 103 |
+
IDEs should not use the "extra generators" with Makefile or Ninja generators,
|
| 104 |
+
which generate IDE project files in addition to the Makefile or Ninja files.
|
| 105 |
+
Instead the :manual:`File API <cmake-file-api(7)>` should be used to get the
|
| 106 |
+
list of build artifacts.
|
| 107 |
+
|
| 108 |
+
Building
|
| 109 |
+
========
|
| 110 |
+
|
| 111 |
+
If a Makefile or Ninja generator is used to generate the build tree, it is not
|
| 112 |
+
recommended to invoke ``make`` or ``ninja`` directly. Instead, it is
|
| 113 |
+
recommended that the IDE invoke :manual:`cmake(1)` with the
|
| 114 |
+
:option:`--build <cmake --build>` argument, which will in turn invoke the
|
| 115 |
+
appropriate build tool.
|
| 116 |
+
|
| 117 |
+
If an IDE project generator is used, such as :generator:`Xcode` or one of the
|
| 118 |
+
Visual Studio generators, and the IDE understands the project format used, the
|
| 119 |
+
IDE should read the project file and build it the same way it would otherwise.
|
| 120 |
+
|
| 121 |
+
The :manual:`File API <cmake-file-api(7)>` can be used to obtain a list of
|
| 122 |
+
build configurations from the build tree, and the IDE should present this list
|
| 123 |
+
to the user to select a build configuration.
|
| 124 |
+
|
| 125 |
+
Testing
|
| 126 |
+
=======
|
| 127 |
+
|
| 128 |
+
:manual:`ctest(1)` supports outputting a JSON format with information about the
|
| 129 |
+
available tests and test configurations. IDEs which want to run CTest should
|
| 130 |
+
obtain this information and use it to present the user with a list of tests.
|
| 131 |
+
|
| 132 |
+
IDEs should not invoke the ``test`` target of the generated buildsystem.
|
| 133 |
+
Instead, they should invoke :manual:`ctest(1)` directly.
|
| 134 |
+
|
| 135 |
+
IDEs with CMake integration
|
| 136 |
+
===========================
|
| 137 |
+
|
| 138 |
+
The following IDEs support CMake natively:
|
| 139 |
+
|
| 140 |
+
* `CLion`_
|
| 141 |
+
* `KDevelop`_
|
| 142 |
+
* `QtCreator`_
|
| 143 |
+
* `Vim`_ (via a plugin)
|
| 144 |
+
* `Visual Studio`_
|
| 145 |
+
* `VSCode`_ (via a plugin)
|
| 146 |
+
|
| 147 |
+
.. _CLion: https://www.jetbrains.com/clion/
|
| 148 |
+
.. _KDevelop: https://kdevelop.org/
|
| 149 |
+
.. _QtCreator: https://www.qt.io/product/development-tools
|
| 150 |
+
.. _Vim: https://www.vim.org/
|
| 151 |
+
.. _Visual Studio: https://visualstudio.microsoft.com/
|
| 152 |
+
.. _VSCode: https://code.visualstudio.com/
|
| 153 |
+
|
| 154 |
+
Additionally, CMake has builtin support for some IDEs:
|
| 155 |
+
|
| 156 |
+
* :ref:`IDE Build Tool Generators`:
|
| 157 |
+
Generate IDE native build systems such as Visual Studio or Xcode.
|
| 158 |
+
* :ref:`Extra Generators`:
|
| 159 |
+
Extend :ref:`Command-Line Build Tool Generators` to generate IDE
|
| 160 |
+
project files that hook into the command-line build system.
|
| 161 |
+
Superseded by the :manual:`File API <cmake-file-api(7)>`.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/importing-exporting/index.rst.txt
ADDED
|
@@ -0,0 +1,772 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Importing and Exporting Guide
|
| 2 |
+
*****************************
|
| 3 |
+
|
| 4 |
+
.. only:: html
|
| 5 |
+
|
| 6 |
+
.. contents::
|
| 7 |
+
|
| 8 |
+
Introduction
|
| 9 |
+
============
|
| 10 |
+
|
| 11 |
+
In this guide, we will present the concept of :prop_tgt:`IMPORTED` targets
|
| 12 |
+
and demonstrate how to import existing executable or library files from disk
|
| 13 |
+
into a CMake project. We will then show how CMake supports exporting targets
|
| 14 |
+
from one CMake-based project and importing them into another. Finally, we
|
| 15 |
+
will demonstrate how to package a project with a configuration file to allow
|
| 16 |
+
for easy integration into other CMake projects. This guide and the complete
|
| 17 |
+
example source code can be found in the ``Help/guide/importing-exporting``
|
| 18 |
+
directory of the CMake source code tree.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Importing Targets
|
| 22 |
+
=================
|
| 23 |
+
|
| 24 |
+
:prop_tgt:`IMPORTED` targets are used to convert files outside of a CMake
|
| 25 |
+
project into logical targets inside of the project. :prop_tgt:`IMPORTED`
|
| 26 |
+
targets are created using the ``IMPORTED`` option of the
|
| 27 |
+
:command:`add_executable` and :command:`add_library` commands. No build
|
| 28 |
+
files are generated for :prop_tgt:`IMPORTED` targets. Once imported,
|
| 29 |
+
:prop_tgt:`IMPORTED` targets may be referenced like any other target within
|
| 30 |
+
the project and provide a convenient, flexible reference to outside
|
| 31 |
+
executables and libraries.
|
| 32 |
+
|
| 33 |
+
By default, the :prop_tgt:`IMPORTED` target name has scope in the directory in
|
| 34 |
+
which it is created and below. We can use the ``GLOBAL`` option to extended
|
| 35 |
+
visibility so that the target is accessible globally in the build system.
|
| 36 |
+
|
| 37 |
+
Details about the :prop_tgt:`IMPORTED` target are specified by setting
|
| 38 |
+
properties whose names begin in ``IMPORTED_`` and ``INTERFACE_``. For example,
|
| 39 |
+
:prop_tgt:`IMPORTED_LOCATION` contains the full path to the target on
|
| 40 |
+
disk.
|
| 41 |
+
|
| 42 |
+
Importing Executables
|
| 43 |
+
---------------------
|
| 44 |
+
|
| 45 |
+
To start, we will walk through a simple example that creates an
|
| 46 |
+
:prop_tgt:`IMPORTED` executable target and then references it from the
|
| 47 |
+
:command:`add_custom_command` command.
|
| 48 |
+
|
| 49 |
+
We'll need to do some setup to get started. We want to create an executable
|
| 50 |
+
that when run creates a basic ``main.cc`` file in the current directory. The
|
| 51 |
+
details of this project are not important. Navigate to
|
| 52 |
+
``Help/guide/importing-exporting/MyExe``, create a build directory, run
|
| 53 |
+
:manual:`cmake <cmake(1)>` and build and install the project.
|
| 54 |
+
|
| 55 |
+
.. code-block:: console
|
| 56 |
+
|
| 57 |
+
$ cd Help/guide/importing-exporting/MyExe
|
| 58 |
+
$ mkdir build
|
| 59 |
+
$ cd build
|
| 60 |
+
$ cmake ..
|
| 61 |
+
$ cmake --build .
|
| 62 |
+
$ cmake --install . --prefix <install location>
|
| 63 |
+
$ <install location>/myexe
|
| 64 |
+
$ ls
|
| 65 |
+
[...] main.cc [...]
|
| 66 |
+
|
| 67 |
+
Now we can import this executable into another CMake project. The source code
|
| 68 |
+
for this section is available in ``Help/guide/importing-exporting/Importing``.
|
| 69 |
+
In the CMakeLists file, use the :command:`add_executable` command to create a
|
| 70 |
+
new target called ``myexe``. Use the ``IMPORTED`` option to tell CMake that
|
| 71 |
+
this target references an executable file located outside of the project. No
|
| 72 |
+
rules will be generated to build it and the :prop_tgt:`IMPORTED` target
|
| 73 |
+
property will be set to ``true``.
|
| 74 |
+
|
| 75 |
+
.. literalinclude:: Importing/CMakeLists.txt
|
| 76 |
+
:language: cmake
|
| 77 |
+
:start-after: # Add executable
|
| 78 |
+
:end-before: # Set imported location
|
| 79 |
+
|
| 80 |
+
Next, set the :prop_tgt:`IMPORTED_LOCATION` property of the target using
|
| 81 |
+
the :command:`set_property` command. This will tell CMake the location of the
|
| 82 |
+
target on disk. The location may need to be adjusted to the
|
| 83 |
+
``<install location>`` specified in the previous step.
|
| 84 |
+
|
| 85 |
+
.. literalinclude:: Importing/CMakeLists.txt
|
| 86 |
+
:language: cmake
|
| 87 |
+
:start-after: # Set imported location
|
| 88 |
+
:end-before: # Add custom command
|
| 89 |
+
|
| 90 |
+
We can now reference this :prop_tgt:`IMPORTED` target just like any target
|
| 91 |
+
built within the project. In this instance, let's imagine that we want to use
|
| 92 |
+
the generated source file in our project. Use the :prop_tgt:`IMPORTED`
|
| 93 |
+
target in the :command:`add_custom_command` command:
|
| 94 |
+
|
| 95 |
+
.. literalinclude:: Importing/CMakeLists.txt
|
| 96 |
+
:language: cmake
|
| 97 |
+
:start-after: # Add custom command
|
| 98 |
+
:end-before: # Use source file
|
| 99 |
+
|
| 100 |
+
As ``COMMAND`` specifies an executable target name, it will automatically be
|
| 101 |
+
replaced by the location of the executable given by the
|
| 102 |
+
:prop_tgt:`IMPORTED_LOCATION` property above.
|
| 103 |
+
|
| 104 |
+
Finally, use the output from :command:`add_custom_command`:
|
| 105 |
+
|
| 106 |
+
.. literalinclude:: Importing/CMakeLists.txt
|
| 107 |
+
:language: cmake
|
| 108 |
+
:start-after: # Use source file
|
| 109 |
+
|
| 110 |
+
Importing Libraries
|
| 111 |
+
-------------------
|
| 112 |
+
|
| 113 |
+
In a similar manner, libraries from other projects may be accessed through
|
| 114 |
+
:prop_tgt:`IMPORTED` targets.
|
| 115 |
+
|
| 116 |
+
Note: The full source code for the examples in this section is not provided
|
| 117 |
+
and is left as an exercise for the reader.
|
| 118 |
+
|
| 119 |
+
In the CMakeLists file, add an :prop_tgt:`IMPORTED` library and specify its
|
| 120 |
+
location on disk:
|
| 121 |
+
|
| 122 |
+
.. code-block:: cmake
|
| 123 |
+
|
| 124 |
+
add_library(foo STATIC IMPORTED)
|
| 125 |
+
set_property(TARGET foo PROPERTY
|
| 126 |
+
IMPORTED_LOCATION "/path/to/libfoo.a")
|
| 127 |
+
|
| 128 |
+
Then use the :prop_tgt:`IMPORTED` library inside of our project:
|
| 129 |
+
|
| 130 |
+
.. code-block:: cmake
|
| 131 |
+
|
| 132 |
+
add_executable(myexe src1.c src2.c)
|
| 133 |
+
target_link_libraries(myexe PRIVATE foo)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
On Windows, a .dll and its .lib import library may be imported together:
|
| 137 |
+
|
| 138 |
+
.. code-block:: cmake
|
| 139 |
+
|
| 140 |
+
add_library(bar SHARED IMPORTED)
|
| 141 |
+
set_property(TARGET bar PROPERTY
|
| 142 |
+
IMPORTED_LOCATION "c:/path/to/bar.dll")
|
| 143 |
+
set_property(TARGET bar PROPERTY
|
| 144 |
+
IMPORTED_IMPLIB "c:/path/to/bar.lib")
|
| 145 |
+
add_executable(myexe src1.c src2.c)
|
| 146 |
+
target_link_libraries(myexe PRIVATE bar)
|
| 147 |
+
|
| 148 |
+
A library with multiple configurations may be imported with a single target:
|
| 149 |
+
|
| 150 |
+
.. code-block:: cmake
|
| 151 |
+
|
| 152 |
+
find_library(math_REL NAMES m)
|
| 153 |
+
find_library(math_DBG NAMES md)
|
| 154 |
+
add_library(math STATIC IMPORTED GLOBAL)
|
| 155 |
+
set_target_properties(math PROPERTIES
|
| 156 |
+
IMPORTED_LOCATION "${math_REL}"
|
| 157 |
+
IMPORTED_LOCATION_DEBUG "${math_DBG}"
|
| 158 |
+
IMPORTED_CONFIGURATIONS "RELEASE;DEBUG"
|
| 159 |
+
)
|
| 160 |
+
add_executable(myexe src1.c src2.c)
|
| 161 |
+
target_link_libraries(myexe PRIVATE math)
|
| 162 |
+
|
| 163 |
+
The generated build system will link ``myexe`` to ``m.lib`` when built in the
|
| 164 |
+
release configuration, and ``md.lib`` when built in the debug configuration.
|
| 165 |
+
|
| 166 |
+
Exporting Targets
|
| 167 |
+
=================
|
| 168 |
+
|
| 169 |
+
While :prop_tgt:`IMPORTED` targets on their own are useful, they still
|
| 170 |
+
require that the project that imports them knows the locations of the target
|
| 171 |
+
files on disk. The real power of :prop_tgt:`IMPORTED` targets is when the
|
| 172 |
+
project providing the target files also provides a CMake file to help import
|
| 173 |
+
them. A project can be setup to produce the necessary information so that it
|
| 174 |
+
can easily be used by other CMake projects be it from a build directory, a
|
| 175 |
+
local install or when packaged.
|
| 176 |
+
|
| 177 |
+
In the remaining sections, we will walk through a set of example projects
|
| 178 |
+
step-by-step. The first project will create and install a library and
|
| 179 |
+
corresponding CMake configuration and package files. The second project will
|
| 180 |
+
use the generated package.
|
| 181 |
+
|
| 182 |
+
Let's start by looking at the ``MathFunctions`` project in the
|
| 183 |
+
``Help/guide/importing-exporting/MathFunctions`` directory. Here we have a
|
| 184 |
+
header file ``MathFunctions.h`` that declares a ``sqrt`` function:
|
| 185 |
+
|
| 186 |
+
.. literalinclude:: MathFunctions/MathFunctions.h
|
| 187 |
+
:language: c++
|
| 188 |
+
|
| 189 |
+
And a corresponding source file ``MathFunctions.cxx``:
|
| 190 |
+
|
| 191 |
+
.. literalinclude:: MathFunctions/MathFunctions.cxx
|
| 192 |
+
:language: c++
|
| 193 |
+
|
| 194 |
+
Don't worry too much about the specifics of the C++ files, they are just meant
|
| 195 |
+
to be a simple example that will compile and run on many build systems.
|
| 196 |
+
|
| 197 |
+
Now we can create a ``CMakeLists.txt`` file for the ``MathFunctions``
|
| 198 |
+
project. Start by specifying the :command:`cmake_minimum_required` version and
|
| 199 |
+
:command:`project` name:
|
| 200 |
+
|
| 201 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 202 |
+
:language: cmake
|
| 203 |
+
:end-before: # create library
|
| 204 |
+
|
| 205 |
+
The :module:`GNUInstallDirs` module is included in order to provide the
|
| 206 |
+
project with the flexibility to install into different platform layouts by
|
| 207 |
+
making the directories available as cache variables.
|
| 208 |
+
|
| 209 |
+
Create a library called ``MathFunctions`` with the :command:`add_library`
|
| 210 |
+
command:
|
| 211 |
+
|
| 212 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 213 |
+
:language: cmake
|
| 214 |
+
:start-after: # create library
|
| 215 |
+
:end-before: # add include directories
|
| 216 |
+
|
| 217 |
+
And then use the :command:`target_include_directories` command to specify the
|
| 218 |
+
include directories for the target:
|
| 219 |
+
|
| 220 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 221 |
+
:language: cmake
|
| 222 |
+
:start-after: # add include directories
|
| 223 |
+
:end-before: # install the target and create export-set
|
| 224 |
+
|
| 225 |
+
We need to tell CMake that we want to use different include directories
|
| 226 |
+
depending on if we're building the library or using it from an installed
|
| 227 |
+
location. If we don't do this, when CMake creates the export information it
|
| 228 |
+
will export a path that is specific to the current build directory
|
| 229 |
+
and will not be valid for other projects. We can use
|
| 230 |
+
:manual:`generator expressions <cmake-generator-expressions(7)>` to specify
|
| 231 |
+
that if we're building the library include the current source directory.
|
| 232 |
+
Otherwise, when installed, include the ``include`` directory. See the `Creating
|
| 233 |
+
Relocatable Packages`_ section for more details.
|
| 234 |
+
|
| 235 |
+
The :command:`install(TARGETS)` and :command:`install(EXPORT)` commands
|
| 236 |
+
work together to install both targets (a library in our case) and a CMake
|
| 237 |
+
file designed to make it easy to import the targets into another CMake project.
|
| 238 |
+
|
| 239 |
+
First, in the :command:`install(TARGETS)` command we will specify the target,
|
| 240 |
+
the ``EXPORT`` name and the destinations that tell CMake where to install the
|
| 241 |
+
targets.
|
| 242 |
+
|
| 243 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 244 |
+
:language: cmake
|
| 245 |
+
:start-after: # install the target and create export-set
|
| 246 |
+
:end-before: # install header file
|
| 247 |
+
|
| 248 |
+
Here, the ``EXPORT`` option tells CMake to create an export called
|
| 249 |
+
``MathFunctionsTargets``. The generated :prop_tgt:`IMPORTED` targets have
|
| 250 |
+
appropriate properties set to define their
|
| 251 |
+
:ref:`usage requirements <Target Usage Requirements>`, such as
|
| 252 |
+
:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`,
|
| 253 |
+
:prop_tgt:`INTERFACE_COMPILE_DEFINITIONS` and other relevant built-in
|
| 254 |
+
``INTERFACE_`` properties. The ``INTERFACE`` variant of user-defined
|
| 255 |
+
properties listed in :prop_tgt:`COMPATIBLE_INTERFACE_STRING` and other
|
| 256 |
+
:ref:`Compatible Interface Properties` are also propagated to the
|
| 257 |
+
generated :prop_tgt:`IMPORTED` targets. For example, in this case, the
|
| 258 |
+
:prop_tgt:`IMPORTED` target will have its
|
| 259 |
+
:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` property populated with
|
| 260 |
+
the directory specified by the ``INCLUDES DESTINATION`` property. As a
|
| 261 |
+
relative path was given, it is treated as relative to the
|
| 262 |
+
:variable:`CMAKE_INSTALL_PREFIX`.
|
| 263 |
+
|
| 264 |
+
Note, we have *not* asked CMake to install the export yet.
|
| 265 |
+
|
| 266 |
+
We don't want to forget to install the ``MathFunctions.h`` header file with the
|
| 267 |
+
:command:`install(FILES)` command. The header file should be installed to the
|
| 268 |
+
``include`` directory, as specified by the
|
| 269 |
+
:command:`target_include_directories` command above.
|
| 270 |
+
|
| 271 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 272 |
+
:language: cmake
|
| 273 |
+
:start-after: # install header file
|
| 274 |
+
:end-before: # generate and install export file
|
| 275 |
+
|
| 276 |
+
Now that the ``MathFunctions`` library and header file are installed, we also
|
| 277 |
+
need to explicitly install the ``MathFunctionsTargets`` export details. Use
|
| 278 |
+
the :command:`install(EXPORT)` command to export the targets in
|
| 279 |
+
``MathFunctionsTargets``, as defined by the :command:`install(TARGETS)`
|
| 280 |
+
command.
|
| 281 |
+
|
| 282 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 283 |
+
:language: cmake
|
| 284 |
+
:start-after: # generate and install export file
|
| 285 |
+
:end-before: # include CMakePackageConfigHelpers macro
|
| 286 |
+
|
| 287 |
+
This command generates the ``MathFunctionsTargets.cmake`` file and arranges
|
| 288 |
+
to install it to ``${CMAKE_INSTALL_LIBDIR}/cmake/MathFunctions``. The file
|
| 289 |
+
contains code suitable for use by downstreams to import all targets listed in
|
| 290 |
+
the install command from the installation tree.
|
| 291 |
+
|
| 292 |
+
The ``NAMESPACE`` option will prepend ``MathFunctions::`` to the target names
|
| 293 |
+
as they are written to the export file. This convention of double-colons
|
| 294 |
+
gives CMake a hint that the name is an :prop_tgt:`IMPORTED` target when it
|
| 295 |
+
is used by downstream projects. This way, CMake can issue a diagnostic
|
| 296 |
+
message if the package providing it was not found.
|
| 297 |
+
|
| 298 |
+
The generated export file contains code that creates an :prop_tgt:`IMPORTED` library.
|
| 299 |
+
|
| 300 |
+
.. code-block:: cmake
|
| 301 |
+
|
| 302 |
+
# Create imported target MathFunctions::MathFunctions
|
| 303 |
+
add_library(MathFunctions::MathFunctions STATIC IMPORTED)
|
| 304 |
+
|
| 305 |
+
set_target_properties(MathFunctions::MathFunctions PROPERTIES
|
| 306 |
+
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
|
| 307 |
+
)
|
| 308 |
+
|
| 309 |
+
This code is very similar to the example we created by hand in the
|
| 310 |
+
`Importing Libraries`_ section. Note that ``${_IMPORT_PREFIX}`` is computed
|
| 311 |
+
relative to the file location.
|
| 312 |
+
|
| 313 |
+
An outside project may load this file with the :command:`include` command and
|
| 314 |
+
reference the ``MathFunctions`` library from the installation tree as if it
|
| 315 |
+
were built in its own tree. For example:
|
| 316 |
+
|
| 317 |
+
.. code-block:: cmake
|
| 318 |
+
:linenos:
|
| 319 |
+
|
| 320 |
+
include(GNUInstallDirs)
|
| 321 |
+
include(${INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/MathFunctions/MathFunctionTargets.cmake)
|
| 322 |
+
add_executable(myexe src1.c src2.c )
|
| 323 |
+
target_link_libraries(myexe PRIVATE MathFunctions::MathFunctions)
|
| 324 |
+
|
| 325 |
+
Line 2 loads the target CMake file. Although we only exported a single
|
| 326 |
+
target, this file may import any number of targets. Their locations are
|
| 327 |
+
computed relative to the file location so that the install tree may be
|
| 328 |
+
easily moved. Line 4 references the imported ``MathFunctions`` library. The
|
| 329 |
+
resulting build system will link to the library from its installed location.
|
| 330 |
+
|
| 331 |
+
Executables may also be exported and imported using the same process.
|
| 332 |
+
|
| 333 |
+
Any number of target installations may be associated with the same
|
| 334 |
+
export name. Export names are considered global so any directory may
|
| 335 |
+
contribute a target installation. The :command:`install(EXPORT)` command only
|
| 336 |
+
needs to be called once to install a file that references all targets. Below
|
| 337 |
+
is an example of how multiple exports may be combined into a single
|
| 338 |
+
export file, even if they are in different subdirectories of the project.
|
| 339 |
+
|
| 340 |
+
.. code-block:: cmake
|
| 341 |
+
|
| 342 |
+
# A/CMakeLists.txt
|
| 343 |
+
add_executable(myexe src1.c)
|
| 344 |
+
install(TARGETS myexe DESTINATION lib/myproj
|
| 345 |
+
EXPORT myproj-targets)
|
| 346 |
+
|
| 347 |
+
# B/CMakeLists.txt
|
| 348 |
+
add_library(foo STATIC foo1.c)
|
| 349 |
+
install(TARGETS foo DESTINATION lib EXPORTS myproj-targets)
|
| 350 |
+
|
| 351 |
+
# Top CMakeLists.txt
|
| 352 |
+
add_subdirectory (A)
|
| 353 |
+
add_subdirectory (B)
|
| 354 |
+
install(EXPORT myproj-targets DESTINATION lib/myproj)
|
| 355 |
+
|
| 356 |
+
Creating Packages
|
| 357 |
+
-----------------
|
| 358 |
+
|
| 359 |
+
At this point, the ``MathFunctions`` project is exporting the target
|
| 360 |
+
information required to be used by other projects. We can make this project
|
| 361 |
+
even easier for other projects to use by generating a configuration file so
|
| 362 |
+
that the CMake :command:`find_package` command can find our project.
|
| 363 |
+
|
| 364 |
+
To start, we will need to make a few additions to the ``CMakeLists.txt``
|
| 365 |
+
file. First, include the :module:`CMakePackageConfigHelpers` module to get
|
| 366 |
+
access to some helper functions for creating config files.
|
| 367 |
+
|
| 368 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 369 |
+
:language: cmake
|
| 370 |
+
:start-after: # include CMakePackageConfigHelpers macro
|
| 371 |
+
:end-before: # set version
|
| 372 |
+
|
| 373 |
+
Then we will create a package configuration file and a package version file.
|
| 374 |
+
|
| 375 |
+
Creating a Package Configuration File
|
| 376 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 377 |
+
|
| 378 |
+
Use the :command:`configure_package_config_file` command provided by the
|
| 379 |
+
:module:`CMakePackageConfigHelpers` to generate the package configuration
|
| 380 |
+
file. Note that this command should be used instead of the plain
|
| 381 |
+
:command:`configure_file` command. It helps to ensure that the resulting
|
| 382 |
+
package is relocatable by avoiding hardcoded paths in the installed
|
| 383 |
+
configuration file. The path given to ``INSTALL_DESTINATION`` must be the
|
| 384 |
+
destination where the ``MathFunctionsConfig.cmake`` file will be installed.
|
| 385 |
+
We will examine the contents of the package configuration file in the next
|
| 386 |
+
section.
|
| 387 |
+
|
| 388 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 389 |
+
:language: cmake
|
| 390 |
+
:start-after: # create config file
|
| 391 |
+
:end-before: # install config files
|
| 392 |
+
|
| 393 |
+
Install the generated configuration files with the :command:`INSTALL(files)`
|
| 394 |
+
command. Both ``MathFunctionsConfigVersion.cmake`` and
|
| 395 |
+
``MathFunctionsConfig.cmake`` are installed to the same location, completing
|
| 396 |
+
the package.
|
| 397 |
+
|
| 398 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 399 |
+
:language: cmake
|
| 400 |
+
:start-after: # install config files
|
| 401 |
+
:end-before: # generate the export targets for the build tree
|
| 402 |
+
|
| 403 |
+
Now we need to create the package configuration file itself. In this case, the
|
| 404 |
+
``Config.cmake.in`` file is very simple but sufficient to allow downstreams
|
| 405 |
+
to use the :prop_tgt:`IMPORTED` targets.
|
| 406 |
+
|
| 407 |
+
.. literalinclude:: MathFunctions/Config.cmake.in
|
| 408 |
+
|
| 409 |
+
The first line of the file contains only the string ``@PACKAGE_INIT@``. This
|
| 410 |
+
expands when the file is configured and allows the use of relocatable paths
|
| 411 |
+
prefixed with ``PACKAGE_``. It also provides the ``set_and_check()`` and
|
| 412 |
+
``check_required_components()`` macros.
|
| 413 |
+
|
| 414 |
+
The ``check_required_components`` helper macro ensures that all requested,
|
| 415 |
+
non-optional components have been found by checking the
|
| 416 |
+
``<Package>_<Component>_FOUND`` variables for all required components. This
|
| 417 |
+
macro should be called at the end of the package configuration file even if the
|
| 418 |
+
package does not have any components. This way, CMake can make sure that the
|
| 419 |
+
downstream project hasn't specified any non-existent components. If
|
| 420 |
+
``check_required_components`` fails, the ``<Package>_FOUND`` variable is set to
|
| 421 |
+
FALSE, and the package is considered to be not found.
|
| 422 |
+
|
| 423 |
+
The ``set_and_check()`` macro should be used in configuration files instead
|
| 424 |
+
of the normal ``set()`` command for setting directories and file locations.
|
| 425 |
+
If a referenced file or directory does not exist, the macro will fail.
|
| 426 |
+
|
| 427 |
+
If any macros should be provided by the ``MathFunctions`` package, they should
|
| 428 |
+
be in a separate file which is installed to the same location as the
|
| 429 |
+
``MathFunctionsConfig.cmake`` file, and included from there.
|
| 430 |
+
|
| 431 |
+
**All required dependencies of a package must also be found in the package
|
| 432 |
+
configuration file.** Let's imagine that we require the ``Stats`` library in
|
| 433 |
+
our project. In the CMakeLists file, we would add:
|
| 434 |
+
|
| 435 |
+
.. code-block:: cmake
|
| 436 |
+
|
| 437 |
+
find_package(Stats 2.6.4 REQUIRED)
|
| 438 |
+
target_link_libraries(MathFunctions PUBLIC Stats::Types)
|
| 439 |
+
|
| 440 |
+
As the ``Stats::Types`` target is a ``PUBLIC`` dependency of ``MathFunctions``,
|
| 441 |
+
downstreams must also find the ``Stats`` package and link to the
|
| 442 |
+
``Stats::Types`` library. The ``Stats`` package should be found in the
|
| 443 |
+
configuration file to ensure this.
|
| 444 |
+
|
| 445 |
+
.. code-block:: cmake
|
| 446 |
+
|
| 447 |
+
include(CMakeFindDependencyMacro)
|
| 448 |
+
find_dependency(Stats 2.6.4)
|
| 449 |
+
|
| 450 |
+
The ``find_dependency`` macro from the :module:`CMakeFindDependencyMacro`
|
| 451 |
+
module helps by propagating whether the package is ``REQUIRED``, or
|
| 452 |
+
``QUIET``, etc. The ``find_dependency`` macro also sets
|
| 453 |
+
``MathFunctions_FOUND`` to ``False`` if the dependency is not found, along
|
| 454 |
+
with a diagnostic that the ``MathFunctions`` package cannot be used without
|
| 455 |
+
the ``Stats`` package.
|
| 456 |
+
|
| 457 |
+
**Exercise:** Add a required library to the ``MathFunctions`` project.
|
| 458 |
+
|
| 459 |
+
Creating a Package Version File
|
| 460 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 461 |
+
|
| 462 |
+
The :module:`CMakePackageConfigHelpers` module provides the
|
| 463 |
+
:command:`write_basic_package_version_file` command for creating a simple
|
| 464 |
+
package version file. This file is read by CMake when :command:`find_package`
|
| 465 |
+
is called to determine the compatibility with the requested version, and to set
|
| 466 |
+
some version-specific variables such as ``<PackageName>_VERSION``,
|
| 467 |
+
``<PackageName>_VERSION_MAJOR``, ``<PackageName>_VERSION_MINOR``, etc. See
|
| 468 |
+
:manual:`cmake-packages <cmake-packages(7)>` documentation for more details.
|
| 469 |
+
|
| 470 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 471 |
+
:language: cmake
|
| 472 |
+
:start-after: # set version
|
| 473 |
+
:end-before: # create config file
|
| 474 |
+
|
| 475 |
+
In our example, ``MathFunctions_MAJOR_VERSION`` is defined as a
|
| 476 |
+
:prop_tgt:`COMPATIBLE_INTERFACE_STRING` which means that it must be
|
| 477 |
+
compatible among the dependencies of any depender. By setting this
|
| 478 |
+
custom defined user property in this version and in the next version of
|
| 479 |
+
``MathFunctions``, :manual:`cmake <cmake(1)>` will issue a diagnostic if
|
| 480 |
+
there is an attempt to use version 3 together with version 4. Packages can
|
| 481 |
+
choose to employ such a pattern if different major versions of the package
|
| 482 |
+
are designed to be incompatible.
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
Exporting Targets from the Build Tree
|
| 486 |
+
-------------------------------------
|
| 487 |
+
|
| 488 |
+
Typically, projects are built and installed before being used by an outside
|
| 489 |
+
project. However, in some cases, it is desirable to export targets directly
|
| 490 |
+
from a build tree. The targets may then be used by an outside project that
|
| 491 |
+
references the build tree with no installation involved. The :command:`export`
|
| 492 |
+
command is used to generate a file exporting targets from a project build tree.
|
| 493 |
+
|
| 494 |
+
If we want our example project to also be used from a build directory we only
|
| 495 |
+
have to add the following to ``CMakeLists.txt``:
|
| 496 |
+
|
| 497 |
+
.. literalinclude:: MathFunctions/CMakeLists.txt
|
| 498 |
+
:language: cmake
|
| 499 |
+
:start-after: # generate the export targets for the build tree
|
| 500 |
+
|
| 501 |
+
Here we use the :command:`export` command to generate the export targets for
|
| 502 |
+
the build tree. In this case, we'll create a file called
|
| 503 |
+
``MathFunctionsTargets.cmake`` in the ``cmake`` subdirectory of the build
|
| 504 |
+
directory. The generated file contains the required code to import the target
|
| 505 |
+
and may be loaded by an outside project that is aware of the project build
|
| 506 |
+
tree. This file is specific to the build-tree, and **is not relocatable**.
|
| 507 |
+
|
| 508 |
+
It is possible to create a suitable package configuration file and package
|
| 509 |
+
version file to define a package for the build tree which may be used without
|
| 510 |
+
installation. Consumers of the build tree can simply ensure that the
|
| 511 |
+
:variable:`CMAKE_PREFIX_PATH` contains the build directory, or set the
|
| 512 |
+
``MathFunctions_DIR`` to ``<build_dir>/MathFunctions`` in the cache.
|
| 513 |
+
|
| 514 |
+
An example application of this feature is for building an executable on a host
|
| 515 |
+
platform when cross-compiling. The project containing the executable may be
|
| 516 |
+
built on the host platform and then the project that is being cross-compiled
|
| 517 |
+
for another platform may load it.
|
| 518 |
+
|
| 519 |
+
Building and Installing a Package
|
| 520 |
+
---------------------------------
|
| 521 |
+
|
| 522 |
+
At this point, we have generated a relocatable CMake configuration for our
|
| 523 |
+
project that can be used after the project has been installed. Let's try to
|
| 524 |
+
build the ``MathFunctions`` project:
|
| 525 |
+
|
| 526 |
+
.. code-block:: console
|
| 527 |
+
|
| 528 |
+
mkdir MathFunctions_build
|
| 529 |
+
cd MathFunctions_build
|
| 530 |
+
cmake ../MathFunctions
|
| 531 |
+
cmake --build .
|
| 532 |
+
|
| 533 |
+
In the build directory, notice that the file ``MathFunctionsTargets.cmake``
|
| 534 |
+
has been created in the ``cmake`` subdirectory.
|
| 535 |
+
|
| 536 |
+
Now install the project:
|
| 537 |
+
|
| 538 |
+
.. code-block:: console
|
| 539 |
+
|
| 540 |
+
$ cmake --install . --prefix "/home/myuser/installdir"
|
| 541 |
+
|
| 542 |
+
Creating Relocatable Packages
|
| 543 |
+
=============================
|
| 544 |
+
|
| 545 |
+
Packages created by :command:`install(EXPORT)` are designed to be relocatable,
|
| 546 |
+
using paths relative to the location of the package itself. They must not
|
| 547 |
+
reference absolute paths of files on the machine where the package is built
|
| 548 |
+
that will not exist on the machines where the package may be installed.
|
| 549 |
+
|
| 550 |
+
When defining the interface of a target for ``EXPORT``, keep in mind that the
|
| 551 |
+
include directories should be specified as relative paths to the
|
| 552 |
+
:variable:`CMAKE_INSTALL_PREFIX` but should not explicitly include the
|
| 553 |
+
:variable:`CMAKE_INSTALL_PREFIX`:
|
| 554 |
+
|
| 555 |
+
.. code-block:: cmake
|
| 556 |
+
|
| 557 |
+
target_include_directories(tgt INTERFACE
|
| 558 |
+
# Wrong, not relocatable:
|
| 559 |
+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/TgtName>
|
| 560 |
+
)
|
| 561 |
+
|
| 562 |
+
target_include_directories(tgt INTERFACE
|
| 563 |
+
# Ok, relocatable:
|
| 564 |
+
$<INSTALL_INTERFACE:include/TgtName>
|
| 565 |
+
)
|
| 566 |
+
|
| 567 |
+
The :genex:`$<INSTALL_PREFIX>` generator expression may be used as
|
| 568 |
+
a placeholder for the install prefix without resulting in a non-relocatable
|
| 569 |
+
package. This is necessary if complex generator expressions are used:
|
| 570 |
+
|
| 571 |
+
.. code-block:: cmake
|
| 572 |
+
|
| 573 |
+
target_include_directories(tgt INTERFACE
|
| 574 |
+
# Ok, relocatable:
|
| 575 |
+
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/TgtName>
|
| 576 |
+
)
|
| 577 |
+
|
| 578 |
+
This also applies to paths referencing external dependencies.
|
| 579 |
+
It is not advisable to populate any properties which may contain
|
| 580 |
+
paths, such as :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` or
|
| 581 |
+
:prop_tgt:`INTERFACE_LINK_LIBRARIES`, with paths relevant to dependencies.
|
| 582 |
+
For example, this code may not work well for a relocatable package:
|
| 583 |
+
|
| 584 |
+
.. code-block:: cmake
|
| 585 |
+
|
| 586 |
+
target_link_libraries(MathFunctions INTERFACE
|
| 587 |
+
${Foo_LIBRARIES} ${Bar_LIBRARIES}
|
| 588 |
+
)
|
| 589 |
+
target_include_directories(MathFunctions INTERFACE
|
| 590 |
+
"$<INSTALL_INTERFACE:${Foo_INCLUDE_DIRS};${Bar_INCLUDE_DIRS}>"
|
| 591 |
+
)
|
| 592 |
+
|
| 593 |
+
The referenced variables may contain the absolute paths to libraries
|
| 594 |
+
and include directories **as found on the machine the package was made on**.
|
| 595 |
+
This would create a package with hard-coded paths to dependencies not
|
| 596 |
+
suitable for relocation.
|
| 597 |
+
|
| 598 |
+
Ideally such dependencies should be used through their own
|
| 599 |
+
:ref:`IMPORTED targets <Imported Targets>` that have their own
|
| 600 |
+
:prop_tgt:`IMPORTED_LOCATION` and usage requirement properties
|
| 601 |
+
such as :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` populated
|
| 602 |
+
appropriately. Those imported targets may then be used with
|
| 603 |
+
the :command:`target_link_libraries` command for ``MathFunctions``:
|
| 604 |
+
|
| 605 |
+
.. code-block:: cmake
|
| 606 |
+
|
| 607 |
+
target_link_libraries(MathFunctions INTERFACE Foo::Foo Bar::Bar)
|
| 608 |
+
|
| 609 |
+
With this approach the package references its external dependencies
|
| 610 |
+
only through the names of :ref:`IMPORTED targets <Imported Targets>`.
|
| 611 |
+
When a consumer uses the installed package, the consumer will run the
|
| 612 |
+
appropriate :command:`find_package` commands (via the ``find_dependency``
|
| 613 |
+
macro described above) to find the dependencies and populate the
|
| 614 |
+
imported targets with appropriate paths on their own machine.
|
| 615 |
+
|
| 616 |
+
Using the Package Configuration File
|
| 617 |
+
====================================
|
| 618 |
+
|
| 619 |
+
Now we're ready to create a project to use the installed ``MathFunctions``
|
| 620 |
+
library. In this section we will be using source code from
|
| 621 |
+
``Help\guide\importing-exporting\Downstream``. In this directory, there is a
|
| 622 |
+
source file called ``main.cc`` that uses the ``MathFunctions`` library to
|
| 623 |
+
calculate the square root of a given number and then prints the results:
|
| 624 |
+
|
| 625 |
+
.. literalinclude:: Downstream/main.cc
|
| 626 |
+
:language: c++
|
| 627 |
+
|
| 628 |
+
As before, we'll start with the :command:`cmake_minimum_required` and
|
| 629 |
+
:command:`project` commands in the ``CMakeLists.txt`` file. For this project,
|
| 630 |
+
we'll also specify the C++ standard.
|
| 631 |
+
|
| 632 |
+
.. literalinclude:: Downstream/CMakeLists.txt
|
| 633 |
+
:language: cmake
|
| 634 |
+
:end-before: # find MathFunctions
|
| 635 |
+
|
| 636 |
+
We can use the :command:`find_package` command:
|
| 637 |
+
|
| 638 |
+
.. literalinclude:: Downstream/CMakeLists.txt
|
| 639 |
+
:language: cmake
|
| 640 |
+
:start-after: # find MathFunctions
|
| 641 |
+
:end-before: # create executable
|
| 642 |
+
|
| 643 |
+
Create an executable:
|
| 644 |
+
|
| 645 |
+
.. literalinclude:: Downstream/CMakeLists.txt
|
| 646 |
+
:language: cmake
|
| 647 |
+
:start-after: # create executable
|
| 648 |
+
:end-before: # use MathFunctions library
|
| 649 |
+
|
| 650 |
+
And link to the ``MathFunctions`` library:
|
| 651 |
+
|
| 652 |
+
.. literalinclude:: Downstream/CMakeLists.txt
|
| 653 |
+
:language: cmake
|
| 654 |
+
:start-after: # use MathFunctions library
|
| 655 |
+
|
| 656 |
+
That's it! Now let's try to build the ``Downstream`` project.
|
| 657 |
+
|
| 658 |
+
.. code-block:: console
|
| 659 |
+
|
| 660 |
+
mkdir Downstream_build
|
| 661 |
+
cd Downstream_build
|
| 662 |
+
cmake ../Downstream
|
| 663 |
+
cmake --build .
|
| 664 |
+
|
| 665 |
+
A warning may have appeared during CMake configuration:
|
| 666 |
+
|
| 667 |
+
.. code-block:: console
|
| 668 |
+
|
| 669 |
+
CMake Warning at CMakeLists.txt:4 (find_package):
|
| 670 |
+
By not providing "FindMathFunctions.cmake" in CMAKE_MODULE_PATH this
|
| 671 |
+
project has asked CMake to find a package configuration file provided by
|
| 672 |
+
"MathFunctions", but CMake did not find one.
|
| 673 |
+
|
| 674 |
+
Could not find a package configuration file provided by "MathFunctions"
|
| 675 |
+
with any of the following names:
|
| 676 |
+
|
| 677 |
+
MathFunctionsConfig.cmake
|
| 678 |
+
mathfunctions-config.cmake
|
| 679 |
+
|
| 680 |
+
Add the installation prefix of "MathFunctions" to CMAKE_PREFIX_PATH or set
|
| 681 |
+
"MathFunctions_DIR" to a directory containing one of the above files. If
|
| 682 |
+
"MathFunctions" provides a separate development package or SDK, be sure it
|
| 683 |
+
has been installed.
|
| 684 |
+
|
| 685 |
+
Set the ``CMAKE_PREFIX_PATH`` to where MathFunctions was installed previously
|
| 686 |
+
and try again. Ensure that the newly created executable runs as expected.
|
| 687 |
+
|
| 688 |
+
Adding Components
|
| 689 |
+
=================
|
| 690 |
+
|
| 691 |
+
Let's edit the ``MathFunctions`` project to use components. The source code for
|
| 692 |
+
this section can be found in
|
| 693 |
+
``Help\guide\importing-exporting\MathFunctionsComponents``. The CMakeLists file
|
| 694 |
+
for this project adds two subdirectories: ``Addition`` and ``SquareRoot``.
|
| 695 |
+
|
| 696 |
+
.. literalinclude:: MathFunctionsComponents/CMakeLists.txt
|
| 697 |
+
:language: cmake
|
| 698 |
+
:end-before: # include CMakePackageConfigHelpers macro
|
| 699 |
+
|
| 700 |
+
Generate and install the package configuration and package version files:
|
| 701 |
+
|
| 702 |
+
.. literalinclude:: MathFunctionsComponents/CMakeLists.txt
|
| 703 |
+
:language: cmake
|
| 704 |
+
:start-after: # include CMakePackageConfigHelpers macro
|
| 705 |
+
|
| 706 |
+
If ``COMPONENTS`` are specified when the downstream uses
|
| 707 |
+
:command:`find_package`, they are listed in the
|
| 708 |
+
``<PackageName>_FIND_COMPONENTS`` variable. We can use this variable to verify
|
| 709 |
+
that all necessary component targets are included in ``Config.cmake.in``. At
|
| 710 |
+
the same time, this function will act as a custom ``check_required_components``
|
| 711 |
+
macro to ensure that the downstream only attempts to use supported components.
|
| 712 |
+
|
| 713 |
+
.. literalinclude:: MathFunctionsComponents/Config.cmake.in
|
| 714 |
+
|
| 715 |
+
Here, the ``MathFunctions_NOT_FOUND_MESSAGE`` is set to a diagnosis that the
|
| 716 |
+
package could not be found because an invalid component was specified. This
|
| 717 |
+
message variable can be set for any case where the ``_FOUND`` variable is set
|
| 718 |
+
to ``False``, and will be displayed to the user.
|
| 719 |
+
|
| 720 |
+
The ``Addition`` and ``SquareRoot`` directories are similar. Let's look at one
|
| 721 |
+
of the CMakeLists files:
|
| 722 |
+
|
| 723 |
+
.. literalinclude:: MathFunctionsComponents/SquareRoot/CMakeLists.txt
|
| 724 |
+
:language: cmake
|
| 725 |
+
|
| 726 |
+
Now we can build the project as described in earlier sections. To test using
|
| 727 |
+
this package, we can use the project in
|
| 728 |
+
``Help\guide\importing-exporting\DownstreamComponents``. There's two
|
| 729 |
+
differences from the previous ``Downstream`` project. First, we need to find
|
| 730 |
+
the package components. Change the ``find_package`` line from:
|
| 731 |
+
|
| 732 |
+
.. literalinclude:: Downstream/CMakeLists.txt
|
| 733 |
+
:language: cmake
|
| 734 |
+
:start-after: # find MathFunctions
|
| 735 |
+
:end-before: # create executable
|
| 736 |
+
|
| 737 |
+
To:
|
| 738 |
+
|
| 739 |
+
.. literalinclude:: DownstreamComponents/CMakeLists.txt
|
| 740 |
+
:language: cmake
|
| 741 |
+
:start-after: # find MathFunctions
|
| 742 |
+
:end-before: # create executable
|
| 743 |
+
|
| 744 |
+
and the ``target_link_libraries`` line from:
|
| 745 |
+
|
| 746 |
+
.. literalinclude:: Downstream/CMakeLists.txt
|
| 747 |
+
:language: cmake
|
| 748 |
+
:start-after: # use MathFunctions library
|
| 749 |
+
|
| 750 |
+
To:
|
| 751 |
+
|
| 752 |
+
.. literalinclude:: DownstreamComponents/CMakeLists.txt
|
| 753 |
+
:language: cmake
|
| 754 |
+
:start-after: # use MathFunctions library
|
| 755 |
+
:end-before: # Workaround for GCC on AIX to avoid -isystem
|
| 756 |
+
|
| 757 |
+
In ``main.cc``, replace ``#include MathFunctions.h`` with:
|
| 758 |
+
|
| 759 |
+
.. literalinclude:: DownstreamComponents/main.cc
|
| 760 |
+
:language: c
|
| 761 |
+
:start-after: #include <string>
|
| 762 |
+
:end-before: int main
|
| 763 |
+
|
| 764 |
+
Finally, use the ``Addition`` library:
|
| 765 |
+
|
| 766 |
+
.. literalinclude:: DownstreamComponents/main.cc
|
| 767 |
+
:language: c
|
| 768 |
+
:start-after: // calculate sum
|
| 769 |
+
:end-before: return 0;
|
| 770 |
+
|
| 771 |
+
Build the ``Downstream`` project and confirm that it can find and use the
|
| 772 |
+
package components.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/A Basic Starting Point.rst.txt
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 1: A Basic Starting Point
|
| 2 |
+
==============================
|
| 3 |
+
|
| 4 |
+
Where do I start with CMake? This step will provide an introduction to some of
|
| 5 |
+
CMake's basic syntax, commands, and variables. As these concepts are
|
| 6 |
+
introduced, we will work through three exercises and create a simple CMake
|
| 7 |
+
project.
|
| 8 |
+
|
| 9 |
+
Each exercise in this step will start with some background information. Then, a
|
| 10 |
+
goal and list of helpful resources are provided. Each file in the
|
| 11 |
+
``Files to Edit`` section is in the ``Step1`` directory and contains one or
|
| 12 |
+
more ``TODO`` comments. Each ``TODO`` represents a line or two of code to
|
| 13 |
+
change or add. The ``TODO`` s are intended to be completed in numerical order,
|
| 14 |
+
first complete ``TODO 1`` then ``TODO 2``, etc. The ``Getting Started``
|
| 15 |
+
section will give some helpful hints and guide you through the exercise. Then
|
| 16 |
+
the ``Build and Run`` section will walk step-by-step through how to build and
|
| 17 |
+
test the exercise. Finally, at the end of each exercise the intended solution
|
| 18 |
+
is discussed.
|
| 19 |
+
|
| 20 |
+
Also note that each step in the tutorial builds on the next. So, for example,
|
| 21 |
+
the starting code for ``Step2`` is the complete solution to ``Step1``.
|
| 22 |
+
|
| 23 |
+
Exercise 1 - Building a Basic Project
|
| 24 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 25 |
+
|
| 26 |
+
The most basic CMake project is an executable built from a single source code
|
| 27 |
+
file. For simple projects like this, a ``CMakeLists.txt`` file with three
|
| 28 |
+
commands is all that is required.
|
| 29 |
+
|
| 30 |
+
**Note:** Although upper, lower and mixed case commands are supported by CMake,
|
| 31 |
+
lower case commands are preferred and will be used throughout the tutorial.
|
| 32 |
+
|
| 33 |
+
Any project's top most CMakeLists.txt must start by specifying a minimum CMake
|
| 34 |
+
version using the :command:`cmake_minimum_required` command. This establishes
|
| 35 |
+
policy settings and ensures that the following CMake functions are run with a
|
| 36 |
+
compatible version of CMake.
|
| 37 |
+
|
| 38 |
+
To start a project, we use the :command:`project` command to set the project
|
| 39 |
+
name. This call is required with every project and should be called soon after
|
| 40 |
+
:command:`cmake_minimum_required`. As we will see later, this command can
|
| 41 |
+
also be used to specify other project level information such as the language
|
| 42 |
+
or version number.
|
| 43 |
+
|
| 44 |
+
Finally, the :command:`add_executable` command tells CMake to create an
|
| 45 |
+
executable using the specified source code files.
|
| 46 |
+
|
| 47 |
+
Goal
|
| 48 |
+
----
|
| 49 |
+
|
| 50 |
+
Understand how to create a simple CMake project.
|
| 51 |
+
|
| 52 |
+
Helpful Resources
|
| 53 |
+
-----------------
|
| 54 |
+
|
| 55 |
+
* :command:`add_executable`
|
| 56 |
+
* :command:`cmake_minimum_required`
|
| 57 |
+
* :command:`project`
|
| 58 |
+
|
| 59 |
+
Files to Edit
|
| 60 |
+
-------------
|
| 61 |
+
|
| 62 |
+
* ``CMakeLists.txt``
|
| 63 |
+
|
| 64 |
+
Getting Started
|
| 65 |
+
----------------
|
| 66 |
+
|
| 67 |
+
The source code for ``tutorial.cxx`` is provided in the
|
| 68 |
+
``Help/guide/tutorial/Step1`` directory and can be used to compute the square
|
| 69 |
+
root of a number. This file does not need to be edited in this step.
|
| 70 |
+
|
| 71 |
+
In the same directory is a ``CMakeLists.txt`` file which you will complete.
|
| 72 |
+
Start with ``TODO 1`` and work through ``TODO 3``.
|
| 73 |
+
|
| 74 |
+
Build and Run
|
| 75 |
+
-------------
|
| 76 |
+
|
| 77 |
+
Once ``TODO 1`` through ``TODO 3`` have been completed, we are ready to build
|
| 78 |
+
and run our project! First, run the :manual:`cmake <cmake(1)>` executable or the
|
| 79 |
+
:manual:`cmake-gui <cmake-gui(1)>` to configure the project and then build it
|
| 80 |
+
with your chosen build tool.
|
| 81 |
+
|
| 82 |
+
For example, from the command line we could navigate to the
|
| 83 |
+
``Help/guide/tutorial`` directory of the CMake source code tree and create a
|
| 84 |
+
build directory:
|
| 85 |
+
|
| 86 |
+
.. code-block:: console
|
| 87 |
+
|
| 88 |
+
mkdir Step1_build
|
| 89 |
+
|
| 90 |
+
Next, navigate to that build directory and run
|
| 91 |
+
:manual:`cmake <cmake(1)>` to configure the project and generate a native build
|
| 92 |
+
system:
|
| 93 |
+
|
| 94 |
+
.. code-block:: console
|
| 95 |
+
|
| 96 |
+
cd Step1_build
|
| 97 |
+
cmake ../Step1
|
| 98 |
+
|
| 99 |
+
Then call that build system to actually compile/link the project:
|
| 100 |
+
|
| 101 |
+
.. code-block:: console
|
| 102 |
+
|
| 103 |
+
cmake --build .
|
| 104 |
+
|
| 105 |
+
Finally, try to use the newly built ``Tutorial`` with these commands:
|
| 106 |
+
|
| 107 |
+
.. code-block:: console
|
| 108 |
+
|
| 109 |
+
Tutorial 4294967296
|
| 110 |
+
Tutorial 10
|
| 111 |
+
Tutorial
|
| 112 |
+
|
| 113 |
+
Solution
|
| 114 |
+
--------
|
| 115 |
+
|
| 116 |
+
As mentioned above, a three line ``CMakeLists.txt`` is all that we need to get
|
| 117 |
+
up and running. The first line is to use :command:`cmake_minimum_required` to
|
| 118 |
+
set the CMake version as follows:
|
| 119 |
+
|
| 120 |
+
.. raw:: html
|
| 121 |
+
|
| 122 |
+
<details><summary>TODO 1: Click to show/hide answer</summary>
|
| 123 |
+
|
| 124 |
+
.. literalinclude:: Step2/CMakeLists.txt
|
| 125 |
+
:caption: TODO 1: CMakeLists.txt
|
| 126 |
+
:name: CMakeLists.txt-cmake_minimum_required
|
| 127 |
+
:language: cmake
|
| 128 |
+
:end-before: # set the project name and version
|
| 129 |
+
|
| 130 |
+
.. raw:: html
|
| 131 |
+
|
| 132 |
+
</details>
|
| 133 |
+
|
| 134 |
+
The next step to make a basic project is to use the :command:`project`
|
| 135 |
+
command as follows to set the project name:
|
| 136 |
+
|
| 137 |
+
.. raw:: html
|
| 138 |
+
|
| 139 |
+
<details><summary>TODO 2: Click to show/hide answer</summary>
|
| 140 |
+
|
| 141 |
+
.. code-block:: cmake
|
| 142 |
+
:caption: TODO 2: CMakeLists.txt
|
| 143 |
+
:name: CMakeLists.txt-project
|
| 144 |
+
|
| 145 |
+
project(Tutorial)
|
| 146 |
+
|
| 147 |
+
.. raw:: html
|
| 148 |
+
|
| 149 |
+
</details>
|
| 150 |
+
|
| 151 |
+
The last command to call for a basic project is
|
| 152 |
+
:command:`add_executable`. We call it as follows:
|
| 153 |
+
|
| 154 |
+
.. raw:: html
|
| 155 |
+
|
| 156 |
+
<details><summary>TODO 3: Click to show/hide answer</summary>
|
| 157 |
+
|
| 158 |
+
.. literalinclude:: Step2/CMakeLists.txt
|
| 159 |
+
:caption: TODO 3: CMakeLists.txt
|
| 160 |
+
:name: CMakeLists.txt-add_executable
|
| 161 |
+
:language: cmake
|
| 162 |
+
:start-after: # add the executable
|
| 163 |
+
:end-before: # TODO 3:
|
| 164 |
+
|
| 165 |
+
.. raw:: html
|
| 166 |
+
|
| 167 |
+
</details>
|
| 168 |
+
|
| 169 |
+
Exercise 2 - Specifying the C++ Standard
|
| 170 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 171 |
+
|
| 172 |
+
CMake has some special variables that are either created behind the scenes or
|
| 173 |
+
have meaning to CMake when set by project code. Many of these variables start
|
| 174 |
+
with ``CMAKE_``. Avoid this naming convention when creating variables for your
|
| 175 |
+
projects. Two of these special user settable variables are
|
| 176 |
+
:variable:`CMAKE_CXX_STANDARD` and :variable:`CMAKE_CXX_STANDARD_REQUIRED`.
|
| 177 |
+
These may be used together to specify the C++ standard needed to build the
|
| 178 |
+
project.
|
| 179 |
+
|
| 180 |
+
Goal
|
| 181 |
+
----
|
| 182 |
+
|
| 183 |
+
Add a feature that requires C++11.
|
| 184 |
+
|
| 185 |
+
Helpful Resources
|
| 186 |
+
-----------------
|
| 187 |
+
|
| 188 |
+
* :variable:`CMAKE_CXX_STANDARD`
|
| 189 |
+
* :variable:`CMAKE_CXX_STANDARD_REQUIRED`
|
| 190 |
+
* :command:`set`
|
| 191 |
+
|
| 192 |
+
Files to Edit
|
| 193 |
+
-------------
|
| 194 |
+
|
| 195 |
+
* ``CMakeLists.txt``
|
| 196 |
+
* ``tutorial.cxx``
|
| 197 |
+
|
| 198 |
+
Getting Started
|
| 199 |
+
---------------
|
| 200 |
+
|
| 201 |
+
Continue editing files in the ``Step1`` directory. Start with ``TODO 4`` and
|
| 202 |
+
complete through ``TODO 6``.
|
| 203 |
+
|
| 204 |
+
First, edit ``tutorial.cxx`` by adding a feature that requires C++11. Then
|
| 205 |
+
update ``CMakeLists.txt`` to require C++11.
|
| 206 |
+
|
| 207 |
+
Build and Run
|
| 208 |
+
-------------
|
| 209 |
+
|
| 210 |
+
Let's build our project again. Since we already created a build directory and
|
| 211 |
+
ran CMake for Exercise 1, we can skip to the build step:
|
| 212 |
+
|
| 213 |
+
.. code-block:: console
|
| 214 |
+
|
| 215 |
+
cd Step1_build
|
| 216 |
+
cmake --build .
|
| 217 |
+
|
| 218 |
+
Now we can try to use the newly built ``Tutorial`` with same commands as
|
| 219 |
+
before:
|
| 220 |
+
|
| 221 |
+
.. code-block:: console
|
| 222 |
+
|
| 223 |
+
Tutorial 4294967296
|
| 224 |
+
Tutorial 10
|
| 225 |
+
Tutorial
|
| 226 |
+
|
| 227 |
+
Solution
|
| 228 |
+
--------
|
| 229 |
+
|
| 230 |
+
We start by adding some C++11 features to our project by replacing
|
| 231 |
+
``atof`` with ``std::stod`` in ``tutorial.cxx``. This looks like
|
| 232 |
+
the following:
|
| 233 |
+
|
| 234 |
+
.. raw:: html
|
| 235 |
+
|
| 236 |
+
<details><summary>TODO 4: Click to show/hide answer</summary>
|
| 237 |
+
|
| 238 |
+
.. literalinclude:: Step2/tutorial.cxx
|
| 239 |
+
:caption: TODO 4: tutorial.cxx
|
| 240 |
+
:name: tutorial.cxx-cxx11
|
| 241 |
+
:language: c++
|
| 242 |
+
:start-after: // convert input to double
|
| 243 |
+
:end-before: // TODO 6:
|
| 244 |
+
|
| 245 |
+
.. raw:: html
|
| 246 |
+
|
| 247 |
+
</details>
|
| 248 |
+
|
| 249 |
+
To complete ``TODO 5``, simply remove ``#include <cstdlib>``.
|
| 250 |
+
|
| 251 |
+
We will need to explicitly state in the CMake code that it should use the
|
| 252 |
+
correct flags. One way to enable support for a specific C++ standard in CMake
|
| 253 |
+
is by using the :variable:`CMAKE_CXX_STANDARD` variable. For this tutorial, set
|
| 254 |
+
the :variable:`CMAKE_CXX_STANDARD` variable in the ``CMakeLists.txt`` file to
|
| 255 |
+
``11`` and :variable:`CMAKE_CXX_STANDARD_REQUIRED` to ``True``. Make sure to
|
| 256 |
+
add the :variable:`CMAKE_CXX_STANDARD` declarations above the call to
|
| 257 |
+
:command:`add_executable`.
|
| 258 |
+
|
| 259 |
+
.. raw:: html
|
| 260 |
+
|
| 261 |
+
<details><summary>TODO 6: Click to show/hide answer</summary>
|
| 262 |
+
|
| 263 |
+
.. literalinclude:: Step2/CMakeLists.txt
|
| 264 |
+
:caption: TODO 6: CMakeLists.txt
|
| 265 |
+
:name: CMakeLists.txt-CXX_STANDARD
|
| 266 |
+
:language: cmake
|
| 267 |
+
:start-after: # specify the C++ standard
|
| 268 |
+
:end-before: # configure a header file
|
| 269 |
+
|
| 270 |
+
.. raw:: html
|
| 271 |
+
|
| 272 |
+
</details>
|
| 273 |
+
|
| 274 |
+
Exercise 3 - Adding a Version Number and Configured Header File
|
| 275 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 276 |
+
|
| 277 |
+
Sometimes it may be useful to have a variable that is defined in your
|
| 278 |
+
``CMakelists.txt`` file also be available in your source code. In this case, we
|
| 279 |
+
would like to print the project version.
|
| 280 |
+
|
| 281 |
+
One way to accomplish this is by using a configured header file. We create an
|
| 282 |
+
input file with one or more variables to replace. These variables have special
|
| 283 |
+
syntax which looks like ``@VAR@``.
|
| 284 |
+
Then, we use the :command:`configure_file` command to copy the input file to a
|
| 285 |
+
given output file and replace these variables with the current value of ``VAR``
|
| 286 |
+
in the ``CMakelists.txt`` file.
|
| 287 |
+
|
| 288 |
+
While we could edit the version directly in the source code, using this
|
| 289 |
+
feature is preferred since it creates a single source of truth and avoids
|
| 290 |
+
duplication.
|
| 291 |
+
|
| 292 |
+
Goal
|
| 293 |
+
----
|
| 294 |
+
|
| 295 |
+
Define and report the project's version number.
|
| 296 |
+
|
| 297 |
+
Helpful Resources
|
| 298 |
+
-----------------
|
| 299 |
+
|
| 300 |
+
* :variable:`<PROJECT-NAME>_VERSION_MAJOR`
|
| 301 |
+
* :variable:`<PROJECT-NAME>_VERSION_MINOR`
|
| 302 |
+
* :command:`configure_file`
|
| 303 |
+
* :command:`target_include_directories`
|
| 304 |
+
|
| 305 |
+
Files to Edit
|
| 306 |
+
-------------
|
| 307 |
+
|
| 308 |
+
* ``CMakeLists.txt``
|
| 309 |
+
* ``tutorial.cxx``
|
| 310 |
+
|
| 311 |
+
Getting Started
|
| 312 |
+
---------------
|
| 313 |
+
|
| 314 |
+
Continue to edit files from ``Step1``. Start on ``TODO 7`` and complete through
|
| 315 |
+
``TODO 12``. In this exercise, we start by adding a project version number in
|
| 316 |
+
``CMakeLists.txt``. In that same file, use :command:`configure_file` to copy a
|
| 317 |
+
given input file to an output file and substitute some variable values in the
|
| 318 |
+
input file content.
|
| 319 |
+
|
| 320 |
+
Next, create an input header file ``TutorialConfig.h.in`` defining version
|
| 321 |
+
numbers which will accept variables passed from :command:`configure_file`.
|
| 322 |
+
|
| 323 |
+
Finally, update ``tutorial.cxx`` to print out its version number.
|
| 324 |
+
|
| 325 |
+
Build and Run
|
| 326 |
+
-------------
|
| 327 |
+
|
| 328 |
+
Let's build our project again. As before, we already created a build directory
|
| 329 |
+
and ran CMake so we can skip to the build step:
|
| 330 |
+
|
| 331 |
+
.. code-block:: console
|
| 332 |
+
|
| 333 |
+
cd Step1_build
|
| 334 |
+
cmake --build .
|
| 335 |
+
|
| 336 |
+
Verify that the version number is now reported when running the executable
|
| 337 |
+
without any arguments.
|
| 338 |
+
|
| 339 |
+
Solution
|
| 340 |
+
--------
|
| 341 |
+
|
| 342 |
+
In this exercise, we improve our executable by printing a version number.
|
| 343 |
+
While we could do this exclusively in the source code, using ``CMakeLists.txt``
|
| 344 |
+
lets us maintain a single source of data for the version number.
|
| 345 |
+
|
| 346 |
+
First, we modify the ``CMakeLists.txt`` file to use the
|
| 347 |
+
:command:`project` command to set both the project name and version number.
|
| 348 |
+
When the :command:`project` command is called, CMake defines
|
| 349 |
+
``Tutorial_VERSION_MAJOR`` and ``Tutorial_VERSION_MINOR`` behind the scenes.
|
| 350 |
+
|
| 351 |
+
.. raw:: html
|
| 352 |
+
|
| 353 |
+
<details><summary>TODO 7: Click to show/hide answer</summary>
|
| 354 |
+
|
| 355 |
+
.. literalinclude:: Step2/CMakeLists.txt
|
| 356 |
+
:caption: TODO 7: CMakeLists.txt
|
| 357 |
+
:name: CMakeLists.txt-project-VERSION
|
| 358 |
+
:language: cmake
|
| 359 |
+
:start-after: # set the project name and version
|
| 360 |
+
:end-before: # specify the C++ standard
|
| 361 |
+
|
| 362 |
+
.. raw:: html
|
| 363 |
+
|
| 364 |
+
</details>
|
| 365 |
+
|
| 366 |
+
Then we used :command:`configure_file` to copy the input file with the
|
| 367 |
+
specified CMake variables replaced:
|
| 368 |
+
|
| 369 |
+
.. raw:: html
|
| 370 |
+
|
| 371 |
+
<details><summary>TODO 8: Click to show/hide answer</summary>
|
| 372 |
+
|
| 373 |
+
.. literalinclude:: Step2/CMakeLists.txt
|
| 374 |
+
:caption: TODO 8: CMakeLists.txt
|
| 375 |
+
:name: CMakeLists.txt-configure_file
|
| 376 |
+
:language: cmake
|
| 377 |
+
:start-after: # to the source code
|
| 378 |
+
:end-before: # TODO 2:
|
| 379 |
+
|
| 380 |
+
.. raw:: html
|
| 381 |
+
|
| 382 |
+
</details>
|
| 383 |
+
|
| 384 |
+
Since the configured file will be written into the project binary
|
| 385 |
+
directory, we must add that directory to the list of paths to search for
|
| 386 |
+
include files.
|
| 387 |
+
|
| 388 |
+
**Note:** Throughout this tutorial, we will refer to the project build and
|
| 389 |
+
the project binary directory interchangeably. These are the same and are not
|
| 390 |
+
meant to refer to a `bin/` directory.
|
| 391 |
+
|
| 392 |
+
We used :command:`target_include_directories` to specify
|
| 393 |
+
where the executable target should look for include files.
|
| 394 |
+
|
| 395 |
+
.. raw:: html
|
| 396 |
+
|
| 397 |
+
<details><summary>TODO 9: Click to show/hide answer</summary>
|
| 398 |
+
|
| 399 |
+
.. literalinclude:: Step2/CMakeLists.txt
|
| 400 |
+
:caption: TODO 9: CMakeLists.txt
|
| 401 |
+
:name: CMakeLists.txt-target_include_directories
|
| 402 |
+
:language: cmake
|
| 403 |
+
:start-after: # so that we will find TutorialConfig.h
|
| 404 |
+
|
| 405 |
+
.. raw:: html
|
| 406 |
+
|
| 407 |
+
</details>
|
| 408 |
+
|
| 409 |
+
``TutorialConfig.h.in`` is the input header file to be configured.
|
| 410 |
+
When :command:`configure_file` is called from our ``CMakeLists.txt``, the
|
| 411 |
+
values for ``@Tutorial_VERSION_MAJOR@`` and ``@Tutorial_VERSION_MINOR@`` will
|
| 412 |
+
be replaced with the corresponding version numbers from the project in
|
| 413 |
+
``TutorialConfig.h``.
|
| 414 |
+
|
| 415 |
+
.. raw:: html
|
| 416 |
+
|
| 417 |
+
<details><summary>TODO 10: Click to show/hide answer</summary>
|
| 418 |
+
|
| 419 |
+
.. literalinclude:: Step2/TutorialConfig.h.in
|
| 420 |
+
:caption: TODO 10: TutorialConfig.h.in
|
| 421 |
+
:name: TutorialConfig.h.in
|
| 422 |
+
:language: c++
|
| 423 |
+
|
| 424 |
+
.. raw:: html
|
| 425 |
+
|
| 426 |
+
</details>
|
| 427 |
+
|
| 428 |
+
Next, we need to modify ``tutorial.cxx`` to include the configured header file,
|
| 429 |
+
``TutorialConfig.h``.
|
| 430 |
+
|
| 431 |
+
.. raw:: html
|
| 432 |
+
|
| 433 |
+
<details><summary>TODO 11: Click to show/hide answer</summary>
|
| 434 |
+
|
| 435 |
+
.. code-block:: c++
|
| 436 |
+
:caption: TODO 11: tutorial.cxx
|
| 437 |
+
|
| 438 |
+
#include "TutorialConfig.h"
|
| 439 |
+
|
| 440 |
+
.. raw:: html
|
| 441 |
+
|
| 442 |
+
</details>
|
| 443 |
+
|
| 444 |
+
Finally, we print out the executable name and version number by updating
|
| 445 |
+
``tutorial.cxx`` as follows:
|
| 446 |
+
|
| 447 |
+
.. raw:: html
|
| 448 |
+
|
| 449 |
+
<details><summary>TODO 12: Click to show/hide answer</summary>
|
| 450 |
+
|
| 451 |
+
.. literalinclude:: Step2/tutorial.cxx
|
| 452 |
+
:caption: TODO 12 : tutorial.cxx
|
| 453 |
+
:name: tutorial.cxx-print-version
|
| 454 |
+
:language: c++
|
| 455 |
+
:start-after: {
|
| 456 |
+
:end-before: // convert input to double
|
| 457 |
+
|
| 458 |
+
.. raw:: html
|
| 459 |
+
|
| 460 |
+
</details>
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding Export Configuration.rst.txt
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 11: Adding Export Configuration
|
| 2 |
+
====================================
|
| 3 |
+
|
| 4 |
+
During :guide:`tutorial/Installing and Testing` of the tutorial we added the
|
| 5 |
+
ability for CMake to install the library and headers of the project. During
|
| 6 |
+
:guide:`tutorial/Packaging an Installer` we added the ability to package up
|
| 7 |
+
this information so it could be distributed to other people.
|
| 8 |
+
|
| 9 |
+
The next step is to add the necessary information so that other CMake projects
|
| 10 |
+
can use our project, be it from a build directory, a local install or when
|
| 11 |
+
packaged.
|
| 12 |
+
|
| 13 |
+
The first step is to update our :command:`install(TARGETS)` commands to not
|
| 14 |
+
only specify a ``DESTINATION`` but also an ``EXPORT``. The ``EXPORT`` keyword
|
| 15 |
+
generates a CMake file containing code to import all targets listed in the
|
| 16 |
+
install command from the installation tree. So let's go ahead and explicitly
|
| 17 |
+
``EXPORT`` the ``MathFunctions`` library by updating the ``install`` command
|
| 18 |
+
in ``MathFunctions/CMakeLists.txt`` to look like:
|
| 19 |
+
|
| 20 |
+
.. literalinclude:: Complete/MathFunctions/CMakeLists.txt
|
| 21 |
+
:caption: MathFunctions/CMakeLists.txt
|
| 22 |
+
:name: MathFunctions/CMakeLists.txt-install-TARGETS-EXPORT
|
| 23 |
+
:language: cmake
|
| 24 |
+
:start-after: # install libs
|
| 25 |
+
|
| 26 |
+
Now that we have ``MathFunctions`` being exported, we also need to explicitly
|
| 27 |
+
install the generated ``MathFunctionsTargets.cmake`` file. This is done by
|
| 28 |
+
adding the following to the bottom of the top-level ``CMakeLists.txt``:
|
| 29 |
+
|
| 30 |
+
.. literalinclude:: Complete/CMakeLists.txt
|
| 31 |
+
:caption: CMakeLists.txt
|
| 32 |
+
:name: CMakeLists.txt-install-EXPORT
|
| 33 |
+
:language: cmake
|
| 34 |
+
:start-after: # install the configuration targets
|
| 35 |
+
:end-before: include(CMakePackageConfigHelpers)
|
| 36 |
+
|
| 37 |
+
At this point you should try and run CMake. If everything is setup properly
|
| 38 |
+
you will see that CMake will generate an error that looks like:
|
| 39 |
+
|
| 40 |
+
.. code-block:: console
|
| 41 |
+
|
| 42 |
+
Target "MathFunctions" INTERFACE_INCLUDE_DIRECTORIES property contains
|
| 43 |
+
path:
|
| 44 |
+
|
| 45 |
+
"/Users/robert/Documents/CMakeClass/Tutorial/Step11/MathFunctions"
|
| 46 |
+
|
| 47 |
+
which is prefixed in the source directory.
|
| 48 |
+
|
| 49 |
+
What CMake is trying to say is that during generating the export information
|
| 50 |
+
it will export a path that is intrinsically tied to the current machine and
|
| 51 |
+
will not be valid on other machines. The solution to this is to update the
|
| 52 |
+
``MathFunctions`` :command:`target_include_directories` to understand that it
|
| 53 |
+
needs different ``INTERFACE`` locations when being used from within the build
|
| 54 |
+
directory and from an install / package. This means converting the
|
| 55 |
+
:command:`target_include_directories` call for ``MathFunctions`` to look like:
|
| 56 |
+
|
| 57 |
+
.. literalinclude:: Step12/MathFunctions/CMakeLists.txt
|
| 58 |
+
:caption: MathFunctions/CMakeLists.txt
|
| 59 |
+
:name: MathFunctions/CMakeLists.txt-target_include_directories
|
| 60 |
+
:language: cmake
|
| 61 |
+
:start-after: # to find MathFunctions.h, while we don't.
|
| 62 |
+
:end-before: # should we use our own math functions
|
| 63 |
+
|
| 64 |
+
Once this has been updated, we can re-run CMake and verify that it doesn't
|
| 65 |
+
warn anymore.
|
| 66 |
+
|
| 67 |
+
At this point, we have CMake properly packaging the target information that is
|
| 68 |
+
required but we will still need to generate a ``MathFunctionsConfig.cmake`` so
|
| 69 |
+
that the CMake :command:`find_package` command can find our project. So let's go
|
| 70 |
+
ahead and add a new file to the top-level of the project called
|
| 71 |
+
``Config.cmake.in`` with the following contents:
|
| 72 |
+
|
| 73 |
+
.. literalinclude:: Step12/Config.cmake.in
|
| 74 |
+
:caption: Config.cmake.in
|
| 75 |
+
:name: Config.cmake.in
|
| 76 |
+
|
| 77 |
+
Then, to properly configure and install that file, add the following to the
|
| 78 |
+
bottom of the top-level ``CMakeLists.txt``:
|
| 79 |
+
|
| 80 |
+
.. literalinclude:: Step12/CMakeLists.txt
|
| 81 |
+
:caption: CMakeLists.txt
|
| 82 |
+
:name: CMakeLists.txt-install-Config.cmake
|
| 83 |
+
:language: cmake
|
| 84 |
+
:start-after: # install the configuration targets
|
| 85 |
+
:end-before: # generate the config file
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
Next, we execute the :command:`configure_package_config_file`. This command
|
| 89 |
+
will configure a provided file but with a few specific differences from the
|
| 90 |
+
standard :command:`configure_file` way.
|
| 91 |
+
To properly utilize this function, the input file should have a single line
|
| 92 |
+
with the text ``@PACKAGE_INIT@`` in addition to the content that is desired.
|
| 93 |
+
That variable will be replaced with a block of code which turns set values into
|
| 94 |
+
relative paths. These values which are new can be referenced by the same name
|
| 95 |
+
but prepended with a ``PACKAGE_`` prefix.
|
| 96 |
+
|
| 97 |
+
.. literalinclude:: Step12/CMakeLists.txt
|
| 98 |
+
:caption: CMakeLists.txt
|
| 99 |
+
:name: CMakeLists.txt-configure-package-config.cmake
|
| 100 |
+
:language: cmake
|
| 101 |
+
:start-after: # install the configuration targets
|
| 102 |
+
:end-before: # generate the version file
|
| 103 |
+
|
| 104 |
+
The :command:`write_basic_package_version_file` is next. This command writes
|
| 105 |
+
a file which is used by :command:`find_package`, documenting the version and
|
| 106 |
+
compatibility of the desired package. Here, we use the ``Tutorial_VERSION_*``
|
| 107 |
+
variables and say that it is compatible with ``AnyNewerVersion``, which
|
| 108 |
+
denotes that this version or any higher one are compatible with the requested
|
| 109 |
+
version.
|
| 110 |
+
|
| 111 |
+
.. literalinclude:: Step12/CMakeLists.txt
|
| 112 |
+
:caption: CMakeLists.txt
|
| 113 |
+
:name: CMakeLists.txt-basic-version-file.cmake
|
| 114 |
+
:language: cmake
|
| 115 |
+
:start-after: # generate the version file
|
| 116 |
+
:end-before: # install the generated configuration files
|
| 117 |
+
|
| 118 |
+
Finally, set both generated files to be installed:
|
| 119 |
+
|
| 120 |
+
.. literalinclude:: Step12/CMakeLists.txt
|
| 121 |
+
:caption: CMakeLists.txt
|
| 122 |
+
:name: CMakeLists.txt-install-configured-files.cmake
|
| 123 |
+
:language: cmake
|
| 124 |
+
:start-after: # install the generated configuration files
|
| 125 |
+
:end-before: # generate the export
|
| 126 |
+
|
| 127 |
+
At this point, we have generated a relocatable CMake Configuration for our
|
| 128 |
+
project that can be used after the project has been installed or packaged. If
|
| 129 |
+
we want our project to also be used from a build directory we only have to add
|
| 130 |
+
the following to the bottom of the top level ``CMakeLists.txt``:
|
| 131 |
+
|
| 132 |
+
.. literalinclude:: Step12/CMakeLists.txt
|
| 133 |
+
:caption: CMakeLists.txt
|
| 134 |
+
:name: CMakeLists.txt-export
|
| 135 |
+
:language: cmake
|
| 136 |
+
:start-after: # needs to be after the install(TARGETS) command
|
| 137 |
+
|
| 138 |
+
With this export call we now generate a ``MathFunctionsTargets.cmake``, allowing the
|
| 139 |
+
configured ``MathFunctionsConfig.cmake`` in the build directory to be used by
|
| 140 |
+
other projects, without needing it to be installed.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding Generator Expressions.rst.txt
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 4: Adding Generator Expressions
|
| 2 |
+
=====================================
|
| 3 |
+
|
| 4 |
+
:manual:`Generator expressions <cmake-generator-expressions(7)>` are evaluated
|
| 5 |
+
during build system generation to produce information specific to each build
|
| 6 |
+
configuration.
|
| 7 |
+
|
| 8 |
+
:manual:`Generator expressions <cmake-generator-expressions(7)>` are allowed in
|
| 9 |
+
the context of many target properties, such as :prop_tgt:`LINK_LIBRARIES`,
|
| 10 |
+
:prop_tgt:`INCLUDE_DIRECTORIES`, :prop_tgt:`COMPILE_DEFINITIONS` and others.
|
| 11 |
+
They may also be used when using commands to populate those properties, such as
|
| 12 |
+
:command:`target_link_libraries`, :command:`target_include_directories`,
|
| 13 |
+
:command:`target_compile_definitions` and others.
|
| 14 |
+
|
| 15 |
+
:manual:`Generator expressions <cmake-generator-expressions(7)>` may be used
|
| 16 |
+
to enable conditional linking, conditional definitions used when compiling,
|
| 17 |
+
conditional include directories and more. The conditions may be based on the
|
| 18 |
+
build configuration, target properties, platform information or any other
|
| 19 |
+
queryable information.
|
| 20 |
+
|
| 21 |
+
There are different types of
|
| 22 |
+
:manual:`generator expressions <cmake-generator-expressions(7)>` including
|
| 23 |
+
Logical, Informational, and Output expressions.
|
| 24 |
+
|
| 25 |
+
Logical expressions are used to create conditional output. The basic
|
| 26 |
+
expressions are the ``0`` and ``1`` expressions. A ``$<0:...>`` results in the
|
| 27 |
+
empty string, and ``<1:...>`` results in the content of ``...``. They can also
|
| 28 |
+
be nested.
|
| 29 |
+
|
| 30 |
+
Exercise 1 - Adding Compiler Warning Flags with Generator Expressions
|
| 31 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 32 |
+
|
| 33 |
+
A common usage of
|
| 34 |
+
:manual:`generator expressions <cmake-generator-expressions(7)>` is to
|
| 35 |
+
conditionally add compiler flags, such as those for language levels or
|
| 36 |
+
warnings. A nice pattern is to associate this information to an ``INTERFACE``
|
| 37 |
+
target allowing this information to propagate.
|
| 38 |
+
|
| 39 |
+
Goal
|
| 40 |
+
----
|
| 41 |
+
|
| 42 |
+
Add compiler warning flags when building but not for installed versions.
|
| 43 |
+
|
| 44 |
+
Helpful Resources
|
| 45 |
+
-----------------
|
| 46 |
+
|
| 47 |
+
* :manual:`cmake-generator-expressions(7)`
|
| 48 |
+
* :command:`cmake_minimum_required`
|
| 49 |
+
* :command:`set`
|
| 50 |
+
* :command:`target_compile_options`
|
| 51 |
+
|
| 52 |
+
Files to Edit
|
| 53 |
+
-------------
|
| 54 |
+
|
| 55 |
+
* ``CMakeLists.txt``
|
| 56 |
+
|
| 57 |
+
Getting Started
|
| 58 |
+
---------------
|
| 59 |
+
|
| 60 |
+
Open the file ``Step4/CMakeLists.txt`` and complete ``TODO 1`` through
|
| 61 |
+
``TODO 4``.
|
| 62 |
+
|
| 63 |
+
First, in the top level ``CMakeLists.txt`` file, we need to set the
|
| 64 |
+
:command:`cmake_minimum_required` to ``3.15``. In this exercise we are going
|
| 65 |
+
to use a generator expression which was introduced in CMake 3.15.
|
| 66 |
+
|
| 67 |
+
Next we add the desired compiler warning flags that we want for our project.
|
| 68 |
+
As warning flags vary based on the compiler, we use the
|
| 69 |
+
``COMPILE_LANG_AND_ID`` generator expression to control which flags to apply
|
| 70 |
+
given a language and a set of compiler ids.
|
| 71 |
+
|
| 72 |
+
Build and Run
|
| 73 |
+
-------------
|
| 74 |
+
|
| 75 |
+
Make a new directory called ``Step4_build``, run the :manual:`cmake <cmake(1)>`
|
| 76 |
+
executable or the :manual:`cmake-gui <cmake-gui(1)>` to configure the project
|
| 77 |
+
and then build it with your chosen build tool or by using ``cmake --build .``
|
| 78 |
+
from the build directory.
|
| 79 |
+
|
| 80 |
+
.. code-block:: console
|
| 81 |
+
|
| 82 |
+
mkdir Step4_build
|
| 83 |
+
cd Step4_build
|
| 84 |
+
cmake ../Step4
|
| 85 |
+
cmake --build .
|
| 86 |
+
|
| 87 |
+
Solution
|
| 88 |
+
--------
|
| 89 |
+
|
| 90 |
+
Update the :command:`cmake_minimum_required` to require at least CMake
|
| 91 |
+
version ``3.15``:
|
| 92 |
+
|
| 93 |
+
.. raw:: html
|
| 94 |
+
|
| 95 |
+
<details><summary>TODO 1: Click to show/hide answer</summary>
|
| 96 |
+
|
| 97 |
+
.. literalinclude:: Step5/CMakeLists.txt
|
| 98 |
+
:caption: TODO 1: CMakeLists.txt
|
| 99 |
+
:name: MathFunctions-CMakeLists.txt-minimum-required-step4
|
| 100 |
+
:language: cmake
|
| 101 |
+
:end-before: # set the project name and version
|
| 102 |
+
|
| 103 |
+
.. raw:: html
|
| 104 |
+
|
| 105 |
+
</details>
|
| 106 |
+
|
| 107 |
+
Next we determine which compiler our system is currently using to build
|
| 108 |
+
since warning flags vary based on the compiler we use. This is done with
|
| 109 |
+
the ``COMPILE_LANG_AND_ID`` generator expression. We set the result in the
|
| 110 |
+
variables ``gcc_like_cxx`` and ``msvc_cxx`` as follows:
|
| 111 |
+
|
| 112 |
+
.. raw:: html
|
| 113 |
+
|
| 114 |
+
<details><summary>TODO 2: Click to show/hide answer</summary>
|
| 115 |
+
|
| 116 |
+
.. literalinclude:: Step5/CMakeLists.txt
|
| 117 |
+
:caption: TODO 2: CMakeLists.txt
|
| 118 |
+
:name: CMakeLists.txt-compile_lang_and_id
|
| 119 |
+
:language: cmake
|
| 120 |
+
:start-after: # the BUILD_INTERFACE genex
|
| 121 |
+
:end-before: target_compile_options(tutorial_compiler_flags INTERFACE
|
| 122 |
+
|
| 123 |
+
.. raw:: html
|
| 124 |
+
|
| 125 |
+
</details>
|
| 126 |
+
|
| 127 |
+
Next we add the desired compiler warning flags that we want for our project.
|
| 128 |
+
Using our variables ``gcc_like_cxx`` and ``msvc_cxx``, we can use another
|
| 129 |
+
generator expression to apply the respective flags only when the variables are
|
| 130 |
+
true. We use :command:`target_compile_options` to apply these flags to our
|
| 131 |
+
interface library.
|
| 132 |
+
|
| 133 |
+
.. raw:: html
|
| 134 |
+
|
| 135 |
+
<details><summary>TODO 3: Click to show/hide answer</summary>
|
| 136 |
+
|
| 137 |
+
.. code-block:: cmake
|
| 138 |
+
:caption: TODO 3: CMakeLists.txt
|
| 139 |
+
:name: CMakeLists.txt-compile_flags
|
| 140 |
+
|
| 141 |
+
target_compile_options(tutorial_compiler_flags INTERFACE
|
| 142 |
+
"$<${gcc_like_cxx}:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>"
|
| 143 |
+
"$<${msvc_cxx}:-W3>"
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
.. raw:: html
|
| 147 |
+
|
| 148 |
+
</details>
|
| 149 |
+
|
| 150 |
+
Lastly, we only want these warning flags to be used during builds. Consumers
|
| 151 |
+
of our installed project should not inherit our warning flags. To specify
|
| 152 |
+
this, we wrap our flags in a generator expression using the ``BUILD_INTERFACE``
|
| 153 |
+
condition. The resulting full code looks like the following:
|
| 154 |
+
|
| 155 |
+
.. raw:: html
|
| 156 |
+
|
| 157 |
+
<details><summary>TODO 4: Click to show/hide answer</summary>
|
| 158 |
+
|
| 159 |
+
.. literalinclude:: Step5/CMakeLists.txt
|
| 160 |
+
:caption: TODO 4: CMakeLists.txt
|
| 161 |
+
:name: CMakeLists.txt-target_compile_options-genex
|
| 162 |
+
:language: cmake
|
| 163 |
+
:start-after: set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")
|
| 164 |
+
:end-before: # configure a header file to pass some of the CMake settings
|
| 165 |
+
|
| 166 |
+
.. raw:: html
|
| 167 |
+
|
| 168 |
+
</details>
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding Support for a Testing Dashboard.rst.txt
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 6: Adding Support for a Testing Dashboard
|
| 2 |
+
==============================================
|
| 3 |
+
|
| 4 |
+
Adding support for submitting our test results to a dashboard is simple. We
|
| 5 |
+
already defined a number of tests for our project in
|
| 6 |
+
:ref:`Testing Support <Tutorial Testing Support>`. Now we just have to run
|
| 7 |
+
those tests and submit them to CDash.
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Exercise 1 - Send Results to a Testing Dashboard
|
| 11 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 12 |
+
|
| 13 |
+
Goal
|
| 14 |
+
----
|
| 15 |
+
|
| 16 |
+
Display our CTest results with CDash.
|
| 17 |
+
|
| 18 |
+
Helpful Resources
|
| 19 |
+
-----------------
|
| 20 |
+
|
| 21 |
+
* :manual:`ctest(1)`
|
| 22 |
+
* :command:`include`
|
| 23 |
+
* :module:`CTest`
|
| 24 |
+
|
| 25 |
+
Files to Edit
|
| 26 |
+
-------------
|
| 27 |
+
|
| 28 |
+
* ``CMakeLists.txt``
|
| 29 |
+
|
| 30 |
+
Getting Started
|
| 31 |
+
---------------
|
| 32 |
+
|
| 33 |
+
For this exercise, complete ``TODO 1`` in the top-level ``CMakeLists.txt`` by
|
| 34 |
+
including the :module:`CTest` module. This will enable testing with CTest as
|
| 35 |
+
well as dashboard submissions to CDash, so we can safely remove the call to
|
| 36 |
+
:command:`enable_testing`.
|
| 37 |
+
|
| 38 |
+
We will also need to acquire a ``CTestConfig.cmake`` file to be placed in the
|
| 39 |
+
top-level directory. When run, the :manual:`ctest <ctest(1)>` executable will
|
| 40 |
+
read this file to gather information about the testing dashboard. It contains:
|
| 41 |
+
|
| 42 |
+
* The project name
|
| 43 |
+
|
| 44 |
+
* The project "Nightly" start time
|
| 45 |
+
|
| 46 |
+
* The time when a 24 hour "day" starts for this project.
|
| 47 |
+
|
| 48 |
+
* The URL of the CDash instance where the submission's generated documents
|
| 49 |
+
will be sent
|
| 50 |
+
|
| 51 |
+
For this tutorial, a public dashboard server is used and its corresponding
|
| 52 |
+
``CTestConfig.cmake`` file is provided for you in this step's root directory.
|
| 53 |
+
In practice, this file would be downloaded from a project's ``Settings`` page
|
| 54 |
+
on the CDash instance intended to host the test results. Once downloaded from
|
| 55 |
+
CDash, the file should not be modified locally.
|
| 56 |
+
|
| 57 |
+
.. literalinclude:: Step7/CTestConfig.cmake
|
| 58 |
+
:caption: CTestConfig.cmake
|
| 59 |
+
:name: CTestConfig.cmake
|
| 60 |
+
:language: cmake
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Build and Run
|
| 64 |
+
-------------
|
| 65 |
+
|
| 66 |
+
Note that as part of the CDash submission some information about your
|
| 67 |
+
development system (e.g. site name or full pathnames) may displayed publicly.
|
| 68 |
+
|
| 69 |
+
To create a simple test dashboard, run the :manual:`cmake <cmake(1)>`
|
| 70 |
+
executable or the :manual:`cmake-gui <cmake-gui(1)>` to configure the project
|
| 71 |
+
but do not build it yet. Instead, navigate to the build directory and run:
|
| 72 |
+
|
| 73 |
+
.. code-block:: console
|
| 74 |
+
|
| 75 |
+
ctest [-VV] -D Experimental
|
| 76 |
+
|
| 77 |
+
Remember, for multi-config generators (e.g. Visual Studio), the configuration
|
| 78 |
+
type must be specified:
|
| 79 |
+
|
| 80 |
+
.. code-block:: console
|
| 81 |
+
|
| 82 |
+
ctest [-VV] -C Debug -D Experimental
|
| 83 |
+
|
| 84 |
+
Or, from an IDE, build the ``Experimental`` target.
|
| 85 |
+
|
| 86 |
+
The :manual:`ctest <ctest(1)>` executable will build the project, run any
|
| 87 |
+
tests, and submit the results to Kitware's public dashboard:
|
| 88 |
+
https://my.cdash.org/index.php?project=CMakeTutorial.
|
| 89 |
+
|
| 90 |
+
Solution
|
| 91 |
+
--------
|
| 92 |
+
|
| 93 |
+
The only CMake code changed needed in this step was to enable dashboard
|
| 94 |
+
submissions to CDash by including the :module:`CTest` module in our top-level
|
| 95 |
+
``CMakeLists.txt``:
|
| 96 |
+
|
| 97 |
+
.. raw:: html
|
| 98 |
+
|
| 99 |
+
<details><summary>TODO 1: Click to show/hide answer</summary>
|
| 100 |
+
|
| 101 |
+
.. literalinclude:: Step7/CMakeLists.txt
|
| 102 |
+
:caption: TODO 1: CMakeLists.txt
|
| 103 |
+
:name: CMakeLists.txt-include-CTest
|
| 104 |
+
:language: cmake
|
| 105 |
+
:start-after: # enable testing
|
| 106 |
+
:end-before: # does the application run
|
| 107 |
+
|
| 108 |
+
.. raw:: html
|
| 109 |
+
|
| 110 |
+
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 7: Adding System Introspection
|
| 2 |
+
===================================
|
| 3 |
+
|
| 4 |
+
Let us consider adding some code to our project that depends on features the
|
| 5 |
+
target platform may not have. For this example, we will add some code that
|
| 6 |
+
depends on whether or not the target platform has the ``log`` and ``exp``
|
| 7 |
+
functions. Of course almost every platform has these functions but for this
|
| 8 |
+
tutorial assume that they are not common.
|
| 9 |
+
|
| 10 |
+
Exercise 1 - Assessing Dependency Availability
|
| 11 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 12 |
+
|
| 13 |
+
Goal
|
| 14 |
+
----
|
| 15 |
+
|
| 16 |
+
Change implementation based on available system dependencies.
|
| 17 |
+
|
| 18 |
+
Helpful Resources
|
| 19 |
+
-----------------
|
| 20 |
+
|
| 21 |
+
* :module:`CheckCXXSourceCompiles`
|
| 22 |
+
* :command:`target_compile_definitions`
|
| 23 |
+
|
| 24 |
+
Files to Edit
|
| 25 |
+
-------------
|
| 26 |
+
|
| 27 |
+
* ``MathFunctions/CMakeLists.txt``
|
| 28 |
+
* ``MathFunctions/mysqrt.cxx``
|
| 29 |
+
|
| 30 |
+
Getting Started
|
| 31 |
+
---------------
|
| 32 |
+
|
| 33 |
+
The starting source code is provided in the ``Step7`` directory. In this
|
| 34 |
+
exercise, complete ``TODO 1`` through ``TODO 5``.
|
| 35 |
+
|
| 36 |
+
Start by editing ``MathFunctions/CMakeLists.txt``. Include the
|
| 37 |
+
:module:`CheckCXXSourceCompiles` module. Then, use
|
| 38 |
+
``check_cxx_source_compiles`` to determine whether ``log`` and ``exp`` are
|
| 39 |
+
available from ``cmath``. If they are available, use
|
| 40 |
+
:command:`target_compile_definitions` to specify ``HAVE_LOG`` and ``HAVE_EXP``
|
| 41 |
+
as compile definitions.
|
| 42 |
+
|
| 43 |
+
In the ``MathFunctions/mysqrt.cxx``, include ``cmath``. Then, if the system has
|
| 44 |
+
``log`` and ``exp``, use them to compute the square root.
|
| 45 |
+
|
| 46 |
+
Build and Run
|
| 47 |
+
-------------
|
| 48 |
+
|
| 49 |
+
Make a new directory called ``Step7_build``. Run the
|
| 50 |
+
:manual:`cmake <cmake(1)>` executable or the
|
| 51 |
+
:manual:`cmake-gui <cmake-gui(1)>` to configure the project and then build it
|
| 52 |
+
with your chosen build tool and run the ``Tutorial`` executable.
|
| 53 |
+
|
| 54 |
+
This can look like the following:
|
| 55 |
+
|
| 56 |
+
.. code-block:: console
|
| 57 |
+
|
| 58 |
+
mkdir Step7_build
|
| 59 |
+
cd Step7_build
|
| 60 |
+
cmake ../Step7
|
| 61 |
+
cmake --build .
|
| 62 |
+
|
| 63 |
+
Which function gives better results now, ``sqrt`` or ``mysqrt``?
|
| 64 |
+
|
| 65 |
+
Solution
|
| 66 |
+
--------
|
| 67 |
+
|
| 68 |
+
In this exercise we will use functions from the
|
| 69 |
+
:module:`CheckCXXSourceCompiles` module so first we must include it in
|
| 70 |
+
``MathFunctions/CMakeLists.txt``.
|
| 71 |
+
|
| 72 |
+
.. raw:: html
|
| 73 |
+
|
| 74 |
+
<details><summary>TODO 1: Click to show/hide answer</summary>
|
| 75 |
+
|
| 76 |
+
.. literalinclude:: Step8/MathFunctions/CMakeLists.txt
|
| 77 |
+
:caption: TODO 1: MathFunctions/CMakeLists.txt
|
| 78 |
+
:name: MathFunctions/CMakeLists.txt-include-check_cxx_source_compiles
|
| 79 |
+
:language: cmake
|
| 80 |
+
:start-after: # does this system provide the log and exp functions?
|
| 81 |
+
:end-before: check_cxx_source_compiles
|
| 82 |
+
|
| 83 |
+
.. raw:: html
|
| 84 |
+
|
| 85 |
+
</details>
|
| 86 |
+
|
| 87 |
+
Then test for the availability of
|
| 88 |
+
``log`` and ``exp`` using ``check_cxx_compiles_source``. This function
|
| 89 |
+
lets us try compiling simple code with the required dependency prior to
|
| 90 |
+
the true source code compilation. The resulting variables ``HAVE_LOG``
|
| 91 |
+
and ``HAVE_EXP`` represent whether those dependencies are available.
|
| 92 |
+
|
| 93 |
+
.. raw:: html
|
| 94 |
+
|
| 95 |
+
<details><summary>TODO 2: Click to show/hide answer</summary>
|
| 96 |
+
|
| 97 |
+
.. literalinclude:: Step8/MathFunctions/CMakeLists.txt
|
| 98 |
+
:caption: TODO 2: MathFunctions/CMakeLists.txt
|
| 99 |
+
:name: MathFunctions/CMakeLists.txt-check_cxx_source_compiles
|
| 100 |
+
:language: cmake
|
| 101 |
+
:start-after: include(CheckCXXSourceCompiles)
|
| 102 |
+
:end-before: # add compile definitions
|
| 103 |
+
|
| 104 |
+
.. raw:: html
|
| 105 |
+
|
| 106 |
+
</details>
|
| 107 |
+
|
| 108 |
+
Next, we need to pass these CMake variables to our source code. This way,
|
| 109 |
+
our source code can tell what resources are available. If both ``log`` and
|
| 110 |
+
``exp`` are available, use :command:`target_compile_definitions` to specify
|
| 111 |
+
``HAVE_LOG`` and ``HAVE_EXP`` as ``PRIVATE`` compile definitions.
|
| 112 |
+
|
| 113 |
+
.. raw:: html
|
| 114 |
+
|
| 115 |
+
<details><summary>TODO 3: Click to show/hide answer</summary>
|
| 116 |
+
|
| 117 |
+
.. literalinclude:: Step8/MathFunctions/CMakeLists.txt
|
| 118 |
+
:caption: TODO 3: MathFunctions/CMakeLists.txt
|
| 119 |
+
:name: MathFunctions/CMakeLists.txt-target_compile_definitions
|
| 120 |
+
:language: cmake
|
| 121 |
+
:start-after: # add compile definitions
|
| 122 |
+
:end-before: # state
|
| 123 |
+
|
| 124 |
+
.. raw:: html
|
| 125 |
+
|
| 126 |
+
</details>
|
| 127 |
+
|
| 128 |
+
Since we may be using ``log`` and ``exp``, we need to modify
|
| 129 |
+
``mysqrt.cxx`` to include ``cmath``.
|
| 130 |
+
|
| 131 |
+
.. raw:: html
|
| 132 |
+
|
| 133 |
+
<details><summary>TODO 4: Click to show/hide answer</summary>
|
| 134 |
+
|
| 135 |
+
.. literalinclude:: Step8/MathFunctions/mysqrt.cxx
|
| 136 |
+
:caption: TODO 4: MathFunctions/mysqrt.cxx
|
| 137 |
+
:name: MathFunctions/mysqrt.cxx-include-cmath
|
| 138 |
+
:language: c++
|
| 139 |
+
:start-after: #include "mysqrt.h"
|
| 140 |
+
:end-before: include <iostream>
|
| 141 |
+
|
| 142 |
+
.. raw:: html
|
| 143 |
+
|
| 144 |
+
</details>
|
| 145 |
+
|
| 146 |
+
If ``log`` and ``exp`` are available on the system, then use them to
|
| 147 |
+
compute the square root in the ``mysqrt`` function. The ``mysqrt`` function in
|
| 148 |
+
``MathFunctions/mysqrt.cxx`` will look as follows:
|
| 149 |
+
|
| 150 |
+
.. raw:: html
|
| 151 |
+
|
| 152 |
+
<details><summary>TODO 5: Click to show/hide answer</summary>
|
| 153 |
+
|
| 154 |
+
.. literalinclude:: Step8/MathFunctions/mysqrt.cxx
|
| 155 |
+
:caption: TODO 5: MathFunctions/mysqrt.cxx
|
| 156 |
+
:name: MathFunctions/mysqrt.cxx-ifdef
|
| 157 |
+
:language: c++
|
| 158 |
+
:start-after: // if we have both log and exp then use them
|
| 159 |
+
:end-before: return result;
|
| 160 |
+
|
| 161 |
+
.. raw:: html
|
| 162 |
+
|
| 163 |
+
</details>
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding Usage Requirements for a Library.rst.txt
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 3: Adding Usage Requirements for a Library
|
| 2 |
+
===============================================
|
| 3 |
+
|
| 4 |
+
Exercise 1 - Adding Usage Requirements for a Library
|
| 5 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 6 |
+
|
| 7 |
+
:ref:`Usage requirements <Target Usage Requirements>` of a target parameters
|
| 8 |
+
allow for far better control over a library or executable's link and include
|
| 9 |
+
line while also giving more control over the transitive property of targets
|
| 10 |
+
inside CMake. The primary commands that
|
| 11 |
+
leverage usage requirements are:
|
| 12 |
+
|
| 13 |
+
* :command:`target_compile_definitions`
|
| 14 |
+
* :command:`target_compile_options`
|
| 15 |
+
* :command:`target_include_directories`
|
| 16 |
+
* :command:`target_link_directories`
|
| 17 |
+
* :command:`target_link_options`
|
| 18 |
+
* :command:`target_precompile_headers`
|
| 19 |
+
* :command:`target_sources`
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Goal
|
| 23 |
+
----
|
| 24 |
+
|
| 25 |
+
Add usage requirements for a library.
|
| 26 |
+
|
| 27 |
+
Helpful Materials
|
| 28 |
+
-----------------
|
| 29 |
+
|
| 30 |
+
* :variable:`CMAKE_CURRENT_SOURCE_DIR`
|
| 31 |
+
|
| 32 |
+
Files to Edit
|
| 33 |
+
-------------
|
| 34 |
+
|
| 35 |
+
* ``MathFunctions/CMakeLists.txt``
|
| 36 |
+
* ``CMakeLists.txt``
|
| 37 |
+
|
| 38 |
+
Getting Started
|
| 39 |
+
---------------
|
| 40 |
+
|
| 41 |
+
In this exercise, we will refactor our code from
|
| 42 |
+
:guide:`tutorial/Adding a Library` to use the modern CMake approach. We will
|
| 43 |
+
let our library define its own usage requirements so they are passed
|
| 44 |
+
transitively to other targets as necessary. In this case, ``MathFunctions``
|
| 45 |
+
will specify any needed include directories itself. Then, the consuming target
|
| 46 |
+
``Tutorial`` simply needs to link to ``MathFunctions`` and not worry about
|
| 47 |
+
any additional include directories.
|
| 48 |
+
|
| 49 |
+
The starting source code is provided in the ``Step3`` directory. In this
|
| 50 |
+
exercise, complete ``TODO 1`` through ``TODO 3``.
|
| 51 |
+
|
| 52 |
+
First, add a call to :command:`target_include_directories` in
|
| 53 |
+
``MathFunctions/CMakeLists``. Remember that
|
| 54 |
+
:variable:`CMAKE_CURRENT_SOURCE_DIR` is the path to the source directory
|
| 55 |
+
currently being processed.
|
| 56 |
+
|
| 57 |
+
Then, update (and simplify!) the call to
|
| 58 |
+
:command:`target_include_directories` in the top-level ``CMakeLists.txt``.
|
| 59 |
+
|
| 60 |
+
Build and Run
|
| 61 |
+
-------------
|
| 62 |
+
|
| 63 |
+
Make a new directory called ``Step3_build``, run the :manual:`cmake
|
| 64 |
+
<cmake(1)>` executable or the :manual:`cmake-gui <cmake-gui(1)>` to
|
| 65 |
+
configure the project and then build it with your chosen build tool or by
|
| 66 |
+
using :option:`cmake --build . <cmake --build>` from the build directory.
|
| 67 |
+
Here's a refresher of what that looks like from the command line:
|
| 68 |
+
|
| 69 |
+
.. code-block:: console
|
| 70 |
+
|
| 71 |
+
mkdir Step3_build
|
| 72 |
+
cd Step3_build
|
| 73 |
+
cmake ../Step3
|
| 74 |
+
cmake --build .
|
| 75 |
+
|
| 76 |
+
Next, use the newly built ``Tutorial`` and verify that it is working as
|
| 77 |
+
expected.
|
| 78 |
+
|
| 79 |
+
Solution
|
| 80 |
+
--------
|
| 81 |
+
|
| 82 |
+
Let's update the code from the previous step to use the modern CMake
|
| 83 |
+
approach of usage requirements.
|
| 84 |
+
|
| 85 |
+
We want to state that anybody linking to ``MathFunctions`` needs to include
|
| 86 |
+
the current source directory, while ``MathFunctions`` itself doesn't. This
|
| 87 |
+
can be expressed with an ``INTERFACE`` usage requirement. Remember
|
| 88 |
+
``INTERFACE`` means things that consumers require but the producer doesn't.
|
| 89 |
+
|
| 90 |
+
At the end of ``MathFunctions/CMakeLists.txt``, use
|
| 91 |
+
:command:`target_include_directories` with the ``INTERFACE`` keyword, as
|
| 92 |
+
follows:
|
| 93 |
+
|
| 94 |
+
.. raw:: html
|
| 95 |
+
|
| 96 |
+
<details><summary>TODO 1: Click to show/hide answer</summary>
|
| 97 |
+
|
| 98 |
+
.. literalinclude:: Step4/MathFunctions/CMakeLists.txt
|
| 99 |
+
:caption: TODO 1: MathFunctions/CMakeLists.txt
|
| 100 |
+
:name: MathFunctions/CMakeLists.txt-target_include_directories-INTERFACE
|
| 101 |
+
:language: cmake
|
| 102 |
+
:start-after: # to find MathFunctions.h
|
| 103 |
+
:end-before: # should we use our own
|
| 104 |
+
|
| 105 |
+
.. raw:: html
|
| 106 |
+
|
| 107 |
+
</details>
|
| 108 |
+
|
| 109 |
+
Now that we've specified usage requirements for ``MathFunctions`` we can
|
| 110 |
+
safely remove our uses of the ``EXTRA_INCLUDES`` variable from the top-level
|
| 111 |
+
``CMakeLists.txt``.
|
| 112 |
+
|
| 113 |
+
Remove this line:
|
| 114 |
+
|
| 115 |
+
.. raw:: html
|
| 116 |
+
|
| 117 |
+
<details><summary>TODO 2: Click to show/hide answer</summary>
|
| 118 |
+
|
| 119 |
+
.. literalinclude:: Step3/CMakeLists.txt
|
| 120 |
+
:caption: TODO 2: CMakeLists.txt
|
| 121 |
+
:name: CMakeLists.txt-remove-EXTRA_INCLUDES
|
| 122 |
+
:language: cmake
|
| 123 |
+
:start-after: add_subdirectory(MathFunctions)
|
| 124 |
+
:end-before: # add the executable
|
| 125 |
+
|
| 126 |
+
.. raw:: html
|
| 127 |
+
|
| 128 |
+
</details>
|
| 129 |
+
|
| 130 |
+
And the lines:
|
| 131 |
+
|
| 132 |
+
.. raw:: html
|
| 133 |
+
|
| 134 |
+
<details><summary>TODO 3: Click to show/hide answer</summary>
|
| 135 |
+
|
| 136 |
+
.. literalinclude:: Step4/CMakeLists.txt
|
| 137 |
+
:caption: TODO 3: CMakeLists.txt
|
| 138 |
+
:name: CMakeLists.txt-target_include_directories-remove-EXTRA_INCLUDES
|
| 139 |
+
:language: cmake
|
| 140 |
+
:start-after: # so that we will find TutorialConfig.h
|
| 141 |
+
|
| 142 |
+
.. raw:: html
|
| 143 |
+
|
| 144 |
+
</details>
|
| 145 |
+
|
| 146 |
+
The remaining code looks like:
|
| 147 |
+
|
| 148 |
+
.. raw:: html
|
| 149 |
+
|
| 150 |
+
<details><summary>Click to show/hide the resulting code</summary>
|
| 151 |
+
|
| 152 |
+
.. literalinclude:: Step4/CMakeLists.txt
|
| 153 |
+
:caption: Remaining code after removing EXTRA_INCLUDES
|
| 154 |
+
:name: CMakeLists.txt-after-removing-EXTRA_INCLUDES
|
| 155 |
+
:language: cmake
|
| 156 |
+
:start-after: add_subdirectory(MathFunctions)
|
| 157 |
+
|
| 158 |
+
.. raw:: html
|
| 159 |
+
|
| 160 |
+
</details>
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
Notice that with this technique, the only thing our executable target does to
|
| 164 |
+
use our library is call :command:`target_link_libraries` with the name
|
| 165 |
+
of the library target. In larger projects, the classic method of specifying
|
| 166 |
+
library dependencies manually becomes very complicated very quickly.
|
| 167 |
+
|
| 168 |
+
Exercise 2 - Setting the C++ Standard with Interface Libraries
|
| 169 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 170 |
+
|
| 171 |
+
Now that we have switched our code to a more modern approach, let's demonstrate
|
| 172 |
+
a modern technique to set properties to multiple targets.
|
| 173 |
+
|
| 174 |
+
Let's refactor our existing code to use an ``INTERFACE`` library. We will
|
| 175 |
+
use that library in the next step to demonstrate a common use for
|
| 176 |
+
:manual:`generator expressions <cmake-generator-expressions(7)>`.
|
| 177 |
+
|
| 178 |
+
Goal
|
| 179 |
+
----
|
| 180 |
+
|
| 181 |
+
Add an ``INTERFACE`` library target to specify the required C++ standard.
|
| 182 |
+
|
| 183 |
+
Helpful Resources
|
| 184 |
+
-----------------
|
| 185 |
+
|
| 186 |
+
* :command:`add_library`
|
| 187 |
+
* :command:`target_compile_features`
|
| 188 |
+
* :command:`target_link_libraries`
|
| 189 |
+
|
| 190 |
+
Files to Edit
|
| 191 |
+
-------------
|
| 192 |
+
|
| 193 |
+
* ``CMakeLists.txt``
|
| 194 |
+
* ``MathFunctions/CMakeLists.txt``
|
| 195 |
+
|
| 196 |
+
Getting Started
|
| 197 |
+
---------------
|
| 198 |
+
|
| 199 |
+
In this exercise, we will refactor our code to use an ``INTERFACE`` library to
|
| 200 |
+
specify the C++ standard.
|
| 201 |
+
|
| 202 |
+
Start this exercise from what we left at the end of Step3 exercise 1. You will
|
| 203 |
+
have to complete ``TODO 4`` through ``TODO 7``.
|
| 204 |
+
|
| 205 |
+
Start by editing the top level ``CMakeLists.txt`` file. Construct an
|
| 206 |
+
``INTERFACE`` library target called ``tutorial_compiler_flags`` and
|
| 207 |
+
specify ``cxx_std_11`` as a target compiler feature.
|
| 208 |
+
|
| 209 |
+
Modify ``CMakeLists.txt`` and ``MathFunctions/CMakeLists.txt`` so that all
|
| 210 |
+
targets have a :command:`target_link_libraries` call to
|
| 211 |
+
``tutorial_compiler_flags``.
|
| 212 |
+
|
| 213 |
+
Build and Run
|
| 214 |
+
-------------
|
| 215 |
+
|
| 216 |
+
Since we have our build directory already configured from Exercise 1, simply
|
| 217 |
+
rebuild our code by calling the following:
|
| 218 |
+
|
| 219 |
+
.. code-block:: console
|
| 220 |
+
|
| 221 |
+
cd Step3_build
|
| 222 |
+
cmake --build .
|
| 223 |
+
|
| 224 |
+
Next, use the newly built ``Tutorial`` and verify that it is working as
|
| 225 |
+
expected.
|
| 226 |
+
|
| 227 |
+
Solution
|
| 228 |
+
--------
|
| 229 |
+
|
| 230 |
+
Let's update our code from the previous step to use interface libraries
|
| 231 |
+
to set our C++ requirements.
|
| 232 |
+
|
| 233 |
+
To start, we need to remove the two :command:`set` calls on the variables
|
| 234 |
+
:variable:`CMAKE_CXX_STANDARD` and :variable:`CMAKE_CXX_STANDARD_REQUIRED`.
|
| 235 |
+
The specific lines to remove are as follows:
|
| 236 |
+
|
| 237 |
+
.. literalinclude:: Step3/CMakeLists.txt
|
| 238 |
+
:caption: CMakeLists.txt
|
| 239 |
+
:name: CMakeLists.txt-CXX_STANDARD-variable-remove
|
| 240 |
+
:language: cmake
|
| 241 |
+
:start-after: # specify the C++ standard
|
| 242 |
+
:end-before: # configure a header file
|
| 243 |
+
|
| 244 |
+
Next, we need to create an interface library, ``tutorial_compiler_flags``. And
|
| 245 |
+
then use :command:`target_compile_features` to add the compiler feature
|
| 246 |
+
``cxx_std_11``.
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
.. raw:: html
|
| 250 |
+
|
| 251 |
+
<details><summary>TODO 4: Click to show/hide answer</summary>
|
| 252 |
+
|
| 253 |
+
.. literalinclude:: Step4/CMakeLists.txt
|
| 254 |
+
:caption: TODO 4: CMakeLists.txt
|
| 255 |
+
:name: CMakeLists.txt-cxx_std-feature
|
| 256 |
+
:language: cmake
|
| 257 |
+
:start-after: # specify the C++ standard
|
| 258 |
+
:end-before: # TODO 2: Create helper
|
| 259 |
+
|
| 260 |
+
.. raw:: html
|
| 261 |
+
|
| 262 |
+
</details>
|
| 263 |
+
|
| 264 |
+
Finally, with our interface library set up, we need to link our
|
| 265 |
+
executable ``Target``, our ``MathFunctions`` library, and our ``SqrtLibrary``
|
| 266 |
+
library to our new
|
| 267 |
+
``tutorial_compiler_flags`` library. Respectively, the code will look like
|
| 268 |
+
this:
|
| 269 |
+
|
| 270 |
+
.. raw:: html
|
| 271 |
+
|
| 272 |
+
<details><summary>TODO 5: Click to show/hide answer</summary>
|
| 273 |
+
|
| 274 |
+
.. literalinclude:: Step4/CMakeLists.txt
|
| 275 |
+
:caption: TODO 5: CMakeLists.txt
|
| 276 |
+
:name: CMakeLists.txt-target_link_libraries-step4
|
| 277 |
+
:language: cmake
|
| 278 |
+
:start-after: add_executable(Tutorial tutorial.cxx)
|
| 279 |
+
:end-before: # add the binary tree to the search path for include file
|
| 280 |
+
|
| 281 |
+
.. raw:: html
|
| 282 |
+
|
| 283 |
+
</details>
|
| 284 |
+
|
| 285 |
+
this:
|
| 286 |
+
|
| 287 |
+
.. raw:: html
|
| 288 |
+
|
| 289 |
+
<details><summary>TODO 6: Click to show/hide answer</summary>
|
| 290 |
+
|
| 291 |
+
.. literalinclude:: Step4/MathFunctions/CMakeLists.txt
|
| 292 |
+
:caption: TODO 6: MathFunctions/CMakeLists.txt
|
| 293 |
+
:name: MathFunctions-CMakeLists.txt-target_link_libraries-step4
|
| 294 |
+
:language: cmake
|
| 295 |
+
:start-after: # link our compiler flags interface library
|
| 296 |
+
:end-before: target_link_libraries(MathFunctions
|
| 297 |
+
|
| 298 |
+
.. raw:: html
|
| 299 |
+
|
| 300 |
+
</details>
|
| 301 |
+
|
| 302 |
+
and this:
|
| 303 |
+
|
| 304 |
+
.. raw:: html
|
| 305 |
+
|
| 306 |
+
<details><summary>TODO 7: Click to show/hide answer</summary>
|
| 307 |
+
|
| 308 |
+
.. literalinclude:: Step4/MathFunctions/CMakeLists.txt
|
| 309 |
+
:caption: TODO 7: MathFunctions/CMakeLists.txt
|
| 310 |
+
:name: MathFunctions-SqrtLibrary-target_link_libraries-step4
|
| 311 |
+
:language: cmake
|
| 312 |
+
:start-after: target_link_libraries(SqrtLibrary
|
| 313 |
+
:end-before: endif()
|
| 314 |
+
|
| 315 |
+
.. raw:: html
|
| 316 |
+
|
| 317 |
+
</details>
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
With this, all of our code still requires C++ 11 to build. Notice
|
| 321 |
+
though that with this method, it gives us the ability to be specific about
|
| 322 |
+
which targets get specific requirements. In addition, we create a single
|
| 323 |
+
source of truth in our interface library.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding a Custom Command and Generated File.rst.txt
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 8: Adding a Custom Command and Generated File
|
| 2 |
+
==================================================
|
| 3 |
+
|
| 4 |
+
Suppose, for the purpose of this tutorial, we decide that we never want to use
|
| 5 |
+
the platform ``log`` and ``exp`` functions and instead would like to
|
| 6 |
+
generate a table of precomputed values to use in the ``mysqrt`` function.
|
| 7 |
+
In this section, we will create the table as part of the build process,
|
| 8 |
+
and then compile that table into our application.
|
| 9 |
+
|
| 10 |
+
First, let's remove the check for the ``log`` and ``exp`` functions in
|
| 11 |
+
``MathFunctions/CMakeLists.txt``. Then remove the check for ``HAVE_LOG`` and
|
| 12 |
+
``HAVE_EXP`` from ``mysqrt.cxx``. At the same time, we can remove
|
| 13 |
+
:code:`#include <cmath>`.
|
| 14 |
+
|
| 15 |
+
In the ``MathFunctions`` subdirectory, a new source file named
|
| 16 |
+
``MakeTable.cxx`` has been provided to generate the table.
|
| 17 |
+
|
| 18 |
+
After reviewing the file, we can see that the table is produced as valid C++
|
| 19 |
+
code and that the output filename is passed in as an argument.
|
| 20 |
+
|
| 21 |
+
The next step is to create ``MathFunctions/MakeTable.cmake``. Then, add the
|
| 22 |
+
appropriate commands to the file to build the ``MakeTable`` executable and
|
| 23 |
+
then run it as part of the build process. A few commands are needed to
|
| 24 |
+
accomplish this.
|
| 25 |
+
|
| 26 |
+
First, we add an executable for ``MakeTable``.
|
| 27 |
+
|
| 28 |
+
.. literalinclude:: Step9/MathFunctions/MakeTable.cmake
|
| 29 |
+
:caption: MathFunctions/MakeTable.cmake
|
| 30 |
+
:name: MathFunctions/MakeTable.cmake-add_executable-MakeTable
|
| 31 |
+
:language: cmake
|
| 32 |
+
:start-after: # first we add the executable that generates the table
|
| 33 |
+
:end-before: target_link_libraries
|
| 34 |
+
|
| 35 |
+
After creating the executable, we add the ``tutorial_compiler_flags`` to our
|
| 36 |
+
executable using :command:`target_link_libraries`.
|
| 37 |
+
|
| 38 |
+
.. literalinclude:: Step9/MathFunctions/MakeTable.cmake
|
| 39 |
+
:caption: MathFunctions/MakeTable.cmake
|
| 40 |
+
:name: MathFunctions/MakeTable.cmake-link-tutorial-compiler-flags
|
| 41 |
+
:language: cmake
|
| 42 |
+
:start-after: add_executable
|
| 43 |
+
:end-before: # add the command to generate
|
| 44 |
+
|
| 45 |
+
Then we add a custom command that specifies how to produce ``Table.h``
|
| 46 |
+
by running MakeTable.
|
| 47 |
+
|
| 48 |
+
.. literalinclude:: Step9/MathFunctions/MakeTable.cmake
|
| 49 |
+
:caption: MathFunctions/MakeTable.cmake
|
| 50 |
+
:name: MathFunctions/MakeTable.cmake-add_custom_command-Table.h
|
| 51 |
+
:language: cmake
|
| 52 |
+
:start-after: # add the command to generate the source code
|
| 53 |
+
|
| 54 |
+
Next we have to let CMake know that ``mysqrt.cxx`` depends on the generated
|
| 55 |
+
file ``Table.h``. This is done by adding the generated ``Table.h`` to the list
|
| 56 |
+
of sources for the library ``SqrtLibrary``.
|
| 57 |
+
|
| 58 |
+
.. literalinclude:: Step9/MathFunctions/CMakeLists.txt
|
| 59 |
+
:caption: MathFunctions/CMakeLists.txt
|
| 60 |
+
:name: MathFunctions/CMakeLists.txt-add_library-Table.h
|
| 61 |
+
:language: cmake
|
| 62 |
+
:start-after: # library that just does sqrt
|
| 63 |
+
:end-before: # state that we depend on
|
| 64 |
+
|
| 65 |
+
We also have to add the current binary directory to the list of include
|
| 66 |
+
directories so that ``Table.h`` can be found and included by ``mysqrt.cxx``.
|
| 67 |
+
|
| 68 |
+
.. literalinclude:: Step9/MathFunctions/CMakeLists.txt
|
| 69 |
+
:caption: MathFunctions/CMakeLists.txt
|
| 70 |
+
:name: MathFunctions/CMakeLists.txt-target_include_directories-Table.h
|
| 71 |
+
:language: cmake
|
| 72 |
+
:start-after: # state that we depend on our bin
|
| 73 |
+
:end-before: target_link_libraries
|
| 74 |
+
|
| 75 |
+
As the last step, we need to include
|
| 76 |
+
``MakeTable.cmake`` at the top of the ``MathFunctions/CMakeLists.txt``.
|
| 77 |
+
|
| 78 |
+
.. literalinclude:: Step9/MathFunctions/CMakeLists.txt
|
| 79 |
+
:caption: MathFunctions/CMakeLists.txt
|
| 80 |
+
:name: MathFunctions/CMakeLists.txt-include-MakeTable.cmake
|
| 81 |
+
:language: cmake
|
| 82 |
+
:start-after: # generate Table.h
|
| 83 |
+
:end-before: # library that just does sqrt
|
| 84 |
+
|
| 85 |
+
Now let's use the generated table. First, modify ``mysqrt.cxx`` to include
|
| 86 |
+
``Table.h``. Next, we can rewrite the ``mysqrt`` function to use the table:
|
| 87 |
+
|
| 88 |
+
.. literalinclude:: Step9/MathFunctions/mysqrt.cxx
|
| 89 |
+
:caption: MathFunctions/mysqrt.cxx
|
| 90 |
+
:name: MathFunctions/mysqrt.cxx
|
| 91 |
+
:language: c++
|
| 92 |
+
:start-after: // a hack square root calculation using simple operations
|
| 93 |
+
|
| 94 |
+
Run the :manual:`cmake <cmake(1)>` executable or the
|
| 95 |
+
:manual:`cmake-gui <cmake-gui(1)>` to configure the project and then build it
|
| 96 |
+
with your chosen build tool.
|
| 97 |
+
|
| 98 |
+
When this project is built it will first build the ``MakeTable`` executable.
|
| 99 |
+
It will then run ``MakeTable`` to produce ``Table.h``. Finally, it will
|
| 100 |
+
compile ``mysqrt.cxx`` which includes ``Table.h`` to produce the
|
| 101 |
+
``MathFunctions`` library.
|
| 102 |
+
|
| 103 |
+
Run the Tutorial executable and verify that it is using the table.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Adding a Library.rst.txt
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 2: Adding a Library
|
| 2 |
+
========================
|
| 3 |
+
|
| 4 |
+
At this point, we have seen how to create a basic project using CMake. In this
|
| 5 |
+
step, we will learn how to create and use a library in our project. We will
|
| 6 |
+
also see how to make the use of our library optional.
|
| 7 |
+
|
| 8 |
+
Exercise 1 - Creating a Library
|
| 9 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 10 |
+
|
| 11 |
+
To add a library in CMake, use the :command:`add_library` command and specify
|
| 12 |
+
which source files should make up the library.
|
| 13 |
+
|
| 14 |
+
Rather than placing all of the source files in one directory, we can organize
|
| 15 |
+
our project with one or more subdirectories. In this case, we will create a
|
| 16 |
+
subdirectory specifically for our library. Here, we can add a new
|
| 17 |
+
``CMakeLists.txt`` file and one or more source files. In the top level
|
| 18 |
+
``CMakeLists.txt`` file, we will use the :command:`add_subdirectory` command
|
| 19 |
+
to add the subdirectory to the build.
|
| 20 |
+
|
| 21 |
+
Once the library is created, it is connected to our executable target with
|
| 22 |
+
:command:`target_include_directories` and :command:`target_link_libraries`.
|
| 23 |
+
|
| 24 |
+
Goal
|
| 25 |
+
----
|
| 26 |
+
|
| 27 |
+
Add and use a library.
|
| 28 |
+
|
| 29 |
+
Helpful Resources
|
| 30 |
+
-----------------
|
| 31 |
+
|
| 32 |
+
* :command:`add_library`
|
| 33 |
+
* :command:`add_subdirectory`
|
| 34 |
+
* :command:`target_include_directories`
|
| 35 |
+
* :command:`target_link_libraries`
|
| 36 |
+
* :variable:`PROJECT_SOURCE_DIR`
|
| 37 |
+
|
| 38 |
+
Files to Edit
|
| 39 |
+
-------------
|
| 40 |
+
|
| 41 |
+
* ``CMakeLists.txt``
|
| 42 |
+
* ``tutorial.cxx``
|
| 43 |
+
* ``MathFunctions/CMakeLists.txt``
|
| 44 |
+
|
| 45 |
+
Getting Started
|
| 46 |
+
---------------
|
| 47 |
+
|
| 48 |
+
In this exercise, we will add a library to our project that contains our own
|
| 49 |
+
implementation for computing the square root of a number. The executable can
|
| 50 |
+
then use this library instead of the standard square root function provided by
|
| 51 |
+
the compiler.
|
| 52 |
+
|
| 53 |
+
For this tutorial we will put the library into a subdirectory called
|
| 54 |
+
``MathFunctions``. This directory already contains the header files
|
| 55 |
+
``MathFunctions.h`` and ``mysqrt.h``. Their respective source files
|
| 56 |
+
``MathFunctions.cxx`` and ``mysqrt.cxx`` are also provided. We will not need
|
| 57 |
+
to modify any of these files. ``mysqrt.cxx`` has one function called
|
| 58 |
+
``mysqrt`` that provides similar functionality to the compiler's ``sqrt``
|
| 59 |
+
function. ``MathFunctions.cxx`` contains one function ``sqrt`` which serves
|
| 60 |
+
to hide the implementation details of ``sqrt``.
|
| 61 |
+
|
| 62 |
+
From the ``Help/guide/tutorial/Step2`` directory, start with ``TODO 1`` and
|
| 63 |
+
complete through ``TODO 6``.
|
| 64 |
+
|
| 65 |
+
First, fill in the one line ``CMakeLists.txt`` in the ``MathFunctions``
|
| 66 |
+
subdirectory.
|
| 67 |
+
|
| 68 |
+
Next, edit the top level ``CMakeLists.txt``.
|
| 69 |
+
|
| 70 |
+
Finally, use the newly created ``MathFunctions`` library in ``tutorial.cxx``
|
| 71 |
+
|
| 72 |
+
Build and Run
|
| 73 |
+
-------------
|
| 74 |
+
|
| 75 |
+
Run the :manual:`cmake <cmake(1)>` executable or the
|
| 76 |
+
:manual:`cmake-gui <cmake-gui(1)>` to configure the project and then build it
|
| 77 |
+
with your chosen build tool.
|
| 78 |
+
|
| 79 |
+
Below is a refresher of what that looks like from the command line:
|
| 80 |
+
|
| 81 |
+
.. code-block:: console
|
| 82 |
+
|
| 83 |
+
mkdir Step2_build
|
| 84 |
+
cd Step2_build
|
| 85 |
+
cmake ../Step2
|
| 86 |
+
cmake --build .
|
| 87 |
+
|
| 88 |
+
Try to use the newly built ``Tutorial`` and ensure that it is still
|
| 89 |
+
producing accurate square root values.
|
| 90 |
+
|
| 91 |
+
Solution
|
| 92 |
+
--------
|
| 93 |
+
|
| 94 |
+
In the ``CMakeLists.txt`` file in the ``MathFunctions`` directory, we create
|
| 95 |
+
a library target called ``MathFunctions`` with :command:`add_library`. The
|
| 96 |
+
source files for the library are passed as an argument to
|
| 97 |
+
:command:`add_library`. This looks like the following line:
|
| 98 |
+
|
| 99 |
+
.. raw:: html/
|
| 100 |
+
|
| 101 |
+
<details><summary>TODO 1: Click to show/hide answer</summary>
|
| 102 |
+
|
| 103 |
+
.. code-block:: cmake
|
| 104 |
+
:caption: TODO 1: MathFunctions/CMakeLists.txt
|
| 105 |
+
:name: MathFunctions/CMakeLists.txt-add_library
|
| 106 |
+
|
| 107 |
+
add_library(MathFunctions MathFunctions.cxx mysqrt.cxx)
|
| 108 |
+
|
| 109 |
+
.. raw:: html
|
| 110 |
+
|
| 111 |
+
</details>
|
| 112 |
+
|
| 113 |
+
To make use of the new library we will add an :command:`add_subdirectory`
|
| 114 |
+
call in the top-level ``CMakeLists.txt`` file so that the library will get
|
| 115 |
+
built.
|
| 116 |
+
|
| 117 |
+
.. raw:: html
|
| 118 |
+
|
| 119 |
+
<details><summary>TODO 2: Click to show/hide answer</summary>
|
| 120 |
+
|
| 121 |
+
.. code-block:: cmake
|
| 122 |
+
:caption: TODO 2: CMakeLists.txt
|
| 123 |
+
:name: CMakeLists.txt-add_subdirectory
|
| 124 |
+
|
| 125 |
+
add_subdirectory(MathFunctions)
|
| 126 |
+
|
| 127 |
+
.. raw:: html
|
| 128 |
+
|
| 129 |
+
</details>
|
| 130 |
+
|
| 131 |
+
Next, the new library target is linked to the executable target using
|
| 132 |
+
:command:`target_link_libraries`.
|
| 133 |
+
|
| 134 |
+
.. raw:: html
|
| 135 |
+
|
| 136 |
+
<details><summary>TODO 3: Click to show/hide answer</summary>
|
| 137 |
+
|
| 138 |
+
.. code-block:: cmake
|
| 139 |
+
:caption: TODO 3: CMakeLists.txt
|
| 140 |
+
:name: CMakeLists.txt-target_link_libraries
|
| 141 |
+
|
| 142 |
+
target_link_libraries(Tutorial PUBLIC MathFunctions)
|
| 143 |
+
|
| 144 |
+
.. raw:: html
|
| 145 |
+
|
| 146 |
+
</details>
|
| 147 |
+
|
| 148 |
+
Finally we need to specify the library's header file location. Modify
|
| 149 |
+
:command:`target_include_directories` to add the ``MathFunctions`` subdirectory
|
| 150 |
+
as an include directory so that the ``MathFunctions.h`` header file can be
|
| 151 |
+
found.
|
| 152 |
+
|
| 153 |
+
.. raw:: html
|
| 154 |
+
|
| 155 |
+
<details><summary>TODO 4: Click to show/hide answer</summary>
|
| 156 |
+
|
| 157 |
+
.. code-block:: cmake
|
| 158 |
+
:caption: TODO 4: CMakeLists.txt
|
| 159 |
+
:name: CMakeLists.txt-target_include_directories-step2
|
| 160 |
+
|
| 161 |
+
target_include_directories(Tutorial PUBLIC
|
| 162 |
+
"${PROJECT_BINARY_DIR}"
|
| 163 |
+
"${PROJECT_SOURCE_DIR}/MathFunctions"
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
.. raw:: html
|
| 167 |
+
|
| 168 |
+
</details>
|
| 169 |
+
|
| 170 |
+
Now let's use our library. In ``tutorial.cxx``, include ``MathFunctions.h``:
|
| 171 |
+
|
| 172 |
+
.. raw:: html
|
| 173 |
+
|
| 174 |
+
<details><summary>TODO 5: Click to show/hide answer</summary>
|
| 175 |
+
|
| 176 |
+
.. literalinclude:: Step3/tutorial.cxx
|
| 177 |
+
:caption: TODO 5: tutorial.cxx
|
| 178 |
+
:name: CMakeLists.txt-include-MathFunctions.h
|
| 179 |
+
:language: cmake
|
| 180 |
+
:start-after: #include <string>
|
| 181 |
+
:end-before: #include "TutorialConfig.h"
|
| 182 |
+
|
| 183 |
+
.. raw:: html
|
| 184 |
+
|
| 185 |
+
</details>
|
| 186 |
+
|
| 187 |
+
Lastly, replace ``sqrt`` with our library function ``mathfunctions::mysqrt``.
|
| 188 |
+
|
| 189 |
+
.. raw:: html
|
| 190 |
+
|
| 191 |
+
<details><summary>TODO 6: Click to show/hide answer</summary>
|
| 192 |
+
|
| 193 |
+
.. literalinclude:: Step3/tutorial.cxx
|
| 194 |
+
:caption: TODO 6: tutorial.cxx
|
| 195 |
+
:name: CMakeLists.txt-option
|
| 196 |
+
:language: cmake
|
| 197 |
+
:start-after: const double inputValue = std::stod(argv[1]);
|
| 198 |
+
:end-before: std::cout
|
| 199 |
+
|
| 200 |
+
.. raw:: html
|
| 201 |
+
|
| 202 |
+
</details>
|
| 203 |
+
|
| 204 |
+
Exercise 2 - Adding an Option
|
| 205 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 206 |
+
|
| 207 |
+
Now let us add an option in the MathFunctions library to allow developers to
|
| 208 |
+
select either the custom square root implementation or the built in standard
|
| 209 |
+
implementation. While for the tutorial
|
| 210 |
+
there really isn't any need to do so, for larger projects this is a common
|
| 211 |
+
occurrence.
|
| 212 |
+
|
| 213 |
+
CMake can do this using the :command:`option` command. This gives users a
|
| 214 |
+
variable which they can change when configuring their cmake build. This
|
| 215 |
+
setting will be stored in the cache so that the user does not need to set
|
| 216 |
+
the value each time they run CMake on a build directory.
|
| 217 |
+
|
| 218 |
+
Goal
|
| 219 |
+
----
|
| 220 |
+
|
| 221 |
+
Add the option to build without ``MathFunctions``.
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
Helpful Resources
|
| 225 |
+
-----------------
|
| 226 |
+
|
| 227 |
+
* :command:`if`
|
| 228 |
+
* :command:`option`
|
| 229 |
+
* :command:`target_compile_definitions`
|
| 230 |
+
|
| 231 |
+
Files to Edit
|
| 232 |
+
-------------
|
| 233 |
+
|
| 234 |
+
* ``MathFunctions/CMakeLists.txt``
|
| 235 |
+
* ``MathFunctions/MathFunctions.cxx``
|
| 236 |
+
|
| 237 |
+
Getting Started
|
| 238 |
+
---------------
|
| 239 |
+
|
| 240 |
+
Start with the resulting files from Exercise 1. Complete ``TODO 7`` through
|
| 241 |
+
``TODO 14``.
|
| 242 |
+
|
| 243 |
+
First create a variable ``USE_MYMATH`` using the :command:`option` command
|
| 244 |
+
in ``MathFunctions/CMakeLists.txt``. In that same file, use that option
|
| 245 |
+
to pass a compile definition to the ``MathFunctions`` library.
|
| 246 |
+
|
| 247 |
+
Then, update ``MathFunctions.cxx`` to redirect compilation based on
|
| 248 |
+
``USE_MYMATH``.
|
| 249 |
+
|
| 250 |
+
Lastly, prevent ``mysqrt.cxx`` from being compiled when ``USE_MYMATH`` is on
|
| 251 |
+
by making it its own library inside of the ``USE_MYMATH`` block of
|
| 252 |
+
``MathFunctions/CMakeLists.txt``.
|
| 253 |
+
|
| 254 |
+
Build and Run
|
| 255 |
+
-------------
|
| 256 |
+
|
| 257 |
+
Since we have our build directory already configured from Exercise 1, we can
|
| 258 |
+
rebuild by simply calling the following:
|
| 259 |
+
|
| 260 |
+
.. code-block:: console
|
| 261 |
+
|
| 262 |
+
cd ../Step2_build
|
| 263 |
+
cmake --build .
|
| 264 |
+
|
| 265 |
+
Next, run the ``Tutorial`` executable on a few numbers to verify that it's
|
| 266 |
+
still correct.
|
| 267 |
+
|
| 268 |
+
Now let's update the value of ``USE_MYMATH`` to ``OFF``. The easiest way is to
|
| 269 |
+
use the :manual:`cmake-gui <cmake-gui(1)>` or :manual:`ccmake <ccmake(1)>`
|
| 270 |
+
if you're in the terminal. Or, alternatively, if you want to change the
|
| 271 |
+
option from the command-line, try:
|
| 272 |
+
|
| 273 |
+
.. code-block:: console
|
| 274 |
+
|
| 275 |
+
cmake ../Step2 -DUSE_MYMATH=OFF
|
| 276 |
+
|
| 277 |
+
Now, rebuild the code with the following:
|
| 278 |
+
|
| 279 |
+
.. code-block:: console
|
| 280 |
+
|
| 281 |
+
cmake --build .
|
| 282 |
+
|
| 283 |
+
Then, run the executable again to ensure that it still works with
|
| 284 |
+
``USE_MYMATH`` set to ``OFF``. Which function gives better results, ``sqrt``
|
| 285 |
+
or ``mysqrt``?
|
| 286 |
+
|
| 287 |
+
Solution
|
| 288 |
+
--------
|
| 289 |
+
|
| 290 |
+
The first step is to add an option to ``MathFunctions/CMakeLists.txt``.
|
| 291 |
+
This option will be displayed in the :manual:`cmake-gui <cmake-gui(1)>` and
|
| 292 |
+
:manual:`ccmake <ccmake(1)>` with a default value of ``ON`` that can be
|
| 293 |
+
changed by the user.
|
| 294 |
+
|
| 295 |
+
.. raw:: html
|
| 296 |
+
|
| 297 |
+
<details><summary>TODO 7: Click to show/hide answer</summary>
|
| 298 |
+
|
| 299 |
+
.. literalinclude:: Step3/MathFunctions/CMakeLists.txt
|
| 300 |
+
:caption: TODO 7: MathFunctions/CMakeLists.txt
|
| 301 |
+
:name: CMakeLists.txt-option-library-level
|
| 302 |
+
:language: cmake
|
| 303 |
+
:start-after: # should we use our own math functions
|
| 304 |
+
:end-before: if (USE_MYMATH)
|
| 305 |
+
|
| 306 |
+
.. raw:: html
|
| 307 |
+
|
| 308 |
+
</details>
|
| 309 |
+
|
| 310 |
+
Next, make building and linking our library with ``mysqrt`` function
|
| 311 |
+
conditional using this new option.
|
| 312 |
+
|
| 313 |
+
Create an :command:`if` statement which checks the value of
|
| 314 |
+
``USE_MYMATH``. Inside the :command:`if` block, put the
|
| 315 |
+
:command:`target_compile_definitions` command with the compile
|
| 316 |
+
definition ``USE_MYMATH``.
|
| 317 |
+
|
| 318 |
+
.. raw:: html
|
| 319 |
+
|
| 320 |
+
<details><summary>TODO 8: Click to show/hide answer</summary>
|
| 321 |
+
|
| 322 |
+
.. code-block:: cmake
|
| 323 |
+
:caption: TODO 8: MathFunctions/CMakeLists.txt
|
| 324 |
+
:name: CMakeLists.txt-USE_MYMATH
|
| 325 |
+
|
| 326 |
+
if (USE_MYMATH)
|
| 327 |
+
target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
|
| 328 |
+
endif()
|
| 329 |
+
|
| 330 |
+
.. raw:: html
|
| 331 |
+
|
| 332 |
+
</details>
|
| 333 |
+
|
| 334 |
+
When ``USE_MYMATH`` is ``ON``, the compile definition ``USE_MYMATH`` will
|
| 335 |
+
be set. We can then use this compile definition to enable or disable
|
| 336 |
+
sections of our source code.
|
| 337 |
+
|
| 338 |
+
The corresponding changes to the source code are fairly straightforward.
|
| 339 |
+
In ``MathFunctions.cxx``, we make ``USE_MYMATH`` control which square root
|
| 340 |
+
function is used:
|
| 341 |
+
|
| 342 |
+
.. raw:: html
|
| 343 |
+
|
| 344 |
+
<details><summary>TODO 9: Click to show/hide answer</summary>
|
| 345 |
+
|
| 346 |
+
.. literalinclude:: Step3/MathFunctions/MathFunctions.cxx
|
| 347 |
+
:caption: TODO 9: MathFunctions/MathFunctions.cxx
|
| 348 |
+
:name: MathFunctions-USE_MYMATH-if
|
| 349 |
+
:language: c++
|
| 350 |
+
:start-after: which square root function should we use?
|
| 351 |
+
:end-before: }
|
| 352 |
+
|
| 353 |
+
.. raw:: html
|
| 354 |
+
|
| 355 |
+
</details>
|
| 356 |
+
|
| 357 |
+
Next, we need to include ``mysqrt.h`` if ``USE_MYMATH`` is defined.
|
| 358 |
+
|
| 359 |
+
.. raw:: html
|
| 360 |
+
|
| 361 |
+
<details><summary>TODO 10: Click to show/hide answer</summary>
|
| 362 |
+
|
| 363 |
+
.. literalinclude:: Step3/MathFunctions/MathFunctions.cxx
|
| 364 |
+
:caption: TODO 10: MathFunctions/MathFunctions.cxx
|
| 365 |
+
:name: MathFunctions-USE_MYMATH-if-include
|
| 366 |
+
:language: c++
|
| 367 |
+
:start-after: include <cmath>
|
| 368 |
+
:end-before: namespace mathfunctions
|
| 369 |
+
|
| 370 |
+
.. raw:: html
|
| 371 |
+
|
| 372 |
+
</details>
|
| 373 |
+
|
| 374 |
+
Finally, we need to include ``cmath`` now that we are using ``std::sqrt``.
|
| 375 |
+
|
| 376 |
+
.. raw:: html
|
| 377 |
+
|
| 378 |
+
<details><summary>TODO 11: Click to show/hide answer</summary>
|
| 379 |
+
|
| 380 |
+
.. code-block:: c++
|
| 381 |
+
:caption: TODO 11 : MathFunctions/MathFunctions.cxx
|
| 382 |
+
:name: tutorial.cxx-include_cmath
|
| 383 |
+
|
| 384 |
+
#include <cmath>
|
| 385 |
+
|
| 386 |
+
.. raw:: html
|
| 387 |
+
|
| 388 |
+
</details>
|
| 389 |
+
|
| 390 |
+
At this point, if ``USE_MYMATH`` is ``OFF``, ``mysqrt.cxx`` would not be used
|
| 391 |
+
but it will still be compiled because the ``MathFunctions`` target has
|
| 392 |
+
``mysqrt.cxx`` listed under sources.
|
| 393 |
+
|
| 394 |
+
There are a few ways to fix this. The first option is to use
|
| 395 |
+
:command:`target_sources` to add ``mysqrt.cxx`` from within the ``USE_MYMATH``
|
| 396 |
+
block. Another option is to create an additional library within the
|
| 397 |
+
``USE_MYMATH`` block which is responsible for compiling ``mysqrt.cxx``. For
|
| 398 |
+
the sake of this tutorial, we are going to create an additional library.
|
| 399 |
+
|
| 400 |
+
First, from within ``USE_MYMATH`` create a library called ``SqrtLibrary``
|
| 401 |
+
that has sources ``mysqrt.cxx``.
|
| 402 |
+
|
| 403 |
+
.. raw:: html
|
| 404 |
+
|
| 405 |
+
<details><summary>TODO 12: Click to show/hide answer</summary>
|
| 406 |
+
|
| 407 |
+
.. literalinclude:: Step3/MathFunctions/CMakeLists.txt
|
| 408 |
+
:caption: TODO 12 : MathFunctions/CMakeLists.txt
|
| 409 |
+
:name: MathFunctions/CMakeLists.txt-add_library-SqrtLibrary
|
| 410 |
+
:language: cmake
|
| 411 |
+
:start-after: # library that just does sqrt
|
| 412 |
+
:end-before: # TODO 7: Link
|
| 413 |
+
|
| 414 |
+
.. raw:: html
|
| 415 |
+
|
| 416 |
+
</details>
|
| 417 |
+
|
| 418 |
+
Next, we link ``SqrtLibrary`` onto ``MathFunctions`` when ``USE_MYMATH`` is
|
| 419 |
+
enabled.
|
| 420 |
+
|
| 421 |
+
.. raw:: html
|
| 422 |
+
|
| 423 |
+
<details><summary>TODO 13: Click to show/hide answer</summary>
|
| 424 |
+
|
| 425 |
+
.. literalinclude:: Step3/MathFunctions/CMakeLists.txt
|
| 426 |
+
:caption: TODO 13 : MathFunctions/CMakeLists.txt
|
| 427 |
+
:name: MathFunctions/CMakeLists.txt-target_link_libraries-SqrtLibrary
|
| 428 |
+
:language: cmake
|
| 429 |
+
:start-after: to tutorial_compiler_flags
|
| 430 |
+
:end-before: endif()
|
| 431 |
+
|
| 432 |
+
.. raw:: html
|
| 433 |
+
|
| 434 |
+
</details>
|
| 435 |
+
|
| 436 |
+
Finally, we can remove ``mysqrt.cxx`` from our ``MathFunctions`` library
|
| 437 |
+
source list because it will be pulled in when ``SqrtLibrary`` is included.
|
| 438 |
+
|
| 439 |
+
.. raw:: html
|
| 440 |
+
|
| 441 |
+
<details><summary>TODO 14: Click to show/hide answer</summary>
|
| 442 |
+
|
| 443 |
+
.. literalinclude:: Step3/MathFunctions/CMakeLists.txt
|
| 444 |
+
:caption: TODO 14 : MathFunctions/CMakeLists.txt
|
| 445 |
+
:name: MathFunctions/CMakeLists.txt-remove-mysqrt.cxx-MathFunctions
|
| 446 |
+
:language: cmake
|
| 447 |
+
:end-before: # TODO 1:
|
| 448 |
+
|
| 449 |
+
.. raw:: html
|
| 450 |
+
|
| 451 |
+
</details>
|
| 452 |
+
|
| 453 |
+
With these changes, the ``mysqrt`` function is now completely optional to
|
| 454 |
+
whoever is building and using the ``MathFunctions`` library. Users can toggle
|
| 455 |
+
``USE_MYMATH`` to manipulate what library is used in the build.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Installing and Testing.rst.txt
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 5: Installing and Testing
|
| 2 |
+
==============================
|
| 3 |
+
|
| 4 |
+
Exercise 1 - Install Rules
|
| 5 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 6 |
+
|
| 7 |
+
Often, it is not enough to only build an executable, it should also be
|
| 8 |
+
installable. With CMake, we can specify install rules using the
|
| 9 |
+
:command:`install` command. Supporting local installations for your builds in
|
| 10 |
+
CMake is often as simple as specifying an install location and the targets and
|
| 11 |
+
files to be installed.
|
| 12 |
+
|
| 13 |
+
Goal
|
| 14 |
+
----
|
| 15 |
+
|
| 16 |
+
Install the ``Tutorial`` executable and the ``MathFunctions`` library.
|
| 17 |
+
|
| 18 |
+
Helpful Materials
|
| 19 |
+
-----------------
|
| 20 |
+
|
| 21 |
+
* :command:`install`
|
| 22 |
+
|
| 23 |
+
Files to Edit
|
| 24 |
+
-------------
|
| 25 |
+
|
| 26 |
+
* ``MathFunctions/CMakeLists.txt``
|
| 27 |
+
* ``CMakeLists.txt``
|
| 28 |
+
|
| 29 |
+
Getting Started
|
| 30 |
+
---------------
|
| 31 |
+
|
| 32 |
+
The starting code is provided in the ``Step5`` directory. In this
|
| 33 |
+
exercise, complete ``TODO 1`` through ``TODO 4``.
|
| 34 |
+
|
| 35 |
+
First, update ``MathFunctions/CMakeLists.txt`` to install the
|
| 36 |
+
``MathFunctions`` and ``tutorial_compiler_flags`` libraries to the ``lib``
|
| 37 |
+
directory. In that same file, specify the install rules needed to install
|
| 38 |
+
``MathFunctions.h`` to the ``include`` directory.
|
| 39 |
+
|
| 40 |
+
Then, update the top level ``CMakeLists.txt`` to install
|
| 41 |
+
the ``Tutorial`` executable to the ``bin`` directory. Lastly, any header files
|
| 42 |
+
should be installed to the ``include`` directory. Remember that
|
| 43 |
+
``TutorialConfig.h`` is in the :variable:`PROJECT_BINARY_DIR`.
|
| 44 |
+
|
| 45 |
+
Build and Run
|
| 46 |
+
-------------
|
| 47 |
+
|
| 48 |
+
Make a new directory called ``Step5_build``. Run the
|
| 49 |
+
:manual:`cmake <cmake(1)>` executable or the
|
| 50 |
+
:manual:`cmake-gui <cmake-gui(1)>` to configure the project and then build it
|
| 51 |
+
with your chosen build tool.
|
| 52 |
+
|
| 53 |
+
Then, run the install step by using the :option:`--install <cmake --install>`
|
| 54 |
+
option of the :manual:`cmake <cmake(1)>` command (introduced in 3.15, older
|
| 55 |
+
versions of CMake must use ``make install``) from the command line. This step
|
| 56 |
+
will install the appropriate header files, libraries, and executables.
|
| 57 |
+
For example:
|
| 58 |
+
|
| 59 |
+
.. code-block:: console
|
| 60 |
+
|
| 61 |
+
cmake --install .
|
| 62 |
+
|
| 63 |
+
For multi-configuration tools, don't forget to use the
|
| 64 |
+
:option:`--config <cmake--build --config>` argument to specify the configuration.
|
| 65 |
+
|
| 66 |
+
.. code-block:: console
|
| 67 |
+
|
| 68 |
+
cmake --install . --config Release
|
| 69 |
+
|
| 70 |
+
If using an IDE, simply build the ``INSTALL`` target. You can build the same
|
| 71 |
+
install target from the command line like the following:
|
| 72 |
+
|
| 73 |
+
.. code-block:: console
|
| 74 |
+
|
| 75 |
+
cmake --build . --target install --config Debug
|
| 76 |
+
|
| 77 |
+
The CMake variable :variable:`CMAKE_INSTALL_PREFIX` is used to determine the
|
| 78 |
+
root of where the files will be installed. If using the :option:`cmake --install`
|
| 79 |
+
command, the installation prefix can be overridden via the
|
| 80 |
+
:option:`--prefix <cmake--install --prefix>` argument. For example:
|
| 81 |
+
|
| 82 |
+
.. code-block:: console
|
| 83 |
+
|
| 84 |
+
cmake --install . --prefix "/home/myuser/installdir"
|
| 85 |
+
|
| 86 |
+
Navigate to the install directory and verify that the installed ``Tutorial``
|
| 87 |
+
runs.
|
| 88 |
+
|
| 89 |
+
Solution
|
| 90 |
+
--------
|
| 91 |
+
|
| 92 |
+
The install rules for our project are fairly simple:
|
| 93 |
+
|
| 94 |
+
* For ``MathFunctions``, we want to install the libraries and header file to
|
| 95 |
+
the ``lib`` and ``include`` directories respectively.
|
| 96 |
+
|
| 97 |
+
* For the ``Tutorial`` executable, we want to install the executable and
|
| 98 |
+
configured header file to the ``bin`` and ``include`` directories
|
| 99 |
+
respectively.
|
| 100 |
+
|
| 101 |
+
So to the end of ``MathFunctions/CMakeLists.txt`` we add:
|
| 102 |
+
|
| 103 |
+
.. raw:: html
|
| 104 |
+
|
| 105 |
+
<details><summary>TODO 1: Click to show/hide answer</summary>
|
| 106 |
+
|
| 107 |
+
.. literalinclude:: Step6/MathFunctions/CMakeLists.txt
|
| 108 |
+
:caption: TODO 1: MathFunctions/CMakeLists.txt
|
| 109 |
+
:name: MathFunctions/CMakeLists.txt-install-TARGETS
|
| 110 |
+
:language: cmake
|
| 111 |
+
:start-after: # install libs
|
| 112 |
+
:end-before: # install include headers
|
| 113 |
+
|
| 114 |
+
.. raw:: html
|
| 115 |
+
|
| 116 |
+
</details>
|
| 117 |
+
|
| 118 |
+
and
|
| 119 |
+
|
| 120 |
+
.. raw:: html
|
| 121 |
+
|
| 122 |
+
<details><summary>TODO 2: Click to show/hide answer</summary>
|
| 123 |
+
|
| 124 |
+
.. literalinclude:: Step6/MathFunctions/CMakeLists.txt
|
| 125 |
+
:caption: TODO 2: MathFunctions/CMakeLists.txt
|
| 126 |
+
:name: MathFunctions/CMakeLists.txt-install-headers
|
| 127 |
+
:language: cmake
|
| 128 |
+
:start-after: # install include headers
|
| 129 |
+
|
| 130 |
+
.. raw:: html
|
| 131 |
+
|
| 132 |
+
</details>
|
| 133 |
+
|
| 134 |
+
The install rules for the ``Tutorial`` executable and configured header file
|
| 135 |
+
are similar. To the end of the top-level ``CMakeLists.txt`` we add:
|
| 136 |
+
|
| 137 |
+
.. raw:: html
|
| 138 |
+
|
| 139 |
+
<details><summary>TODO 3,4: Click to show/hide answer</summary>
|
| 140 |
+
|
| 141 |
+
.. literalinclude:: Step6/CMakeLists.txt
|
| 142 |
+
:caption: CMakeLists.txt
|
| 143 |
+
:name: TODO 3,4: CMakeLists.txt-install-TARGETS
|
| 144 |
+
:language: cmake
|
| 145 |
+
:start-after: # add the install targets
|
| 146 |
+
:end-before: # TODO 1: Replace enable_testing() with include(CTest)
|
| 147 |
+
|
| 148 |
+
.. raw:: html
|
| 149 |
+
|
| 150 |
+
</details>
|
| 151 |
+
|
| 152 |
+
That is all that is needed to create a basic local
|
| 153 |
+
install of the tutorial.
|
| 154 |
+
|
| 155 |
+
.. _`Tutorial Testing Support`:
|
| 156 |
+
|
| 157 |
+
Exercise 2 - Testing Support
|
| 158 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 159 |
+
|
| 160 |
+
CTest offers a way to easily manage tests for your project. Tests can be
|
| 161 |
+
added through the :command:`add_test` command. Although it is not
|
| 162 |
+
explicitly covered in this tutorial, there is a lot of compatibility
|
| 163 |
+
between CTest and other testing frameworks such as :module:`GoogleTest`.
|
| 164 |
+
|
| 165 |
+
Goal
|
| 166 |
+
----
|
| 167 |
+
|
| 168 |
+
Create unit tests for our executable using CTest.
|
| 169 |
+
|
| 170 |
+
Helpful Materials
|
| 171 |
+
-----------------
|
| 172 |
+
|
| 173 |
+
* :command:`enable_testing`
|
| 174 |
+
* :command:`add_test`
|
| 175 |
+
* :command:`function`
|
| 176 |
+
* :command:`set_tests_properties`
|
| 177 |
+
* :manual:`ctest <ctest(1)>`
|
| 178 |
+
|
| 179 |
+
Files to Edit
|
| 180 |
+
-------------
|
| 181 |
+
|
| 182 |
+
* ``CMakeLists.txt``
|
| 183 |
+
|
| 184 |
+
Getting Started
|
| 185 |
+
---------------
|
| 186 |
+
|
| 187 |
+
The starting source code is provided in the ``Step5`` directory. In this
|
| 188 |
+
exercise, complete ``TODO 5`` through ``TODO 9``.
|
| 189 |
+
|
| 190 |
+
First, we need to enable testing. Next, begin adding tests to our project
|
| 191 |
+
using :command:`add_test`. We will work through adding 3 simple tests and
|
| 192 |
+
then you can add additional testing as you see fit.
|
| 193 |
+
|
| 194 |
+
Build and Run
|
| 195 |
+
-------------
|
| 196 |
+
|
| 197 |
+
Navigate to the build directory and rebuild the application. Then, run the
|
| 198 |
+
:program:`ctest` executable: :option:`ctest -N` and :option:`ctest -VV`. For
|
| 199 |
+
multi-config generators (e.g. Visual Studio), the configuration type must be
|
| 200 |
+
specified with the :option:`-C \<mode\> <ctest -C>` flag. For example, to run tests in Debug
|
| 201 |
+
mode use ``ctest -C Debug -VV`` from the build directory
|
| 202 |
+
(not the Debug subdirectory!). Release mode would be executed from the same
|
| 203 |
+
location but with a ``-C Release``. Alternatively, build the ``RUN_TESTS``
|
| 204 |
+
target from the IDE.
|
| 205 |
+
|
| 206 |
+
Solution
|
| 207 |
+
--------
|
| 208 |
+
|
| 209 |
+
Let's test our application. At the end of the top-level ``CMakeLists.txt``
|
| 210 |
+
file we first need to enable testing with the
|
| 211 |
+
:command:`enable_testing` command.
|
| 212 |
+
|
| 213 |
+
.. raw:: html
|
| 214 |
+
|
| 215 |
+
<details><summary>TODO 5: Click to show/hide answer</summary>
|
| 216 |
+
|
| 217 |
+
.. literalinclude:: Step6/CMakeLists.txt
|
| 218 |
+
:caption: TODO 5: CMakeLists.txt
|
| 219 |
+
:name: CMakeLists.txt-enable_testing
|
| 220 |
+
:language: cmake
|
| 221 |
+
:start-after: # enable testing
|
| 222 |
+
:end-before: # does the application run
|
| 223 |
+
|
| 224 |
+
.. raw:: html
|
| 225 |
+
|
| 226 |
+
</details>
|
| 227 |
+
|
| 228 |
+
With testing enabled, we will add a number of basic tests to verify
|
| 229 |
+
that the application is working correctly. First, we create a test using
|
| 230 |
+
:command:`add_test` which runs the ``Tutorial`` executable with the
|
| 231 |
+
parameter 25 passed in. For this test, we are not going to check the
|
| 232 |
+
executable's computed answer. This test will verify that
|
| 233 |
+
application runs, does not segfault or otherwise crash, and has a zero
|
| 234 |
+
return value. This is the basic form of a CTest test.
|
| 235 |
+
|
| 236 |
+
.. raw:: html
|
| 237 |
+
|
| 238 |
+
<details><summary>TODO 6: Click to show/hide answer</summary>
|
| 239 |
+
|
| 240 |
+
.. literalinclude:: Step6/CMakeLists.txt
|
| 241 |
+
:caption: TODO 6: CMakeLists.txt
|
| 242 |
+
:name: CMakeLists.txt-test-runs
|
| 243 |
+
:language: cmake
|
| 244 |
+
:start-after: # does the application run
|
| 245 |
+
:end-before: # does the usage message work
|
| 246 |
+
|
| 247 |
+
.. raw:: html
|
| 248 |
+
|
| 249 |
+
</details>
|
| 250 |
+
|
| 251 |
+
Next, let's use the :prop_test:`PASS_REGULAR_EXPRESSION` test property to
|
| 252 |
+
verify that the output of the test contains certain strings. In this case,
|
| 253 |
+
verifying that the usage message is printed when an incorrect number of
|
| 254 |
+
arguments are provided.
|
| 255 |
+
|
| 256 |
+
.. raw:: html
|
| 257 |
+
|
| 258 |
+
<details><summary>TODO 7: Click to show/hide answer</summary>
|
| 259 |
+
|
| 260 |
+
.. literalinclude:: Step6/CMakeLists.txt
|
| 261 |
+
:caption: TODO 7: CMakeLists.txt
|
| 262 |
+
:name: CMakeLists.txt-test-usage
|
| 263 |
+
:language: cmake
|
| 264 |
+
:start-after: # does the usage message work?
|
| 265 |
+
:end-before: # define a function to simplify adding tests
|
| 266 |
+
|
| 267 |
+
.. raw:: html
|
| 268 |
+
|
| 269 |
+
</details>
|
| 270 |
+
|
| 271 |
+
The next test we will add verifies the computed value is truly the
|
| 272 |
+
square root.
|
| 273 |
+
|
| 274 |
+
.. raw:: html
|
| 275 |
+
|
| 276 |
+
<details><summary>TODO 8: Click to show/hide answer</summary>
|
| 277 |
+
|
| 278 |
+
.. code-block:: cmake
|
| 279 |
+
:caption: TODO 8: CMakeLists.txt
|
| 280 |
+
:name: CMakeLists.txt-test-standard
|
| 281 |
+
|
| 282 |
+
add_test(NAME StandardUse COMMAND Tutorial 4)
|
| 283 |
+
set_tests_properties(StandardUse
|
| 284 |
+
PROPERTIES PASS_REGULAR_EXPRESSION "4 is 2"
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
.. raw:: html
|
| 288 |
+
|
| 289 |
+
</details>
|
| 290 |
+
|
| 291 |
+
This one test is not enough to give us confidence that it will
|
| 292 |
+
work for all values passed in. We should add more tests to verify this.
|
| 293 |
+
To easily add more tests, we make a function called ``do_test`` that runs the
|
| 294 |
+
application and verifies that the computed square root is correct for
|
| 295 |
+
given input. For each invocation of ``do_test``, another test is added to
|
| 296 |
+
the project with a name, input, and expected results based on the passed
|
| 297 |
+
arguments.
|
| 298 |
+
|
| 299 |
+
.. raw:: html
|
| 300 |
+
|
| 301 |
+
<details><summary>TODO 9: Click to show/hide answer</summary>
|
| 302 |
+
|
| 303 |
+
.. literalinclude:: Step6/CMakeLists.txt
|
| 304 |
+
:caption: TODO 9: CMakeLists.txt
|
| 305 |
+
:name: CMakeLists.txt-generalized-tests
|
| 306 |
+
:language: cmake
|
| 307 |
+
:start-after: # define a function to simplify adding tests
|
| 308 |
+
|
| 309 |
+
.. raw:: html
|
| 310 |
+
|
| 311 |
+
</details>
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Packaging Debug and Release.rst.txt
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 12: Packaging Debug and Release
|
| 2 |
+
====================================
|
| 3 |
+
|
| 4 |
+
**Note:** This example is valid for single-configuration generators and will
|
| 5 |
+
not work for multi-configuration generators (e.g. Visual Studio).
|
| 6 |
+
|
| 7 |
+
By default, CMake's model is that a build directory only contains a single
|
| 8 |
+
configuration, be it Debug, Release, MinSizeRel, or RelWithDebInfo. It is
|
| 9 |
+
possible, however, to setup CPack to bundle multiple build directories and
|
| 10 |
+
construct a package that contains multiple configurations of the same project.
|
| 11 |
+
|
| 12 |
+
First, we want to ensure that the debug and release builds use different names
|
| 13 |
+
for the libraries that will be installed. Let's use `d` as the
|
| 14 |
+
postfix for the debug libraries.
|
| 15 |
+
|
| 16 |
+
Set :variable:`CMAKE_DEBUG_POSTFIX` near the beginning of the top-level
|
| 17 |
+
``CMakeLists.txt`` file:
|
| 18 |
+
|
| 19 |
+
.. literalinclude:: Complete/CMakeLists.txt
|
| 20 |
+
:caption: CMakeLists.txt
|
| 21 |
+
:name: CMakeLists.txt-CMAKE_DEBUG_POSTFIX-variable
|
| 22 |
+
:language: cmake
|
| 23 |
+
:start-after: project(Tutorial VERSION 1.0)
|
| 24 |
+
:end-before: target_compile_features(tutorial_compiler_flags
|
| 25 |
+
|
| 26 |
+
And the :prop_tgt:`DEBUG_POSTFIX` property on the tutorial executable:
|
| 27 |
+
|
| 28 |
+
.. literalinclude:: Complete/CMakeLists.txt
|
| 29 |
+
:caption: CMakeLists.txt
|
| 30 |
+
:name: CMakeLists.txt-DEBUG_POSTFIX-property
|
| 31 |
+
:language: cmake
|
| 32 |
+
:start-after: # add the executable
|
| 33 |
+
:end-before: # add the binary tree to the search path for include files
|
| 34 |
+
|
| 35 |
+
Let's also add version numbering to the ``MathFunctions`` library. In
|
| 36 |
+
``MathFunctions/CMakeLists.txt``, set the :prop_tgt:`VERSION` and
|
| 37 |
+
:prop_tgt:`SOVERSION` properties:
|
| 38 |
+
|
| 39 |
+
.. literalinclude:: Complete/MathFunctions/CMakeLists.txt
|
| 40 |
+
:caption: MathFunctions/CMakeLists.txt
|
| 41 |
+
:name: MathFunctions/CMakeLists.txt-VERSION-properties
|
| 42 |
+
:language: cmake
|
| 43 |
+
:start-after: # setup the version numbering
|
| 44 |
+
:end-before: # install libs
|
| 45 |
+
|
| 46 |
+
From the ``Step12`` directory, create ``debug`` and ``release``
|
| 47 |
+
subdirectories. The layout will look like:
|
| 48 |
+
|
| 49 |
+
.. code-block:: none
|
| 50 |
+
|
| 51 |
+
- Step12
|
| 52 |
+
- debug
|
| 53 |
+
- release
|
| 54 |
+
|
| 55 |
+
Now we need to setup debug and release builds. We can use
|
| 56 |
+
:variable:`CMAKE_BUILD_TYPE` to set the configuration type:
|
| 57 |
+
|
| 58 |
+
.. code-block:: console
|
| 59 |
+
|
| 60 |
+
cd debug
|
| 61 |
+
cmake -DCMAKE_BUILD_TYPE=Debug ..
|
| 62 |
+
cmake --build .
|
| 63 |
+
cd ../release
|
| 64 |
+
cmake -DCMAKE_BUILD_TYPE=Release ..
|
| 65 |
+
cmake --build .
|
| 66 |
+
|
| 67 |
+
Now that both the debug and release builds are complete, we can use a custom
|
| 68 |
+
configuration file to package both builds into a single release. In the
|
| 69 |
+
``Step12`` directory, create a file called ``MultiCPackConfig.cmake``. In this
|
| 70 |
+
file, first include the default configuration file that was created by the
|
| 71 |
+
:manual:`cmake <cmake(1)>` executable.
|
| 72 |
+
|
| 73 |
+
Next, use the ``CPACK_INSTALL_CMAKE_PROJECTS`` variable to specify which
|
| 74 |
+
projects to install. In this case, we want to install both debug and release.
|
| 75 |
+
|
| 76 |
+
.. literalinclude:: Complete/MultiCPackConfig.cmake
|
| 77 |
+
:caption: MultiCPackConfig.cmake
|
| 78 |
+
:name: MultiCPackConfig.cmake
|
| 79 |
+
:language: cmake
|
| 80 |
+
|
| 81 |
+
From the ``Step12`` directory, run :manual:`cpack <cpack(1)>` specifying our
|
| 82 |
+
custom configuration file with the ``config`` option:
|
| 83 |
+
|
| 84 |
+
.. code-block:: console
|
| 85 |
+
|
| 86 |
+
cpack --config MultiCPackConfig.cmake
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Packaging an Installer.rst.txt
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 9: Packaging an Installer
|
| 2 |
+
==============================
|
| 3 |
+
|
| 4 |
+
Next suppose that we want to distribute our project to other people so that
|
| 5 |
+
they can use it. We want to provide both binary and source distributions on a
|
| 6 |
+
variety of platforms. This is a little different from the install we did
|
| 7 |
+
previously in :guide:`tutorial/Installing and Testing`, where we were
|
| 8 |
+
installing the binaries that we had built from the source code. In this
|
| 9 |
+
example we will be building installation packages that support binary
|
| 10 |
+
installations and package management features. To accomplish this we will use
|
| 11 |
+
CPack to create platform specific installers. Specifically we need to add a
|
| 12 |
+
few lines to the bottom of our top-level ``CMakeLists.txt`` file.
|
| 13 |
+
|
| 14 |
+
.. literalinclude:: Step10/CMakeLists.txt
|
| 15 |
+
:caption: CMakeLists.txt
|
| 16 |
+
:name: CMakeLists.txt-include-CPack
|
| 17 |
+
:language: cmake
|
| 18 |
+
:start-after: # setup installer
|
| 19 |
+
|
| 20 |
+
That is all there is to it. We start by including
|
| 21 |
+
:module:`InstallRequiredSystemLibraries`. This module will include any runtime
|
| 22 |
+
libraries that are needed by the project for the current platform. Next we set
|
| 23 |
+
some CPack variables to where we have stored the license and version
|
| 24 |
+
information for this project. The version information was set earlier in this
|
| 25 |
+
tutorial and the ``License.txt`` has been included in the top-level source
|
| 26 |
+
directory for this step. The :variable:`CPACK_SOURCE_GENERATOR` variable
|
| 27 |
+
selects a file format for the source package.
|
| 28 |
+
|
| 29 |
+
Finally we include the :module:`CPack module <CPack>` which will use these
|
| 30 |
+
variables and some other properties of the current system to setup an
|
| 31 |
+
installer.
|
| 32 |
+
|
| 33 |
+
The next step is to build the project in the usual manner and then run the
|
| 34 |
+
:manual:`cpack <cpack(1)>` executable. To build a binary distribution, from the
|
| 35 |
+
binary directory run:
|
| 36 |
+
|
| 37 |
+
.. code-block:: console
|
| 38 |
+
|
| 39 |
+
cpack
|
| 40 |
+
|
| 41 |
+
To specify the generator, use the :option:`-G <cpack -G>` option. For multi-config builds,
|
| 42 |
+
use :option:`-C <cpack -C>` to specify the configuration. For example:
|
| 43 |
+
|
| 44 |
+
.. code-block:: console
|
| 45 |
+
|
| 46 |
+
cpack -G ZIP -C Debug
|
| 47 |
+
|
| 48 |
+
For a list of available generators, see :manual:`cpack-generators(7)` or call
|
| 49 |
+
:option:`cpack --help`. An :cpack_gen:`archive generator <CPack Archive Generator>`
|
| 50 |
+
like ZIP creates a compressed archive of all *installed* files.
|
| 51 |
+
|
| 52 |
+
To create an archive of the *full* source tree you would type:
|
| 53 |
+
|
| 54 |
+
.. code-block:: console
|
| 55 |
+
|
| 56 |
+
cpack --config CPackSourceConfig.cmake
|
| 57 |
+
|
| 58 |
+
Alternatively, run ``make package`` or right click the ``Package`` target and
|
| 59 |
+
``Build Project`` from an IDE.
|
| 60 |
+
|
| 61 |
+
Run the installer found in the binary directory. Then run the installed
|
| 62 |
+
executable and verify that it works.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/Selecting Static or Shared Libraries.rst.txt
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Step 10: Selecting Static or Shared Libraries
|
| 2 |
+
=============================================
|
| 3 |
+
|
| 4 |
+
In this section we will show how the :variable:`BUILD_SHARED_LIBS` variable can
|
| 5 |
+
be used to control the default behavior of :command:`add_library`,
|
| 6 |
+
and allow control over how libraries without an explicit type (``STATIC``,
|
| 7 |
+
``SHARED``, ``MODULE`` or ``OBJECT``) are built.
|
| 8 |
+
|
| 9 |
+
To accomplish this we need to add :variable:`BUILD_SHARED_LIBS` to the
|
| 10 |
+
top-level ``CMakeLists.txt``. We use the :command:`option` command as it allows
|
| 11 |
+
users to optionally select if the value should be ``ON`` or ``OFF``.
|
| 12 |
+
|
| 13 |
+
.. literalinclude:: Step11/CMakeLists.txt
|
| 14 |
+
:caption: CMakeLists.txt
|
| 15 |
+
:name: CMakeLists.txt-option-BUILD_SHARED_LIBS
|
| 16 |
+
:language: cmake
|
| 17 |
+
:start-after: set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
|
| 18 |
+
:end-before: # configure a header file to pass the version number only
|
| 19 |
+
|
| 20 |
+
Next, we need to specify output directories for our static and shared
|
| 21 |
+
libraries.
|
| 22 |
+
|
| 23 |
+
.. literalinclude:: Step11/CMakeLists.txt
|
| 24 |
+
:caption: CMakeLists.txt
|
| 25 |
+
:name: CMakeLists.txt-cmake-output-directories
|
| 26 |
+
:language: cmake
|
| 27 |
+
:start-after: # we don't need to tinker with the path to run the executable
|
| 28 |
+
:end-before: # configure a header file to pass the version number only
|
| 29 |
+
|
| 30 |
+
Finally, update ``MathFunctions/MathFunctions.h`` to use dll export defines:
|
| 31 |
+
|
| 32 |
+
.. literalinclude:: Step11/MathFunctions/MathFunctions.h
|
| 33 |
+
:caption: MathFunctions/MathFunctions.h
|
| 34 |
+
:name: MathFunctions/MathFunctions.h
|
| 35 |
+
:language: c++
|
| 36 |
+
|
| 37 |
+
At this point, if you build everything, you may notice that linking fails
|
| 38 |
+
as we are combining a static library without position independent code with a
|
| 39 |
+
library that has position independent code. The solution to this is to
|
| 40 |
+
explicitly set the :prop_tgt:`POSITION_INDEPENDENT_CODE` target property of
|
| 41 |
+
SqrtLibrary to be ``True`` when building shared libraries.
|
| 42 |
+
|
| 43 |
+
.. literalinclude:: Step11/MathFunctions/CMakeLists.txt
|
| 44 |
+
:caption: MathFunctions/CMakeLists.txt
|
| 45 |
+
:name: MathFunctions/CMakeLists.txt-POSITION_INDEPENDENT_CODE
|
| 46 |
+
:language: cmake
|
| 47 |
+
:lines: 37-42
|
| 48 |
+
|
| 49 |
+
**Exercise**: We modified ``MathFunctions.h`` to use dll export defines.
|
| 50 |
+
Using CMake documentation can you find a helper module to simplify this?
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/tutorial/index.rst.txt
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMake Tutorial
|
| 2 |
+
**************
|
| 3 |
+
|
| 4 |
+
Introduction
|
| 5 |
+
============
|
| 6 |
+
|
| 7 |
+
The CMake tutorial provides a step-by-step guide that covers common build
|
| 8 |
+
system issues that CMake helps address. Seeing how various topics all
|
| 9 |
+
work together in an example project can be very helpful.
|
| 10 |
+
|
| 11 |
+
Steps
|
| 12 |
+
=====
|
| 13 |
+
|
| 14 |
+
.. include:: source.txt
|
| 15 |
+
|
| 16 |
+
|tutorial_source|
|
| 17 |
+
Each step has its own subdirectory containing code that may be used as a
|
| 18 |
+
starting point. The tutorial examples are progressive so that each step
|
| 19 |
+
provides the complete solution for the previous step.
|
| 20 |
+
|
| 21 |
+
.. toctree::
|
| 22 |
+
:maxdepth: 2
|
| 23 |
+
|
| 24 |
+
A Basic Starting Point
|
| 25 |
+
Adding a Library
|
| 26 |
+
Adding Usage Requirements for a Library
|
| 27 |
+
Adding Generator Expressions
|
| 28 |
+
Installing and Testing
|
| 29 |
+
Adding Support for a Testing Dashboard
|
| 30 |
+
Adding System Introspection
|
| 31 |
+
Adding a Custom Command and Generated File
|
| 32 |
+
Packaging an Installer
|
| 33 |
+
Selecting Static or Shared Libraries
|
| 34 |
+
Adding Export Configuration
|
| 35 |
+
Packaging Debug and Release
|
| 36 |
+
|
| 37 |
+
..
|
| 38 |
+
Whenever a step above is renamed or removed, leave forwarding text in
|
| 39 |
+
its original document file, and list it below to preserve old links
|
| 40 |
+
to cmake.org/cmake/help/latest/ URLs.
|
| 41 |
+
|
| 42 |
+
.. toctree::
|
| 43 |
+
:maxdepth: 1
|
| 44 |
+
:hidden:
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/user-interaction/index.rst.txt
ADDED
|
@@ -0,0 +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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
User Interaction Guide
|
| 2 |
+
**********************
|
| 3 |
+
|
| 4 |
+
.. only:: html
|
| 5 |
+
|
| 6 |
+
.. contents::
|
| 7 |
+
|
| 8 |
+
Introduction
|
| 9 |
+
============
|
| 10 |
+
|
| 11 |
+
Where a software package supplies a CMake-based buildsystem
|
| 12 |
+
with the source of their software, the consumer of the
|
| 13 |
+
software is required to run a CMake user interaction tool
|
| 14 |
+
in order to build it.
|
| 15 |
+
|
| 16 |
+
Well-behaved CMake-based buildsystems do not create any
|
| 17 |
+
output in the source directory, so typically, the user
|
| 18 |
+
performs an out-of-source build and performs the build
|
| 19 |
+
there. First, CMake must be instructed to generate a
|
| 20 |
+
suitable buildsystem, then the user invokes a build tool
|
| 21 |
+
to process that generated buildsystem. The generated
|
| 22 |
+
buildsystem is specific to the machine used to generate
|
| 23 |
+
it and is not redistributable. Each consumer of a provided
|
| 24 |
+
source software package is required to use CMake to
|
| 25 |
+
generate a buildsystem specific to their system.
|
| 26 |
+
|
| 27 |
+
Generated buildsystems should generally be treated as
|
| 28 |
+
read-only. The CMake files as a primary artifact should
|
| 29 |
+
completely specify the buildsystem and there should be no
|
| 30 |
+
reason to populate properties manually in an IDE for
|
| 31 |
+
example after generating the buildsystem. CMake will
|
| 32 |
+
periodically rewrite the generated buildsystem, so
|
| 33 |
+
modifications by users will be overwritten.
|
| 34 |
+
|
| 35 |
+
The features and user interfaces described in this manual
|
| 36 |
+
are available for all CMake-based build systems by virtue
|
| 37 |
+
of providing CMake files.
|
| 38 |
+
|
| 39 |
+
The CMake tooling may report errors to the user when
|
| 40 |
+
processing provided CMake files, such as reporting that
|
| 41 |
+
the compiler is not supported, or the compiler does not
|
| 42 |
+
support a required compile option, or a dependency can
|
| 43 |
+
not be found. These errors must be resolved by the user
|
| 44 |
+
by choosing a different compiler,
|
| 45 |
+
:guide:`installing dependencies <Using Dependencies Guide>`,
|
| 46 |
+
or instructing CMake where to find them, etc.
|
| 47 |
+
|
| 48 |
+
Command Line cmake tool
|
| 49 |
+
-----------------------
|
| 50 |
+
|
| 51 |
+
A simple but typical use of :manual:`cmake(1)` with a fresh
|
| 52 |
+
copy of software source code is to create a build directory
|
| 53 |
+
and invoke cmake there:
|
| 54 |
+
|
| 55 |
+
.. code-block:: console
|
| 56 |
+
|
| 57 |
+
$ cd some_software-1.4.2
|
| 58 |
+
$ mkdir build
|
| 59 |
+
$ cd build
|
| 60 |
+
$ cmake .. -DCMAKE_INSTALL_PREFIX=/opt/the/prefix
|
| 61 |
+
$ cmake --build .
|
| 62 |
+
$ cmake --build . --target install
|
| 63 |
+
|
| 64 |
+
It is recommended to build in a separate directory to the
|
| 65 |
+
source because that keeps the source directory pristine,
|
| 66 |
+
allows for building a single source with multiple
|
| 67 |
+
toolchains, and allows easy clearing of build artifacts by
|
| 68 |
+
simply deleting the build directory.
|
| 69 |
+
|
| 70 |
+
The CMake tooling may report warnings which are intended
|
| 71 |
+
for the provider of the software, not intended for the
|
| 72 |
+
consumer of the software. Such warnings end with "This
|
| 73 |
+
warning is for project developers". Users may disable
|
| 74 |
+
such warnings by passing the :option:`-Wno-dev <cmake -Wno-dev>`
|
| 75 |
+
flag to :manual:`cmake(1)`.
|
| 76 |
+
|
| 77 |
+
cmake-gui tool
|
| 78 |
+
--------------
|
| 79 |
+
|
| 80 |
+
Users more accustomed to GUI interfaces may use the
|
| 81 |
+
:manual:`cmake-gui(1)` tool to invoke CMake and generate
|
| 82 |
+
a buildsystem.
|
| 83 |
+
|
| 84 |
+
The source and binary directories must first be
|
| 85 |
+
populated. It is always advised to use different
|
| 86 |
+
directories for the source and the build.
|
| 87 |
+
|
| 88 |
+
.. image:: GUI-Source-Binary.png
|
| 89 |
+
:alt: Choosing source and binary directories
|
| 90 |
+
|
| 91 |
+
Generating a Buildsystem
|
| 92 |
+
========================
|
| 93 |
+
|
| 94 |
+
There are several user interface tools which may be used
|
| 95 |
+
to generate a buildsystem from CMake files. The
|
| 96 |
+
:manual:`ccmake(1)` and :manual:`cmake-gui(1)` tools guide
|
| 97 |
+
the user through setting the various necessary options.
|
| 98 |
+
The :manual:`cmake(1)` tool can be invoked to specify
|
| 99 |
+
options on the command line. This manual describes options
|
| 100 |
+
which may be set using any of the user interface tools,
|
| 101 |
+
though the mode of setting an option is different for each
|
| 102 |
+
tool.
|
| 103 |
+
|
| 104 |
+
Command line environment
|
| 105 |
+
------------------------
|
| 106 |
+
|
| 107 |
+
When invoking :manual:`cmake(1)` with a command line
|
| 108 |
+
buildsystem such as ``Makefiles`` or ``Ninja``, it is
|
| 109 |
+
necessary to use the correct build environment to
|
| 110 |
+
ensure that build tools are available. CMake must be
|
| 111 |
+
able to find the appropriate
|
| 112 |
+
:variable:`build tool <CMAKE_MAKE_PROGRAM>`,
|
| 113 |
+
compiler, linker and other tools as needed.
|
| 114 |
+
|
| 115 |
+
On Linux systems, the appropriate tools are often
|
| 116 |
+
provided in system-wide locations and may be readily
|
| 117 |
+
installed through the system package manager. Other
|
| 118 |
+
toolchains provided by the user or installed in
|
| 119 |
+
non-default locations can also be used.
|
| 120 |
+
|
| 121 |
+
When cross-compiling, some platforms may require
|
| 122 |
+
environment variables to be set or may provide
|
| 123 |
+
scripts to set the environment.
|
| 124 |
+
|
| 125 |
+
Visual Studio ships multiple command prompts and
|
| 126 |
+
``vcvarsall.bat`` scripts for setting up the
|
| 127 |
+
correct environments for command line buildsystems. While
|
| 128 |
+
not strictly necessary to use a corresponding
|
| 129 |
+
command line environment when using a Visual Studio
|
| 130 |
+
generator, doing so has no disadvantages.
|
| 131 |
+
|
| 132 |
+
When using Xcode, there can be more than one Xcode
|
| 133 |
+
version installed. Which one to use can be selected
|
| 134 |
+
in a number of different ways, but the most common
|
| 135 |
+
methods are:
|
| 136 |
+
|
| 137 |
+
* Setting the default version in the preferences
|
| 138 |
+
of the Xcode IDE.
|
| 139 |
+
* Setting the default version via the ``xcode-select``
|
| 140 |
+
command line tool.
|
| 141 |
+
* Overriding the default version by setting the
|
| 142 |
+
``DEVELOPER_DIR`` environment variable when running
|
| 143 |
+
CMake and the build tool.
|
| 144 |
+
|
| 145 |
+
For convenience, :manual:`cmake-gui(1)` provides an
|
| 146 |
+
environment variable editor.
|
| 147 |
+
|
| 148 |
+
Command line ``-G`` option
|
| 149 |
+
--------------------------
|
| 150 |
+
|
| 151 |
+
CMake chooses a generator by default based on the
|
| 152 |
+
platform. Usually, the default generator is sufficient
|
| 153 |
+
to allow the user to proceed to build the software.
|
| 154 |
+
|
| 155 |
+
The user may override the default generator with
|
| 156 |
+
the :option:`-G <cmake -G>` option:
|
| 157 |
+
|
| 158 |
+
.. code-block:: console
|
| 159 |
+
|
| 160 |
+
$ cmake .. -G Ninja
|
| 161 |
+
|
| 162 |
+
The output of :option:`cmake --help` includes a list of
|
| 163 |
+
:manual:`generators <cmake-generators(7)>` available
|
| 164 |
+
for the user to choose from. Note that generator
|
| 165 |
+
names are case sensitive.
|
| 166 |
+
|
| 167 |
+
On Unix-like systems (including Mac OS X), the
|
| 168 |
+
:generator:`Unix Makefiles` generator is used by
|
| 169 |
+
default. A variant of that generator can also be used
|
| 170 |
+
on Windows in various environments, such as the
|
| 171 |
+
:generator:`NMake Makefiles` and
|
| 172 |
+
:generator:`MinGW Makefiles` generator. These generators
|
| 173 |
+
generate a ``Makefile`` variant which can be executed
|
| 174 |
+
with ``make``, ``gmake``, ``nmake`` or similar tools.
|
| 175 |
+
See the individual generator documentation for more
|
| 176 |
+
information on targeted environments and tools.
|
| 177 |
+
|
| 178 |
+
The :generator:`Ninja` generator is available on all
|
| 179 |
+
major platforms. ``ninja`` is a build tool similar
|
| 180 |
+
in use-cases to ``make``, but with a focus on
|
| 181 |
+
performance and efficiency.
|
| 182 |
+
|
| 183 |
+
On Windows, :manual:`cmake(1)` can be used to generate
|
| 184 |
+
solutions for the Visual Studio IDE. Visual Studio
|
| 185 |
+
versions may be specified by the product name of the
|
| 186 |
+
IDE, which includes a four-digit year. Aliases are
|
| 187 |
+
provided for other means by which Visual Studio
|
| 188 |
+
versions are sometimes referred to, such as two
|
| 189 |
+
digits which correspond to the product version of the
|
| 190 |
+
VisualC++ compiler, or a combination of the two:
|
| 191 |
+
|
| 192 |
+
.. code-block:: console
|
| 193 |
+
|
| 194 |
+
$ cmake .. -G "Visual Studio 2019"
|
| 195 |
+
$ cmake .. -G "Visual Studio 16"
|
| 196 |
+
$ cmake .. -G "Visual Studio 16 2019"
|
| 197 |
+
|
| 198 |
+
Visual Studio generators can target different architectures.
|
| 199 |
+
One can specify the target architecture using the
|
| 200 |
+
:option:`-A <cmake -A>` option:
|
| 201 |
+
|
| 202 |
+
.. code-block:: console
|
| 203 |
+
|
| 204 |
+
cmake .. -G "Visual Studio 2019" -A x64
|
| 205 |
+
cmake .. -G "Visual Studio 16" -A ARM
|
| 206 |
+
cmake .. -G "Visual Studio 16 2019" -A ARM64
|
| 207 |
+
|
| 208 |
+
On Apple, the :generator:`Xcode` generator may be used to
|
| 209 |
+
generate project files for the Xcode IDE.
|
| 210 |
+
|
| 211 |
+
Some IDEs such as KDevelop4, QtCreator and CLion have
|
| 212 |
+
native support for CMake-based buildsystems. Those IDEs
|
| 213 |
+
provide user interface for selecting an underlying
|
| 214 |
+
generator to use, typically a choice between a ``Makefile``
|
| 215 |
+
or a ``Ninja`` based generator.
|
| 216 |
+
|
| 217 |
+
Note that it is not possible to change the generator
|
| 218 |
+
with :option:`-G <cmake -G>` after the first invocation of CMake.
|
| 219 |
+
To change the generator, the build directory must be
|
| 220 |
+
deleted and the build must be started from scratch.
|
| 221 |
+
|
| 222 |
+
When generating Visual Studio project and solutions
|
| 223 |
+
files several other options are available to use when
|
| 224 |
+
initially running :manual:`cmake(1)`.
|
| 225 |
+
|
| 226 |
+
The Visual Studio toolset can be specified with the
|
| 227 |
+
:option:`cmake -T` option:
|
| 228 |
+
|
| 229 |
+
.. code-block:: console
|
| 230 |
+
|
| 231 |
+
$ # Build with the clang-cl toolset
|
| 232 |
+
$ cmake.exe .. -G "Visual Studio 16 2019" -A x64 -T ClangCL
|
| 233 |
+
$ # Build targeting Windows XP
|
| 234 |
+
$ cmake.exe .. -G "Visual Studio 16 2019" -A x64 -T v120_xp
|
| 235 |
+
|
| 236 |
+
Whereas the :option:`-A <cmake -A>` option specifies the _target_
|
| 237 |
+
architecture, the :option:`-T <cmake -T>` option can be used to specify
|
| 238 |
+
details of the toolchain used. For example, ``-Thost=x64``
|
| 239 |
+
can be given to select the 64-bit version of the host
|
| 240 |
+
tools. The following demonstrates how to use 64-bit
|
| 241 |
+
tools and also build for a 64-bit target architecture:
|
| 242 |
+
|
| 243 |
+
.. code-block:: console
|
| 244 |
+
|
| 245 |
+
$ cmake .. -G "Visual Studio 16 2019" -A x64 -Thost=x64
|
| 246 |
+
|
| 247 |
+
Choosing a generator in cmake-gui
|
| 248 |
+
---------------------------------
|
| 249 |
+
|
| 250 |
+
The "Configure" button triggers a new dialog to
|
| 251 |
+
select the CMake generator to use.
|
| 252 |
+
|
| 253 |
+
.. image:: GUI-Configure-Dialog.png
|
| 254 |
+
:alt: Configuring a generator
|
| 255 |
+
|
| 256 |
+
All generators available on the command line are also
|
| 257 |
+
available in :manual:`cmake-gui(1)`.
|
| 258 |
+
|
| 259 |
+
.. image:: GUI-Choose-Generator.png
|
| 260 |
+
:alt: Choosing a generator
|
| 261 |
+
|
| 262 |
+
When choosing a Visual Studio generator, further options
|
| 263 |
+
are available to set an architecture to generate for.
|
| 264 |
+
|
| 265 |
+
.. image:: VS-Choose-Arch.png
|
| 266 |
+
:alt: Choosing an architecture for Visual Studio generators
|
| 267 |
+
|
| 268 |
+
.. _`Setting Build Variables`:
|
| 269 |
+
|
| 270 |
+
Setting Build Variables
|
| 271 |
+
=======================
|
| 272 |
+
|
| 273 |
+
Software projects often require variables to be
|
| 274 |
+
set on the command line when invoking CMake. Some of
|
| 275 |
+
the most commonly used CMake variables are listed in
|
| 276 |
+
the table below:
|
| 277 |
+
|
| 278 |
+
========================================== ============================================================
|
| 279 |
+
Variable Meaning
|
| 280 |
+
========================================== ============================================================
|
| 281 |
+
:variable:`CMAKE_PREFIX_PATH` Path to search for
|
| 282 |
+
:guide:`dependent packages <Using Dependencies Guide>`
|
| 283 |
+
:variable:`CMAKE_MODULE_PATH` Path to search for additional CMake modules
|
| 284 |
+
:variable:`CMAKE_BUILD_TYPE` Build configuration, such as
|
| 285 |
+
``Debug`` or ``Release``, determining
|
| 286 |
+
debug/optimization flags. This is only
|
| 287 |
+
relevant for single-configuration buildsystems such
|
| 288 |
+
as ``Makefile`` and ``Ninja``. Multi-configuration
|
| 289 |
+
buildsystems such as those for Visual Studio and Xcode
|
| 290 |
+
ignore this setting.
|
| 291 |
+
:variable:`CMAKE_INSTALL_PREFIX` Location to install the
|
| 292 |
+
software to with the
|
| 293 |
+
``install`` build target
|
| 294 |
+
:variable:`CMAKE_TOOLCHAIN_FILE` File containing cross-compiling
|
| 295 |
+
data such as
|
| 296 |
+
:manual:`toolchains and sysroots <cmake-toolchains(7)>`.
|
| 297 |
+
:variable:`BUILD_SHARED_LIBS` Whether to build shared
|
| 298 |
+
instead of static libraries
|
| 299 |
+
for :command:`add_library`
|
| 300 |
+
commands used without a type
|
| 301 |
+
:variable:`CMAKE_EXPORT_COMPILE_COMMANDS` Generate a ``compile_commands.json``
|
| 302 |
+
file for use with clang-based tools
|
| 303 |
+
========================================== ============================================================
|
| 304 |
+
|
| 305 |
+
Other project-specific variables may be available
|
| 306 |
+
to control builds, such as enabling or disabling
|
| 307 |
+
components of the project.
|
| 308 |
+
|
| 309 |
+
There is no convention provided by CMake for how
|
| 310 |
+
such variables are named between different
|
| 311 |
+
provided buildsystems, except that variables with
|
| 312 |
+
the prefix ``CMAKE_`` usually refer to options
|
| 313 |
+
provided by CMake itself and should not be used
|
| 314 |
+
in third-party options, which should use
|
| 315 |
+
their own prefix instead. The
|
| 316 |
+
:manual:`cmake-gui(1)` tool can display options
|
| 317 |
+
in groups defined by their prefix, so it makes
|
| 318 |
+
sense for third parties to ensure that they use a
|
| 319 |
+
self-consistent prefix.
|
| 320 |
+
|
| 321 |
+
Setting variables on the command line
|
| 322 |
+
-------------------------------------
|
| 323 |
+
|
| 324 |
+
CMake variables can be set on the command line either
|
| 325 |
+
when creating the initial build:
|
| 326 |
+
|
| 327 |
+
.. code-block:: console
|
| 328 |
+
|
| 329 |
+
$ mkdir build
|
| 330 |
+
$ cd build
|
| 331 |
+
$ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug
|
| 332 |
+
|
| 333 |
+
or later on a subsequent invocation of
|
| 334 |
+
:manual:`cmake(1)`:
|
| 335 |
+
|
| 336 |
+
.. code-block:: console
|
| 337 |
+
|
| 338 |
+
$ cd build
|
| 339 |
+
$ cmake . -DCMAKE_BUILD_TYPE=Debug
|
| 340 |
+
|
| 341 |
+
The :option:`-U <cmake -U>` flag may be used to unset variables
|
| 342 |
+
on the :manual:`cmake(1)` command line:
|
| 343 |
+
|
| 344 |
+
.. code-block:: console
|
| 345 |
+
|
| 346 |
+
$ cd build
|
| 347 |
+
$ cmake . -UMyPackage_DIR
|
| 348 |
+
|
| 349 |
+
A CMake buildsystem which was initially created
|
| 350 |
+
on the command line can be modified using the
|
| 351 |
+
:manual:`cmake-gui(1)` and vice-versa.
|
| 352 |
+
|
| 353 |
+
The :manual:`cmake(1)` tool allows specifying a
|
| 354 |
+
file to use to populate the initial cache using
|
| 355 |
+
the :option:`-C <cmake -C>` option. This can be useful to simplify
|
| 356 |
+
commands and scripts which repeatedly require the
|
| 357 |
+
same cache entries.
|
| 358 |
+
|
| 359 |
+
Setting variables with cmake-gui
|
| 360 |
+
--------------------------------
|
| 361 |
+
|
| 362 |
+
Variables may be set in the cmake-gui using the "Add Entry"
|
| 363 |
+
button. This triggers a new dialog to set the value of
|
| 364 |
+
the variable.
|
| 365 |
+
|
| 366 |
+
.. image:: GUI-Add-Entry.png
|
| 367 |
+
:alt: Editing a cache entry
|
| 368 |
+
|
| 369 |
+
The main view of the :manual:`cmake-gui(1)` user interface
|
| 370 |
+
can be used to edit existing variables.
|
| 371 |
+
|
| 372 |
+
The CMake Cache
|
| 373 |
+
---------------
|
| 374 |
+
|
| 375 |
+
When CMake is executed, it needs to find the locations of
|
| 376 |
+
compilers, tools and dependencies. It also needs to be
|
| 377 |
+
able to consistently re-generate a buildsystem to use the
|
| 378 |
+
same compile/link flags and paths to dependencies. Such
|
| 379 |
+
parameters are also required to be configurable by the
|
| 380 |
+
user because they are paths and options specific to the
|
| 381 |
+
users system.
|
| 382 |
+
|
| 383 |
+
When it is first executed, CMake generates a
|
| 384 |
+
``CMakeCache.txt`` file in the build directory containing
|
| 385 |
+
key-value pairs for such artifacts. The cache file can be
|
| 386 |
+
viewed or edited by the user by running the
|
| 387 |
+
:manual:`cmake-gui(1)` or :manual:`ccmake(1)` tool. The
|
| 388 |
+
tools provide an interactive interface for re-configuring
|
| 389 |
+
the provided software and re-generating the buildsystem,
|
| 390 |
+
as is needed after editing cached values. Each cache
|
| 391 |
+
entry may have an associated short help text which is
|
| 392 |
+
displayed in the user interface tools.
|
| 393 |
+
|
| 394 |
+
The cache entries may also have a type to signify how it
|
| 395 |
+
should be presented in the user interface. For example,
|
| 396 |
+
a cache entry of type ``BOOL`` can be edited by a
|
| 397 |
+
checkbox in a user interface, a ``STRING`` can be edited
|
| 398 |
+
in a text field, and a ``FILEPATH`` while similar to a
|
| 399 |
+
``STRING`` should also provide a way to locate filesystem
|
| 400 |
+
paths using a file dialog. An entry of type ``STRING``
|
| 401 |
+
may provide a restricted list of allowed values which are
|
| 402 |
+
then provided in a drop-down menu in the
|
| 403 |
+
:manual:`cmake-gui(1)` user interface (see the
|
| 404 |
+
:prop_cache:`STRINGS` cache property).
|
| 405 |
+
|
| 406 |
+
The CMake files shipped with a software package may also
|
| 407 |
+
define boolean toggle options using the :command:`option`
|
| 408 |
+
command. The command creates a cache entry which has a
|
| 409 |
+
help text and a default value. Such cache entries are
|
| 410 |
+
typically specific to the provided software and affect
|
| 411 |
+
the configuration of the build, such as whether tests
|
| 412 |
+
and examples are built, whether to build with exceptions
|
| 413 |
+
enabled etc.
|
| 414 |
+
|
| 415 |
+
Presets
|
| 416 |
+
=======
|
| 417 |
+
|
| 418 |
+
CMake understands a file, ``CMakePresets.json``, and its
|
| 419 |
+
user-specific counterpart, ``CMakeUserPresets.json``, for
|
| 420 |
+
saving presets for commonly-used configure settings. These
|
| 421 |
+
presets can set the build directory, generator, cache
|
| 422 |
+
variables, environment variables, and other command-line
|
| 423 |
+
options. All of these options can be overridden by the
|
| 424 |
+
user. The full details of the ``CMakePresets.json`` format
|
| 425 |
+
are listed in the :manual:`cmake-presets(7)` manual.
|
| 426 |
+
|
| 427 |
+
Using presets on the command-line
|
| 428 |
+
---------------------------------
|
| 429 |
+
|
| 430 |
+
When using the :manual:`cmake(1)` command line tool, a
|
| 431 |
+
preset can be invoked by using the :option:`--preset <cmake --preset>`
|
| 432 |
+
option. If :option:`--preset <cmake --preset>` is specified,
|
| 433 |
+
the generator and build directory are not required, but can be
|
| 434 |
+
specified to override them. For example, if you have the following
|
| 435 |
+
``CMakePresets.json`` file:
|
| 436 |
+
|
| 437 |
+
.. code-block:: json
|
| 438 |
+
|
| 439 |
+
{
|
| 440 |
+
"version": 1,
|
| 441 |
+
"configurePresets": [
|
| 442 |
+
{
|
| 443 |
+
"name": "ninja-release",
|
| 444 |
+
"binaryDir": "${sourceDir}/build/${presetName}",
|
| 445 |
+
"generator": "Ninja",
|
| 446 |
+
"cacheVariables": {
|
| 447 |
+
"CMAKE_BUILD_TYPE": "Release"
|
| 448 |
+
}
|
| 449 |
+
}
|
| 450 |
+
]
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
and you run the following:
|
| 454 |
+
|
| 455 |
+
.. code-block:: console
|
| 456 |
+
|
| 457 |
+
cmake -S /path/to/source --preset=ninja-release
|
| 458 |
+
|
| 459 |
+
This will generate a build directory in
|
| 460 |
+
``/path/to/source/build/ninja-release`` with the
|
| 461 |
+
:generator:`Ninja` generator, and with
|
| 462 |
+
:variable:`CMAKE_BUILD_TYPE` set to ``Release``.
|
| 463 |
+
|
| 464 |
+
If you want to see the list of available presets, you can
|
| 465 |
+
run:
|
| 466 |
+
|
| 467 |
+
.. code-block:: console
|
| 468 |
+
|
| 469 |
+
cmake -S /path/to/source --list-presets
|
| 470 |
+
|
| 471 |
+
This will list the presets available in
|
| 472 |
+
``/path/to/source/CMakePresets.json`` and
|
| 473 |
+
``/path/to/source/CMakeUsersPresets.json`` without
|
| 474 |
+
generating a build tree.
|
| 475 |
+
|
| 476 |
+
Using presets in cmake-gui
|
| 477 |
+
--------------------------
|
| 478 |
+
|
| 479 |
+
If a project has presets available, either through
|
| 480 |
+
``CMakePresets.json`` or ``CMakeUserPresets.json``, the
|
| 481 |
+
list of presets will appear in a drop-down menu in
|
| 482 |
+
:manual:`cmake-gui(1)` between the source directory and
|
| 483 |
+
the binary directory. Choosing a preset sets the binary
|
| 484 |
+
directory, generator, environment variables, and cache
|
| 485 |
+
variables, but all of these options can be overridden after
|
| 486 |
+
a preset is selected.
|
| 487 |
+
|
| 488 |
+
Invoking the Buildsystem
|
| 489 |
+
========================
|
| 490 |
+
|
| 491 |
+
After generating the buildsystem, the software can be
|
| 492 |
+
built by invoking the particular build tool. In the
|
| 493 |
+
case of the IDE generators, this can involve loading
|
| 494 |
+
the generated project file into the IDE to invoke the
|
| 495 |
+
build.
|
| 496 |
+
|
| 497 |
+
CMake is aware of the specific build tool needed to invoke
|
| 498 |
+
a build so in general, to build a buildsystem or project
|
| 499 |
+
from the command line after generating, the following
|
| 500 |
+
command may be invoked in the build directory:
|
| 501 |
+
|
| 502 |
+
.. code-block:: console
|
| 503 |
+
|
| 504 |
+
$ cmake --build .
|
| 505 |
+
|
| 506 |
+
The :option:`--build <cmake --build>` flag enables a
|
| 507 |
+
particular mode of operation for the :manual:`cmake(1)`
|
| 508 |
+
tool. It invokes the :variable:`CMAKE_MAKE_PROGRAM`
|
| 509 |
+
command associated with the
|
| 510 |
+
:manual:`generator <cmake-generators(7)>`, or
|
| 511 |
+
the build tool configured by the user.
|
| 512 |
+
|
| 513 |
+
The :option:`--build <cmake --build>` mode also accepts
|
| 514 |
+
the parameter :option:`--target <cmake--build --target>` to
|
| 515 |
+
specify a particular target to build, for example a
|
| 516 |
+
particular library, executable or custom target, or a
|
| 517 |
+
particular special target like ``install``:
|
| 518 |
+
|
| 519 |
+
.. code-block:: console
|
| 520 |
+
|
| 521 |
+
$ cmake --build . --target myexe
|
| 522 |
+
|
| 523 |
+
The :option:`--build <cmake --build>` mode also accepts a
|
| 524 |
+
:option:`--config <cmake--build --config>` parameter
|
| 525 |
+
in the case of multi-config generators to specify which
|
| 526 |
+
particular configuration to build:
|
| 527 |
+
|
| 528 |
+
.. code-block:: console
|
| 529 |
+
|
| 530 |
+
$ cmake --build . --target myexe --config Release
|
| 531 |
+
|
| 532 |
+
The :option:`--config <cmake--build --config>` option has no
|
| 533 |
+
effect if the generator generates a buildsystem specific
|
| 534 |
+
to a configuration which is chosen when invoking cmake
|
| 535 |
+
with the :variable:`CMAKE_BUILD_TYPE` variable.
|
| 536 |
+
|
| 537 |
+
Some buildsystems omit details of command lines invoked
|
| 538 |
+
during the build. The :option:`--verbose <cmake--build --verbose>`
|
| 539 |
+
flag can be used to cause those command lines to be shown:
|
| 540 |
+
|
| 541 |
+
.. code-block:: console
|
| 542 |
+
|
| 543 |
+
$ cmake --build . --target myexe --verbose
|
| 544 |
+
|
| 545 |
+
The :option:`--build <cmake --build>` mode can also pass
|
| 546 |
+
particular command line options to the underlying build
|
| 547 |
+
tool by listing them after ``--``. This can be useful
|
| 548 |
+
to specify options to the build tool, such as to continue the
|
| 549 |
+
build after a failed job, where CMake does not
|
| 550 |
+
provide a high-level user interface.
|
| 551 |
+
|
| 552 |
+
For all generators, it is possible to run the underlying
|
| 553 |
+
build tool after invoking CMake. For example, ``make``
|
| 554 |
+
may be executed after generating with the
|
| 555 |
+
:generator:`Unix Makefiles` generator to invoke the build,
|
| 556 |
+
or ``ninja`` after generating with the :generator:`Ninja`
|
| 557 |
+
generator etc. The IDE buildsystems usually provide
|
| 558 |
+
command line tooling for building a project which can
|
| 559 |
+
also be invoked.
|
| 560 |
+
|
| 561 |
+
Selecting a Target
|
| 562 |
+
------------------
|
| 563 |
+
|
| 564 |
+
Each executable and library described in the CMake files
|
| 565 |
+
is a build target, and the buildsystem may describe
|
| 566 |
+
custom targets, either for internal use, or for user
|
| 567 |
+
consumption, for example to create documentation.
|
| 568 |
+
|
| 569 |
+
CMake provides some built-in targets for all buildsystems
|
| 570 |
+
providing CMake files.
|
| 571 |
+
|
| 572 |
+
``all``
|
| 573 |
+
The default target used by ``Makefile`` and ``Ninja``
|
| 574 |
+
generators. Builds all targets in the buildsystem,
|
| 575 |
+
except those which are excluded by their
|
| 576 |
+
:prop_tgt:`EXCLUDE_FROM_ALL` target property or
|
| 577 |
+
:prop_dir:`EXCLUDE_FROM_ALL` directory property. The
|
| 578 |
+
name ``ALL_BUILD`` is used for this purpose for the
|
| 579 |
+
Xcode and Visual Studio generators.
|
| 580 |
+
``help``
|
| 581 |
+
Lists the targets available for build. This target is
|
| 582 |
+
available when using the :generator:`Unix Makefiles` or
|
| 583 |
+
:generator:`Ninja` generator, and the exact output is
|
| 584 |
+
tool-specific.
|
| 585 |
+
``clean``
|
| 586 |
+
Delete built object files and other output files. The
|
| 587 |
+
``Makefile`` based generators create a ``clean`` target
|
| 588 |
+
per directory, so that an individual directory can be
|
| 589 |
+
cleaned. The ``Ninja`` tool provides its own granular
|
| 590 |
+
``-t clean`` system.
|
| 591 |
+
``test``
|
| 592 |
+
Runs tests. This target is only automatically available
|
| 593 |
+
if the CMake files provide CTest-based tests. See also
|
| 594 |
+
`Running Tests`_.
|
| 595 |
+
``install``
|
| 596 |
+
Installs the software. This target is only automatically
|
| 597 |
+
available if the software defines install rules with the
|
| 598 |
+
:command:`install` command. See also
|
| 599 |
+
`Software Installation`_.
|
| 600 |
+
``package``
|
| 601 |
+
Creates a binary package. This target is only
|
| 602 |
+
automatically available if the CMake files provide
|
| 603 |
+
CPack-based packages.
|
| 604 |
+
``package_source``
|
| 605 |
+
Creates a source package. This target is only
|
| 606 |
+
automatically available if the CMake files provide
|
| 607 |
+
CPack-based packages.
|
| 608 |
+
|
| 609 |
+
For ``Makefile`` based systems, ``/fast`` variants of binary
|
| 610 |
+
build targets are provided. The ``/fast`` variants are used
|
| 611 |
+
to build the specified target without regard for its
|
| 612 |
+
dependencies. The dependencies are not checked and
|
| 613 |
+
are not rebuilt if out of date. The :generator:`Ninja`
|
| 614 |
+
generator is sufficiently fast at dependency checking that
|
| 615 |
+
such targets are not provided for that generator.
|
| 616 |
+
|
| 617 |
+
``Makefile`` based systems also provide build-targets to
|
| 618 |
+
preprocess, assemble and compile individual files in a
|
| 619 |
+
particular directory.
|
| 620 |
+
|
| 621 |
+
.. code-block:: console
|
| 622 |
+
|
| 623 |
+
$ make foo.cpp.i
|
| 624 |
+
$ make foo.cpp.s
|
| 625 |
+
$ make foo.cpp.o
|
| 626 |
+
|
| 627 |
+
The file extension is built into the name of the target
|
| 628 |
+
because another file with the same name but a different
|
| 629 |
+
extension may exist. However, build-targets without the
|
| 630 |
+
file extension are also provided.
|
| 631 |
+
|
| 632 |
+
.. code-block:: console
|
| 633 |
+
|
| 634 |
+
$ make foo.i
|
| 635 |
+
$ make foo.s
|
| 636 |
+
$ make foo.o
|
| 637 |
+
|
| 638 |
+
In buildsystems which contain ``foo.c`` and ``foo.cpp``,
|
| 639 |
+
building the ``foo.i`` target will preprocess both files.
|
| 640 |
+
|
| 641 |
+
Specifying a Build Program
|
| 642 |
+
--------------------------
|
| 643 |
+
|
| 644 |
+
The program invoked by the :option:`--build <cmake --build>`
|
| 645 |
+
mode is determined by the :variable:`CMAKE_MAKE_PROGRAM` variable.
|
| 646 |
+
For most generators, the particular program does not need to be
|
| 647 |
+
configured.
|
| 648 |
+
|
| 649 |
+
===================== =========================== ===========================
|
| 650 |
+
Generator Default make program Alternatives
|
| 651 |
+
===================== =========================== ===========================
|
| 652 |
+
XCode ``xcodebuild``
|
| 653 |
+
Unix Makefiles ``make``
|
| 654 |
+
NMake Makefiles ``nmake`` ``jom``
|
| 655 |
+
NMake Makefiles JOM ``jom`` ``nmake``
|
| 656 |
+
MinGW Makefiles ``mingw32-make``
|
| 657 |
+
MSYS Makefiles ``make``
|
| 658 |
+
Ninja ``ninja``
|
| 659 |
+
Visual Studio ``msbuild``
|
| 660 |
+
Watcom WMake ``wmake``
|
| 661 |
+
===================== =========================== ===========================
|
| 662 |
+
|
| 663 |
+
The ``jom`` tool is capable of reading makefiles of the
|
| 664 |
+
``NMake`` flavor and building in parallel, while the
|
| 665 |
+
``nmake`` tool always builds serially. After generating
|
| 666 |
+
with the :generator:`NMake Makefiles` generator a user
|
| 667 |
+
can run ``jom`` instead of ``nmake``. The
|
| 668 |
+
:option:`--build <cmake --build>`
|
| 669 |
+
mode would also use ``jom`` if the
|
| 670 |
+
:variable:`CMAKE_MAKE_PROGRAM` was set to ``jom`` while
|
| 671 |
+
using the :generator:`NMake Makefiles` generator, and
|
| 672 |
+
as a convenience, the :generator:`NMake Makefiles JOM`
|
| 673 |
+
generator is provided to find ``jom`` in the normal way
|
| 674 |
+
and use it as the :variable:`CMAKE_MAKE_PROGRAM`. For
|
| 675 |
+
completeness, ``nmake`` is an alternative tool which
|
| 676 |
+
can process the output of the
|
| 677 |
+
:generator:`NMake Makefiles JOM` generator, but doing
|
| 678 |
+
so would be a pessimization.
|
| 679 |
+
|
| 680 |
+
Software Installation
|
| 681 |
+
=====================
|
| 682 |
+
|
| 683 |
+
The :variable:`CMAKE_INSTALL_PREFIX` variable can be
|
| 684 |
+
set in the CMake cache to specify where to install the
|
| 685 |
+
provided software. If the provided software has install
|
| 686 |
+
rules, specified using the :command:`install` command,
|
| 687 |
+
they will install artifacts into that prefix. On Windows,
|
| 688 |
+
the default installation location corresponds to the
|
| 689 |
+
``ProgramFiles`` system directory which may be
|
| 690 |
+
architecture specific. On Unix hosts, ``/usr/local`` is
|
| 691 |
+
the default installation location.
|
| 692 |
+
|
| 693 |
+
The :variable:`CMAKE_INSTALL_PREFIX` variable always
|
| 694 |
+
refers to the installation prefix on the target
|
| 695 |
+
filesystem.
|
| 696 |
+
|
| 697 |
+
In cross-compiling or packaging scenarios where the
|
| 698 |
+
sysroot is read-only or where the sysroot should otherwise
|
| 699 |
+
remain pristine, the :variable:`CMAKE_STAGING_PREFIX`
|
| 700 |
+
variable can be set to a location to actually install
|
| 701 |
+
the files.
|
| 702 |
+
|
| 703 |
+
The commands:
|
| 704 |
+
|
| 705 |
+
.. code-block:: console
|
| 706 |
+
|
| 707 |
+
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \
|
| 708 |
+
-DCMAKE_SYSROOT=$HOME/root \
|
| 709 |
+
-DCMAKE_STAGING_PREFIX=/tmp/package
|
| 710 |
+
$ cmake --build .
|
| 711 |
+
$ cmake --build . --target install
|
| 712 |
+
|
| 713 |
+
result in files being installed to paths such
|
| 714 |
+
as ``/tmp/package/lib/libfoo.so`` on the host machine.
|
| 715 |
+
The ``/usr/local`` location on the host machine is
|
| 716 |
+
not affected.
|
| 717 |
+
|
| 718 |
+
Some provided software may specify ``uninstall`` rules,
|
| 719 |
+
but CMake does not generate such rules by default itself.
|
| 720 |
+
|
| 721 |
+
Running Tests
|
| 722 |
+
=============
|
| 723 |
+
|
| 724 |
+
The :manual:`ctest(1)` tool is shipped with the CMake
|
| 725 |
+
distribution to execute provided tests and report
|
| 726 |
+
results. The ``test`` build-target is provided to run
|
| 727 |
+
all available tests, but the :manual:`ctest(1)` tool
|
| 728 |
+
allows granular control over which tests to run, how to
|
| 729 |
+
run them, and how to report results. Executing
|
| 730 |
+
:manual:`ctest(1)` in the build directory is equivalent
|
| 731 |
+
to running the ``test`` target:
|
| 732 |
+
|
| 733 |
+
.. code-block:: console
|
| 734 |
+
|
| 735 |
+
$ ctest
|
| 736 |
+
|
| 737 |
+
A regular expression can be passed to run only tests
|
| 738 |
+
which match the expression. To run only tests with
|
| 739 |
+
``Qt`` in their name:
|
| 740 |
+
|
| 741 |
+
.. code-block:: console
|
| 742 |
+
|
| 743 |
+
$ ctest -R Qt
|
| 744 |
+
|
| 745 |
+
Tests can be excluded by regular expression too. To
|
| 746 |
+
run only tests without ``Qt`` in their name:
|
| 747 |
+
|
| 748 |
+
.. code-block:: console
|
| 749 |
+
|
| 750 |
+
$ ctest -E Qt
|
| 751 |
+
|
| 752 |
+
Tests can be run in parallel by passing :option:`-j <ctest -j>`
|
| 753 |
+
arguments to :manual:`ctest(1)`:
|
| 754 |
+
|
| 755 |
+
.. code-block:: console
|
| 756 |
+
|
| 757 |
+
$ ctest -R Qt -j8
|
| 758 |
+
|
| 759 |
+
The environment variable :envvar:`CTEST_PARALLEL_LEVEL`
|
| 760 |
+
can alternatively be set to avoid the need to pass
|
| 761 |
+
:option:`-j <ctest -j>`.
|
| 762 |
+
|
| 763 |
+
By default :manual:`ctest(1)` does not print the output
|
| 764 |
+
from the tests. The command line argument :option:`-V <ctest -V>`
|
| 765 |
+
(or ``--verbose``) enables verbose mode to print the
|
| 766 |
+
output from all tests.
|
| 767 |
+
The :option:`--output-on-failure <ctest --output-on-failure>`
|
| 768 |
+
option prints the test output for failing tests only.
|
| 769 |
+
The environment variable :envvar:`CTEST_OUTPUT_ON_FAILURE`
|
| 770 |
+
can be set to ``1`` as an alternative to passing the
|
| 771 |
+
:option:`--output-on-failure <ctest --output-on-failure>`
|
| 772 |
+
option to :manual:`ctest(1)`.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/guide/using-dependencies/index.rst.txt
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Using Dependencies Guide
|
| 2 |
+
************************
|
| 3 |
+
|
| 4 |
+
.. only:: html
|
| 5 |
+
|
| 6 |
+
.. contents::
|
| 7 |
+
|
| 8 |
+
Introduction
|
| 9 |
+
============
|
| 10 |
+
|
| 11 |
+
Projects will frequently depend on other projects, assets, and artifacts.
|
| 12 |
+
CMake provides a number of ways to incorporate such things into the build.
|
| 13 |
+
Projects and users have the flexibility to choose between methods that
|
| 14 |
+
best suit their needs.
|
| 15 |
+
|
| 16 |
+
The primary methods of bringing dependencies into the build are the
|
| 17 |
+
:command:`find_package` command and the :module:`FetchContent` module.
|
| 18 |
+
The :module:`FindPkgConfig` module is also sometimes used, although it
|
| 19 |
+
lacks some of the integration of the other two and is not discussed any
|
| 20 |
+
further in this guide.
|
| 21 |
+
|
| 22 |
+
Dependencies can also be made available by a custom
|
| 23 |
+
:ref:`dependency provider <dependency_providers>`.
|
| 24 |
+
This might be a third party package manager, or it might be custom code
|
| 25 |
+
implemented by the developer. Dependency providers co-operate with the
|
| 26 |
+
primary methods mentioned above to extend their flexibility.
|
| 27 |
+
|
| 28 |
+
.. _prebuilt_find_package:
|
| 29 |
+
|
| 30 |
+
Using Pre-built Packages With ``find_package()``
|
| 31 |
+
================================================
|
| 32 |
+
|
| 33 |
+
A package needed by the project may already be built and available at some
|
| 34 |
+
location on the user's system. That package might have also been built by
|
| 35 |
+
CMake, or it could have used a different build system entirely. It might
|
| 36 |
+
even just be a collection of files that didn't need to be built at all.
|
| 37 |
+
CMake provides the :command:`find_package` command for these scenarios.
|
| 38 |
+
It searches well-known locations, along with additional hints and paths
|
| 39 |
+
provided by the project or user. It also supports package components and
|
| 40 |
+
packages being optional. Result variables are provided to allow the project
|
| 41 |
+
to customize its own behavior according to whether the package or specific
|
| 42 |
+
components were found.
|
| 43 |
+
|
| 44 |
+
In most cases, projects should generally use the :ref:`basic signature`.
|
| 45 |
+
Most of the time, this will involve just the package name, maybe a version
|
| 46 |
+
constraint, and the ``REQUIRED`` keyword if the dependency is not optional.
|
| 47 |
+
A set of package components may also be specified.
|
| 48 |
+
|
| 49 |
+
.. code-block:: cmake
|
| 50 |
+
:caption: Examples of ``find_package()`` basic signature
|
| 51 |
+
|
| 52 |
+
find_package(Catch2)
|
| 53 |
+
find_package(GTest REQUIRED)
|
| 54 |
+
find_package(Boost 1.79 COMPONENTS date_time)
|
| 55 |
+
|
| 56 |
+
The :command:`find_package` command supports two main methods for carrying
|
| 57 |
+
out the search:
|
| 58 |
+
|
| 59 |
+
**Config mode**
|
| 60 |
+
With this method, the command looks for files that are typically provided
|
| 61 |
+
by the package itself. This is the more reliable method of the two, since
|
| 62 |
+
the package details should always be in sync with the package.
|
| 63 |
+
|
| 64 |
+
**Module mode**
|
| 65 |
+
Not all packages are CMake-aware. Many don't provide the files needed to
|
| 66 |
+
support config mode. For such cases, a Find module file can be provided
|
| 67 |
+
separately, either by the project or by CMake. A Find module is typically
|
| 68 |
+
a heuristic implementation which knows what the package normally provides
|
| 69 |
+
and how to present that package to the project. Since Find modules are
|
| 70 |
+
usually distributed separately from the package, they are not as reliable.
|
| 71 |
+
They are typically maintained separately, and they are likely to follow
|
| 72 |
+
different release schedules, so they can easily become out-of-date.
|
| 73 |
+
|
| 74 |
+
Depending on the arguments used, :command:`find_package` may use one or both
|
| 75 |
+
of the above methods. By restricting the options to just the basic signature,
|
| 76 |
+
both config mode and module mode can be used to satisfy the dependency.
|
| 77 |
+
The presence of other options may restrict the call to using only one of the
|
| 78 |
+
two methods, potentially reducing the command's ability to find the dependency.
|
| 79 |
+
See the :command:`find_package` documentation for full details about this
|
| 80 |
+
complex topic.
|
| 81 |
+
|
| 82 |
+
For both search methods, the user can also set cache variables on the
|
| 83 |
+
:manual:`cmake(1)` command line or in the :manual:`ccmake(1)` or
|
| 84 |
+
:manual:`cmake-gui(1)` UI tools to influence and override where to find
|
| 85 |
+
packages. See the :ref:`User Interaction Guide <Setting Build Variables>`
|
| 86 |
+
for more on how to set cache variables.
|
| 87 |
+
|
| 88 |
+
.. _Libraries providing Config-file packages:
|
| 89 |
+
|
| 90 |
+
Config-file packages
|
| 91 |
+
--------------------
|
| 92 |
+
|
| 93 |
+
The preferred way for a third party to provide executables, libraries,
|
| 94 |
+
headers, and other files for use with CMake is to provide
|
| 95 |
+
:ref:`config files <Config File Packages>`. These are text files shipped
|
| 96 |
+
with the package, which define CMake targets, variables, commands, and so on.
|
| 97 |
+
The config file is an ordinary CMake script, which is read in by the
|
| 98 |
+
:command:`find_package` command.
|
| 99 |
+
|
| 100 |
+
The config files can usually be found in a directory whose name matches the
|
| 101 |
+
pattern ``lib/cmake/<PackageName>``, although they may be in other locations
|
| 102 |
+
instead (see :ref:`search procedure`). The ``<PackageName>`` is usually the
|
| 103 |
+
first argument to the :command:`find_package` command, and it may even be the
|
| 104 |
+
only argument. Alternative names can also be specified with the ``NAMES``
|
| 105 |
+
option:
|
| 106 |
+
|
| 107 |
+
.. code-block:: cmake
|
| 108 |
+
:caption: Providing alternative names when finding a package
|
| 109 |
+
|
| 110 |
+
find_package(SomeThing
|
| 111 |
+
NAMES
|
| 112 |
+
SameThingOtherName # Another name for the package
|
| 113 |
+
SomeThing # Also still look for its canonical name
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
The config file must be named either ``<PackageName>Config.cmake`` or
|
| 117 |
+
``<LowercasePackageName>-config.cmake`` (the former is used for the remainder
|
| 118 |
+
of this guide, but both are supported). This file is the entry point
|
| 119 |
+
to the package for CMake. A separate optional file named
|
| 120 |
+
``<PackageName>ConfigVersion.cmake`` or
|
| 121 |
+
``<LowercasePackageName>-config-version.cmake`` may also exist in the same
|
| 122 |
+
directory. This file is used by CMake to determine whether the version of
|
| 123 |
+
the package satisfies any version constraint included in the call to
|
| 124 |
+
:command:`find_package`. It is optional to specify a version when calling
|
| 125 |
+
:command:`find_package`, even if a ``<PackageName>ConfigVersion.cmake``
|
| 126 |
+
file is present.
|
| 127 |
+
|
| 128 |
+
If the ``<PackageName>Config.cmake`` file is found and any version constraint
|
| 129 |
+
is satisfied, the :command:`find_package` command considers the package to be
|
| 130 |
+
found, and the entire package is assumed to be complete as designed.
|
| 131 |
+
|
| 132 |
+
There may be additional files providing CMake commands or
|
| 133 |
+
:ref:`imported targets` for you to use. CMake does not enforce any naming
|
| 134 |
+
convention for these files. They are related to the primary
|
| 135 |
+
``<PackageName>Config.cmake`` file by use of the CMake :command:`include`
|
| 136 |
+
command. The ``<PackageName>Config.cmake`` file would typically include
|
| 137 |
+
these for you, so they won't usually require any additional step other than
|
| 138 |
+
the call to :command:`find_package`.
|
| 139 |
+
|
| 140 |
+
If the location of the package is in a
|
| 141 |
+
:ref:`directory known to CMake <search procedure>`, the
|
| 142 |
+
:command:`find_package` call should succeed. The directories known to CMake
|
| 143 |
+
are platform-specific. For example, packages installed on Linux with a
|
| 144 |
+
standard system package manager will be found in the ``/usr`` prefix
|
| 145 |
+
automatically. Packages installed in ``Program Files`` on Windows will
|
| 146 |
+
similarly be found automatically.
|
| 147 |
+
|
| 148 |
+
Packages will not be found automatically without help if they are in
|
| 149 |
+
locations not known to CMake, such as ``/opt/mylib`` or ``$HOME/dev/prefix``.
|
| 150 |
+
This is a normal situation, and CMake provides several ways for users to
|
| 151 |
+
specify where to find such libraries.
|
| 152 |
+
|
| 153 |
+
The :variable:`CMAKE_PREFIX_PATH` variable may be
|
| 154 |
+
:ref:`set when invoking CMake <Setting Build Variables>`.
|
| 155 |
+
It is treated as a list of base paths in which to search for
|
| 156 |
+
:ref:`config files <Config File Packages>`. A package installed in
|
| 157 |
+
``/opt/somepackage`` will typically install config files such as
|
| 158 |
+
``/opt/somepackage/lib/cmake/somePackage/SomePackageConfig.cmake``.
|
| 159 |
+
In that case, ``/opt/somepackage`` should be added to
|
| 160 |
+
:variable:`CMAKE_PREFIX_PATH`.
|
| 161 |
+
|
| 162 |
+
The environment variable ``CMAKE_PREFIX_PATH`` may also be populated with
|
| 163 |
+
prefixes to search for packages. Like the ``PATH`` environment variable,
|
| 164 |
+
this is a list, but it needs to use the platform-specific environment variable
|
| 165 |
+
list item separator (``:`` on Unix and ``;`` on Windows).
|
| 166 |
+
|
| 167 |
+
The :variable:`CMAKE_PREFIX_PATH` variable provides convenience in cases
|
| 168 |
+
where multiple prefixes need to be specified, or when multiple packages
|
| 169 |
+
are available under the same prefix. Paths to packages may also be
|
| 170 |
+
specified by setting variables matching ``<PackageName>_DIR``, such as
|
| 171 |
+
``SomePackage_DIR``. Note that this is not a prefix, but should be a full
|
| 172 |
+
path to a directory containing a config-style package file, such as
|
| 173 |
+
``/opt/somepackage/lib/cmake/SomePackage`` in the above example.
|
| 174 |
+
See the :command:`find_package` documentation for other CMake variables and
|
| 175 |
+
environment variables that can affect the search.
|
| 176 |
+
|
| 177 |
+
.. _Libraries not Providing Config-file Packages:
|
| 178 |
+
|
| 179 |
+
Find Module Files
|
| 180 |
+
-----------------
|
| 181 |
+
|
| 182 |
+
Packages which do not provide config files can still be found with the
|
| 183 |
+
:command:`find_package` command, if a ``FindSomePackage.cmake`` file is
|
| 184 |
+
available. These Find module files are different to config files in that:
|
| 185 |
+
|
| 186 |
+
#. Find module files should not be provided by the package itself.
|
| 187 |
+
#. The availability of a ``Find<PackageName>.cmake`` file does not indicate
|
| 188 |
+
the availability of the package, or any particular part of the package.
|
| 189 |
+
#. CMake does not search the locations specified in the
|
| 190 |
+
:variable:`CMAKE_PREFIX_PATH` variable for ``Find<PackageName>.cmake``
|
| 191 |
+
files. Instead, CMake searches for such files in the locations given
|
| 192 |
+
by the :variable:`CMAKE_MODULE_PATH` variable. It is common for users to
|
| 193 |
+
set the :variable:`CMAKE_MODULE_PATH` when running CMake, and it is common
|
| 194 |
+
for CMake projects to append to :variable:`CMAKE_MODULE_PATH` to allow use
|
| 195 |
+
of local Find module files.
|
| 196 |
+
#. CMake ships ``Find<PackageName>.cmake`` files for some
|
| 197 |
+
:manual:`third party packages <cmake-modules(7)>`. These files are a
|
| 198 |
+
maintenance burden for CMake, and it is not unusual for these to fall
|
| 199 |
+
behind the latest releases of the packages they are associated with.
|
| 200 |
+
In general, new Find modules are not added to CMake any more. Projects
|
| 201 |
+
should encourage the upstream packages to provide a config file where
|
| 202 |
+
possible. If that is unsuccessful, the project should provide its own
|
| 203 |
+
Find module for the package.
|
| 204 |
+
|
| 205 |
+
See :ref:`Find Modules` for a detailed discussion of how to write a
|
| 206 |
+
Find module file.
|
| 207 |
+
|
| 208 |
+
.. _Imported Targets from Packages:
|
| 209 |
+
|
| 210 |
+
Imported Targets
|
| 211 |
+
----------------
|
| 212 |
+
|
| 213 |
+
Both config files and Find module files can define :ref:`Imported targets`.
|
| 214 |
+
These will typically have names of the form ``SomePrefix::ThingName``.
|
| 215 |
+
Where these are available, the project should prefer to use them instead of
|
| 216 |
+
any CMake variables that may also be provided. Such targets typically carry
|
| 217 |
+
usage requirements and apply things like header search paths, compiler
|
| 218 |
+
definitions, etc. automatically to other targets that link to them (e.g. using
|
| 219 |
+
:command:`target_link_libraries`). This is both more robust and more
|
| 220 |
+
convenient than trying to apply the same things manually using variables.
|
| 221 |
+
Check the documentation for the package or Find module to see what imported
|
| 222 |
+
targets it defines, if any.
|
| 223 |
+
|
| 224 |
+
Imported targets should also encapsulate any configuration-specific paths.
|
| 225 |
+
This includes the location of binaries (libraries, executables), compiler
|
| 226 |
+
flags, and any other configuration-dependent quantities. Find modules may
|
| 227 |
+
be less reliable in providing these details than config files.
|
| 228 |
+
|
| 229 |
+
A complete example which finds a third party package and uses a library
|
| 230 |
+
from it might look like the following:
|
| 231 |
+
|
| 232 |
+
.. code-block:: cmake
|
| 233 |
+
|
| 234 |
+
cmake_minimum_required(VERSION 3.10)
|
| 235 |
+
project(MyExeProject VERSION 1.0.0)
|
| 236 |
+
|
| 237 |
+
# Make project-provided Find modules available
|
| 238 |
+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
| 239 |
+
|
| 240 |
+
find_package(SomePackage REQUIRED)
|
| 241 |
+
add_executable(MyExe main.cpp)
|
| 242 |
+
target_link_libraries(MyExe PRIVATE SomePrefix::LibName)
|
| 243 |
+
|
| 244 |
+
Note that the above call to :command:`find_package` could be resolved by
|
| 245 |
+
a config file or a Find module. It uses only the basic arguments supported
|
| 246 |
+
by the :ref:`basic signature`. A ``FindSomePackage.cmake`` file in the
|
| 247 |
+
``${CMAKE_CURRENT_SOURCE_DIR}/cmake`` directory would allow the
|
| 248 |
+
:command:`find_package` command to succeed using module mode, for example.
|
| 249 |
+
If no such module file is present, the system would be searched for a config
|
| 250 |
+
file.
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
Downloading And Building From Source With ``FetchContent``
|
| 254 |
+
==========================================================
|
| 255 |
+
|
| 256 |
+
Dependencies do not necessarily have to be pre-built in order to use them
|
| 257 |
+
with CMake. They can be built from sources as part of the main project.
|
| 258 |
+
The :module:`FetchContent` module provides functionality to download
|
| 259 |
+
content (typically sources, but can be anything) and add it to the main
|
| 260 |
+
project if the dependency also uses CMake. The dependency's sources will
|
| 261 |
+
be built along with the rest of the project, just as though the sources were
|
| 262 |
+
part of the project's own sources.
|
| 263 |
+
|
| 264 |
+
The general pattern is that the project should first declare all the
|
| 265 |
+
dependencies it wants to use, then ask for them to be made available.
|
| 266 |
+
The following demonstrates the principle (see :ref:`fetch-content-examples`
|
| 267 |
+
for more):
|
| 268 |
+
|
| 269 |
+
.. code-block:: cmake
|
| 270 |
+
|
| 271 |
+
include(FetchContent)
|
| 272 |
+
FetchContent_Declare(
|
| 273 |
+
googletest
|
| 274 |
+
GIT_REPOSITORY https://github.com/google/googletest.git
|
| 275 |
+
GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
|
| 276 |
+
)
|
| 277 |
+
FetchContent_Declare(
|
| 278 |
+
Catch2
|
| 279 |
+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
| 280 |
+
GIT_TAG 605a34765aa5d5ecbf476b4598a862ada971b0cc # v3.0.1
|
| 281 |
+
)
|
| 282 |
+
FetchContent_MakeAvailable(googletest Catch2)
|
| 283 |
+
|
| 284 |
+
Various download methods are supported, including downloading and extracting
|
| 285 |
+
archives from a URL (a range of archive formats are supported), and a number
|
| 286 |
+
of repository formats including Git, Subversion, and Mercurial.
|
| 287 |
+
Custom download, update, and patch commands can also be used to support
|
| 288 |
+
arbitrary use cases.
|
| 289 |
+
|
| 290 |
+
When a dependency is added to the project with :module:`FetchContent`, the
|
| 291 |
+
project links to the dependency's targets just like any other target from the
|
| 292 |
+
project. If the dependency provides namespaced targets of the form
|
| 293 |
+
``SomePrefix::ThingName``, the project should link to those rather than to
|
| 294 |
+
any non-namespaced targets. See the next section for why this is recommended.
|
| 295 |
+
|
| 296 |
+
Not all dependencies can be brought into the project this way. Some
|
| 297 |
+
dependencies define targets whose names clash with other targets from the
|
| 298 |
+
project or other dependencies. Concrete executable and library targets
|
| 299 |
+
created by :command:`add_executable` and :command:`add_library` are global,
|
| 300 |
+
so each one must be unique across the whole build. If a dependency would
|
| 301 |
+
add a clashing target name, it cannot be brought directly into the build
|
| 302 |
+
with this method.
|
| 303 |
+
|
| 304 |
+
``FetchContent`` And ``find_package()`` Integration
|
| 305 |
+
===================================================
|
| 306 |
+
|
| 307 |
+
.. versionadded:: 3.24
|
| 308 |
+
|
| 309 |
+
Some dependencies support being added by either :command:`find_package` or
|
| 310 |
+
:module:`FetchContent`. Such dependencies must ensure they define the same
|
| 311 |
+
namespaced targets in both installed and built-from-source scenarios.
|
| 312 |
+
A consuming project then links to those namespaced targets and can handle
|
| 313 |
+
both scenarios transparently, as long as the project does not use anything
|
| 314 |
+
else that isn't provided by both methods.
|
| 315 |
+
|
| 316 |
+
The project can indicate it is happy to accept a dependency by either method
|
| 317 |
+
using the ``FIND_PACKAGE_ARGS`` option to :command:`FetchContent_Declare`.
|
| 318 |
+
This allows :command:`FetchContent_MakeAvailable` to try satisfying the
|
| 319 |
+
dependency with a call to :command:`find_package` first, using the arguments
|
| 320 |
+
after the ``FIND_PACKAGE_ARGS`` keyword, if any. If that doesn't find the
|
| 321 |
+
dependency, it is built from source as described previously instead.
|
| 322 |
+
|
| 323 |
+
.. code-block:: cmake
|
| 324 |
+
|
| 325 |
+
include(FetchContent)
|
| 326 |
+
FetchContent_Declare(
|
| 327 |
+
googletest
|
| 328 |
+
GIT_REPOSITORY https://github.com/google/googletest.git
|
| 329 |
+
GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
|
| 330 |
+
FIND_PACKAGE_ARGS NAMES GTest
|
| 331 |
+
)
|
| 332 |
+
FetchContent_MakeAvailable(googletest)
|
| 333 |
+
|
| 334 |
+
add_executable(ThingUnitTest thing_ut.cpp)
|
| 335 |
+
target_link_libraries(ThingUnitTest GTest::gtest_main)
|
| 336 |
+
|
| 337 |
+
The above example calls
|
| 338 |
+
:command:`find_package(googletest NAMES GTest) <find_package>` first.
|
| 339 |
+
CMake provides a :module:`FindGTest` module, so if that finds a GTest package
|
| 340 |
+
installed somewhere, it will make it available, and the dependency will not be
|
| 341 |
+
built from source. If no GTest package is found, it *will* be built from
|
| 342 |
+
source. In either case, the ``GTest::gtest_main`` target is expected to be
|
| 343 |
+
defined, so we link our unit test executable to that target.
|
| 344 |
+
|
| 345 |
+
High-level control is also available through the
|
| 346 |
+
:variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` variable. This can be set to
|
| 347 |
+
``NEVER`` to disable all redirection to :command:`find_package`. It can be
|
| 348 |
+
set to ``ALWAYS`` to try :command:`find_package` even if ``FIND_PACKAGE_ARGS``
|
| 349 |
+
was not specified (this should be used with caution).
|
| 350 |
+
|
| 351 |
+
The project might also decide that a particular dependency must be built from
|
| 352 |
+
source. This might be needed if a patched or unreleased version of the
|
| 353 |
+
dependency is required, or to satisfy some policy that requires all
|
| 354 |
+
dependencies to be built from source. The project can enforce this by adding
|
| 355 |
+
the ``OVERRIDE_FIND_PACKAGE`` keyword to :command:`FetchContent_Declare`.
|
| 356 |
+
A call to :command:`find_package` for that dependency will then be redirected
|
| 357 |
+
to :command:`FetchContent_MakeAvailable` instead.
|
| 358 |
+
|
| 359 |
+
.. code-block:: cmake
|
| 360 |
+
|
| 361 |
+
include(FetchContent)
|
| 362 |
+
FetchContent_Declare(
|
| 363 |
+
Catch2
|
| 364 |
+
URL https://intranet.mycomp.com/vendored/Catch2_2.13.4_patched.tgz
|
| 365 |
+
URL_HASH MD5=abc123...
|
| 366 |
+
OVERRIDE_FIND_PACKAGE
|
| 367 |
+
)
|
| 368 |
+
|
| 369 |
+
# The following is automatically redirected to FetchContent_MakeAvailable(Catch2)
|
| 370 |
+
find_package(Catch2)
|
| 371 |
+
|
| 372 |
+
For more advanced use cases, see the
|
| 373 |
+
:variable:`CMAKE_FIND_PACKAGE_REDIRECTS_DIR` variable.
|
| 374 |
+
|
| 375 |
+
.. _dependency_providers_overview:
|
| 376 |
+
|
| 377 |
+
Dependency Providers
|
| 378 |
+
====================
|
| 379 |
+
|
| 380 |
+
.. versionadded:: 3.24
|
| 381 |
+
|
| 382 |
+
The preceding section discussed techniques that projects can use to specify
|
| 383 |
+
their dependencies. Ideally, the project shouldn't really care where a
|
| 384 |
+
dependency comes from, as long as it provides the things it expects (often
|
| 385 |
+
just some imported targets). The project says what it needs and may also
|
| 386 |
+
specify where to get it from, in the absence of any other details, so that it
|
| 387 |
+
can still be built out-of-the-box.
|
| 388 |
+
|
| 389 |
+
The developer, on the other hand, may be much more interested in controlling
|
| 390 |
+
*how* a dependency is provided to the project. You might want to use a
|
| 391 |
+
particular version of a package that you built yourself. You might want
|
| 392 |
+
to use a third party package manager. You might want to redirect some
|
| 393 |
+
requests to a different URL on a system you control for security or
|
| 394 |
+
performance reasons. CMake supports these sort of scenarios through
|
| 395 |
+
:ref:`dependency_providers`.
|
| 396 |
+
|
| 397 |
+
A dependency provider can be set to intercept :command:`find_package` and
|
| 398 |
+
:command:`FetchContent_MakeAvailable` calls. The provider is given an
|
| 399 |
+
opportunity to satisfy such requests before falling back to the built-in
|
| 400 |
+
implementation if the provider doesn't fulfill it.
|
| 401 |
+
|
| 402 |
+
Only one dependency provider can be set, and it can only be set at a very
|
| 403 |
+
specific point early in the CMake run.
|
| 404 |
+
The :variable:`CMAKE_PROJECT_TOP_LEVEL_INCLUDES` variable lists CMake files
|
| 405 |
+
that will be read while processing the first :command:`project()` call (and
|
| 406 |
+
only that call). This is the only time a dependency provider may be set.
|
| 407 |
+
At most, one single provider is expected to be used throughout the whole
|
| 408 |
+
project.
|
| 409 |
+
|
| 410 |
+
For some scenarios, the user wouldn't need to know the details of how the
|
| 411 |
+
dependency provider is set. A third party may provide a file that can be
|
| 412 |
+
added to :variable:`CMAKE_PROJECT_TOP_LEVEL_INCLUDES`, which will set up
|
| 413 |
+
the dependency provider on the user's behalf. This is the recommended
|
| 414 |
+
approach for package managers. The developer can use such a file like so::
|
| 415 |
+
|
| 416 |
+
cmake -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=/path/to/package_manager/setup.cmake ...
|
| 417 |
+
|
| 418 |
+
For details on how to implement your own custom dependency provider, see the
|
| 419 |
+
:command:`cmake_language(SET_DEPENDENCY_PROVIDER)` command.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/ADVANCED.rst.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ADVANCED
|
| 2 |
+
--------
|
| 3 |
+
|
| 4 |
+
True if entry should be hidden by default in GUIs.
|
| 5 |
+
|
| 6 |
+
This is a boolean value indicating whether the entry is considered
|
| 7 |
+
interesting only for advanced configuration. The :command:`mark_as_advanced`
|
| 8 |
+
command modifies this property.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/HELPSTRING.rst.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
HELPSTRING
|
| 2 |
+
----------
|
| 3 |
+
|
| 4 |
+
Help associated with entry in GUIs.
|
| 5 |
+
|
| 6 |
+
This string summarizes the purpose of an entry to help users set it
|
| 7 |
+
through a CMake GUI.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/MODIFIED.rst.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MODIFIED
|
| 2 |
+
--------
|
| 3 |
+
|
| 4 |
+
Internal management property. Do not set or get.
|
| 5 |
+
|
| 6 |
+
This is an internal cache entry property managed by CMake to track
|
| 7 |
+
interactive user modification of entries. Ignore it.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/STRINGS.rst.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
STRINGS
|
| 2 |
+
-------
|
| 3 |
+
|
| 4 |
+
Enumerate possible ``STRING`` entry values for GUI selection.
|
| 5 |
+
|
| 6 |
+
For cache entries with type ``STRING``, this enumerates a set of values.
|
| 7 |
+
CMake GUIs may use this to provide a selection widget instead of a
|
| 8 |
+
generic string entry field. This is for convenience only. CMake does
|
| 9 |
+
not enforce that the value matches one of those listed.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/TYPE.rst.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TYPE
|
| 2 |
+
----
|
| 3 |
+
|
| 4 |
+
Widget type for entry in GUIs.
|
| 5 |
+
|
| 6 |
+
Cache entry values are always strings, but CMake GUIs present widgets
|
| 7 |
+
to help users set values. The GUIs use this property as a hint to
|
| 8 |
+
determine the widget type. Valid ``TYPE`` values are:
|
| 9 |
+
|
| 10 |
+
::
|
| 11 |
+
|
| 12 |
+
BOOL = Boolean ON/OFF value.
|
| 13 |
+
PATH = Path to a directory.
|
| 14 |
+
FILEPATH = Path to a file.
|
| 15 |
+
STRING = Generic string value.
|
| 16 |
+
INTERNAL = Do not present in GUI at all.
|
| 17 |
+
STATIC = Value managed by CMake, do not change.
|
| 18 |
+
UNINITIALIZED = Type not yet specified.
|
| 19 |
+
|
| 20 |
+
Generally the ``TYPE`` of a cache entry should be set by the command which
|
| 21 |
+
creates it ( :command:`set`, :command:`option`, :command:`find_library`, etc.).
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_cache/VALUE.rst.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
VALUE
|
| 2 |
+
-----
|
| 3 |
+
|
| 4 |
+
Value of a cache entry.
|
| 5 |
+
|
| 6 |
+
This property maps to the actual value of a cache entry. Setting this
|
| 7 |
+
property always sets the value without checking, so use with care.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ALLOW_DUPLICATE_CUSTOM_TARGETS
|
| 2 |
+
------------------------------
|
| 3 |
+
|
| 4 |
+
Allow duplicate custom targets to be created.
|
| 5 |
+
|
| 6 |
+
Normally CMake requires that all targets built in a project have
|
| 7 |
+
globally unique logical names (see policy :policy:`CMP0002`).
|
| 8 |
+
This is necessary to generate meaningful project file names in
|
| 9 |
+
:generator:`Xcode` and :ref:`Visual Studio Generators` IDE
|
| 10 |
+
generators. It also allows the target names to be referenced
|
| 11 |
+
unambiguously.
|
| 12 |
+
|
| 13 |
+
Makefile generators are capable of supporting duplicate :command:`add_custom_target`
|
| 14 |
+
names. For projects that care only about :ref:`Makefile Generators` and do
|
| 15 |
+
not wish to support :generator:`Xcode` or :ref:`Visual Studio Generators` IDE
|
| 16 |
+
generators, one may set this property to ``True``
|
| 17 |
+
to allow duplicate custom targets. The property
|
| 18 |
+
allows multiple :command:`add_custom_target` command calls in different
|
| 19 |
+
directories to specify the same target name. However, setting this
|
| 20 |
+
property will cause non-Makefile generators to produce an error and
|
| 21 |
+
refuse to generate the project.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOGEN_SOURCE_GROUP.rst.txt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AUTOGEN_SOURCE_GROUP
|
| 2 |
+
--------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.9
|
| 5 |
+
|
| 6 |
+
Name of the :command:`source_group` for :prop_tgt:`AUTOMOC`,
|
| 7 |
+
:prop_tgt:`AUTORCC` and :prop_tgt:`AUTOUIC` generated files.
|
| 8 |
+
|
| 9 |
+
Files generated by :prop_tgt:`AUTOMOC`, :prop_tgt:`AUTORCC` and
|
| 10 |
+
:prop_tgt:`AUTOUIC` are not always known at configure time and therefore can't
|
| 11 |
+
be passed to :command:`source_group`.
|
| 12 |
+
``AUTOGEN_SOURCE_GROUP`` can be used instead to generate or select
|
| 13 |
+
a source group for :prop_tgt:`AUTOMOC`, :prop_tgt:`AUTORCC` and
|
| 14 |
+
:prop_tgt:`AUTOUIC` generated files.
|
| 15 |
+
|
| 16 |
+
For :prop_tgt:`AUTOMOC`, :prop_tgt:`AUTORCC` and :prop_tgt:`AUTOUIC` specific
|
| 17 |
+
overrides see :prop_gbl:`AUTOMOC_SOURCE_GROUP`, :prop_gbl:`AUTORCC_SOURCE_GROUP`
|
| 18 |
+
and :prop_gbl:`AUTOUIC_SOURCE_GROUP` respectively.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AUTOGEN_TARGETS_FOLDER
|
| 2 |
+
----------------------
|
| 3 |
+
|
| 4 |
+
Name of :prop_tgt:`FOLDER` for ``*_autogen`` targets that are added
|
| 5 |
+
automatically by CMake for targets for which :prop_tgt:`AUTOMOC` is enabled.
|
| 6 |
+
|
| 7 |
+
If not set, CMake uses the :prop_tgt:`FOLDER` property of the parent target as a
|
| 8 |
+
default value for this property. See also the documentation for the
|
| 9 |
+
:prop_tgt:`FOLDER` target property and the :prop_tgt:`AUTOMOC` target property.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOMOC_SOURCE_GROUP.rst.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AUTOMOC_SOURCE_GROUP
|
| 2 |
+
--------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.9
|
| 5 |
+
|
| 6 |
+
Name of the :command:`source_group` for :prop_tgt:`AUTOMOC` generated files.
|
| 7 |
+
|
| 8 |
+
When set this is used instead of :prop_gbl:`AUTOGEN_SOURCE_GROUP` for
|
| 9 |
+
files generated by :prop_tgt:`AUTOMOC`.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AUTOMOC_TARGETS_FOLDER
|
| 2 |
+
----------------------
|
| 3 |
+
|
| 4 |
+
Name of :prop_tgt:`FOLDER` for ``*_autogen`` targets that are added automatically by
|
| 5 |
+
CMake for targets for which :prop_tgt:`AUTOMOC` is enabled.
|
| 6 |
+
|
| 7 |
+
This property is obsolete. Use :prop_gbl:`AUTOGEN_TARGETS_FOLDER` instead.
|
| 8 |
+
|
| 9 |
+
If not set, CMake uses the :prop_tgt:`FOLDER` property of the parent target as a
|
| 10 |
+
default value for this property. See also the documentation for the
|
| 11 |
+
:prop_tgt:`FOLDER` target property and the :prop_tgt:`AUTOMOC` target property.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTORCC_SOURCE_GROUP.rst.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AUTORCC_SOURCE_GROUP
|
| 2 |
+
--------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.9
|
| 5 |
+
|
| 6 |
+
Name of the :command:`source_group` for :prop_tgt:`AUTORCC` generated files.
|
| 7 |
+
|
| 8 |
+
When set this is used instead of :prop_gbl:`AUTOGEN_SOURCE_GROUP` for
|
| 9 |
+
files generated by :prop_tgt:`AUTORCC`.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/AUTOUIC_SOURCE_GROUP.rst.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AUTOUIC_SOURCE_GROUP
|
| 2 |
+
--------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.21
|
| 5 |
+
|
| 6 |
+
Name of the :command:`source_group` for :prop_tgt:`AUTOUIC` generated files.
|
| 7 |
+
|
| 8 |
+
When set this is used instead of :prop_gbl:`AUTOGEN_SOURCE_GROUP` for
|
| 9 |
+
files generated by :prop_tgt:`AUTOUIC`.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/CMAKE_CUDA_KNOWN_FEATURES.rst.txt
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMAKE_CUDA_KNOWN_FEATURES
|
| 2 |
+
-------------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.17
|
| 5 |
+
|
| 6 |
+
List of CUDA features known to this version of CMake.
|
| 7 |
+
|
| 8 |
+
The features listed in this global property may be known to be available to the
|
| 9 |
+
CUDA compiler. If the feature is available with the C++ compiler, it will
|
| 10 |
+
be listed in the :variable:`CMAKE_CUDA_COMPILE_FEATURES` variable.
|
| 11 |
+
|
| 12 |
+
The features listed here may be used with the :command:`target_compile_features`
|
| 13 |
+
command. See the :manual:`cmake-compile-features(7)` manual for information on
|
| 14 |
+
compile features and a list of supported compilers.
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
The features known to this version of CMake are:
|
| 18 |
+
|
| 19 |
+
``cuda_std_03``
|
| 20 |
+
Compiler mode is at least CUDA/C++ 03.
|
| 21 |
+
|
| 22 |
+
``cuda_std_11``
|
| 23 |
+
Compiler mode is at least CUDA/C++ 11.
|
| 24 |
+
|
| 25 |
+
``cuda_std_14``
|
| 26 |
+
Compiler mode is at least CUDA/C++ 14.
|
| 27 |
+
|
| 28 |
+
``cuda_std_17``
|
| 29 |
+
Compiler mode is at least CUDA/C++ 17.
|
| 30 |
+
|
| 31 |
+
``cuda_std_20``
|
| 32 |
+
Compiler mode is at least CUDA/C++ 20.
|
| 33 |
+
|
| 34 |
+
``cuda_std_23``
|
| 35 |
+
.. versionadded:: 3.20
|
| 36 |
+
|
| 37 |
+
Compiler mode is at least CUDA/C++ 23.
|
| 38 |
+
|
| 39 |
+
``cuda_std_26``
|
| 40 |
+
.. versionadded:: 3.25
|
| 41 |
+
|
| 42 |
+
Compiler mode is at least CUDA/C++ 26.
|
| 43 |
+
|
| 44 |
+
.. include:: CMAKE_LANG_STD_FLAGS.txt
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst.txt
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMAKE_CXX_KNOWN_FEATURES
|
| 2 |
+
------------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.1
|
| 5 |
+
|
| 6 |
+
List of C++ features known to this version of CMake.
|
| 7 |
+
|
| 8 |
+
The features listed in this global property may be known to be available to the
|
| 9 |
+
C++ compiler. If the feature is available with the C++ compiler, it will
|
| 10 |
+
be listed in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable.
|
| 11 |
+
|
| 12 |
+
The features listed here may be used with the :command:`target_compile_features`
|
| 13 |
+
command. See the :manual:`cmake-compile-features(7)` manual for information on
|
| 14 |
+
compile features and a list of supported compilers.
|
| 15 |
+
|
| 16 |
+
The features known to this version of CMake are listed below.
|
| 17 |
+
|
| 18 |
+
High level meta features indicating C++ standard support
|
| 19 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 20 |
+
|
| 21 |
+
.. versionadded:: 3.8
|
| 22 |
+
|
| 23 |
+
The following meta features indicate general support for the associated
|
| 24 |
+
language standard. It reflects the language support claimed by the compiler,
|
| 25 |
+
but it does not necessarily imply complete conformance to that standard.
|
| 26 |
+
|
| 27 |
+
``cxx_std_98``
|
| 28 |
+
Compiler mode is at least C++ 98.
|
| 29 |
+
|
| 30 |
+
``cxx_std_11``
|
| 31 |
+
Compiler mode is at least C++ 11.
|
| 32 |
+
|
| 33 |
+
``cxx_std_14``
|
| 34 |
+
Compiler mode is at least C++ 14.
|
| 35 |
+
|
| 36 |
+
``cxx_std_17``
|
| 37 |
+
Compiler mode is at least C++ 17.
|
| 38 |
+
|
| 39 |
+
``cxx_std_20``
|
| 40 |
+
.. versionadded:: 3.12
|
| 41 |
+
|
| 42 |
+
Compiler mode is at least C++ 20.
|
| 43 |
+
|
| 44 |
+
``cxx_std_23``
|
| 45 |
+
.. versionadded:: 3.20
|
| 46 |
+
|
| 47 |
+
Compiler mode is at least C++ 23.
|
| 48 |
+
|
| 49 |
+
``cxx_std_26``
|
| 50 |
+
.. versionadded:: 3.25
|
| 51 |
+
|
| 52 |
+
Compiler mode is at least C++ 26.
|
| 53 |
+
|
| 54 |
+
.. include:: CMAKE_LANG_STD_FLAGS.txt
|
| 55 |
+
|
| 56 |
+
Low level individual compile features
|
| 57 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 58 |
+
|
| 59 |
+
For C++ 11 and C++ 14, compilers were sometimes slow to implement certain
|
| 60 |
+
language features. CMake provided some individual compile features to help
|
| 61 |
+
projects determine whether specific features were available. These individual
|
| 62 |
+
features are now less relevant and projects should generally prefer to use the
|
| 63 |
+
high level meta features instead. Individual compile features are not provided
|
| 64 |
+
for C++ 17 or later.
|
| 65 |
+
|
| 66 |
+
See the :manual:`cmake-compile-features(7)` manual for further discussion of
|
| 67 |
+
the use of individual compile features.
|
| 68 |
+
|
| 69 |
+
Individual features from C++ 98
|
| 70 |
+
"""""""""""""""""""""""""""""""
|
| 71 |
+
|
| 72 |
+
``cxx_template_template_parameters``
|
| 73 |
+
Template template parameters, as defined in ``ISO/IEC 14882:1998``.
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
Individual features from C++ 11
|
| 77 |
+
"""""""""""""""""""""""""""""""
|
| 78 |
+
|
| 79 |
+
``cxx_alias_templates``
|
| 80 |
+
Template aliases, as defined in N2258_.
|
| 81 |
+
|
| 82 |
+
.. _N2258: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2258.pdf
|
| 83 |
+
|
| 84 |
+
``cxx_alignas``
|
| 85 |
+
Alignment control ``alignas``, as defined in N2341_.
|
| 86 |
+
|
| 87 |
+
.. _N2341: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf
|
| 88 |
+
|
| 89 |
+
``cxx_alignof``
|
| 90 |
+
Alignment control ``alignof``, as defined in N2341_.
|
| 91 |
+
|
| 92 |
+
.. _N2341: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf
|
| 93 |
+
|
| 94 |
+
``cxx_attributes``
|
| 95 |
+
Generic attributes, as defined in N2761_.
|
| 96 |
+
|
| 97 |
+
.. _N2761: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2761.pdf
|
| 98 |
+
|
| 99 |
+
``cxx_auto_type``
|
| 100 |
+
Automatic type deduction, as defined in N1984_.
|
| 101 |
+
|
| 102 |
+
.. _N1984: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1984.pdf
|
| 103 |
+
|
| 104 |
+
``cxx_constexpr``
|
| 105 |
+
Constant expressions, as defined in N2235_.
|
| 106 |
+
|
| 107 |
+
.. _N2235: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
``cxx_decltype_incomplete_return_types``
|
| 111 |
+
Decltype on incomplete return types, as defined in N3276_.
|
| 112 |
+
|
| 113 |
+
.. _N3276 : https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3276.pdf
|
| 114 |
+
|
| 115 |
+
``cxx_decltype``
|
| 116 |
+
Decltype, as defined in N2343_.
|
| 117 |
+
|
| 118 |
+
.. _N2343: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2343.pdf
|
| 119 |
+
|
| 120 |
+
``cxx_default_function_template_args``
|
| 121 |
+
Default template arguments for function templates, as defined in DR226_
|
| 122 |
+
|
| 123 |
+
.. _DR226: https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#226
|
| 124 |
+
|
| 125 |
+
``cxx_defaulted_functions``
|
| 126 |
+
Defaulted functions, as defined in N2346_.
|
| 127 |
+
|
| 128 |
+
.. _N2346: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm
|
| 129 |
+
|
| 130 |
+
``cxx_defaulted_move_initializers``
|
| 131 |
+
Defaulted move initializers, as defined in N3053_.
|
| 132 |
+
|
| 133 |
+
.. _N3053: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3053.html
|
| 134 |
+
|
| 135 |
+
``cxx_delegating_constructors``
|
| 136 |
+
Delegating constructors, as defined in N1986_.
|
| 137 |
+
|
| 138 |
+
.. _N1986: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1986.pdf
|
| 139 |
+
|
| 140 |
+
``cxx_deleted_functions``
|
| 141 |
+
Deleted functions, as defined in N2346_.
|
| 142 |
+
|
| 143 |
+
.. _N2346: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm
|
| 144 |
+
|
| 145 |
+
``cxx_enum_forward_declarations``
|
| 146 |
+
Enum forward declarations, as defined in N2764_.
|
| 147 |
+
|
| 148 |
+
.. _N2764: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf
|
| 149 |
+
|
| 150 |
+
``cxx_explicit_conversions``
|
| 151 |
+
Explicit conversion operators, as defined in N2437_.
|
| 152 |
+
|
| 153 |
+
.. _N2437: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2437.pdf
|
| 154 |
+
|
| 155 |
+
``cxx_extended_friend_declarations``
|
| 156 |
+
Extended friend declarations, as defined in N1791_.
|
| 157 |
+
|
| 158 |
+
.. _N1791: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1791.pdf
|
| 159 |
+
|
| 160 |
+
``cxx_extern_templates``
|
| 161 |
+
Extern templates, as defined in N1987_.
|
| 162 |
+
|
| 163 |
+
.. _N1987: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1987.htm
|
| 164 |
+
|
| 165 |
+
``cxx_final``
|
| 166 |
+
Override control ``final`` keyword, as defined in N2928_, N3206_ and N3272_.
|
| 167 |
+
|
| 168 |
+
.. _N2928: https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2928.htm
|
| 169 |
+
.. _N3206: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3206.htm
|
| 170 |
+
.. _N3272: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3272.htm
|
| 171 |
+
|
| 172 |
+
``cxx_func_identifier``
|
| 173 |
+
Predefined ``__func__`` identifier, as defined in N2340_.
|
| 174 |
+
|
| 175 |
+
.. _N2340: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2340.htm
|
| 176 |
+
|
| 177 |
+
``cxx_generalized_initializers``
|
| 178 |
+
Initializer lists, as defined in N2672_.
|
| 179 |
+
|
| 180 |
+
.. _N2672: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2672.htm
|
| 181 |
+
|
| 182 |
+
``cxx_inheriting_constructors``
|
| 183 |
+
Inheriting constructors, as defined in N2540_.
|
| 184 |
+
|
| 185 |
+
.. _N2540: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2540.htm
|
| 186 |
+
|
| 187 |
+
``cxx_inline_namespaces``
|
| 188 |
+
Inline namespaces, as defined in N2535_.
|
| 189 |
+
|
| 190 |
+
.. _N2535: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2535.htm
|
| 191 |
+
|
| 192 |
+
``cxx_lambdas``
|
| 193 |
+
Lambda functions, as defined in N2927_.
|
| 194 |
+
|
| 195 |
+
.. _N2927: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2927.pdf
|
| 196 |
+
|
| 197 |
+
``cxx_local_type_template_args``
|
| 198 |
+
Local and unnamed types as template arguments, as defined in N2657_.
|
| 199 |
+
|
| 200 |
+
.. _N2657: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm
|
| 201 |
+
|
| 202 |
+
``cxx_long_long_type``
|
| 203 |
+
``long long`` type, as defined in N1811_.
|
| 204 |
+
|
| 205 |
+
.. _N1811: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1811.pdf
|
| 206 |
+
|
| 207 |
+
``cxx_noexcept``
|
| 208 |
+
Exception specifications, as defined in N3050_.
|
| 209 |
+
|
| 210 |
+
.. _N3050: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3050.html
|
| 211 |
+
|
| 212 |
+
``cxx_nonstatic_member_init``
|
| 213 |
+
Non-static data member initialization, as defined in N2756_.
|
| 214 |
+
|
| 215 |
+
.. _N2756: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2756.htm
|
| 216 |
+
|
| 217 |
+
``cxx_nullptr``
|
| 218 |
+
Null pointer, as defined in N2431_.
|
| 219 |
+
|
| 220 |
+
.. _N2431: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf
|
| 221 |
+
|
| 222 |
+
``cxx_override``
|
| 223 |
+
Override control ``override`` keyword, as defined in N2928_, N3206_
|
| 224 |
+
and N3272_.
|
| 225 |
+
|
| 226 |
+
.. _N2928: https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2928.htm
|
| 227 |
+
.. _N3206: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3206.htm
|
| 228 |
+
.. _N3272: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3272.htm
|
| 229 |
+
|
| 230 |
+
``cxx_range_for``
|
| 231 |
+
Range-based for, as defined in N2930_.
|
| 232 |
+
|
| 233 |
+
.. _N2930: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2930.html
|
| 234 |
+
|
| 235 |
+
``cxx_raw_string_literals``
|
| 236 |
+
Raw string literals, as defined in N2442_.
|
| 237 |
+
|
| 238 |
+
.. _N2442: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2442.htm
|
| 239 |
+
|
| 240 |
+
``cxx_reference_qualified_functions``
|
| 241 |
+
Reference qualified functions, as defined in N2439_.
|
| 242 |
+
|
| 243 |
+
.. _N2439: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2439.htm
|
| 244 |
+
|
| 245 |
+
``cxx_right_angle_brackets``
|
| 246 |
+
Right angle bracket parsing, as defined in N1757_.
|
| 247 |
+
|
| 248 |
+
.. _N1757: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html
|
| 249 |
+
|
| 250 |
+
``cxx_rvalue_references``
|
| 251 |
+
R-value references, as defined in N2118_.
|
| 252 |
+
|
| 253 |
+
.. _N2118: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2118.html
|
| 254 |
+
|
| 255 |
+
``cxx_sizeof_member``
|
| 256 |
+
Size of non-static data members, as defined in N2253_.
|
| 257 |
+
|
| 258 |
+
.. _N2253: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2253.html
|
| 259 |
+
|
| 260 |
+
``cxx_static_assert``
|
| 261 |
+
Static assert, as defined in N1720_.
|
| 262 |
+
|
| 263 |
+
.. _N1720: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html
|
| 264 |
+
|
| 265 |
+
``cxx_strong_enums``
|
| 266 |
+
Strongly typed enums, as defined in N2347_.
|
| 267 |
+
|
| 268 |
+
.. _N2347: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf
|
| 269 |
+
|
| 270 |
+
``cxx_thread_local``
|
| 271 |
+
Thread-local variables, as defined in N2659_.
|
| 272 |
+
|
| 273 |
+
.. _N2659: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2659.htm
|
| 274 |
+
|
| 275 |
+
``cxx_trailing_return_types``
|
| 276 |
+
Automatic function return type, as defined in N2541_.
|
| 277 |
+
|
| 278 |
+
.. _N2541: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2541.htm
|
| 279 |
+
|
| 280 |
+
``cxx_unicode_literals``
|
| 281 |
+
Unicode string literals, as defined in N2442_.
|
| 282 |
+
|
| 283 |
+
.. _N2442: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2442.htm
|
| 284 |
+
|
| 285 |
+
``cxx_uniform_initialization``
|
| 286 |
+
Uniform initialization, as defined in N2640_.
|
| 287 |
+
|
| 288 |
+
.. _N2640: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2640.pdf
|
| 289 |
+
|
| 290 |
+
``cxx_unrestricted_unions``
|
| 291 |
+
Unrestricted unions, as defined in N2544_.
|
| 292 |
+
|
| 293 |
+
.. _N2544: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2544.pdf
|
| 294 |
+
|
| 295 |
+
``cxx_user_literals``
|
| 296 |
+
User-defined literals, as defined in N2765_.
|
| 297 |
+
|
| 298 |
+
.. _N2765: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf
|
| 299 |
+
|
| 300 |
+
``cxx_variadic_macros``
|
| 301 |
+
Variadic macros, as defined in N1653_.
|
| 302 |
+
|
| 303 |
+
.. _N1653: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1653.htm
|
| 304 |
+
|
| 305 |
+
``cxx_variadic_templates``
|
| 306 |
+
Variadic templates, as defined in N2242_.
|
| 307 |
+
|
| 308 |
+
.. _N2242: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2242.pdf
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
Individual features from C++ 14
|
| 312 |
+
"""""""""""""""""""""""""""""""
|
| 313 |
+
|
| 314 |
+
``cxx_aggregate_default_initializers``
|
| 315 |
+
Aggregate default initializers, as defined in N3605_.
|
| 316 |
+
|
| 317 |
+
.. _N3605: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3605.html
|
| 318 |
+
|
| 319 |
+
``cxx_attribute_deprecated``
|
| 320 |
+
``[[deprecated]]`` attribute, as defined in N3760_.
|
| 321 |
+
|
| 322 |
+
.. _N3760: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3760.html
|
| 323 |
+
|
| 324 |
+
``cxx_binary_literals``
|
| 325 |
+
Binary literals, as defined in N3472_.
|
| 326 |
+
|
| 327 |
+
.. _N3472: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3472.pdf
|
| 328 |
+
|
| 329 |
+
``cxx_contextual_conversions``
|
| 330 |
+
Contextual conversions, as defined in N3323_.
|
| 331 |
+
|
| 332 |
+
.. _N3323: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3323.pdf
|
| 333 |
+
|
| 334 |
+
``cxx_decltype_auto``
|
| 335 |
+
``decltype(auto)`` semantics, as defined in N3638_.
|
| 336 |
+
|
| 337 |
+
.. _N3638: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3638.html
|
| 338 |
+
|
| 339 |
+
``cxx_digit_separators``
|
| 340 |
+
Digit separators, as defined in N3781_.
|
| 341 |
+
|
| 342 |
+
.. _N3781: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3781.pdf
|
| 343 |
+
|
| 344 |
+
``cxx_generic_lambdas``
|
| 345 |
+
Generic lambdas, as defined in N3649_.
|
| 346 |
+
|
| 347 |
+
.. _N3649: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3649.html
|
| 348 |
+
|
| 349 |
+
``cxx_lambda_init_captures``
|
| 350 |
+
Initialized lambda captures, as defined in N3648_.
|
| 351 |
+
|
| 352 |
+
.. _N3648: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3648.html
|
| 353 |
+
|
| 354 |
+
``cxx_relaxed_constexpr``
|
| 355 |
+
Relaxed constexpr, as defined in N3652_.
|
| 356 |
+
|
| 357 |
+
.. _N3652: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3652.html
|
| 358 |
+
|
| 359 |
+
``cxx_return_type_deduction``
|
| 360 |
+
Return type deduction on normal functions, as defined in N3386_.
|
| 361 |
+
|
| 362 |
+
.. _N3386: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3386.html
|
| 363 |
+
|
| 364 |
+
``cxx_variable_templates``
|
| 365 |
+
Variable templates, as defined in N3651_.
|
| 366 |
+
|
| 367 |
+
.. _N3651: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3651.pdf
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/CMAKE_C_KNOWN_FEATURES.rst.txt
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMAKE_C_KNOWN_FEATURES
|
| 2 |
+
----------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.1
|
| 5 |
+
|
| 6 |
+
List of C features known to this version of CMake.
|
| 7 |
+
|
| 8 |
+
The features listed in this global property may be known to be available to the
|
| 9 |
+
C compiler. If the feature is available with the C compiler, it will
|
| 10 |
+
be listed in the :variable:`CMAKE_C_COMPILE_FEATURES` variable.
|
| 11 |
+
|
| 12 |
+
The features listed here may be used with the :command:`target_compile_features`
|
| 13 |
+
command. See the :manual:`cmake-compile-features(7)` manual for information on
|
| 14 |
+
compile features and a list of supported compilers.
|
| 15 |
+
|
| 16 |
+
The features known to this version of CMake are listed below.
|
| 17 |
+
|
| 18 |
+
High level meta features indicating C standard support
|
| 19 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 20 |
+
|
| 21 |
+
.. versionadded:: 3.8
|
| 22 |
+
|
| 23 |
+
``c_std_90``
|
| 24 |
+
Compiler mode is at least C 90.
|
| 25 |
+
|
| 26 |
+
``c_std_99``
|
| 27 |
+
Compiler mode is at least C 99.
|
| 28 |
+
|
| 29 |
+
``c_std_11``
|
| 30 |
+
Compiler mode is at least C 11.
|
| 31 |
+
|
| 32 |
+
``c_std_17``
|
| 33 |
+
.. versionadded:: 3.21
|
| 34 |
+
|
| 35 |
+
Compiler mode is at least C 17.
|
| 36 |
+
|
| 37 |
+
``c_std_23``
|
| 38 |
+
.. versionadded:: 3.21
|
| 39 |
+
|
| 40 |
+
Compiler mode is at least C 23.
|
| 41 |
+
|
| 42 |
+
.. include:: CMAKE_LANG_STD_FLAGS.txt
|
| 43 |
+
|
| 44 |
+
Low level individual compile features
|
| 45 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 46 |
+
|
| 47 |
+
``c_function_prototypes``
|
| 48 |
+
Function prototypes, as defined in ``ISO/IEC 9899:1990``.
|
| 49 |
+
|
| 50 |
+
``c_restrict``
|
| 51 |
+
``restrict`` keyword, as defined in ``ISO/IEC 9899:1999``.
|
| 52 |
+
|
| 53 |
+
``c_static_assert``
|
| 54 |
+
Static assert, as defined in ``ISO/IEC 9899:2011``.
|
| 55 |
+
|
| 56 |
+
``c_variadic_macros``
|
| 57 |
+
Variadic macros, as defined in ``ISO/IEC 9899:1999``.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/CMAKE_ROLE.rst.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CMAKE_ROLE
|
| 2 |
+
----------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.14
|
| 5 |
+
|
| 6 |
+
Tells what mode the current running script is in. Could be one of several
|
| 7 |
+
values:
|
| 8 |
+
|
| 9 |
+
``PROJECT``
|
| 10 |
+
Running in project mode (processing a ``CMakeLists.txt`` file).
|
| 11 |
+
|
| 12 |
+
``SCRIPT``
|
| 13 |
+
Running in ``-P`` script mode.
|
| 14 |
+
|
| 15 |
+
``FIND_PACKAGE``
|
| 16 |
+
Running in ``--find-package`` mode.
|
| 17 |
+
|
| 18 |
+
``CTEST``
|
| 19 |
+
Running in CTest script mode.
|
| 20 |
+
|
| 21 |
+
``CPACK``
|
| 22 |
+
Running in CPack.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/DEBUG_CONFIGURATIONS.rst.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
DEBUG_CONFIGURATIONS
|
| 2 |
+
--------------------
|
| 3 |
+
|
| 4 |
+
Specify which configurations are for debugging.
|
| 5 |
+
|
| 6 |
+
The value must be a semi-colon separated list of configuration names.
|
| 7 |
+
Currently this property is used only by the :command:`target_link_libraries`
|
| 8 |
+
command. Additional uses may be defined in the future.
|
| 9 |
+
|
| 10 |
+
This property must be set at the top level of the project and before
|
| 11 |
+
the first :command:`target_link_libraries` command invocation. If any entry in
|
| 12 |
+
the list does not match a valid configuration for the project the
|
| 13 |
+
behavior is undefined.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/DISABLED_FEATURES.rst.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
DISABLED_FEATURES
|
| 2 |
+
-----------------
|
| 3 |
+
|
| 4 |
+
List of features which are disabled during the CMake run.
|
| 5 |
+
|
| 6 |
+
List of features which are disabled during the CMake run. By default
|
| 7 |
+
it contains the names of all packages which were not found. This is
|
| 8 |
+
determined using the ``<NAME>_FOUND`` variables. Packages which are
|
| 9 |
+
searched ``QUIET`` are not listed. A project can add its own features to
|
| 10 |
+
this list. This property is used by the macros in
|
| 11 |
+
``FeatureSummary.cmake``.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ECLIPSE_EXTRA_CPROJECT_CONTENTS.rst.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ECLIPSE_EXTRA_CPROJECT_CONTENTS
|
| 2 |
+
-------------------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.12
|
| 5 |
+
|
| 6 |
+
Additional contents to be inserted into the generated Eclipse cproject file.
|
| 7 |
+
|
| 8 |
+
The cproject file defines the CDT specific information. Some third party IDE's
|
| 9 |
+
are based on Eclipse with the addition of other information specific to that IDE.
|
| 10 |
+
Through this property, it is possible to add this additional contents to
|
| 11 |
+
the generated project.
|
| 12 |
+
It is expected to contain valid XML.
|
| 13 |
+
|
| 14 |
+
Also see the :prop_gbl:`ECLIPSE_EXTRA_NATURES` property.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ECLIPSE_EXTRA_NATURES.rst.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ECLIPSE_EXTRA_NATURES
|
| 2 |
+
---------------------
|
| 3 |
+
|
| 4 |
+
List of natures to add to the generated Eclipse project file.
|
| 5 |
+
|
| 6 |
+
Eclipse projects specify language plugins by using natures. This property
|
| 7 |
+
should be set to the unique identifier for a nature (which looks like a Java
|
| 8 |
+
package name).
|
| 9 |
+
|
| 10 |
+
Also see the :prop_gbl:`ECLIPSE_EXTRA_CPROJECT_CONTENTS` property.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ENABLED_FEATURES.rst.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ENABLED_FEATURES
|
| 2 |
+
----------------
|
| 3 |
+
|
| 4 |
+
List of features which are enabled during the CMake run.
|
| 5 |
+
|
| 6 |
+
List of features which are enabled during the CMake run. By default
|
| 7 |
+
it contains the names of all packages which were found. This is
|
| 8 |
+
determined using the ``<NAME>_FOUND`` variables. Packages which are
|
| 9 |
+
searched ``QUIET`` are not listed. A project can add its own features to
|
| 10 |
+
this list. This property is used by the macros in
|
| 11 |
+
``FeatureSummary.cmake``.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/ENABLED_LANGUAGES.rst.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ENABLED_LANGUAGES
|
| 2 |
+
-----------------
|
| 3 |
+
|
| 4 |
+
Read-only property that contains the list of currently enabled languages
|
| 5 |
+
|
| 6 |
+
Set to list of currently enabled languages.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/FIND_LIBRARY_USE_LIB32_PATHS.rst.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FIND_LIBRARY_USE_LIB32_PATHS
|
| 2 |
+
----------------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.7
|
| 5 |
+
|
| 6 |
+
Whether the :command:`find_library` command should automatically search
|
| 7 |
+
``lib32`` directories.
|
| 8 |
+
|
| 9 |
+
``FIND_LIBRARY_USE_LIB32_PATHS`` is a boolean specifying whether the
|
| 10 |
+
:command:`find_library` command should automatically search the ``lib32``
|
| 11 |
+
variant of directories called ``lib`` in the search path when building 32-bit
|
| 12 |
+
binaries.
|
| 13 |
+
|
| 14 |
+
See also the :variable:`CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX` variable.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS.rst.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FIND_LIBRARY_USE_LIB64_PATHS
|
| 2 |
+
----------------------------
|
| 3 |
+
|
| 4 |
+
Whether :command:`find_library` should automatically search lib64
|
| 5 |
+
directories.
|
| 6 |
+
|
| 7 |
+
FIND_LIBRARY_USE_LIB64_PATHS is a boolean specifying whether the
|
| 8 |
+
:command:`find_library` command should automatically search the lib64
|
| 9 |
+
variant of directories called lib in the search path when building
|
| 10 |
+
64-bit binaries.
|
| 11 |
+
|
| 12 |
+
See also the :variable:`CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX` variable.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/FIND_LIBRARY_USE_LIBX32_PATHS.rst.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FIND_LIBRARY_USE_LIBX32_PATHS
|
| 2 |
+
-----------------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.9
|
| 5 |
+
|
| 6 |
+
Whether the :command:`find_library` command should automatically search
|
| 7 |
+
``libx32`` directories.
|
| 8 |
+
|
| 9 |
+
``FIND_LIBRARY_USE_LIBX32_PATHS`` is a boolean specifying whether the
|
| 10 |
+
:command:`find_library` command should automatically search the ``libx32``
|
| 11 |
+
variant of directories called ``lib`` in the search path when building
|
| 12 |
+
x32-abi binaries.
|
| 13 |
+
|
| 14 |
+
See also the :variable:`CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX` variable.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING.rst.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FIND_LIBRARY_USE_OPENBSD_VERSIONING
|
| 2 |
+
-----------------------------------
|
| 3 |
+
|
| 4 |
+
Whether :command:`find_library` should find OpenBSD-style shared
|
| 5 |
+
libraries.
|
| 6 |
+
|
| 7 |
+
This property is a boolean specifying whether the
|
| 8 |
+
:command:`find_library` command should find shared libraries with
|
| 9 |
+
OpenBSD-style versioned extension: ".so.<major>.<minor>". The
|
| 10 |
+
property is set to true on OpenBSD and false on other platforms.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/GENERATOR_IS_MULTI_CONFIG.rst.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GENERATOR_IS_MULTI_CONFIG
|
| 2 |
+
-------------------------
|
| 3 |
+
|
| 4 |
+
.. versionadded:: 3.9
|
| 5 |
+
|
| 6 |
+
Read-only property that is true on multi-configuration generators.
|
| 7 |
+
|
| 8 |
+
True when using a multi-configuration generator such as:
|
| 9 |
+
|
| 10 |
+
* :generator:`Ninja Multi-Config`
|
| 11 |
+
* :ref:`Visual Studio Generators`
|
| 12 |
+
* :generator:`Xcode`
|
| 13 |
+
|
| 14 |
+
Multi-config generators use :variable:`CMAKE_CONFIGURATION_TYPES`
|
| 15 |
+
as the set of configurations and ignore :variable:`CMAKE_BUILD_TYPE`.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/GLOBAL_DEPENDS_DEBUG_MODE.rst.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GLOBAL_DEPENDS_DEBUG_MODE
|
| 2 |
+
-------------------------
|
| 3 |
+
|
| 4 |
+
Enable global target dependency graph debug mode.
|
| 5 |
+
|
| 6 |
+
CMake automatically analyzes the global inter-target dependency graph
|
| 7 |
+
at the beginning of native build system generation. This property
|
| 8 |
+
causes it to display details of its analysis to stderr.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/GLOBAL_DEPENDS_NO_CYCLES.rst.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GLOBAL_DEPENDS_NO_CYCLES
|
| 2 |
+
------------------------
|
| 3 |
+
|
| 4 |
+
Disallow global target dependency graph cycles.
|
| 5 |
+
|
| 6 |
+
CMake automatically analyzes the global inter-target dependency graph
|
| 7 |
+
at the beginning of native build system generation. It reports an
|
| 8 |
+
error if the dependency graph contains a cycle that does not consist
|
| 9 |
+
of all STATIC library targets. This property tells CMake to disallow
|
| 10 |
+
all cycles completely, even among static libraries.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/IN_TRY_COMPILE.rst.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
IN_TRY_COMPILE
|
| 2 |
+
--------------
|
| 3 |
+
|
| 4 |
+
Read-only property that is true during a try-compile configuration.
|
| 5 |
+
|
| 6 |
+
True when building a project inside a :command:`try_compile` or
|
| 7 |
+
:command:`try_run` command.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/JOB_POOLS.rst.txt
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
JOB_POOLS
|
| 2 |
+
---------
|
| 3 |
+
|
| 4 |
+
Ninja only: List of available pools.
|
| 5 |
+
|
| 6 |
+
A pool is a named integer property and defines the maximum number
|
| 7 |
+
of concurrent jobs which can be started by a rule assigned to the pool.
|
| 8 |
+
The ``JOB_POOLS`` property is a semicolon-separated list of
|
| 9 |
+
pairs using the syntax ``NAME=integer`` (without a space after the equality sign).
|
| 10 |
+
|
| 11 |
+
For instance:
|
| 12 |
+
|
| 13 |
+
.. code-block:: cmake
|
| 14 |
+
|
| 15 |
+
set_property(GLOBAL PROPERTY JOB_POOLS two_jobs=2 ten_jobs=10)
|
| 16 |
+
|
| 17 |
+
Defined pools could be used globally by setting
|
| 18 |
+
:variable:`CMAKE_JOB_POOL_COMPILE` and :variable:`CMAKE_JOB_POOL_LINK`
|
| 19 |
+
or per target by setting the target properties
|
| 20 |
+
:prop_tgt:`JOB_POOL_COMPILE` and :prop_tgt:`JOB_POOL_LINK`.
|
| 21 |
+
:command:`Custom commands <add_custom_command>` and
|
| 22 |
+
:command:`custom targets <add_custom_target>` can specify pools using the
|
| 23 |
+
option ``JOB_POOL``.
|
| 24 |
+
Using a pool that is not defined by ``JOB_POOLS`` causes
|
| 25 |
+
an error by ninja at build time.
|
| 26 |
+
|
| 27 |
+
If not set, this property uses the value of the :variable:`CMAKE_JOB_POOLS`
|
| 28 |
+
variable.
|
| 29 |
+
|
| 30 |
+
Build targets provided by CMake that are meant for individual interactive
|
| 31 |
+
use, such as ``install``, are placed in the ``console`` pool automatically.
|
toolchain/cmake-3.27.9-linux-x86_64/doc/cmake/html/_sources/prop_gbl/PACKAGES_FOUND.rst.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PACKAGES_FOUND
|
| 2 |
+
--------------
|
| 3 |
+
|
| 4 |
+
List of packages which were found during the CMake run.
|
| 5 |
+
|
| 6 |
+
List of packages which were found during the CMake run. Whether a
|
| 7 |
+
package has been found is determined using the <NAME>_FOUND variables.
|