summaryrefslogtreecommitdiffstats
path: root/Help/command/add_library.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Help/command/add_library.rst')
-rw-r--r--Help/command/add_library.rst70
1 files changed, 46 insertions, 24 deletions
diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst
index b7dfabc..d3fbdcf 100644
--- a/Help/command/add_library.rst
+++ b/Help/command/add_library.rst
@@ -17,13 +17,21 @@ Normal Libraries
[<source>...])
Adds a library target called ``<name>`` to be built from the source files
-listed in the command invocation. (The source files can be omitted here
-if they are added later using :command:`target_sources`.) The ``<name>``
+listed in the command invocation. The ``<name>``
corresponds to the logical target name and must be globally unique within
a project. The actual file name of the library built is constructed based
on conventions of the native platform (such as ``lib<name>.a`` or
``<name>.lib``).
+.. versionadded:: 3.1
+ Source arguments to ``add_library`` may use "generator expressions" with
+ the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
+ manual for available expressions.
+
+.. versionadded:: 3.11
+ The source files can be omitted if they are added later using
+ :command:`target_sources`.
+
``STATIC``, ``SHARED``, or ``MODULE`` may be given to specify the type of
library to be created. ``STATIC`` libraries are archives of object files
for use when linking other targets. ``SHARED`` libraries are linked
@@ -34,9 +42,13 @@ type is ``STATIC`` or ``SHARED`` based on whether the current value of the
variable :variable:`BUILD_SHARED_LIBS` is ``ON``. For ``SHARED`` and
``MODULE`` libraries the :prop_tgt:`POSITION_INDEPENDENT_CODE` target
property is set to ``ON`` automatically.
-A ``SHARED`` or ``STATIC`` library may be marked with the :prop_tgt:`FRAMEWORK`
+A ``SHARED`` library may be marked with the :prop_tgt:`FRAMEWORK`
target property to create an macOS Framework.
+.. versionadded:: 3.8
+ A ``STATIC`` library may be marked with the :prop_tgt:`FRAMEWORK`
+ target property to create a static Framework.
+
If a library does not export any symbols, it must not be declared as a
``SHARED`` library. For example, a Windows resource DLL or a managed C++/CLI
DLL that exports no unmanaged symbols would need to be a ``MODULE`` library.
@@ -55,10 +67,8 @@ If ``EXCLUDE_FROM_ALL`` is given the corresponding property will be set on
the created target. See documentation of the :prop_tgt:`EXCLUDE_FROM_ALL`
target property for details.
-Source arguments to ``add_library`` may use "generator expressions" with
-the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
-manual for available expressions. See the :manual:`cmake-buildsystem(7)`
-manual for more on defining buildsystem properties.
+See the :manual:`cmake-buildsystem(7)` manual for more on defining
+buildsystem properties.
See also :prop_sf:`HEADER_FILE_ONLY` on what to do if some sources are
pre-processed, and you want to have the original sources reachable from
@@ -93,6 +103,9 @@ systems (such as Xcode) may not like targets that have only object files, so
consider adding at least one real source file to any target that references
``$<TARGET_OBJECTS:objlib>``.
+.. versionadded:: 3.12
+ Object libraries can be linked to with :command:`target_link_libraries`.
+
Interface Libraries
^^^^^^^^^^^^^^^^^^^
@@ -121,23 +134,28 @@ like any other target.
An interface library created with the above signature has no source files
itself and is not included as a target in the generated buildsystem.
-Since CMake 3.19, an interface library target may be created with
-source files:
+.. versionadded:: 3.15
+ An interface library can have :prop_tgt:`PUBLIC_HEADER` and
+ :prop_tgt:`PRIVATE_HEADER` properties. The headers specified by those
+ properties can be installed using the :command:`install(TARGETS)` command.
-.. code-block:: cmake
+.. versionadded:: 3.19
+ An interface library target may be created with source files:
+
+ .. code-block:: cmake
- add_library(<name> INTERFACE [<source>...] [EXCLUDE_FROM_ALL])
+ add_library(<name> INTERFACE [<source>...] [EXCLUDE_FROM_ALL])
-Source files may be listed directly in the ``add_library`` call or added
-later by calls to :command:`target_sources` with the ``PRIVATE`` or
-``PUBLIC`` keywords.
+ Source files may be listed directly in the ``add_library`` call or added
+ later by calls to :command:`target_sources` with the ``PRIVATE`` or
+ ``PUBLIC`` keywords.
-If an interface library has source files (i.e. the :prop_tgt:`SOURCES`
-target property is set), it will appear in the generated buildsystem
-as a build target much like a target defined by the
-:command:`add_custom_target` command. It does not compile any sources,
-but does contain build rules for custom commands created by the
-:command:`add_custom_command` command.
+ If an interface library has source files (i.e. the :prop_tgt:`SOURCES`
+ target property is set), it will appear in the generated buildsystem
+ as a build target much like a target defined by the
+ :command:`add_custom_target` command. It does not compile any sources,
+ but does contain build rules for custom commands created by the
+ :command:`add_custom_command` command.
.. note::
In most command signatures where the ``INTERFACE`` keyword appears,
@@ -211,10 +229,14 @@ used to refer to ``<target>`` in subsequent commands. The ``<name>`` does
not appear in the generated buildsystem as a make target. The ``<target>``
may not be an ``ALIAS``.
-An ``ALIAS`` to a non-``GLOBAL`` :ref:`Imported Target <Imported Targets>`
-has scope in the directory in which the alias is created and below.
-The :prop_tgt:`ALIAS_GLOBAL` target property can be used to check if the
-alias is global or not.
+.. versionadded:: 3.11
+ An ``ALIAS`` can target a ``GLOBAL`` :ref:`Imported Target <Imported Targets>`
+
+.. versionadded:: 3.18
+ An ``ALIAS`` can target a non-``GLOBAL`` Imported Target. Such alias is
+ scoped to the directory in which it is created and below.
+ The :prop_tgt:`ALIAS_GLOBAL` target property can be used to check if the
+ alias is global or not.
``ALIAS`` targets can be used as linkable targets and as targets to
read properties from. They can also be tested for existence with the