ThirdPartyBoost.cmake 7.22 KB
Newer Older
Dave Moxey's avatar
Dave Moxey committed
1 2 3 4 5 6 7 8
########################################################################
#
# ThirdParty configuration for Nektar++
#
# Boost
#
########################################################################

9
#If the user has not set BOOST_ROOT, look in a couple common places first.
10
MESSAGE(STATUS "Searching for Boost:")
11
SET(MIN_VER "1.52.0")
12
SET(NEEDED_BOOST_LIBS thread iostreams date_time filesystem system
13
    program_options regex timer)
14 15
SET(Boost_DEBUG 0)
SET(Boost_NO_BOOST_CMAKE ON)
16
IF( BOOST_ROOT )
17
    SET(Boost_NO_SYSTEM_PATHS ON)
18
    FIND_PACKAGE( Boost ${MIN_VER} COMPONENTS ${NEEDED_BOOST_LIBS})
19 20 21 22 23
ELSE ()
    SET(TEST_ENV1 $ENV{BOOST_HOME})
    SET(TEST_ENV2 $ENV{BOOST_DIR})
    IF (DEFINED TEST_ENV1)
        SET(BOOST_ROOT $ENV{BOOST_HOME})
24
        SET(Boost_NO_SYSTEM_PATHS ON)
25
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
26 27
    ELSEIF (DEFINED TEST_ENV2)
        SET(BOOST_ROOT $ENV{BOOST_DIR})
28
        SET(Boost_NO_SYSTEM_PATHS ON)
29
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
30 31
    ELSE ()
        SET(BOOST_ROOT ${TPDIST})
32
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    ENDIF()
ENDIF()

# Check what we found and determine if we need to build boost
FOREACH(FOUND_VAR ${NEEDED_BOOST_LIBS})
    STRING(TOUPPER ${FOUND_VAR} FOUND_VAR_UPPER)
    IF (Boost_${FOUND_VAR_UPPER}_FOUND )
        MESSAGE(STATUS "-- Found Boost ${FOUND_VAR} library: "
                "${Boost_${FOUND_VAR_UPPER}_LIBRARY}")
    ELSE ()
        MESSAGE(STATUS "-- Pre-installed Boost ${FOUND_VAR} library not found")
    ENDIF()
ENDFOREACH()

IF (NOT Boost_FOUND)
    SET(BUILD_BOOST ON)
ELSE()
    SET(BUILD_BOOST OFF)
ENDIF ()


OPTION(THIRDPARTY_BUILD_BOOST "Build Boost libraries" ${BUILD_BOOST})
55 56 57
SET(Boost_USE_MULTITHREADED ON CACHE BOOL
    "Search for multithreaded boost libraries")
MARK_AS_ADVANCED(Boost_USE_MULTITHREADED)
58

59

60 61 62 63
IF (WIN32)
    ADD_DEFINITIONS("-DBOOST_ALL_NO_LIB")
ENDIF()

64 65
IF (THIRDPARTY_BUILD_BOOST)
    INCLUDE(ExternalProject)
66 67

    # Only build the libraries we need
Dave Moxey's avatar
Dave Moxey committed
68
    SET(BOOST_LIB_LIST --with-system --with-iostreams --with-filesystem
Dave Moxey's avatar
Dave Moxey committed
69
        --with-program_options --with-date_time --with-thread
70
        --with-regex --with-timer)
Dave Moxey's avatar
Dave Moxey committed
71

Dave Moxey's avatar
Dave Moxey committed
72 73
    IF (NOT WIN32)
        # We need -fPIC for 64-bit builds
74 75 76
        IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
            SET(BOOST_FLAGS cxxflags=-fPIC cflags=-fPIC linkflags=-fPIC)
        ENDIF ()
77 78
    ENDIF()

Dave Moxey's avatar
Dave Moxey committed
79
    # Build Boost
80 81
    IF (APPLE)
        SET(TOOLSET darwin)
Dave Moxey's avatar
Dave Moxey committed
82 83 84 85 86 87 88 89
    ELSEIF (WIN32)
        IF (MSVC10)
            SET(TOOLSET msvc-10.0)
        ELSEIF (MSVC11)
            SET(TOOLSET msvc-11.0)
        ELSEIF (MSVC12)
            SET(TOOLSET msvc-12.0)
        ENDIF()
90 91 92
    ELSE(APPLE)
        SET(TOOLSET gcc)
    ENDIF(APPLE)
Chris Cantwell's avatar
Chris Cantwell committed
93

Dave Moxey's avatar
Dave Moxey committed
94
    IF (NOT WIN32)
Dave Moxey's avatar
Dave Moxey committed
95 96 97
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Chris Cantwell's avatar
Chris Cantwell committed
98 99
            URL ${TPURL}/boost_1_57_0.tar.bz2
            URL_MD5 "1be49befbdd9a5ce9def2983ba3e7b76"
Dave Moxey's avatar
Dave Moxey committed
100 101 102 103 104 105 106
            STAMP_DIR ${TPBUILD}/stamp
            DOWNLOAD_DIR ${TPSRC}
            SOURCE_DIR ${TPBUILD}/boost
            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}
107
            BUILD_COMMAND NO_BZIP2=1 ./b2
Dave Moxey's avatar
Dave Moxey committed
108 109 110 111 112 113
                variant=release
                link=shared
                include=${TPDIST}/include
                linkflags="-L${TPDIST}/lib"
                ${BOOST_FLAGS} ${BOOST_LIB_LIST}
                --layout=system toolset=${TOOLSET} install
114
            INSTALL_COMMAND ""
Dave Moxey's avatar
Dave Moxey committed
115 116 117 118 119 120 121
            )
    ELSE ()
        IF (CMAKE_CL_64)
            SET(ADDRESS_MODEL 64)
        ELSE()
            SET(ADDRESS_MODEL 32)
        ENDIF()
122 123 124
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Chris Cantwell's avatar
Chris Cantwell committed
125 126
            URL ${TPURL}/boost_1_57_0.tar.bz2
            URL_MD5 "1be49befbdd9a5ce9def2983ba3e7b76"
127
            STAMP_DIR ${TPBUILD}/stamp
128
            DOWNLOAD_DIR ${TPSRC}
129
            SOURCE_DIR ${TPBUILD}/boost
130 131 132
            BINARY_DIR ${TPBUILD}/boost
            TMP_DIR ${TPBUILD}/boost-tmp
            INSTALL_DIR ${TPDIST}
133 134
            CONFIGURE_COMMAND call bootstrap.bat
            BUILD_COMMAND b2 variant=release
Dave Moxey's avatar
Dave Moxey committed
135 136 137 138 139 140 141 142 143 144 145
                toolset=${TOOLSET}
                address-model=${ADDRESS_MODEL}
                link=shared
                runtime-link=shared
                -s NO_BZIP2=1
                -s ZLIB_BINARY=zlib
                -s ZLIB_INCLUDE=${TPDIST}/include
                -s ZLIB_LIBPATH=${TPDIST}/lib
                ${BOOST_LIB_LIST}
                --layout=system
                --prefix=${TPDIST} install
146
            INSTALL_COMMAND ""
Dave Moxey's avatar
Dave Moxey committed
147 148
            )
    ENDIF()
Dave Moxey's avatar
Dave Moxey committed
149

150 151
    IF (APPLE)
        EXTERNALPROJECT_ADD_STEP(boost patch-install-path
152
            COMMAND sed -i ".bak" "s|-install_name \"|&${TPDIST}/lib/|" ${TPBUILD}/boost/tools/build/src/tools/darwin.jam
153 154 155 156 157 158 159 160 161 162
            DEPENDERS build
            DEPENDEES download)
    ENDIF (APPLE)

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

    # Set up CMake variables
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    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)
    SET(Boost_REGEX_LIBRARY boost_regex)
    SET(Boost_REGEX_LIBRARY_DEBUG boost_regex)
    SET(Boost_REGEX_LIBRARY_RELEASE boost_regex)
    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)
184 185 186 187
    SET(Boost_TIMER_LIBRARY boost_timer)
    SET(Boost_TIMER_LIBRARY_DEBUG boost_timer)
    SET(Boost_TIMER_LIBRARY_RELEASE boost_timer)

188
    SET(Boost_INCLUDE_DIRS ${TPSRC}/dist/include)
189
    SET(Boost_CONFIG_INCLUDE_DIR ${TPINC})
190
    SET(Boost_LIBRARY_DIRS ${TPSRC}/dist/lib)
191
    SET(Boost_CONFIG_LIBRARY_DIR ${TPLIB})
192
    SET(Boost_LIBRARIES boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_system boost_thread boost_timer)
193
    LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
194 195 196

    STRING(REPLACE ";" ", " NEEDED_BOOST_LIBS_STRING "${NEEDED_BOOST_LIBS}")
    MESSAGE(STATUS "Build boost libs: ${NEEDED_BOOST_LIBS_STRING}")
Dave Moxey's avatar
Dave Moxey committed
197
ELSE (THIRDPARTY_BUILD_BOOST)
198
    ADD_CUSTOM_TARGET(boost ALL)
199 200 201
    IF (BOOST_THREAD_LIBRARY)
        MARK_AS_ADVANCED(BOOST_THREAD_LIBRARY)
    ENDIF (BOOST_THREAD_LIBRARY)
202 203
    SET(Boost_CONFIG_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
    SET(Boost_CONFIG_LIBRARY_DIR ${Boost_LIBRARY_DIRS})
204
ENDIF (THIRDPARTY_BUILD_BOOST)
205

206
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})