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

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
# Define a macro that checks for common Boost environment variables.
MACRO(NektarFindBoost)
    SET(Boost_DEBUG 0)
    SET(Boost_NO_BOOST_CMAKE ON)
    IF (BOOST_ROOT)
        SET(Boost_NO_SYSTEM_PATHS ON)
        FIND_PACKAGE(Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS})
    ELSE ()
        SET(TEST_ENV1 $ENV{BOOST_HOME})
        SET(TEST_ENV2 $ENV{BOOST_DIR})
        IF (DEFINED TEST_ENV1)
            SET(BOOST_ROOT $ENV{BOOST_HOME})
            SET(Boost_NO_SYSTEM_PATHS ON)
            FIND_PACKAGE(Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS})
        ELSEIF (DEFINED TEST_ENV2)
            SET(BOOST_ROOT $ENV{BOOST_DIR})
            SET(Boost_NO_SYSTEM_PATHS ON)
            FIND_PACKAGE(Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS})
        ELSE ()
            SET(BOOST_ROOT ${TPDIST})
            FIND_PACKAGE(Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS})
        ENDIF()
    ENDIF()
ENDMACRO()

34
#If the user has not set BOOST_ROOT, look in a couple common places first.
35
MESSAGE(STATUS "Searching for Boost:")
Dave Moxey's avatar
Dave Moxey committed
36

37 38
# Minimum version and boost libraries required
SET(MIN_VER "1.56.0")
39
SET(NEEDED_BOOST_LIBS thread iostreams filesystem system program_options regex)
Dave Moxey's avatar
Dave Moxey committed
40 41

IF (NEKTAR_BUILD_PYTHON)
42 43 44 45 46 47 48
    # We need to try a few variants, depending on if we're doing Python 2 or
    # Python 3. Irritatingly this is all very much distriution dependent so we
    # just take our best guess at filenames.
    STRING(REPLACE "." ";" BOOST_PYTHON_VERSION ${PYTHONLIBS_VERSION_STRING})
    LIST(GET BOOST_PYTHON_VERSION 0 BOOST_PYTHON_VERSION_MAJOR)
    LIST(GET BOOST_PYTHON_VERSION 1 BOOST_PYTHON_VERSION_MINOR)
    SET(TMP_BOOST_LIST ${NEEDED_BOOST_LIBS})
Dave Moxey's avatar
Dave Moxey committed
49

50 51 52 53 54 55 56 57 58
    # Now try different versions of the string.
    SET(NAMES_TO_TRY python-py${BOOST_PYTHON_VERSION_MAJOR}${BOOST_PYTHON_VERSION_MINOR} python-py${BOOST_PYTHON_VERSION_MAJOR} python${BOOST_PYTHON_VERSION_MAJOR} python)

    FOREACH(BPLIB ${NAMES_TO_TRY})
        SET(NEEDED_BOOST_LIBS ${TMP_BOOST_LIST} ${BPLIB})
        NektarFindBoost()
        STRING(TOUPPER ${BPLIB} BPLIB_UPPER)

        IF (Boost_${BPLIB_UPPER}_FOUND)
59
            SET(Boost_PYTHON_LIBRARY ${Boost_${BPLIB_UPPER}_LIBRARY})
60 61 62 63 64
            break()
        ENDIF()
    ENDFOREACH()
ELSE()
    NektarFindBoost()
65 66
ENDIF()

67
SET(Boost_NO_BOOST_CMAKE ON)
68
IF( BOOST_ROOT )
69
    SET(Boost_NO_SYSTEM_PATHS ON)
70
    FIND_PACKAGE( Boost ${MIN_VER} COMPONENTS ${NEEDED_BOOST_LIBS})
71 72 73 74 75
ELSE ()
    SET(TEST_ENV1 $ENV{BOOST_HOME})
    SET(TEST_ENV2 $ENV{BOOST_DIR})
    IF (DEFINED TEST_ENV1)
        SET(BOOST_ROOT $ENV{BOOST_HOME})
76
        SET(Boost_NO_SYSTEM_PATHS ON)
77
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
78 79
    ELSEIF (DEFINED TEST_ENV2)
        SET(BOOST_ROOT $ENV{BOOST_DIR})
80
        SET(Boost_NO_SYSTEM_PATHS ON)
81
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
82 83
    ELSE ()
        SET(BOOST_ROOT ${TPDIST})
84
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
85 86 87 88 89 90
    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)
91
    IF (Boost_${FOUND_VAR_UPPER}_FOUND)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        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})
107 108 109
SET(Boost_USE_MULTITHREADED ON CACHE BOOL
    "Search for multithreaded boost libraries")
MARK_AS_ADVANCED(Boost_USE_MULTITHREADED)
110

111

112 113 114 115
IF (WIN32)
    ADD_DEFINITIONS("-DBOOST_ALL_NO_LIB")
ENDIF()

116 117
IF (THIRDPARTY_BUILD_BOOST)
    INCLUDE(ExternalProject)
118 119

    # Only build the libraries we need
120 121 122
    FOREACH(boostlib ${NEEDED_BOOST_LIBS})
 	LIST(APPEND BOOST_LIB_LIST --with-${boostlib})
    ENDFOREACH()
Dave Moxey's avatar
Dave Moxey committed
123

Dave Moxey's avatar
Dave Moxey committed
124 125
    IF (NOT WIN32)
        # We need -fPIC for 64-bit builds
126 127 128
        IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
            SET(BOOST_FLAGS cxxflags=-fPIC cflags=-fPIC linkflags=-fPIC)
        ENDIF ()
129 130
    ENDIF()

Dave Moxey's avatar
Dave Moxey committed
131
    # Build Boost
132 133
    IF (APPLE)
        SET(TOOLSET darwin)
Dave Moxey's avatar
Dave Moxey committed
134 135 136 137 138 139 140
    ELSEIF (WIN32)
        IF (MSVC10)
            SET(TOOLSET msvc-10.0)
        ELSEIF (MSVC11)
            SET(TOOLSET msvc-11.0)
        ELSEIF (MSVC12)
            SET(TOOLSET msvc-12.0)
141 142
        ELSEIF (MSVC14)
            SET(TOOLSET msvc-14.0)
Dave Moxey's avatar
Dave Moxey committed
143
        ENDIF()
144
    ELSE()
145
        SET(TOOLSET gcc)
146
    ENDIF()
Chris Cantwell's avatar
Chris Cantwell committed
147

Dave Moxey's avatar
Dave Moxey committed
148
    IF (NOT WIN32)
Dave Moxey's avatar
Dave Moxey committed
149 150 151
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Chris Cantwell's avatar
Chris Cantwell committed
152 153
            URL ${TPURL}/boost_1_57_0.tar.bz2
            URL_MD5 "1be49befbdd9a5ce9def2983ba3e7b76"
Dave Moxey's avatar
Dave Moxey committed
154 155 156 157 158 159 160
            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}
161
            BUILD_COMMAND NO_BZIP2=1 ./b2
Dave Moxey's avatar
Dave Moxey committed
162 163 164 165 166 167
                variant=release
                link=shared
                include=${TPDIST}/include
                linkflags="-L${TPDIST}/lib"
                ${BOOST_FLAGS} ${BOOST_LIB_LIST}
                --layout=system toolset=${TOOLSET} install
168
            INSTALL_COMMAND ""
Dave Moxey's avatar
Dave Moxey committed
169 170 171 172 173 174 175
            )
    ELSE ()
        IF (CMAKE_CL_64)
            SET(ADDRESS_MODEL 64)
        ELSE()
            SET(ADDRESS_MODEL 32)
        ENDIF()
176 177 178
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Chris Cantwell's avatar
Chris Cantwell committed
179 180
            URL ${TPURL}/boost_1_57_0.tar.bz2
            URL_MD5 "1be49befbdd9a5ce9def2983ba3e7b76"
181
            STAMP_DIR ${TPBUILD}/stamp
182
            DOWNLOAD_DIR ${TPSRC}
183
            SOURCE_DIR ${TPBUILD}/boost
184 185 186
            BINARY_DIR ${TPBUILD}/boost
            TMP_DIR ${TPBUILD}/boost-tmp
            INSTALL_DIR ${TPDIST}
187 188
            CONFIGURE_COMMAND call bootstrap.bat
            BUILD_COMMAND b2 variant=release
Dave Moxey's avatar
Dave Moxey committed
189 190 191 192 193 194 195 196 197 198 199
                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
200
            INSTALL_COMMAND ""
Dave Moxey's avatar
Dave Moxey committed
201 202
            )
    ENDIF()
Dave Moxey's avatar
Dave Moxey committed
203

204 205
    IF (APPLE)
        EXTERNALPROJECT_ADD_STEP(boost patch-install-path
206
            COMMAND sed -i ".bak" "s|-install_name \"|&${TPDIST}/lib/|" ${TPBUILD}/boost/tools/build/src/tools/darwin.jam
207 208 209 210 211 212 213 214 215 216
            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
217 218 219 220 221 222 223
    FOREACH(BOOSTLIB ${NEEDED_BOOST_LIBS})
        STRING(TOUPPER ${BOOSTLIB} BOOSTLIB_UPPER)
        THIRDPARTY_LIBRARY(Boost_${BOOSTLIB_UPPER}_LIBRARY
            SHARED boost_${BOOSTLIB} DESCRIPTION "Boost ${BOOSTLIB} library")
        MARK_AS_ADVANCED(Boost_${BOOSTLIB_UPPER}_LIBRARY)
        LIST(APPEND Boost_LIBRARIES ${Boost_${BOOSTLIB_UPPER}_LIBRARY})
    ENDFOREACH()
224

225
    SET(Boost_INCLUDE_DIRS ${TPSRC}/dist/include)
226
    SET(Boost_CONFIG_INCLUDE_DIR ${TPINC})
227
    SET(Boost_LIBRARY_DIRS ${TPSRC}/dist/lib)
228
    SET(Boost_CONFIG_LIBRARY_DIR ${TPLIB})
229 230 231

    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
232
ELSE (THIRDPARTY_BUILD_BOOST)
233
    ADD_CUSTOM_TARGET(boost ALL)
234 235 236
    IF (BOOST_THREAD_LIBRARY)
        MARK_AS_ADVANCED(BOOST_THREAD_LIBRARY)
    ENDIF (BOOST_THREAD_LIBRARY)
237 238
    SET(Boost_CONFIG_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
    SET(Boost_CONFIG_LIBRARY_DIR ${Boost_LIBRARY_DIRS})
239
ENDIF (THIRDPARTY_BUILD_BOOST)
240

241
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})