target_enable_boost.cmake 1.35 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
    target_include_directories(${_TARGET_} ${_SCOPE_} ${Boost_INCLUDE_DIR})
30

31
    if (LINK_EXECUTABLE)
32
      target_link_libraries(${_TARGET_} ${_SCOPE_} ${Boost_LIBRARIES})
33
    endif (LINK_EXECUTABLE)
34

35
36
37
38
    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)
39
40

endmacro(target_enable_boost)