ThirdPartyBoost.cmake 6.2 KB
Newer Older
1
OPTION(THIRDPARTY_BUILD_BOOST "Build Boost libraries" OFF)
2 3 4
SET(Boost_USE_MULTITHREADED ON CACHE BOOL
    "Search for multithreaded boost libraries")
MARK_AS_ADVANCED(Boost_USE_MULTITHREADED)
5 6 7

IF (THIRDPARTY_BUILD_BOOST)
    INCLUDE(ExternalProject)
8
   
9 10 11
    IF (NOT WIN32)
        # Only build the libraries we need
        SET(BOOST_LIB_LIST --with-system --with-iostreams --with-filesystem 
12 13
                           --with-program_options --with-date_time --with-thread
                           --with-regex)
14 15 16 17 18 19 20
                           
        # We need -fPIC for 64-bit builds
        IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
            SET(BOOST_FLAGS cxxflags=-fPIC cflags=-fPIC linkflags=-fPIC)
        ENDIF ()
        
        # Build Boost
21 22 23 24 25
        IF (APPLE)
            SET(TOOLSET darwin)
        ELSE(APPLE)
            SET(TOOLSET gcc)
        ENDIF(APPLE)
26 27 28
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Chris Cantwell's avatar
Chris Cantwell committed
29 30
            URL ${TPURL}/boost_1_55_0.tar.bz2
            URL_MD5 "d6eef4b4cacb2183f2bf265a5a03a354"
31
            STAMP_DIR ${TPBUILD}/stamp
32
            DOWNLOAD_DIR ${TPSRC}
33
            SOURCE_DIR ${TPBUILD}/boost
34 35 36 37
            BINARY_DIR ${TPBUILD}/boost
            TMP_DIR ${TPBUILD}/boost-tmp
            INSTALL_DIR ${TPDIST}
            CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} ./bootstrap.sh --prefix=${TPDIST}
38 39 40
            BUILD_COMMAND NO_BZIP2=1 ./b2
                            variant=release
                            link=shared 
41 42
                            include=${TPDIST}/include
                            linkflags="-L${TPDIST}/lib"
43
                            ${BOOST_FLAGS} ${BOOST_LIB_LIST} 
44
                            --layout=system toolset=${TOOLSET} install
45 46
            INSTALL_COMMAND ""
        )
47
    
48 49
        IF (APPLE)
            EXTERNALPROJECT_ADD_STEP(boost patch-install-path
50
                COMMAND sed -i ".bak" "s|-install_name \"|&${TPDIST}/lib/|" ${TPSRC}/boost/tools/build/v2/tools/darwin.jam
51 52 53 54
                DEPENDERS build
                DEPENDEES download)
        ENDIF (APPLE)

55 56
        # If building ThirdParty zlib, force zlib build before boost
        IF (THIRDPARTY_BUILD_ZLIB)
57
             ADD_DEPENDENCIES(boost zlib-1.2.7)
58 59
        ENDIF(THIRDPARTY_BUILD_ZLIB)

60
        # Set up CMake variables
61 62 63 64 65 66 67 68 69 70 71 72
        SET(Boost_DATE_TIME_LIBRARY boost_date_time)
        SET(Boost_DATE_TIME_LIBRARY_DEBUG boost_date_time)
        SET(Boost_DATE_TIME_LIBRARY_RELEASE boost_date_time)
        SET(Boost_FILESYSTEM_LIBRARY boost_filesystem)
        SET(Boost_FILESYSTEM_LIBRARY_DEBUG boost_filesystem)
        SET(Boost_FILESYSTEM_LIBRARY_RELEASE boost_filesystem)
        SET(Boost_IOSTREAMS_LIBRARY boost_iostreams)
        SET(Boost_IOSTREAMS_LIBRARY_DEBUG boost_iostreams)
        SET(Boost_IOSTREAMS_LIBRARY_RELEASE boost_iostreams)
        SET(Boost_PROGRAM_OPTIONS_LIBRARY boost_program_options)
        SET(Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG boost_program_options)
        SET(Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE boost_program_options)
73 74 75
        SET(Boost_REGEX_LIBRARY boost_regex)
        SET(Boost_REGEX_LIBRARY_DEBUG boost_regex)
        SET(Boost_REGEX_LIBRARY_RELEASE boost_regex)
76 77 78 79 80 81
        SET(Boost_SYSTEM_LIBRARY boost_system)
        SET(Boost_SYSTEM_LIBRARY_DEBUG boost_system)
        SET(Boost_SYSTEM_LIBRARY_RELEASE boost_system)
        SET(Boost_THREAD_LIBRARY boost_thread)
        SET(Boost_THREAD_LIBRARY_DEBUG boost_thread)
        SET(Boost_THREAD_LIBRARY_RELEASE boost_thread)
82 83
        SET(Boost_INCLUDE_DIRS ${TPSRC}/dist/include 
                               ${TPSRC}/dist/include/boost-1_49)
84 85
        SET(Boost_LIBRARY_DIRS ${TPSRC}/dist/lib)
        LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
86 87 88 89
    ELSE ()
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Chris Cantwell's avatar
Chris Cantwell committed
90 91
            URL ${TPURL}/boost_1_55_0.tar.bz2
            URL_MD5 "d6eef4b4cacb2183f2bf265a5a03a354"
92
            STAMP_DIR ${TPSRC}/stamp
93
            DOWNLOAD_DIR ${TPSRC}
94 95 96 97 98
            SOURCE_DIR ${TPSRC}/boost
            BINARY_DIR ${TPBUILD}/boost
            TMP_DIR ${TPBUILD}/boost-tmp
            INSTALL_DIR ${TPDIST}
            CONFIGURE_COMMAND bootstrap.bat --prefix=${TPDIST}/boost
99 100 101 102 103
            BUILD_COMMAND b2 --layout=system install
            INSTALL_COMMAND ""
        )
    ENDIF ()
ELSE (THIRDPARTY_BUILD_BOOST)
104
    ADD_CUSTOM_TARGET(boost ALL)
105
    SET(Boost_DEBUG 0)
106
    SET(Boost_NO_BOOST_CMAKE ON)
107
    #If the user has not set BOOST_ROOT, look in a couple common places first.
108
    IF( NOT BOOST_ROOT )
109 110 111
        SET(TEST_ENV1 $ENV{BOOST_HOME})
        SET(TEST_ENV2 $ENV{BOOST_DIR})
        IF (DEFINED TEST_ENV1)
112
            SET(BOOST_ROOT $ENV{BOOST_HOME})
113
            FIND_PACKAGE( Boost QUIET COMPONENTS thread iostreams date_time
114
                filesystem system program_options regex )
115 116 117 118
        ELSEIF (DEFINED TEST_ENV2)
            SET(BOOST_ROOT $ENV{BOOST_DIR})
            FIND_PACKAGE( Boost QUIET COMPONENTS thread iostreams date_time
                filesystem system program_options regex )
119
        ELSE ()
120
            SET(BOOST_ROOT ${TPDIST})
121
            FIND_PACKAGE( Boost QUIET COMPONENTS thread iostreams date_time filesystem system program_options regex)
122
        ENDIF()
123
    ELSE()
124
        FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
125
    ENDIF()
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    IF (Boost_IOSTREAMS_FOUND)
        MESSAGE(STATUS "Found Boost iostreams library: ${Boost_IOSTREAMS_LIBRARY}")
    ENDIF ()
    IF (Boost_THREAD_FOUND)
        MESSAGE(STATUS "Found Boost thread library: ${Boost_THREAD_LIBRARY}")
    ENDIF ()
    IF (Boost_DATE_TIME_FOUND)
        MESSAGE(STATUS "Found Boost date_time library: ${Boost_DATE_TIME_LIBRARY}")
    ENDIF ()
    IF (Boost_FILESYSTEM_FOUND)
        MESSAGE(STATUS "Found Boost filesystem library: ${Boost_FILESYSTEM_LIBRARY}")
    ENDIF ()
    IF (Boost_SYSTEM_FOUND)
        MESSAGE(STATUS "Found Boost system library: ${Boost_SYSTEM_LIBRARY}")
    ENDIF ()
    IF (Boost_PROGRAM_OPTIONS_FOUND)
        MESSAGE(STATUS "Found Boost program_options library: ${Boost_PROGRAM_OPTIONS_LIBRARY}")
    ENDIF ()
    IF (Boost_REGEX_FOUND)
        MESSAGE(STATUS "Found Boost regex library: ${Boost_REGEX_LIBRARY}")
    ENDIF ()
147
ENDIF (THIRDPARTY_BUILD_BOOST)
148

149
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})