I have attached a patch to add imported targets to FindBoost, in the form
of Boost::<component> (e.g. Boost::date_time) or Boost::Boost as a generic
interface library for header-only components.

If this type of patch is acceptable, I would like to do this for a number
of other modules for which I would like to be able to use so I export
generic configurations for my own libraries, including XercesC, PNG, TIFF
and a few others.  If that's OK, I'll follow up with patches for these
modules.


Regards,
Roger Leigh
>From 2fd86f82b12569c990dd2befbfb82d3d8103d374 Mon Sep 17 00:00:00 2001
From: Roger Leigh <rle...@dundee.ac.uk>
Date: Mon, 16 Nov 2015 13:21:33 +0000
Subject: [PATCH] FindBoost: Add imported targets

---
 Modules/FindBoost.cmake | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake
index 33e6a49..b5f5e22 100644
--- a/Modules/FindBoost.cmake
+++ b/Modules/FindBoost.cmake
@@ -34,6 +34,11 @@
 #                            information about Boost's automatic linking
 #                            displayed during compilation
 #
+# The following :prop_tgt:`IMPORTED` targets are also defined::
+#
+#   Boost::Boost           - Target for header-only dependencies
+#   Boost::<C>             - Library target for specific component dependency
+#
 # This module reads hints about search locations from variables::
 #
 #   BOOST_ROOT             - Preferred installation prefix
@@ -142,6 +147,14 @@
 #     add_executable(foo foo.cc)
 #   endif()
 #
+# Example to find Boost libraries and use imported targets::
+#
+#   find_package(Boost 1.56 REQUIRED COMPONENTS
+#                date_time filesystem system iostreams)
+#   add_executable(foo foo.cc)
+#   target_link_libraries(foo Boost::date_time Boost::filesystem
+#                             Boost::system Boost::iostreams)
+#
 # Example to find Boost headers and some *static* libraries::
 #
 #   set(Boost_USE_STATIC_LIBS        ON) # only find static libs
@@ -1222,6 +1235,51 @@ else()
 endif()
 
 # ------------------------------------------------------------------------
+#  Add imported targets
+# ------------------------------------------------------------------------
+
+if(Boost_FOUND)
+  # For header-only libraries
+  if(NOT TARGET Boost::Boost)
+    add_library(Boost::Boost INTERFACE IMPORTED)
+    if(Boost_INCLUDE_DIRS)
+      set_target_properties(Boost::Boost PROPERTIES
+        INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}")
+    endif()
+  endif()
+
+  foreach(COMPONENT ${Boost_FIND_COMPONENTS})
+    string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+    if(Boost_${UPPERCOMPONENT}_FOUND)
+      add_library(Boost::${COMPONENT} UNKNOWN IMPORTED)
+      if(Boost_INCLUDE_DIRS)
+        set_target_properties(Boost PROPERTIES
+          INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}")
+      endif()
+      if(EXISTS "${Boost_${UPPERCOMPONENT}_LIBRARY}")
+        set_target_properties(Boost::${COMPONENT} PROPERTIES
+          IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
+          IMPORTED_LOCATION "${Boost_${UPPERCOMPONENT}_LIBRARY}")
+      endif()
+      if(EXISTS "${Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG}")
+        set_property(TARGET Boost::${COMPONENT} APPEND PROPERTY
+          IMPORTED_CONFIGURATIONS DEBUG)
+        set_target_properties(Boost::${COMPONENT} PROPERTIES
+          IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
+          IMPORTED_LOCATION_DEBUG "${Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG}")
+      endif()
+      if(EXISTS "${Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE}")
+        set_property(TARGET Boost::${COMPONENT} APPEND PROPERTY
+          IMPORTED_CONFIGURATIONS RELEASE)
+        set_target_properties(Boost::${COMPONENT} PROPERTIES
+          IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
+          IMPORTED_LOCATION_RELEASE "${Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE}")
+      endif()
+    endif()
+  endforeach()
+endif()
+
+# ------------------------------------------------------------------------
 #  Notification to end user about what was found
 # ------------------------------------------------------------------------
 
-- 
2.1.4
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to