ThirdPartyBoost.cmake 7.61 KB
Newer Older
1
OPTION(THIRDPARTY_BUILD_BOOST "Build Boost libraries" OFF)
2
3
4
SET(Boost_USE_MULTITHREADED ON CACHE BOOL
    "Search for multithreaded boost libraries")
MARK_AS_ADVANCED(Boost_USE_MULTITHREADED)
5

6
7
8
9
IF (WIN32)
    ADD_DEFINITIONS("-DBOOST_ALL_NO_LIB")
ENDIF()

10
11
IF (THIRDPARTY_BUILD_BOOST)
    INCLUDE(ExternalProject)
12
13
14
15
16

    # Only build the libraries we need
    SET(BOOST_LIB_LIST --with-system --with-iostreams --with-filesystem 
                       --with-program_options --with-date_time --with-thread
                       --with-regex)
17
   
18
19
	IF (NOT WIN32)
    # We need -fPIC for 64-bit builds
20
21
22
        IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
            SET(BOOST_FLAGS cxxflags=-fPIC cflags=-fPIC linkflags=-fPIC)
        ENDIF ()
23
24
25
26
27
28
29
30
31
32
33
    ENDIF()

	# Build Boost
    IF (APPLE)
        SET(TOOLSET darwin)
    ELSE(APPLE)
        SET(TOOLSET gcc)
    ENDIF(APPLE)

	IF (NOT WIN32)
    	EXTERNALPROJECT_ADD(
Dave Moxey's avatar
Dave Moxey committed
34
35
36
37
38
39
40
41
42
43
44
	    boost
	    PREFIX ${TPSRC}
	    URL ${TPURL}/boost_1_55_0.tar.bz2
	    URL_MD5 "d6eef4b4cacb2183f2bf265a5a03a354"
	    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}
45
46
47
            BUILD_COMMAND NO_BZIP2=1 ./b2
                            variant=release
                            link=shared 
48
49
                            include=${TPDIST}/include
                            linkflags="-L${TPDIST}/lib"
50
                            ${BOOST_FLAGS} ${BOOST_LIB_LIST} 
51
                            --layout=system toolset=${TOOLSET} install
52
53
            INSTALL_COMMAND ""
        )
54
	ELSE ()
55
56
57
        EXTERNALPROJECT_ADD(
            boost
            PREFIX ${TPSRC}
Chris Cantwell's avatar
Chris Cantwell committed
58
59
            URL ${TPURL}/boost_1_55_0.tar.bz2
            URL_MD5 "d6eef4b4cacb2183f2bf265a5a03a354"
60
            STAMP_DIR ${TPBUILD}/stamp
61
            DOWNLOAD_DIR ${TPSRC}
62
            SOURCE_DIR ${TPBUILD}/boost
63
64
65
            BINARY_DIR ${TPBUILD}/boost
            TMP_DIR ${TPBUILD}/boost-tmp
            INSTALL_DIR ${TPDIST}
66
67
68
            CONFIGURE_COMMAND call bootstrap.bat
            BUILD_COMMAND b2 variant=release
                             toolset=msvc-12.0
Dave Moxey's avatar
Dave Moxey committed
69
70
71
72
73
74
75
                             address-model=32
	                     -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
76
77
            INSTALL_COMMAND ""
        )
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
	ENDIF()
    
    IF (APPLE)
        EXTERNALPROJECT_ADD_STEP(boost patch-install-path
            COMMAND sed -i ".bak" "s|-install_name \"|&${TPDIST}/lib/|" ${TPSRC}/boost/tools/build/v2/tools/darwin.jam
            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
Dave Moxey's avatar
Dave Moxey committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    IF (WIN32)
	SET(Boost_DATE_TIME_LIBRARY libboost_date_time)
	SET(Boost_DATE_TIME_LIBRARY_DEBUG libboost_date_time)
	SET(Boost_DATE_TIME_LIBRARY_RELEASE libboost_date_time)
	SET(Boost_FILESYSTEM_LIBRARY libboost_filesystem)
	SET(Boost_FILESYSTEM_LIBRARY_DEBUG libboost_filesystem)
	SET(Boost_FILESYSTEM_LIBRARY_RELEASE libboost_filesystem)
	SET(Boost_IOSTREAMS_LIBRARY libboost_iostreams)
	SET(Boost_IOSTREAMS_LIBRARY_DEBUG libboost_iostreams)
	SET(Boost_IOSTREAMS_LIBRARY_RELEASE libboost_iostreams)
	SET(Boost_PROGRAM_OPTIONS_LIBRARY libboost_program_options)
	SET(Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG libboost_program_options)
	SET(Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE libboost_program_options)
	SET(Boost_REGEX_LIBRARY libboost_regex)
	SET(Boost_REGEX_LIBRARY_DEBUG libboost_regex)
	SET(Boost_REGEX_LIBRARY_RELEASE libboost_regex)
	SET(Boost_SYSTEM_LIBRARY libboost_system)
	SET(Boost_SYSTEM_LIBRARY_DEBUG libboost_system)
	SET(Boost_SYSTEM_LIBRARY_RELEASE libboost_system)
	SET(Boost_THREAD_LIBRARY libboost_thread)
	SET(Boost_THREAD_LIBRARY_DEBUG libboost_thread)
	SET(Boost_THREAD_LIBRARY_RELEASE libboost_thread)
	SET(Boost_INCLUDE_DIRS ${TPDIST}/include)
	SET(Boost_LIBRARY_DIRS ${TPDIST}/lib)
	MESSAGE(STATUS ${Boost_DATE_TIME_LIBRARY})
	LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
    ELSE()
	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 
	    ${TPSRC}/dist/include/boost-1_49)
	SET(Boost_LIBRARY_DIRS ${TPSRC}/dist/lib)
	LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
    ENDIF()
ELSE (THIRDPARTY_BUILD_BOOST)
147
    ADD_CUSTOM_TARGET(boost ALL)
148
    SET(Boost_DEBUG 0)
149
    SET(Boost_NO_BOOST_CMAKE ON)
150
    #If the user has not set BOOST_ROOT, look in a couple common places first.
151
    IF( NOT BOOST_ROOT )
152
153
154
        SET(TEST_ENV1 $ENV{BOOST_HOME})
        SET(TEST_ENV2 $ENV{BOOST_DIR})
        IF (DEFINED TEST_ENV1)
155
            SET(BOOST_ROOT $ENV{BOOST_HOME})
156
            FIND_PACKAGE( Boost QUIET COMPONENTS thread iostreams date_time
157
                filesystem system program_options regex )
158
159
160
161
        ELSEIF (DEFINED TEST_ENV2)
            SET(BOOST_ROOT $ENV{BOOST_DIR})
            FIND_PACKAGE( Boost QUIET COMPONENTS thread iostreams date_time
                filesystem system program_options regex )
162
        ELSE ()
Dave Moxey's avatar
Dave Moxey committed
163
164
	    SET(BOOST_ROOT ${TPDIST})
	    FIND_PACKAGE( Boost QUIET COMPONENTS thread iostreams date_time filesystem system program_options regex)
165
        ENDIF()
166
    ELSE()
167
        FIND_PACKAGE( Boost COMPONENTS thread iostreams zlib date_time filesystem system program_options regex)
168
    ENDIF()
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
    IF (Boost_IOSTREAMS_FOUND)
        MESSAGE(STATUS "Found Boost iostreams library: ${Boost_IOSTREAMS_LIBRARY}")
    ENDIF ()
    IF (Boost_THREAD_FOUND)
        MESSAGE(STATUS "Found Boost thread library: ${Boost_THREAD_LIBRARY}")
    ENDIF ()
    IF (Boost_DATE_TIME_FOUND)
        MESSAGE(STATUS "Found Boost date_time library: ${Boost_DATE_TIME_LIBRARY}")
    ENDIF ()
    IF (Boost_FILESYSTEM_FOUND)
        MESSAGE(STATUS "Found Boost filesystem library: ${Boost_FILESYSTEM_LIBRARY}")
    ENDIF ()
    IF (Boost_SYSTEM_FOUND)
        MESSAGE(STATUS "Found Boost system library: ${Boost_SYSTEM_LIBRARY}")
    ENDIF ()
    IF (Boost_PROGRAM_OPTIONS_FOUND)
        MESSAGE(STATUS "Found Boost program_options library: ${Boost_PROGRAM_OPTIONS_LIBRARY}")
    ENDIF ()
    IF (Boost_REGEX_FOUND)
        MESSAGE(STATUS "Found Boost regex library: ${Boost_REGEX_LIBRARY}")
    ENDIF ()
190
191
192
    IF (BOOST_THREAD_LIBRARY)
        MARK_AS_ADVANCED(BOOST_THREAD_LIBRARY)
    ENDIF (BOOST_THREAD_LIBRARY)
193
ENDIF (THIRDPARTY_BUILD_BOOST)
194

195
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})