Преглед изворни кода

INTERFACE Target: allow (PUBLIC/PRIVATE)_HEADER properties

Also support installing headers on an INTERFACE library.

Signed-off-by: Avraham Shukron <[email protected]>
Fixes: #15234
Avraham Shukron пре 6 година
родитељ
комит
a40f9083dd

+ 11 - 6
Help/command/add_library.rst

@@ -80,12 +80,17 @@ option extends visibility.  It may be referenced like any target built
 within the project.  ``IMPORTED`` libraries are useful for convenient
 reference from commands like :command:`target_link_libraries`.  Details
 about the imported library are specified by setting properties whose names
-begin in ``IMPORTED_`` and ``INTERFACE_``.  The most important such
-property is :prop_tgt:`IMPORTED_LOCATION` (and its per-configuration
-variant :prop_tgt:`IMPORTED_LOCATION_<CONFIG>`) which specifies the
-location of the main library file on disk.  Or, for object libraries,
-:prop_tgt:`IMPORTED_OBJECTS` (and :prop_tgt:`IMPORTED_OBJECTS_<CONFIG>`)
-specifies the locations of object files on disk.
+begin in ``IMPORTED_`` and ``INTERFACE_``.
+
+The most important properties are:
+
+* :prop_tgt:`IMPORTED_LOCATION` (and its per-configuration
+  variant :prop_tgt:`IMPORTED_LOCATION_<CONFIG>`) which specifies the
+  location of the main library file on disk.
+* :prop_tgt:`IMPORTED_OBJECTS` (and :prop_tgt:`IMPORTED_OBJECTS_<CONFIG>`)
+  for object libraries, specifies the locations of object files on disk.
+* :prop_tgt:`PUBLIC_HEADER` files to be installed during :command:`install` invocation
+
 See documentation of the ``IMPORTED_*`` and ``INTERFACE_*`` properties
 for more information.
 

+ 3 - 3
Help/command/install.rst

@@ -148,13 +148,13 @@ project.  There are several kinds of target files that may be installed:
   property are treated as ``FRAMEWORK`` targets on macOS.
 
 ``BUNDLE``
-  Executables marked with the ``MACOSX_BUNDLE`` property are treated as
+  Executables marked with the :prop_tgt:`MACOSX_BUNDLE` property are treated as
   ``BUNDLE`` targets on macOS.
 
 ``PUBLIC_HEADER``
-  Any ``PUBLIC_HEADER`` files associated with a library are installed in
+  Any :prop_tgt:`PUBLIC_HEADER` files associated with a library are installed in
   the destination specified by the ``PUBLIC_HEADER`` argument on non-Apple
-  platforms. Rules defined by this argument are ignored for ``FRAMEWORK``
+  platforms. Rules defined by this argument are ignored for :prop_tgt:`FRAMEWORK`
   libraries on Apple platforms because the associated files are installed
   into the appropriate locations inside the framework folder. See
   :prop_tgt:`PUBLIC_HEADER` for details.

+ 7 - 0
Help/release/dev/iface-headers.rst

@@ -0,0 +1,7 @@
+iface-headers
+-------------
+
+* ``INTERFACE`` library can now have :prop_tgt:`PUBLIC_HEADER` and
+  :prop_tgt:`PRIVATE_HEADER` properties set. The headers specified by those
+  properties can be installed using the :command:`install(TARGETS)` command by
+  passing the ``PUBLIC_HEADER`` and ``PRIVATE_HEADER`` arguments respectively.

+ 1 - 2
Source/cmInstallCommand.cxx

@@ -663,8 +663,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
     // generators for them.
     bool createInstallGeneratorsForTargetFileSets = true;
 
-    if (target.IsFrameworkOnApple() ||
-        target.GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+    if (target.IsFrameworkOnApple()) {
       createInstallGeneratorsForTargetFileSets = false;
     }
 

+ 2 - 0
Source/cmTargetPropertyComputer.cxx

@@ -67,6 +67,8 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
     builtIns.insert("IMPORTED_GLOBAL");
     builtIns.insert("MANUALLY_ADDED_DEPENDENCIES");
     builtIns.insert("NAME");
+    builtIns.insert("PRIVATE_HEADER");
+    builtIns.insert("PUBLIC_HEADER");
     builtIns.insert("TYPE");
   }
 

+ 6 - 0
Tests/RunCMake/install/TARGETS-Defaults-all-check.cmake

@@ -4,6 +4,8 @@ if(WIN32)
     [[bin/exe\.exe]]
     [[bin/(lib)?lib1\.dll]]
     [[include]]
+    [[include/obj1\.h]]
+    [[include/obj2\.h]]
     [[include/obj4\.h]]
     [[include/obj5\.h]]
     [[lib]]
@@ -20,6 +22,8 @@ elseif(CYGWIN)
     [[bin/cyglib1\.dll]]
     [[bin/exe\.exe]]
     [[include]]
+    [[include/obj1\.h]]
+    [[include/obj2\.h]]
     [[include/obj4\.h]]
     [[include/obj5\.h]]
     [[lib]]
@@ -35,6 +39,8 @@ else()
     [[bin]]
     [[bin/exe]]
     [[include]]
+    [[include/obj1\.h]]
+    [[include/obj2\.h]]
     [[include/obj4\.h]]
     [[include/obj5\.h]]
     [[lib]]

+ 8 - 0
Tests/RunCMake/install/TARGETS-Defaults.cmake

@@ -8,6 +8,11 @@ set_property(TARGET lib3 PROPERTY PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/obj
 add_library(lib4 SHARED obj5.c)
 set_property(TARGET lib4 PROPERTY PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/obj5.h)
 
+add_library(iface INTERFACE)
+set_target_properties(iface PROPERTIES
+  PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/obj1.h
+  PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/obj2.h)
+
 install(TARGETS exe lib1 lib2)
 install(TARGETS lib3
   LIBRARY DESTINATION lib3
@@ -17,3 +22,6 @@ install(TARGETS lib4
   LIBRARY DESTINATION lib4
   RUNTIME DESTINATION lib4
   )
+install(TARGETS iface
+  PUBLIC_HEADER DESTINATION include
+  PRIVATE_HEADER DESTINATION include)

+ 6 - 0
Tests/RunCMake/install/obj2.h

@@ -0,0 +1,6 @@
+#ifndef OBJ2_H
+#define OBJ2_H
+
+int obj2(void);
+
+#endif /* OBJ2_H */

+ 9 - 0
Tests/RunCMake/interface_library/whitelist.cmake

@@ -14,3 +14,12 @@ get_target_property(outname iface "_custom_property")
 set_property(TARGET iface PROPERTY "custom_property" output)
 set_property(TARGET iface APPEND PROPERTY "custom_property" append)
 get_target_property(outname iface "custom_property")
+
+# PUBLIC_HEADER / PRIVATE_HEADER properties are allowed
+set_property(TARGET iface PROPERTY PUBLIC_HEADER foo.h)
+set_property(TARGET iface APPEND PROPERTY PUBLIC_HEADER bar.h)
+get_target_property(outname iface PUBLIC_HEADER)
+
+set_property(TARGET iface PROPERTY PRIVATE_HEADER foo.h)
+set_property(TARGET iface APPEND PROPERTY PRIVATE_HEADER bar.h)
+get_target_property(outname iface PRIVATE_HEADER)