ThirdPartyBoost.cmake 6.23 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
13
# Minimum version and boost libraries required
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
62
63
64
IF (WIN32)
    ADD_DEFINITIONS("-DBOOST_ALL_NO_LIB")
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()

Dave Moxey's avatar
Dave Moxey committed
80
    # Build Boost
81
82
    IF (APPLE)
        SET(TOOLSET darwin)
Dave Moxey's avatar
Dave Moxey committed
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)
90
91
        ELSEIF (MSVC14)
            SET(TOOLSET msvc-14.0)
Dave Moxey's avatar
Dave Moxey committed
92
        ENDIF()
93
    ELSE()
94
        SET(TOOLSET gcc)
95
    ENDIF()
Chris Cantwell's avatar
Chris Cantwell committed
96

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

153
154
    IF (APPLE)
        EXTERNALPROJECT_ADD_STEP(boost patch-install-path
155
            COMMAND sed -i ".bak" "s|-install_name \"|&${TPDIST}/lib/|" ${TPBUILD}/boost/tools/build/src/tools/darwin.jam
156
157
158
159
160
161
162
163
164
165
            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
166
167
168
169
170
171
172
    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()
173

174
    SET(Boost_INCLUDE_DIRS ${TPSRC}/dist/include)
175
    SET(Boost_CONFIG_INCLUDE_DIR ${TPINC})
176
    SET(Boost_LIBRARY_DIRS ${TPSRC}/dist/lib)
177
    SET(Boost_CONFIG_LIBRARY_DIR ${TPLIB})
178

179
180
    INCLUDE_DIRECTORIES(${TPDIST}/include)

181
182
    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
183
ELSE (THIRDPARTY_BUILD_BOOST)
184
    ADD_CUSTOM_TARGET(boost ALL)
185
186
187
    IF (BOOST_THREAD_LIBRARY)
        MARK_AS_ADVANCED(BOOST_THREAD_LIBRARY)
    ENDIF (BOOST_THREAD_LIBRARY)
188
189
    SET(Boost_CONFIG_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
    SET(Boost_CONFIG_LIBRARY_DIR ${Boost_LIBRARY_DIRS})
190
ENDIF (THIRDPARTY_BUILD_BOOST)
191

192
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})