ThirdPartyBoost.cmake 4.93 KB
Newer Older
1 2 3 4 5
SET(THIRDPARTY_BUILD_BOOST OFF CACHE BOOL
    "Build Boost libraries")

IF (THIRDPARTY_BUILD_BOOST)
    INCLUDE(ExternalProject)
6
   
7 8 9
    IF (NOT WIN32)
        # Only build the libraries we need
        SET(BOOST_LIB_LIST --with-system --with-iostreams --with-filesystem 
10 11
                           --with-program_options --with-date_time --with-thread
                           --with-regex)
12 13 14 15 16 17 18
                           
        # 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
19 20 21 22 23
        IF (APPLE)
            SET(TOOLSET darwin)
        ELSE(APPLE)
            SET(TOOLSET gcc)
        ENDIF(APPLE)
24 25 26 27 28 29 30
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
            URL ${TPURL}/boost_1_49_0.tar.bz2
            URL_MD5 "0d202cb811f934282dea64856a175698"
            DOWNLOAD_DIR ${TPSRC}
            CONFIGURE_COMMAND ./bootstrap.sh --prefix=${TPSRC}/dist
31 32 33 34 35 36
            BUILD_COMMAND NO_BZIP2=1 ./b2
                            variant=release
                            link=shared 
                            include=${TPSRC}/dist/include
                            linkflags="-L${TPSRC}/dist/lib"
                            ${BOOST_FLAGS} ${BOOST_LIB_LIST} 
37
                            --layout=system toolset=${TOOLSET} install
38 39 40
            INSTALL_COMMAND ""
            BUILD_IN_SOURCE 1
        )
41 42 43 44 45 46

        # If building ThirdParty zlib, force zlib build before boost
        IF (THIRDPARTY_BUILD_ZLIB)
            ADD_DEPENDENCIES(boost zlib)
        ENDIF(THIRDPARTY_BUILD_ZLIB)

47
        # Set up CMake variables
48 49 50 51 52 53 54 55 56 57 58 59
        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)
60 61 62
        SET(Boost_REGEX_LIBRARY boost_regex)
        SET(Boost_REGEX_LIBRARY_DEBUG boost_regex)
        SET(Boost_REGEX_LIBRARY_RELEASE boost_regex)
63 64 65 66 67 68
        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)
69 70
        SET(Boost_INCLUDE_DIRS ${TPSRC}/dist/include 
                               ${TPSRC}/dist/include/boost-1_49)
71 72
        SET(Boost_LIBRARY_DIRS ${TPSRC}/dist/lib)
        LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
73 74 75 76 77 78 79 80 81 82 83 84 85 86
    ELSE ()
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
            URL ${TPURL}/boost_1_49_0.tar.bz2
            URL_MD5 "0d202cb811f934282dea64856a175698"
            DOWNLOAD_DIR ${TPSRC}
            CONFIGURE_COMMAND bootstrap.bat --prefix=${TPSRC}/boost
            BUILD_COMMAND b2 --layout=system install
            INSTALL_COMMAND ""
            BUILD_IN_SOURCE 1
        )
    ENDIF ()
ELSE (THIRDPARTY_BUILD_BOOST)
87
    SET(Boost_DEBUG 1)
88 89
    SET(Boost_USE_MULTITHREADED OFF)
    SET(Boost_ADDITIONAL_VERSIONS "1.51" "1.51.0" "1.50" "1.50.0" "1.49" "1.49.0" "1.48" "1.48.0" "1.47.0" "1.47" "1.46" "1.46. 1" "1.40" "1.40.0" "1.35.0" "1.35")
90
    SET(Boost_NO_BOOST_CMAKE ON)
91 92 93

    IF( NOT BOOST_ROOT )
        #If the user has not set BOOST_ROOT, look in a couple common places first.
94 95
        SET(BOOST_ROOT $ENV{BOOST_HOME})
        FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
96
        SET(BOOST_ROOT ${CMAKE_SOURCE_DIR}/ThirdParty/boost)
97
        FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
98
        SET(BOOST_ROOT ${CMAKE_SOURCE_DIR}/../ThirdParty/boost)
99
        FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
100
        SET(BOOST_ROOT ${CMAKE_SOURCE_DIR}/ThirdParty/dist)
101
        FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
102 103 104 105 106
        # Hack for odd distributions which do not symlink for non -mt thread lib
        IF( NOT BOOST_THREAD_FOUND )
            SET( Boost_USE_MULTITHREADED ON)
            FIND_PACKAGE( Boost COMPONENTS thread )
        ENDIF()
107
    ELSE()
108
        FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
109 110 111
    ENDIF()
ENDIF (THIRDPARTY_BUILD_BOOST)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})