summaryrefslogtreecommitdiffstats
path: root/Help/manual/cmake-buildsystem.7.rst
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-03-01 14:25:45 (GMT)
committerBrad King <brad.king@kitware.com>2018-03-01 14:27:50 (GMT)
commitbafe655b11c876b45a5ce1fbaf4643593bdd22a3 (patch)
treefe91cba040f960f97d85c36e8e5635e8bdeb31d9 /Help/manual/cmake-buildsystem.7.rst
parent57538224d06225ce039f9c883465c6743186c2f4 (diff)
downloadCMake-bafe655b11c876b45a5ce1fbaf4643593bdd22a3.zip
CMake-bafe655b11c876b45a5ce1fbaf4643593bdd22a3.tar.gz
CMake-bafe655b11c876b45a5ce1fbaf4643593bdd22a3.tar.bz2
Help: Document linking behavior of OBJECT libraries
Inspired-by: Deniz Bahadir <dbahadir@benocs.com> Issue: #14778
Diffstat (limited to 'Help/manual/cmake-buildsystem.7.rst')
-rw-r--r--Help/manual/cmake-buildsystem.7.rst41
1 files changed, 25 insertions, 16 deletions
diff --git a/Help/manual/cmake-buildsystem.7.rst b/Help/manual/cmake-buildsystem.7.rst
index ae538ed..3516d48 100644
--- a/Help/manual/cmake-buildsystem.7.rst
+++ b/Help/manual/cmake-buildsystem.7.rst
@@ -113,9 +113,9 @@ and it uniquely identifies the bundle.
Object Libraries
^^^^^^^^^^^^^^^^
-The ``OBJECT`` library type is also not linked to. It defines a non-archival
-collection of object files resulting from compiling the given source files.
-The object files collection can be used as source inputs to other targets:
+The ``OBJECT`` library type defines a non-archival collection of object files
+resulting from compiling the given source files. The object files collection
+may be used as source inputs to other targets:
.. code-block:: cmake
@@ -125,22 +125,31 @@ The object files collection can be used as source inputs to other targets:
add_executable(test_exe $<TARGET_OBJECTS:archive> test.cpp)
-``OBJECT`` libraries may not be used in the right hand side of
-:command:`target_link_libraries`. They also may not be used as the ``TARGET``
-in a use of the :command:`add_custom_command(TARGET)` command signature. They
-may be installed, and will be exported as an INTERFACE library.
+The link (or archiving) step of those other targets will use the object
+files collection in addition to those from their own sources.
-Although object libraries may not be named directly in calls to
-the :command:`target_link_libraries` command, they can be "linked"
-indirectly by using an :ref:`Interface Library <Interface Libraries>`
-whose :prop_tgt:`INTERFACE_SOURCES` target property is set to name
-``$<TARGET_OBJECTS:objlib>``.
+Alternatively, object libraries may be linked into other targets:
-Although object libraries may not be used as the ``TARGET``
-in a use of the :command:`add_custom_command(TARGET)` command signature,
-the list of objects can be used by :command:`add_custom_command(OUTPUT)` or
-:command:`file(GENERATE)` by using ``$<TARGET_OBJECTS:objlib>``.
+.. code-block:: cmake
+
+ add_library(archive OBJECT archive.cpp zip.cpp lzma.cpp)
+
+ add_library(archiveExtras STATIC extras.cpp)
+ target_link_libraries(archiveExtras PUBLIC archive)
+
+ add_executable(test_exe test.cpp)
+ target_link_libraries(test_exe archive)
+
+The link (or archiving) step of those other targets will use the object
+files from object libraries that are *directly* linked. Additionally,
+usage requirements of the object libraries will be honored when compiling
+sources in those other targets. Furthermore, those usage requirements
+will propagate transitively to dependents of those other targets.
+Object libraries may not be used as the ``TARGET`` in a use of the
+:command:`add_custom_command(TARGET)` command signature. However,
+the list of objects can be used by :command:`add_custom_command(OUTPUT)`
+or :command:`file(GENERATE)` by using ``$<TARGET_OBJECTS:objlib>``.
Build Specification and Usage Requirements
==========================================