ThirdPartyBoost.cmake 7.25 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.56.0")
12
SET(NEEDED_BOOST_LIBS thread iostreams filesystem system program_options regex)
13 14
SET(Boost_DEBUG 0)
SET(Boost_NO_BOOST_CMAKE ON)
15
IF( BOOST_ROOT )
16
    SET(Boost_NO_SYSTEM_PATHS ON)
17
    FIND_PACKAGE( Boost ${MIN_VER} COMPONENTS ${NEEDED_BOOST_LIBS})
18 19 20 21 22
ELSE ()
    SET(TEST_ENV1 $ENV{BOOST_HOME})
    SET(TEST_ENV2 $ENV{BOOST_DIR})
    IF (DEFINED TEST_ENV1)
        SET(BOOST_ROOT $ENV{BOOST_HOME})
23
        SET(Boost_NO_SYSTEM_PATHS ON)
24
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
25 26
    ELSEIF (DEFINED TEST_ENV2)
        SET(BOOST_ROOT $ENV{BOOST_DIR})
27
        SET(Boost_NO_SYSTEM_PATHS ON)
28
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
29 30
    ELSE ()
        SET(BOOST_ROOT ${TPDIST})
31
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    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})
54 55 56
SET(Boost_USE_MULTITHREADED ON CACHE BOOL
    "Search for multithreaded boost libraries")
MARK_AS_ADVANCED(Boost_USE_MULTITHREADED)
57

58

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

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

    # Only build the libraries we need
67 68 69
    FOREACH(boostlib ${NEEDED_BOOST_LIBS})
 	LIST(APPEND BOOST_LIB_LIST --with-${boostlib})
    ENDFOREACH()
Dave Moxey's avatar
Dave Moxey committed
70

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

Dave Moxey's avatar
Dave Moxey committed
78
    # Build Boost: first need to select toolset. 
79 80
    IF (APPLE)
        SET(TOOLSET darwin)
Dave Moxey's avatar
Dave Moxey committed
81
    ELSEIF (WIN32)
Dave Moxey's avatar
Dave Moxey committed
82 83 84 85 86 87 88 89 90 91
        IF (MSVC_VERSION EQUAL 1600)
            SET(TOOLSET msvc-10.0) # Visual Studio 2010
        ELSEIF (MSVC_VERSION EQUAL 1700)
            SET(TOOLSET msvc-11.0) # Visual Studio 2012
        ELSEIF (MSVC_VERSION EQUAL 1800)
            SET(TOOLSET msvc-12.0) # Visual Studio 2013
        ELSEIF (MSVC_VERSION EQUAL 1900)
            SET(TOOLSET msvc-14.0) # Visual Studio 2015
        ELSEIF (MSVC_VERSION GREATER 1909 OR MSVC_VERSION LESS 1920)
            SET(TOOLSET msvc-14.1) # Visual Studio 2017
Dave Moxey's avatar
Dave Moxey committed
92
        ENDIF()
Dave Moxey's avatar
Dave Moxey committed
93 94
    ELSEIF(${CMAKE_CXX_COMPILER_ID} STREQUAL "Cray")
        SET(TOOLSET cray)
95
    ELSE()
Michael Turner's avatar
Michael Turner committed
96
        SET(TOOLSET gcc-${CMAKE_CXX_COMPILER_VERSION})
97
    ENDIF()
Chris Cantwell's avatar
Chris Cantwell committed
98

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

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

Michael Turner's avatar
Michael Turner committed
163 164 165 166 167 168 169 170 171
    SET(cmd_string "using gcc : ${CMAKE_CXX_COMPILER_VERSION} : ${CMAKE_CXX_COMPILER} \\\;")

    IF (UNIX)
	EXTERNALPROJECT_ADD_STEP(boost conf-project-conf
            COMMAND cmake -E echo "${cmd_string}" > ${TPBUILD}/boost/project-config.jam
            DEPENDERS build
            DEPENDEES configure)
    ENDIF()

172 173 174 175 176 177
    # 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
178 179 180 181 182 183 184 185 186 187 188 189 190
    FOREACH(BOOSTLIB ${NEEDED_BOOST_LIBS})
        STRING(TOUPPER ${BOOSTLIB} BOOSTLIB_UPPER)
        THIRDPARTY_LIBRARY(Boost_${BOOSTLIB_UPPER}_LIBRARY
            SHARED boost_${BOOSTLIB} DESCRIPTION "Boost ${BOOSTLIB} library")
        THIRDPARTY_LIBRARY(Boost_${BOOSTLIB_UPPER}_LIBRARY_DEBUG
            SHARED boost_${BOOSTLIB} DESCRIPTION "Boost ${BOOSTLIB} library, debug")
        THIRDPARTY_LIBRARY(Boost_${BOOSTLIB_UPPER}_LIBRARY_RELEASE
            SHARED boost_${BOOSTLIB} DESCRIPTION "Boost ${BOOSTLIB} library, release")
        MARK_AS_ADVANCED(Boost_${BOOSTLIB_UPPER}_LIBRARY)
        MARK_AS_ADVANCED(Boost_${BOOSTLIB_UPPER}_LIBRARY_DEBUG)
        MARK_AS_ADVANCED(Boost_${BOOSTLIB_UPPER}_LIBRARY_RELEASE)
        LIST(APPEND Boost_LIBRARIES ${Boost_${BOOSTLIB_UPPER}_LIBRARY})
    ENDFOREACH()
191

192
    SET(Boost_INCLUDE_DIRS ${TPSRC}/dist/include)
193
    SET(Boost_CONFIG_INCLUDE_DIR ${TPINC})
194
    SET(Boost_LIBRARY_DIRS ${TPSRC}/dist/lib)
195
    SET(Boost_CONFIG_LIBRARY_DIR ${TPLIB})
196 197 198

    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
199
ELSE (THIRDPARTY_BUILD_BOOST)
200
    ADD_CUSTOM_TARGET(boost ALL)
201 202 203
    IF (BOOST_THREAD_LIBRARY)
        MARK_AS_ADVANCED(BOOST_THREAD_LIBRARY)
    ENDIF (BOOST_THREAD_LIBRARY)
204 205
    SET(Boost_CONFIG_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
    SET(Boost_CONFIG_LIBRARY_DIR ${Boost_LIBRARY_DIRS})
206
ENDIF (THIRDPARTY_BUILD_BOOST)
207

Michael Turner's avatar
Michael Turner committed
208
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})