summaryrefslogtreecommitdiffstats
path: root/Help
diff options
context:
space:
mode:
Diffstat (limited to 'Help')
-rw-r--r--Help/command/add_library.rst31
-rw-r--r--Help/manual/cmake-buildsystem.7.rst29
-rw-r--r--Help/prop_tgt/EXPORT_PROPERTIES.rst8
-rw-r--r--Help/release/dev/build-interface-targets.rst6
4 files changed, 64 insertions, 10 deletions
diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst
index ed8447e..f7e6792 100644
--- a/Help/command/add_library.rst
+++ b/Help/command/add_library.rst
@@ -118,8 +118,35 @@ target using the commands:
and then it is used as an argument to :command:`target_link_libraries`
like any other target.
-An interface library has no source files itself and is not included
-as a target in the generated buildsystem.
+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:
+
+.. code-block:: cmake
+
+ 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.
+
+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,
+ the items listed after it only become part of that target's usage
+ requirements and are not part of the target's own settings. However,
+ in this signature of ``add_library``, the ``INTERFACE`` keyword refers
+ to the library type only. Sources listed after it in the ``add_library``
+ call are ``PRIVATE`` to the interface library and do not appear in its
+ :prop_tgt:`INTERFACE_SOURCES` target property.
Imported Libraries
^^^^^^^^^^^^^^^^^^
diff --git a/Help/manual/cmake-buildsystem.7.rst b/Help/manual/cmake-buildsystem.7.rst
index 6eea191..cd27316 100644
--- a/Help/manual/cmake-buildsystem.7.rst
+++ b/Help/manual/cmake-buildsystem.7.rst
@@ -922,8 +922,8 @@ property from it:
Interface Libraries
-------------------
-An ``INTERFACE`` target has no :prop_tgt:`LOCATION` and is mutable, but is
-otherwise similar to an :prop_tgt:`IMPORTED` target.
+An ``INTERFACE`` library target does not compile sources and does not
+produce a library artifact on disk, so it has no :prop_tgt:`LOCATION`.
It may specify usage requirements such as
:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`,
@@ -937,11 +937,22 @@ Only the ``INTERFACE`` modes of the :command:`target_include_directories`,
:command:`target_sources`, and :command:`target_link_libraries` commands
may be used with ``INTERFACE`` libraries.
+Since CMake 3.19, an ``INTERFACE`` library target may optionally contain
+source files. An interface library that contains source files will be
+included as a build target in the generated buildsystem. It does not
+compile sources, but may contain custom commands to generate other sources.
+Additionally, IDEs will show the source files as part of the target for
+interactive reading and editing.
+
A primary use-case for ``INTERFACE`` libraries is header-only libraries.
.. code-block:: cmake
- add_library(Eigen INTERFACE)
+ add_library(Eigen INTERFACE
+ src/eigen.h
+ src/vector.h
+ src/matrix.h
+ )
target_include_directories(Eigen INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include/Eigen>
@@ -980,7 +991,12 @@ to must be installed separately:
.. code-block:: cmake
- add_library(Eigen INTERFACE)
+ set(Eigen_headers
+ src/eigen.h
+ src/vector.h
+ src/matrix.h
+ )
+ add_library(Eigen INTERFACE ${Eigen_headers})
target_include_directories(Eigen INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include/Eigen>
@@ -990,9 +1006,6 @@ to must be installed separately:
install(EXPORT eigenExport NAMESPACE Upstream::
DESTINATION lib/cmake/Eigen
)
- install(FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/src/eigen.h
- ${CMAKE_CURRENT_SOURCE_DIR}/src/vector.h
- ${CMAKE_CURRENT_SOURCE_DIR}/src/matrix.h
+ install(FILES ${Eigen_headers}
DESTINATION include/Eigen
)
diff --git a/Help/prop_tgt/EXPORT_PROPERTIES.rst b/Help/prop_tgt/EXPORT_PROPERTIES.rst
index 34c054f..2d54f8b 100644
--- a/Help/prop_tgt/EXPORT_PROPERTIES.rst
+++ b/Help/prop_tgt/EXPORT_PROPERTIES.rst
@@ -14,3 +14,11 @@ Properties starting with ``INTERFACE_`` or ``IMPORTED_`` are not allowed as
they are reserved for internal CMake use.
Properties containing generator expressions are also not allowed.
+
+.. note::
+
+ Since CMake 3.19, :ref:`Interface Libraries` may have arbitrary
+ target properties. If a project exports an interface library
+ with custom properties, the resulting package may not work with
+ dependents configured by older versions of CMake that reject the
+ custom properties.
diff --git a/Help/release/dev/build-interface-targets.rst b/Help/release/dev/build-interface-targets.rst
new file mode 100644
index 0000000..37bded4
--- /dev/null
+++ b/Help/release/dev/build-interface-targets.rst
@@ -0,0 +1,6 @@
+build-interface-targets
+-----------------------
+
+* :ref:`Interface Libraries` may now have source files added via
+ :command:`add_library` or :command:`target_sources`. Those
+ with sources will be generated as part of the build system.