target_enable_boost.cmake 1.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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")
    set(BOOST_LIBS_REQUIRED system iostreams filesystem program_options date_time)
    if (WIN32)
        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)
    endif (WIN32)

    if (NOT BUILD_SHARED_LIBS)
        set(Boost_USE_STATIC_LIBS ON)
    endif (NOT BUILD_SHARED_LIBS)
    find_package(Boost ${BOOST_VERSION} REQUIRED ${BOOST_LIBS_REQUIRED})
    if (Boost_FOUND)
        add_library(boost INTERFACE)
        target_include_directories(boost INTERFACE ${Boost_INCLUDE_DIR})

        if (LINK_EXECUTABLE)
          target_link_libraries(boost INTERFACE  ${Boost_LIBRARIES})
        endif (LINK_EXECUTABLE)

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

        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)
    endif (Boost_FOUND)

endmacro(target_enable_boost)