From 9912507b5a65dd1d97113f3dbbe8adc40eda331a Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Wed, 13 May 2015 18:06:02 +0200 Subject: [PATCH] CMake: Detect we are using static libs for Boost Previously we relied on the user to supply Boost_USE_STATIC_LIBS in order to link Boost dependencies. --- CMakeLists.txt | 3 ++- cmake/UseStaticLibs.cmake | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c652bde..5f53f2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,8 @@ list(APPEND LIBRARIES ${Boost_LIBRARIES}) link_directories(${Boost_LIBRARY_DIRS}) include_directories(SYSTEM ${Boost_INCLUDE_DIR}) -if(Boost_USE_STATIC_LIBS) +has_static_libs(Boost Boost_LIBRARIES) +if(Boost_HAS_STATIC_LIBS) use_static_libs(ZLIB) find_package(ZLIB REQUIRED) diff --git a/cmake/UseStaticLibs.cmake b/cmake/UseStaticLibs.cmake index 8ee3b20..6e4e2af 100644 --- a/cmake/UseStaticLibs.cmake +++ b/cmake/UseStaticLibs.cmake @@ -44,3 +44,18 @@ macro(use_static_libs_restore) unset(_UseStaticLibs_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) endif() endmacro() + +macro(has_static_libs PREFIX LIBS) + if(WIN32) + # On Windows we can't really tell import libraries from proper static libraries. + set(${PREFIX}_HAS_STATIC_LIBS ${${PREFIX}_USE_STATIC_LIBS}) + else() + set(${PREFIX}_HAS_STATIC_LIBS 0) + foreach(lib IN LISTS ${LIBS}) + if(lib MATCHES "\\.a$") + set(${PREFIX}_HAS_STATIC_LIBS 1) + break() + endif() + endforeach() + endif() +endmacro()