Browse Source

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.
pull/44/head
Daniel Scharrer 11 years ago
parent
commit
9912507b5a
  1. 3
      CMakeLists.txt
  2. 15
      cmake/UseStaticLibs.cmake

3
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)

15
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()

Loading…
Cancel
Save