[cmake-developers] Imported Locations in FindBoost.cmake

Andreas Weis der_ghulbus at ghulbus-inc.de
Sun Jun 19 07:00:07 EDT 2016


Hi there,

I ran into a small issue with the new imported target interface of
FindBoost.cmake.

Just like the old variable-based interface, the script only detects
Debug and Release configurations of installed Boost binaries.

In the old interface, the debug binaries where used only for debug
builds (care of the debug keyword in the classic target_link_libraries
function), while the release binaries were used for all other
configurations (optimized keyword).

It seems that with the new interface, this was inverted. On MSVC for
instance, the RelWithDebInfo and MinSizeRel configurations use the debug
binaries of Boost. This is not desirable and can even break those
configurations on MSVC due to inconsistent use of the debug runtime and
STL debug iterators.

After fiddling around with the issue, I found that reversing the order
in which the IMPORTED_LOCATION_* fields on the imported target are being
set resolves the issue. It seems that the first configuration that's
added here will be used as a default for the not explicitly added
configurations?

I attached a small patch to demonstrate what I mean, but I am unsure if
this is a proper fix for the issue.

Thanks and regards,
Andreas
-------------- next part --------------
From c201749b494c5aa44d7cc6c9139d8c71db849cf2 Mon Sep 17 00:00:00 2001
From: Andreas Weis <github at ghulbus-inc.de>
Date: Sun, 19 Jun 2016 12:44:29 +0200
Subject: [PATCH] Switched order of adding locations to imported target

FindBoost only detects Debug and Release configurations; All other
configurations will fall back to whichever IMPORTED_LOCATION_<CONFIG> was
added *first*. This change makes sure that that is the Release
configuration. Adding Debug first is likely to cause conflicts on MSVC,
where the Debug runtime is not to be used for RelWithDebInfo and
MinSizeRel builds.
---
 Modules/FindBoost.cmake | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake
index 6bf6401..2560459 100644
--- a/Modules/FindBoost.cmake
+++ b/Modules/FindBoost.cmake
@@ -1734,13 +1734,6 @@ if(Boost_FOUND)
             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)
@@ -1748,6 +1741,13 @@ if(Boost_FOUND)
             IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
             IMPORTED_LOCATION_RELEASE "${Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE}")
         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(_Boost_${UPPERCOMPONENT}_DEPENDENCIES)
           unset(_Boost_${UPPERCOMPONENT}_TARGET_DEPENDENCIES)
           foreach(dep ${_Boost_${UPPERCOMPONENT}_DEPENDENCIES})
-- 
2.5.0.windows.1



More information about the cmake-developers mailing list