From b61faf895e889f9f22103f15fdbd9c85f006b634 Mon Sep 17 00:00:00 2001
From: Chuck Atkins <chuck.atkins@kitware.com>
Date: Wed, 28 Jun 2017 10:33:02 -0400
Subject: [PATCH] Fix install rules and usage requirements for interface+object
 libs

---
 CMakeLists.txt | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c877c909..001db5e9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,14 +28,13 @@
 #                            requirements.
 #                        ${KWSYS_NAMESPACE}_objects
 #                          - An OBJECT library for the built kwsys objects.
+#                            Note: This is omitted from the install rules
 #                        ${KWSYS_NAMESPACE}_private
 #                          - An INTERFACE library combining both that is
 #                            appropriate for use with PRIVATE linking in
 #                            target_link_libraries. Because of how interface
 #                            properties propagate, this target is not suitable
 #                            for use with PUBLIC or INTERFACE linking.
-#                      Note: only the ${KWSYS_NAMESPACE} library will be
-#                      installed
 #
 #    Example:
 #
@@ -819,6 +818,7 @@ IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
     SET(KWSYS_TARGET_INTERFACE ${KWSYS_NAMESPACE})
     SET(KWSYS_TARGET_OBJECT ${KWSYS_NAMESPACE}_objects)
     SET(KWSYS_TARGET_LINK ${KWSYS_NAMESPACE}_private)
+    SET(KWSYS_TARGET_INSTALL ${KWSYS_TARGET_INTERFACE} ${KWSYS_TARGET_LINK})
     SET(KWSYS_LINK_DEPENDENCY INTERFACE)
     ADD_LIBRARY(${KWSYS_TARGET_OBJECT} OBJECT
       ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS})
@@ -836,6 +836,7 @@ IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
     SET(KWSYS_TARGET_INTERFACE ${KWSYS_NAMESPACE})
     SET(KWSYS_TARGET_OBJECT ${KWSYS_NAMESPACE})
     SET(KWSYS_TARGET_LINK ${KWSYS_NAMESPACE})
+    set(KWSYS_TARGET_INSTALL ${KWSYS_TARGET_LINK})
     SET(KWSYS_LINK_DEPENDENCY PUBLIC)
     ADD_LIBRARY(${KWSYS_TARGET_INTERFACE} ${KWSYS_LIBRARY_TYPE}
       ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS})
@@ -887,12 +888,16 @@ IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
   # Set up include usage requirement
   IF(COMMAND TARGET_INCLUDE_DIRECTORIES)
     TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_INTERFACE} INTERFACE
-      ${CMAKE_CURRENT_BINARY_DIR})
+      $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
+    IF(KWSYS_INSTALL_INCLUDE_DIR)
+      TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_INTERFACE} INTERFACE
+        $<INSTALL_INTERFACE:${KWSYS_INSTALL_INCLUDE_DIR}>)
+    ENDIF()
   ENDIF()
 
   # Create an install target for the library.
   IF(KWSYS_INSTALL_LIBRARY_RULE)
-    INSTALL(TARGETS ${KWSYS_TARGET_INTERFACE} ${KWSYS_INSTALL_LIBRARY_RULE})
+    INSTALL(TARGETS ${KWSYS_TARGET_INSTALL} ${KWSYS_INSTALL_LIBRARY_RULE})
   ENDIF()
 ENDIF()
 
@@ -902,6 +907,8 @@ IF(KWSYS_ENABLE_C AND KWSYS_C_SRCS)
     SET(KWSYS_TARGET_C_INTERFACE ${KWSYS_NAMESPACE}_c)
     SET(KWSYS_TARGET_C_OBJECT ${KWSYS_NAMESPACE}_c_objects)
     SET(KWSYS_TARGET_C_LINK ${KWSYS_NAMESPACE}_c_private)
+    SET(KWSYS_TARGET_C_INSTALL
+      ${KWSYS_TARGET_C_INTERFACE} ${KWSYS_TARGET_C_LINK})
     SET(KWSYS_LINK_DEPENDENCY INTERFACE)
     ADD_LIBRARY(${KWSYS_TARGET_C_OBJECT} OBJECT ${KWSYS_C_SRCS})
     IF(KWSYS_BUILD_SHARED)
@@ -918,6 +925,7 @@ IF(KWSYS_ENABLE_C AND KWSYS_C_SRCS)
     SET(KWSYS_TARGET_C_INTERFACE ${KWSYS_NAMESPACE}_c)
     SET(KWSYS_TARGET_C_OBJECT ${KWSYS_NAMESPACE}_c)
     SET(KWSYS_TARGET_C_LINK ${KWSYS_NAMESPACE}_c)
+    SET(KWSYS_TARGET_C_INSTALL ${KWSYS_TARGET_C_LINK})
     SET(KWSYS_LINK_DEPENDENCY PUBLIC)
     ADD_LIBRARY(${KWSYS_TARGET_C_INTERFACE} ${KWSYS_LIBRARY_TYPE}
       ${KWSYS_C_SRCS})
@@ -931,10 +939,20 @@ IF(KWSYS_ENABLE_C AND KWSYS_C_SRCS)
       ${KWSYS_PROPERTIES_C})
   ENDIF()
 
+  # Set up include usage requirement
+  IF(COMMAND TARGET_INCLUDE_DIRECTORIES)
+    TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_C_INTERFACE} INTERFACE
+      $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
+    IF(KWSYS_INSTALL_INCLUDE_DIR)
+      TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_C_INTERFACE} INTERFACE
+        $<INSTALL_INTERFACE:${KWSYS_INSTALL_INCLUDE_DIR}>)
+    ENDIF()
+  ENDIF()
+
   # Create an install target for the library.
   IF(KWSYS_INSTALL_LIBRARY_RULE)
-    INSTALL(TARGETS ${KWSYS_TARGET_C_INTERFACE} ${KWSYS_INSTALL_LIBRARY_RULE})
-   ENDIF()
+    INSTALL(TARGETS ${KWSYS_TARGET_C_INSTALL})
+  ENDIF()
 ENDIF()
 
 # For building kwsys itself, we use a macro defined on the command
-- 
GitLab