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

9
OPTION(THIRDPARTY_BUILD_BOOST "Build Boost libraries" OFF)
10 11 12
SET(Boost_USE_MULTITHREADED ON CACHE BOOL
    "Search for multithreaded boost libraries")
MARK_AS_ADVANCED(Boost_USE_MULTITHREADED)
13

14 15 16 17
IF (WIN32)
    ADD_DEFINITIONS("-DBOOST_ALL_NO_LIB")
ENDIF()

18 19
IF (THIRDPARTY_BUILD_BOOST)
    INCLUDE(ExternalProject)
20 21

    # Only build the libraries we need
Dave Moxey's avatar
Dave Moxey committed
22
    SET(BOOST_LIB_LIST --with-system --with-iostreams --with-filesystem
Dave Moxey's avatar
Dave Moxey committed
23 24
        --with-program_options --with-date_time --with-thread
        --with-regex)
Dave Moxey's avatar
Dave Moxey committed
25

Dave Moxey's avatar
Dave Moxey committed
26 27
    IF (NOT WIN32)
        # We need -fPIC for 64-bit builds
28 29 30
        IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
            SET(BOOST_FLAGS cxxflags=-fPIC cflags=-fPIC linkflags=-fPIC)
        ENDIF ()
31 32
    ENDIF()

Dave Moxey's avatar
Dave Moxey committed
33
    # Build Boost
34 35
    IF (APPLE)
        SET(TOOLSET darwin)
Dave Moxey's avatar
Dave Moxey committed
36 37 38 39 40 41 42 43
    ELSEIF (WIN32)
        IF (MSVC10)
            SET(TOOLSET msvc-10.0)
        ELSEIF (MSVC11)
            SET(TOOLSET msvc-11.0)
        ELSEIF (MSVC12)
            SET(TOOLSET msvc-12.0)
        ENDIF()
44 45 46
    ELSE(APPLE)
        SET(TOOLSET gcc)
    ENDIF(APPLE)
Chris Cantwell's avatar
Chris Cantwell committed
47

Dave Moxey's avatar
Dave Moxey committed
48
    IF (NOT WIN32)
Dave Moxey's avatar
Dave Moxey committed
49 50 51
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Chris Cantwell's avatar
Chris Cantwell committed
52 53
            URL ${TPURL}/boost_1_57_0.tar.bz2
            URL_MD5 "1be49befbdd9a5ce9def2983ba3e7b76"
Dave Moxey's avatar
Dave Moxey committed
54 55 56 57 58 59 60
            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}
61
            BUILD_COMMAND NO_BZIP2=1 ./b2
Dave Moxey's avatar
Dave Moxey committed
62 63 64 65 66 67
                variant=release
                link=shared
                include=${TPDIST}/include
                linkflags="-L${TPDIST}/lib"
                ${BOOST_FLAGS} ${BOOST_LIB_LIST}
                --layout=system toolset=${TOOLSET} install
68
            INSTALL_COMMAND ""
Dave Moxey's avatar
Dave Moxey committed
69 70 71 72 73 74 75
            )
    ELSE ()
        IF (CMAKE_CL_64)
            SET(ADDRESS_MODEL 64)
        ELSE()
            SET(ADDRESS_MODEL 32)
        ENDIF()
76 77 78
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Chris Cantwell's avatar
Chris Cantwell committed
79 80
            URL ${TPURL}/boost_1_57_0.tar.bz2
            URL_MD5 "1be49befbdd9a5ce9def2983ba3e7b76"
81
            STAMP_DIR ${TPBUILD}/stamp
82
            DOWNLOAD_DIR ${TPSRC}
83
            SOURCE_DIR ${TPBUILD}/boost
84 85 86
            BINARY_DIR ${TPBUILD}/boost
            TMP_DIR ${TPBUILD}/boost-tmp
            INSTALL_DIR ${TPDIST}
87 88
            CONFIGURE_COMMAND call bootstrap.bat
            BUILD_COMMAND b2 variant=release
Dave Moxey's avatar
Dave Moxey committed
89 90 91 92 93 94 95 96 97 98 99
                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
100
            INSTALL_COMMAND ""
Dave Moxey's avatar
Dave Moxey committed
101 102
            )
    ENDIF()
Dave Moxey's avatar
Dave Moxey committed
103

104 105
    IF (APPLE)
        EXTERNALPROJECT_ADD_STEP(boost patch-install-path
Chris Cantwell's avatar
Chris Cantwell committed
106
            COMMAND sed -i ".bak" "s|-install_name \"|&${TPDIST}/lib/|" ${TPBUILD}/boost/tools/build/src/tools/darwin.jam
107 108 109 110 111 112 113 114 115 116
            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
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    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)
    SET(Boost_INCLUDE_DIRS ${TPSRC}/dist/include)
139
    SET(Boost_CONFIG_INCLUDE_DIR ${TPINC})
140
    SET(Boost_LIBRARY_DIRS ${TPSRC}/dist/lib)
141 142
    SET(Boost_CONFIG_LIBRARY_DIR ${TPLIB})
    SET(Boost_LIBRARIES boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_system boost_thread)
143
    LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
Dave Moxey's avatar
Dave Moxey committed
144
ELSE (THIRDPARTY_BUILD_BOOST)
145
    ADD_CUSTOM_TARGET(boost ALL)
146
    SET(Boost_DEBUG 0)
147
    SET(Boost_NO_BOOST_CMAKE ON)
148
    #If the user has not set BOOST_ROOT, look in a couple common places first.
149
    IF( NOT BOOST_ROOT )
150 151 152
        SET(TEST_ENV1 $ENV{BOOST_HOME})
        SET(TEST_ENV2 $ENV{BOOST_DIR})
        IF (DEFINED TEST_ENV1)
153
            SET(BOOST_ROOT $ENV{BOOST_HOME})
154
            FIND_PACKAGE( Boost QUIET COMPONENTS thread iostreams date_time
155
                filesystem system program_options regex )
156 157 158 159
        ELSEIF (DEFINED TEST_ENV2)
            SET(BOOST_ROOT $ENV{BOOST_DIR})
            FIND_PACKAGE( Boost QUIET COMPONENTS thread iostreams date_time
                filesystem system program_options regex )
160
        ELSE ()
Dave Moxey's avatar
Dave Moxey committed
161 162
            SET(BOOST_ROOT ${TPDIST})
            FIND_PACKAGE( Boost QUIET COMPONENTS thread iostreams date_time filesystem system program_options regex)
163
        ENDIF()
164
    ELSE()
165
        FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
166
    ENDIF()
167

168
    IF (Boost_IOSTREAMS_FOUND)
169 170 171 172 173 174
        MESSAGE(STATUS "Found Boost iostreams library: "
                       "${Boost_IOSTREAMS_LIBRARY}")
    ELSE ()
        MESSAGE(WARNING "Boost IOSTREAM library not found. "
                        "Please ensure it is installed, or Boost was "
                        "compiled with the --with-iostreams option.")
175
    ENDIF ()
176

177
    IF (Boost_THREAD_FOUND)
178 179 180 181 182 183
        MESSAGE(STATUS "Found Boost thread library: "
                       "${Boost_THREAD_LIBRARY}")
    ELSE ()
        MESSAGE(WARNING "Boost THREAD library not found. "
                        "Please ensure it is installed, or Boost was "
                        "compiled with the --with-thread option.")
184
    ENDIF ()
185

186
    IF (Boost_DATE_TIME_FOUND)
187 188 189 190 191 192
        MESSAGE(STATUS "Found Boost date_time library: "
                       "${Boost_DATE_TIME_LIBRARY}")
    ELSE ()
        MESSAGE(WARNING "Boost DATE_TIME library not found. "
                        "Please ensure it is installed, or Boost was "
                        "compiled with the --with-date_time option.")
193
    ENDIF ()
194

195
    IF (Boost_FILESYSTEM_FOUND)
196 197 198 199 200 201
        MESSAGE(STATUS "Found Boost filesystem library: "
                       "${Boost_FILESYSTEM_LIBRARY}")
    ELSE ()
        MESSAGE(WARNING "Boost FILESYSTEM library not found. "
                        "Please ensure it is installed, or Boost was "
                        "compiled with the --with-filesystem option.")
202
    ENDIF ()
203

204
    IF (Boost_SYSTEM_FOUND)
205 206 207 208 209 210
        MESSAGE(STATUS "Found Boost system library: "
                       "${Boost_SYSTEM_LIBRARY}")
    ELSE ()
        MESSAGE(WARNING "Boost SYSTEM library not found. "
                        "Please ensure it is installed, or Boost was "
                        "compiled with the --with-filesystem option.")
211
    ENDIF ()
212

213
    IF (Boost_PROGRAM_OPTIONS_FOUND)
214 215 216 217 218 219
        MESSAGE(STATUS "Found Boost program_options library: "
                       "${Boost_PROGRAM_OPTIONS_LIBRARY}")
    ELSE ()
        MESSAGE(WARNING "Boost PROGRAM_OPTIONS library not found. "
                        "Please ensure it is installed, or Boost was "
                        "compiled with the --with-program_options option.")
220
    ENDIF ()
221

222
    IF (Boost_REGEX_FOUND)
223 224 225 226 227 228
        MESSAGE(STATUS "Found Boost regex library: "
                       "${Boost_REGEX_LIBRARY}")
    ELSE ()
        MESSAGE(WARNING "Boost REGEX library not found. "
                        "Please ensure it is installed, or Boost was "
                        "compiled with the --with-regex option.")
229
    ENDIF ()
230

231 232 233
    IF (BOOST_THREAD_LIBRARY)
        MARK_AS_ADVANCED(BOOST_THREAD_LIBRARY)
    ENDIF (BOOST_THREAD_LIBRARY)
234 235
    SET(Boost_CONFIG_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
    SET(Boost_CONFIG_LIBRARY_DIR ${Boost_LIBRARY_DIRS})
236 237 238 239 240 241 242

    IF (NOT Boost_FOUND)
        MESSAGE(FATAL_ERROR "One of more Boost libraries could not be found. "
                            "See above warnings. To have CMake automatically "
                            "build and install the necessary Boost libraries "
                            "select the THIRDPARTY_BUILD_BOOST option.")
    ENDIF ()
243
ENDIF (THIRDPARTY_BUILD_BOOST)
244

245
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})