From cfbaa51c7ec4aea8dc5a884ba14bd32ebd69ae62 Mon Sep 17 00:00:00 2001 From: Stephen Roderick Date: Tue, 20 Jul 2010 10:42:02 -0400 Subject: [PATCH] cmake: Properly deal with boost multiple installed libraries occuring in CMake lists --- config/check_depend.cmake | 65 ++++++++++++++++++++++++++++++++++----------- 1 files changed, 49 insertions(+), 16 deletions(-) diff --git a/config/check_depend.cmake b/config/check_depend.cmake index a445d9b..932e7f5 100644 --- a/config/check_depend.cmake +++ b/config/check_depend.cmake @@ -4,6 +4,45 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/config") SET(CMAKE_VERSION "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}") MESSAGE(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") +# Select one library from a list of libraries +# +# Commonly used when dealing with Boost_XXX_LIBRARY values, which typically +# encode "optimized" and "debug" versions of the libraries. CMake can deal +# with these lists, however, we can't pass that list to pkgconfig as it will +# write it directly to file, and then when it reads it in in the dependant +# package _then_ pkgconfig gets confused and errors out. +# +# As _libraries may be a list of libraries, and we can't deal +# with that in pkgconfig, we take 1) the library for this build type, or +# 2) the library if only one is listed, or 3) we error out. +# +# _libraries is the name of the library variable (e.g. Boost_THREAD_LIBRARY) +# _output is the selected library +# +MACRO(PKGCONFIG_SELECT_ONE_LIBRARY _library _output) + + STRING(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) + + if (DEFINED ${_library}_${CMAKE_BUILD_TYPE_UPPER}) + + SET(${_output} ${${_library}_${CMAKE_BUILD_TYPE_UPPER}}) + + else (DEFINED ${_library}_${CMAKE_BUILD_TYPE_UPPER}) + + LIST(LENGTH ${_library} count) + + if (1 LESS count) + + MESSAGE(FATAL_ERROR "Found multiple libraries for ${_library}, but not one specific to the current build type '${CMAKE_BUILD_TYPE_UPPER}'. Libraries are: ${${_library}}") + + endif (1 LESS count) + + SET(${_output} ${${_library}}) + + endif (DEFINED ${_library}_${CMAKE_BUILD_TYPE_UPPER}) + +ENDMACRO(PKGCONFIG_SELECT_ONE_LIBRARY) + ########################################################### # # @@ -41,7 +80,7 @@ OPTION(PLUGINS_ENABLE "Enable plugins" ON) # Necessary to play nice on win32 and Linux: set(CMAKE_DEBUG_LIB_SUFFIX "" CACHE STRING "The suffix applied to libraries compiled with debugging information. Defaults to 'd' on win32 and '' for all other platforms.") - + ########################################################### # # # Look for dependencies required by individual components # @@ -57,8 +96,14 @@ endif() # Look for boost if ( PLUGINS_ENABLE ) find_package(Boost 1.36 REQUIRED filesystem system serialization) + list(APPEND OROCOS-RTT_INCLUDE_DIRS ${Boost_FILESYSTEM_INCLUDE_DIRS} ${Boost_SYSTEM_INCLUDE_DIRS} ${Boost_SERIALIZATION_INCLUDE_DIRS}) - list(APPEND OROCOS-RTT_LIBRARIES ${Boost_FILESYSTEM_LIBRARIES} ${Boost_SYSTEM_LIBRARIES} ${Boost_SERIALIZATION_LIBRARIES}) + + # take only the library that pertains to the current build type (otherwise pkgconfig gets confused) + PKGCONFIG_SELECT_ONE_LIBRARY(Boost_FILESYSTEM_LIBRARY boost_fs_lib) + PKGCONFIG_SELECT_ONE_LIBRARY(Boost_SYSTEM_LIBRARY boost_sys_lib) + PKGCONFIG_SELECT_ONE_LIBRARY(Boost_SERIALIZATION_LIBRARY boost_serial_lib) + list(APPEND OROCOS-RTT_LIBRARIES ${boost_fs_lib} ${boost_sys_lib} ${boost_serial_lib}) else() find_package(Boost 1.36 REQUIRED) endif() @@ -172,20 +217,8 @@ if(OROCOS_TARGET STREQUAL "macosx") list(APPEND OROCOS-RTT_INCLUDE_DIRS ${Boost_THREAD_INCLUDE_DIRS} ) - # add to list of libraries in pkgconfig file - # As Boost_THREAD_LIBRARY may be a list of libraries, and we can't deal - # with that in pkgconfig, we take 1) the library for this build type, or - # 2) the library if only one is listed, or 3) we error out. - STRING(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) - if (DEFINED Boost_THREAD_LIBRARY_${CMAKE_BUILD_TYPE_UPPER}) - LIST(APPEND OROCOS-RTT_USER_LINK_LIBS ${Boost_THREAD_LIBRARY_${CMAKE_BUILD_TYPE_UPPER}}) - else (DEFINED Boost_THREAD_LIBRARY_${CMAKE_BUILD_TYPE_UPPER}) - LIST(LENGTH Boost_THREAD_LIBRARY COUNT_Boost_THREAD_LIBRARY) - if (1 LESS COUNT_Boost_THREAD_LIBRARY) - MESSAGE(FATAL_ERROR "Found multiple boost thread libraries, but not one specific to the current build type '${CMAKE_BUILD_TYPE_UPPER}'.") - endif (1 LESS COUNT_Boost_THREAD_LIBRARY) - LIST(APPEND OROCOS-RTT_USER_LINK_LIBS ${Boost_THREAD_LIBRARY}}) - endif (DEFINED Boost_THREAD_LIBRARY_${CMAKE_BUILD_TYPE_UPPER}) + PKGCONFIG_SELECT_ONE_LIBRARY(Boost_THREAD_LIBRARY boost_thread_lib) + LIST(APPEND OROCOS-RTT_USER_LINK_LIBS ${boost_thread_lib}}) message( "Forcing ORO_OS_USE_BOOST_THREAD to ON") set( ORO_OS_USE_BOOST_THREAD ON CACHE BOOL "Forced enable use of Boost.thread on macosx." FORCE) -- 1.7.1