ThirdPartyBoost.cmake 8.13 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:")
Dave Moxey's avatar
Dave Moxey committed
11

12
# Minimum version and boost libraries required
13
SET(MIN_VER "1.56.0")
14
SET(NEEDED_BOOST_LIBS thread iostreams filesystem system program_options regex)
Dave Moxey's avatar
Dave Moxey committed
15

16
SET(Boost_NO_BOOST_CMAKE ON)
17
IF( BOOST_ROOT )
18
    SET(Boost_NO_SYSTEM_PATHS ON)
Dave Moxey's avatar
Dave Moxey committed
19
    FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS})
20 21 22 23 24
ELSE ()
    SET(TEST_ENV1 $ENV{BOOST_HOME})
    SET(TEST_ENV2 $ENV{BOOST_DIR})
    IF (DEFINED TEST_ENV1)
        SET(BOOST_ROOT $ENV{BOOST_HOME})
25
        SET(Boost_NO_SYSTEM_PATHS ON)
26
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
27 28
    ELSEIF (DEFINED TEST_ENV2)
        SET(BOOST_ROOT $ENV{BOOST_DIR})
29
        SET(Boost_NO_SYSTEM_PATHS ON)
30
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
31 32
    ELSE ()
        SET(BOOST_ROOT ${TPDIST})
33
        FIND_PACKAGE( Boost ${MIN_VER} QUIET COMPONENTS ${NEEDED_BOOST_LIBS} )
34 35 36 37 38 39
    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)
40
    IF (Boost_${FOUND_VAR_UPPER}_FOUND)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
        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})
56 57 58
SET(Boost_USE_MULTITHREADED ON CACHE BOOL
    "Search for multithreaded boost libraries")
MARK_AS_ADVANCED(Boost_USE_MULTITHREADED)
59

60

61
IF (WIN32)
Jeremy Cohen's avatar
Jeremy Cohen committed
62
    ADD_DEFINITIONS("-DBOOST_ALL_NO_LIB")
63 64
ENDIF()

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

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

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

80 81 82
    # Build Boost: first need to select toolset. Some will have specific
    # versions.
    SET(TOOLSET_VERSION "")
83
    IF (APPLE)
84
        # macOS should have the darwin toolset regardless of gcc/clang.
85
        SET(TOOLSET darwin)
86 87
    ELSEIF (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
        SET(TOOLSET msvc)
Dave Moxey's avatar
Dave Moxey committed
88
        IF (MSVC_VERSION EQUAL 1600)
89
            SET(TOOLSET_VERSION 10.0) # Visual Studio 2010
Dave Moxey's avatar
Dave Moxey committed
90
        ELSEIF (MSVC_VERSION EQUAL 1700)
91
            SET(TOOLSET_VERSION 11.0) # Visual Studio 2012
Dave Moxey's avatar
Dave Moxey committed
92
        ELSEIF (MSVC_VERSION EQUAL 1800)
93
            SET(TOOLSET_VERSION 12.0) # Visual Studio 2013
Dave Moxey's avatar
Dave Moxey committed
94
        ELSEIF (MSVC_VERSION EQUAL 1900)
95
            SET(TOOLSET_VERSION 14.0) # Visual Studio 2015
Dave Moxey's avatar
Dave Moxey committed
96
        ELSEIF (MSVC_VERSION GREATER 1909 AND MSVC_VERSION LESS 1920)
97
            SET(TOOLSET_VERSION 14.1) # Visual Studio 2017
Dave Moxey's avatar
Dave Moxey committed
98
        ELSEIF (MSVC_VERSION GREATER 1919 AND MSVC_VERSION LESS 1930)
99
            SET(TOOLSET_VERSION 14.2) # Visual Studio 2019
Dave Moxey's avatar
Dave Moxey committed
100
        ENDIF()
101
    ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Cray")
Dave Moxey's avatar
Dave Moxey committed
102
        SET(TOOLSET cray)
103 104 105 106
    ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
        SET(TOOLSET intel)
    ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
        SET(TOOLSET gcc)
107
        SET(TOOLSET_VERSION ${CMAKE_CXX_COMPILER_VERSION})
108 109
    ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
        SET(TOOLSET clang)
110
        SET(TOOLSET_VERSION ${CMAKE_CXX_COMPILER_VERSION})
111
    ELSE()
Dave Moxey's avatar
Dave Moxey committed
112
        MESSAGE(STATUS "Unknown compiler for boost, assuming gcc toolset")
113 114 115 116 117 118 119
        SET(TOOLSET gcc)
    ENDIF()

    IF (TOOLSET_VERSION STREQUAL "")
        SET(TOOLSET_CMDLINE ${TOOLSET})
    ELSE()
        SET(TOOLSET_CMDLINE ${TOOLSET}-${TOOLSET_VERSION})
120
    ENDIF()
Chris Cantwell's avatar
Chris Cantwell committed
121

Dave Moxey's avatar
Dave Moxey committed
122
    IF (NOT WIN32)
Dave Moxey's avatar
Dave Moxey committed
123 124 125
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Jeremy Cohen's avatar
Jeremy Cohen committed
126 127
            URL ${TPURL}/boost_1_71_0.tar.bz2
            URL_MD5 "4cdf9b5c2dc01fb2b7b733d5af30e558"
Dave Moxey's avatar
Dave Moxey committed
128 129 130 131 132 133
            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
134
            CONFIGURE_COMMAND ./bootstrap.sh
135
            BUILD_COMMAND NO_BZIP2=1 ./b2
Dave Moxey's avatar
Dave Moxey committed
136 137 138
                variant=release
                link=shared
                include=${TPDIST}/include
139
                cxxflags="-w"
Dave Moxey's avatar
Dave Moxey committed
140 141
                linkflags="-L${TPDIST}/lib"
                ${BOOST_FLAGS} ${BOOST_LIB_LIST}
Michael Turner's avatar
Michael Turner committed
142
		--prefix=${TPDIST}
143
                --layout=system toolset=${TOOLSET_CMDLINE} install
144
            INSTALL_COMMAND ""
Dave Moxey's avatar
Dave Moxey committed
145 146
            )
    ELSE ()
147 148
	    MESSAGE(STATUS "Windows MSVC build - toolset is: ${TOOLSET_CMDLINE}")
        IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
Dave Moxey's avatar
Dave Moxey committed
149 150 151 152
            SET(ADDRESS_MODEL 64)
        ELSE()
            SET(ADDRESS_MODEL 32)
        ENDIF()
153
		MESSAGE(STATUS "Windows MSVC build - address model is: ${ADDRESS_MODEL}")
154 155 156
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Jeremy Cohen's avatar
Jeremy Cohen committed
157 158
            URL ${TPURL}/boost_1_71_0.tar.bz2
            URL_MD5 "4cdf9b5c2dc01fb2b7b733d5af30e558"
159
            STAMP_DIR ${TPBUILD}/stamp
160
            DOWNLOAD_DIR ${TPSRC}
161
            SOURCE_DIR ${TPBUILD}/boost
162 163 164
            BINARY_DIR ${TPBUILD}/boost
            TMP_DIR ${TPBUILD}/boost-tmp
            INSTALL_DIR ${TPDIST}
165 166
            CONFIGURE_COMMAND call bootstrap.bat
            BUILD_COMMAND b2 variant=release
167
                toolset=${TOOLSET_CMDLINE}
Dave Moxey's avatar
Dave Moxey committed
168 169 170 171 172 173 174 175 176 177
                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
178
            INSTALL_COMMAND ""
Dave Moxey's avatar
Dave Moxey committed
179 180
            )
    ENDIF()
Dave Moxey's avatar
Dave Moxey committed
181

182 183
    IF (APPLE)
        EXTERNALPROJECT_ADD_STEP(boost patch-install-path
Dave Moxey's avatar
Dave Moxey committed
184 185
            COMMAND sed -i ".bak" "s|-install_name \"|&${TPDIST}/lib/|"
                ${TPBUILD}/boost/tools/build/src/tools/darwin.jam
186 187 188 189
            DEPENDERS build
            DEPENDEES download)
    ENDIF (APPLE)

190
    # Write to jamfile to use appropriate toolset.
Dave Moxey's avatar
Dave Moxey committed
191
    SET(cmd_string "using ${TOOLSET} : ${TOOLSET_VERSION}")
Dave Moxey's avatar
Dave Moxey committed
192
    SET(cmd_string "${cmd_string} : ${CMAKE_CXX_COMPILER} $<SEMICOLON>")
Dave Moxey's avatar
Dave Moxey committed
193

Michael Turner's avatar
Michael Turner committed
194 195
    IF (UNIX)
	EXTERNALPROJECT_ADD_STEP(boost conf-project-conf
Dave Moxey's avatar
Dave Moxey committed
196 197
            COMMAND cmake -E echo "${cmd_string}" >
                ${TPBUILD}/boost/tools/build/src/user-config.jam
Michael Turner's avatar
Michael Turner committed
198 199 200 201
            DEPENDERS build
            DEPENDEES configure)
    ENDIF()

202 203 204 205 206 207
    # 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
208 209 210 211 212 213 214
    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()
215

216
    SET(Boost_INCLUDE_DIRS ${TPSRC}/dist/include)
217
    SET(Boost_CONFIG_INCLUDE_DIR ${TPINC})
218
    SET(Boost_LIBRARY_DIRS ${TPSRC}/dist/lib)
219
    SET(Boost_CONFIG_LIBRARY_DIR ${TPLIB})
220

Chris Cantwell's avatar
Chris Cantwell committed
221
    INCLUDE_DIRECTORIES(SYSTEM ${TPDIST}/include)
222

223 224
    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
225
ELSE (THIRDPARTY_BUILD_BOOST)
226
    ADD_CUSTOM_TARGET(boost ALL)
227 228 229
    IF (BOOST_THREAD_LIBRARY)
        MARK_AS_ADVANCED(BOOST_THREAD_LIBRARY)
    ENDIF (BOOST_THREAD_LIBRARY)
230 231
    SET(Boost_CONFIG_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
    SET(Boost_CONFIG_LIBRARY_DIR ${Boost_LIBRARY_DIRS})
232
ENDIF (THIRDPARTY_BUILD_BOOST)
233

Chris Cantwell's avatar
Chris Cantwell committed
234
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})