target_enable_boost.cmake 1.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
macro(target_enable_boost _TARGET_ _SCOPE_)
    if (${ARGC} GREATER 2)
      set(LINK_EXECUTABLE ON)
    else ()
      set(LINK_EXECUTABLE OFF)
    endif ()

    if (BOOST_ROOT)
        file(TO_CMAKE_PATH ${BOOST_ROOT} BOOST_ROOT)
    endif (BOOST_ROOT)
    if (BOOST_LIBRARYDIR)
        file(TO_CMAKE_PATH ${BOOST_LIBRARYDIR} BOOST_LIBRARYDIR)
    endif (BOOST_LIBRARYDIR)

    set(BOOST_VERSION "1.48")
16
    set(BOOST_LIBS_REQUIRED system iostreams filesystem program_options date_time thread)
17
    if (WIN32)
18 19 20 21
      list(APPEND BOOST_LIBS_REQUIRED zlib)
      if (ENABLE_COMPRESSION OR AMDIS_NEED_COMPRESSION)
        list(APPEND BOOST_LIBS_REQUIRED bzip2)
      endif (ENABLE_COMPRESSION OR AMDIS_NEED_COMPRESSION)
22 23 24 25 26
    endif (WIN32)

    if (NOT BUILD_SHARED_LIBS)
        set(Boost_USE_STATIC_LIBS ON)
    endif (NOT BUILD_SHARED_LIBS)
27

28
    find_package(Boost ${BOOST_VERSION} REQUIRED ${BOOST_LIBS_REQUIRED})
29 30
    add_library(boost INTERFACE)
    target_include_directories(boost INTERFACE ${Boost_INCLUDE_DIR})
31

32 33 34
    if (LINK_EXECUTABLE)
      target_link_libraries(boost INTERFACE  ${Boost_LIBRARIES})
    endif (LINK_EXECUTABLE)
35

36
    target_link_libraries(${_TARGET_} ${_SCOPE_} boost)
37

38 39 40 41
    if (MSVC_SHARED_LIBS AND LINK_EXECUTABLE)
      link_directories(${Boost_LIBRARY_DIRS})
      target_compile_definitions(${_TARGET_} ${_SCOPE_} ${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
    endif (MSVC_SHARED_LIBS AND LINK_EXECUTABLE)
42 43

endmacro(target_enable_boost)