1 # - Try to find Boost include dirs and libraries
2 # Usage of this module as follows:
3 #
4 # FIND_PACKAGE( Boost COMPONENTS date_time filesystem iostreams ... )
5 #
6 # The Boost_ADDITIONAL_VERSIONS variable can be used to specify a list of
7 # boost version numbers that should be taken into account when searching
8 # for the libraries. Unfortunately boost puts the version number into the
9 # actual filename for the libraries, so this might be needed in the future
10 # when new boost versions are released.
11 #
12 # Currently this module searches for the following version numbers:
13 # 1.33, 1.33.0, 1.33.1, 1.34, 1.34.0, 1.34.1
14 #
15 # The components list needs to be the actual names of boost libraries, that is
16 # the part of the actual library files that differ on different libraries. So
17 # its "date_time" for "libboost_date_time...". Anything else will result in
18 # errors
19 #
20 # Variables used by this module, they can change the default behaviour:
21 # Boost_USE_NONMULTITHREAD Can be set to TRUE to use the non-multithreaded
22 # boost libraries.
23 # Boost_ADDITIONAL_VERSIONS A list of version numbers to use for searching
24 # the boost include directory. The default list
25 # of version numbers is:
26 # 1.33, 1.33.0, 1.33.1, 1.34, 1.34.0, 1.34.1
27 # If you want to look for an older or newer
28 # version set this variable to a list of
29 # strings, where each string contains a number, i.e.
30 # SET(Boost_ADDITIONAL_VERSIONS "0.99.0" "1.35.0")
31 # Boost_ROOT Preferred installation prefix for searching for Boost,
32 # set this if the module has problems finding the proper Boost installation
33 # Boost_INCLUDEDIR Set this to the include directory of Boost, if the
34 # module has problems finding the proper Boost installation
35 # Boost_LIBRARYDIR Set this to the lib directory of Boost, if the
36 # module has problems finding the proper Boost installation
37 #
38 # The last three variables are available also as environment variables
39 #
40 #
41 # Variables defined by this module:
42 #
43 # Boost_FOUND System has Boost, this means the include dir was found,
44 # as well as all the libraries specified in the COMPONENTS list
45 # Boost_INCLUDE_DIRS Boost include directories, not cached
46 # Boost_INCLUDE_DIR This is almost the same as above, but this one is cached and may be
47 # modified by advanced users
48 # Boost_LIBRARIES Link these to use the Boost libraries that you specified, not cached
49 # Boost_LIBRARY_DIRS The path to where the Boost library files are.
50 # Boost_VERSION The version number of the boost libraries that have been found,
51 # same as in version.hpp from Boost
52 # Boost_LIB_VERSION The version number in filename form as its appended to the library filenames
53 # Boost_MAJOR_VERSION major version number of boost
54 # Boost_MINOR_VERSION minor version number of boost
55 # Boost_SUBMINOR_VERSION subminor version number of boost
57 # For each component you list the following variables are set.
58 # ATTENTION: The component names need to be in lower case, just as the boost
59 # library names however the cmake variables use upper case for the component
60 # part. So you'd get Boost_SERIALIZATION_FOUND for example.
61 #
62 # Boost_${COMPONENT}_FOUND True IF the Boost library "component" was found.
63 # Boost_${COMPONENT}_LIBRARY The absolute path of the Boost library "component".
64 # Boost_${COMPONENT}_LIBRARY_DEBUG The absolute path of the debug version of the
65 # Boost library "component".
66 # Boost_${COMPONENT}_LIBRARY_RELEASE The absolute path of the release version of the
67 # Boost library "component"
68 #
69 # Copyright (c) 2006-2008 Andreas Schneider <mail@cynapses.org>
70 # Copyright (c) 2007 Wengo
71 # Copyright (c) 2007 Mike Jackson
72 # Copyright (c) 2008 Andreas Pakulat <apaku@gmx.de>
73 #
74 # Redistribution AND use is allowed according to the terms of the New
75 # BSD license.
76 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
77 #
79 # MESSAGE(STATUS "Finding Boost libraries.... ")
81 SET( _boost_TEST_VERSIONS ${Boost_ADDITIONAL_VERSIONS} "1.33" "1.33.0" "1.33.1" "1.34" "1.34.0" "1.34.1" )
83 ############################################
84 #
85 # Check the existence of the libraries.
86 #
87 ############################################
88 # This macro was taken directly from the FindQt4.cmake file that is included
89 # with the CMake distribution. This is NOT my work. All work was done by the
90 # original authors of the FindQt4.cmake file. Only minor modifications were
91 # made to remove references to Qt and make this file more generally applicable
92 #########################################################################
94 MACRO (_Boost_ADJUST_LIB_VARS basename)
95 IF (Boost_INCLUDE_DIR )
96 #MESSAGE(STATUS "Adjusting ${basename} ")
98 IF (Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
99 # if the generator supports configuration types then set
100 # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
101 IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
102 SET(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
103 ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
104 # if there are no configuration types and CMAKE_BUILD_TYPE has no value
105 # then just use the release libraries
106 SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} )
107 ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
108 SET(Boost_${basename}_LIBRARIES optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
109 ENDIF (Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
111 # if only the release version was found, set the debug variable also to the release version
112 IF (Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
113 SET(Boost_${basename}_LIBRARY_DEBUG ${Boost_${basename}_LIBRARY_RELEASE})
114 SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE})
115 SET(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE})
116 ENDIF (Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
118 # if only the debug version was found, set the release variable also to the debug version
119 IF (Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
120 SET(Boost_${basename}_LIBRARY_RELEASE ${Boost_${basename}_LIBRARY_DEBUG})
121 SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_DEBUG})
122 SET(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_DEBUG})
123 ENDIF (Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
125 IF (Boost_${basename}_LIBRARY)
126 SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY} CACHE FILEPATH "The Boost ${basename} library")
127 GET_FILENAME_COMPONENT(Boost_LIBRARY_DIRS "${Boost_${basename}_LIBRARY}" PATH)
128 SET(Boost_${basename}_FOUND 1)
129 ENDIF (Boost_${basename}_LIBRARY)
131 ENDIF (Boost_INCLUDE_DIR )
132 # Make variables changeble to the advanced user
133 MARK_AS_ADVANCED(
134 Boost_${basename}_LIBRARY
135 Boost_${basename}_LIBRARY_RELEASE
136 Boost_${basename}_LIBRARY_DEBUG
137 )
138 ENDMACRO (_Boost_ADJUST_LIB_VARS)
140 #-------------------------------------------------------------------------------
143 SET( _boost_IN_CACHE TRUE)
145 IF(Boost_INCLUDE_DIR)
146 FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
147 STRING(TOUPPER ${COMPONENT} COMPONENT)
148 IF(NOT Boost_${COMPONENT}_FOUND)
149 SET( _boost_IN_CACHE FALSE)
150 ENDIF(NOT Boost_${COMPONENT}_FOUND)
151 ENDFOREACH(COMPONENT)
152 ELSE(Boost_INCLUDE_DIR)
153 SET( _boost_IN_CACHE FALSE)
154 ENDIF(Boost_INCLUDE_DIR)
156 IF (_boost_IN_CACHE)
157 # in cache already
158 SET(Boost_FOUND TRUE)
159 FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
160 STRING(TOUPPER ${COMPONENT} COMPONENT)
161 _Boost_ADJUST_LIB_VARS( ${COMPONENT} )
162 ENDFOREACH(COMPONENT)
163 SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
164 ELSE (_boost_IN_CACHE)
165 # Need to search for boost
167 SET(_boost_INCLUDE_SEARCH_DIRS
168 C:/boost/include
169 "C:/Program Files/boost/boost_${Boost_REQUIRED_VERSION}"
170 # D: is very often the cdrom drive, IF you don't have a
171 # cdrom inserted it will popup a very annoying dialog
172 #D:/boost/include
173 /sw/local/include
174 )
176 SET(_boost_LIBRARIES_SEARCH_DIRS
177 C:/boost/lib
178 "C:/Program Files/boost/boost_${Boost_REQUIRED_VERSION}/lib"
179 /sw/local/lib
180 )
182 IF( NOT $ENV{Boost_ROOT} STREQUAL "" )
183 SET(_boost_INCLUDE_SEARCH_DIRS $ENV{Boost_ROOT}/include ${_boost_INCLUDE_SEARCH_DIRS})
184 SET(_boost_LIBRARIES_SEARCH_DIRS $ENV{Boost_ROOT}/lib ${_boost_INCLUDE_SEARCH_DIRS})
185 ENDIF( NOT $ENV{Boost_ROOT} STREQUAL "" )
187 IF( NOT $ENV{Boost_INCLUDEDIR} STREQUAL "" )
188 SET(_boost_INCLUDE_SEARCH_DIRS $ENV{Boost_INCLUDEDIR} ${_boost_INCLUDE_SEARCH_DIRS})
189 ENDIF( NOT $ENV{Boost_INCLUDEDIR} STREQUAL "" )
191 IF( NOT $ENV{Boost_LIBRARYDIR} STREQUAL "" )
192 SET(_boost_LIBRARIES_SEARCH_DIRS $ENV{Boost_LIBRARYDIR} ${_boost_INCLUDE_SEARCH_DIRS})
193 ENDIF( NOT $ENV{Boost_LIBRARYDIR} STREQUAL "" )
195 IF( Boost_ROOT )
196 SET(_boost_INCLUDE_SEARCH_DIRS ${Boost_ROOT}/include ${_boost_INCLUDE_SEARCH_DIRS})
197 SET(_boost_LIBRARIES_SEARCH_DIRS ${Boost_ROOT}/lib ${_boost_LIBRARIES_SEARCH_DIRS})
198 ENDIF( Boost_ROOT )
200 IF( Boost_INCLUDEDIR )
201 SET(_boost_INCLUDE_SEARCH_DIRS ${Boost_INCLUDEDIR}/include ${_boost_INCLUDE_SEARCH_DIRS})
202 ENDIF( Boost_INCLUDEDIR )
204 IF( Boost_LIBRARYDIR )
205 SET(_boost_LIBRARIES_SEARCH_DIRS ${Boost_LIBRARYDIR}/include ${_boost_LIBRARIES_SEARCH_DIRS})
206 ENDIF( Boost_LIBRARYDIR )
208 FOREACH(_boost_VER ${_boost_TEST_VERSIONS})
209 IF( NOT Boost_INCLUDE_DIR )
211 # Add in a path suffix, based on the required version, ideally we could
212 # read this from version.hpp, but for that to work we'd need to know the include
213 # dir already
214 SET(_boost_PATH_SUFFIX
215 boost-${_boost_VER}
216 )
217 STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1_\\2_\\3" _boost_PATH_SUFFIX ${_boost_PATH_SUFFIX})
220 FIND_PATH(Boost_INCLUDE_DIR
221 NAMES boost/config.hpp
222 PATHS ${_boost_INCLUDE_SEARCH_DIRS}
223 PATH_SUFFIXES ${_boost_PATH_SUFFIX}
224 )
226 # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
227 # Read the whole file:
228 #
229 SET(BOOST_VERSION 0)
230 SET(BOOST_LIB_VERSION "")
231 FILE(READ "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS)
233 STRING(REGEX REPLACE ".*#define BOOST_VERSION ([0-9]+).*" "\\1" Boost_VERSION "${_boost_VERSION_HPP_CONTENTS}")
234 STRING(REGEX REPLACE ".*#define BOOST_LIB_VERSION \"([0-9_]+)\".*" "\\1" Boost_LIB_VERSION "${_boost_VERSION_HPP_CONTENTS}")
236 SET(Boost_LIB_VERSION ${Boost_LIB_VERSION} CACHE STRING "The library version string for boost libraries")
237 SET(Boost_VERSION ${Boost_VERSION} CACHE STRING "The version number for boost libraries")
239 IF(NOT "${Boost_VERSION}" STREQUAL "0")
240 MATH(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000")
241 MATH(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000")
242 MATH(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100")
243 ENDIF(NOT "${Boost_VERSION}" STREQUAL "0")
246 ENDIF( NOT Boost_INCLUDE_DIR )
247 ENDFOREACH(_boost_VER)
249 #Setting some more suffixes for the library
250 SET (Boost_LIB_PREFIX "")
251 IF ( WIN32 )
252 SET (Boost_LIB_PREFIX "lib")
253 ENDIF ( WIN32 )
254 SET (_boost_COMPILER "-gcc")
255 IF (MSVC71)
256 SET (_boost_COMPILER "-vc71")
257 ENDIF(MSVC71)
258 IF (MSVC80)
259 SET (_boost_COMPILER "-vc80")
260 ENDIF(MSVC80)
261 IF (MINGW)
262 SET (_boost_COMPILER "-mgw")
263 ENDIF(MINGW)
264 IF (CYGWIN)
265 SET (_boost_COMPILER "-gcc")
266 ENDIF (CYGWIN)
267 IF (UNIX)
268 IF (APPLE)
269 SET (_boost_COMPILER "")
270 ELSE (APPLE)
271 IF (NOT CMAKE_COMPILER_IS_GNUCC)
272 # This is for the intel compiler
273 SET (_boost_COMPILER "-il")
274 ELSE (NOT CMAKE_COMPILER_IS_GNUCC)
275 #find out the version of gcc being used.
276 EXEC_PROGRAM(${CMAKE_CXX_COMPILER}
277 ARGS --version
278 OUTPUT_VARIABLE _boost_COMPILER_VERSION
279 )
280 STRING(REGEX REPLACE ".* ([0-9])\\.([0-9])\\.[0-9] .*" "\\1\\2"
281 _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION})
282 SET (_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}")
283 ENDIF (NOT CMAKE_COMPILER_IS_GNUCC)
284 ENDIF (APPLE)
285 ENDIF(UNIX)
287 SET (_boost_MULTITHREADED "-mt")
289 IF( Boost_USE_NONMULTITHREADED )
290 SET (_boost_MULTITHREADED "")
291 ENDIF( Boost_USE_NONMULTITHREADED )
293 SET( _boost_STATIC_TAG "")
294 IF (WIN32)
295 SET (_boost_ABI_TAG "g")
296 SET( _boost_STATIC_TAG "-s")
297 ENDIF(WIN32)
298 SET (_boost_ABI_TAG "${_boost_ABI_TAG}d")
300 # ------------------------------------------------------------------------
301 # Begin finding boost libraries
302 # ------------------------------------------------------------------------
303 FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
304 STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
305 SET( Boost_{UPPERCOMPONENT}_LIBRARY FALSE)
306 SET( Boost_{UPPERCOMPONENT}_LIBRARY_RELEASE FALSE)
307 SET( Boost_{UPPERCOMPONENT}_LIBRARY_DEBUG FALSE)
308 FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE
309 NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${Boost_LIB_VERSION}
310 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}-${Boost_LIB_VERSION}
311 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}
312 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}
313 ${Boost_LIB_PREFIX}boost_${COMPONENT}
314 PATHS ${_boost_LIBRARIES_SEARCH_DIRS}
315 NO_DEFAULT_PATH
316 )
318 IF( NOT ${Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE} )
319 FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE
320 NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${Boost_LIB_VERSION}
321 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}-${Boost_LIB_VERSION}
322 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}
323 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}
324 ${Boost_LIB_PREFIX}boost_${COMPONENT}
325 )
326 ENDIF( NOT ${Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE} )
328 FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG
329 NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${_boost_ABI_TAG}-${Boost_LIB_VERSION}
330 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}-${Boost_LIB_VERSION}
331 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}-${_boost_ABI_TAG}
332 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}
333 ${Boost_LIB_PREFIX}boost_${COMPONENT}-${_boost_ABI_TAG}
334 PATHS ${_boost_LIBRARIES_SEARCH_DIRS}
335 NO_DEFAULT_PATH
336 )
338 IF( NOT ${Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG} )
339 FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG
340 NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${_boost_ABI_TAG}-${Boost_LIB_VERSION}
341 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}-${Boost_LIB_VERSION}
342 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}-${_boost_ABI_TAG}
343 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}
344 ${Boost_LIB_PREFIX}boost_${COMPONENT}-${_boost_ABI_TAG}
345 )
346 ENDIF( NOT ${Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG} )
347 _Boost_ADJUST_LIB_VARS(${UPPERCOMPONENT})
348 ENDFOREACH(COMPONENT)
349 # ------------------------------------------------------------------------
350 # End finding boost libraries
351 # ------------------------------------------------------------------------
353 SET(Boost_INCLUDE_DIRS
354 ${Boost_INCLUDE_DIR}
355 )
357 # MESSAGE(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
358 # MESSAGE(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
360 SET(Boost_FOUND FALSE)
361 IF(Boost_INCLUDE_DIR)
362 SET( Boost_FOUND TRUE )
363 FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
364 STRING(TOUPPER ${COMPONENT} COMPONENT)
365 IF(NOT Boost_${COMPONENT}_FOUND)
366 SET( Boost_FOUND FALSE)
367 ENDIF(NOT Boost_${COMPONENT}_FOUND)
368 ENDFOREACH(COMPONENT)
369 ELSE(Boost_INCLUDE_DIR)
370 SET( Boost_FOUND FALSE)
371 ENDIF(Boost_INCLUDE_DIR)
373 IF (Boost_FOUND)
374 IF (NOT Boost_FIND_QUIETLY)
375 MESSAGE(STATUS "Found The Following Boost Libraries:")
376 FOREACH ( COMPONENT ${Boost_FIND_COMPONENTS} )
377 STRING( TOUPPER ${COMPONENT} UPPERCOMPONENT )
378 IF ( Boost_${UPPERCOMPONENT}_FOUND )
379 MESSAGE (STATUS " ${COMPONENT}")
380 SET(Boost_LIBRARIES ${Boost_LIBRARIES} ${Boost_${UPPERCOMPONENT}_LIBRARY})
381 ENDIF ( Boost_${UPPERCOMPONENT}_FOUND )
382 ENDFOREACH(COMPONENT)
383 MESSAGE(STATUS "Boost Version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
384 ENDIF(NOT Boost_FIND_QUIETLY)
385 ELSE (Boost_FOUND)
386 IF (Boost_FIND_REQUIRED)
387 MESSAGE(FATAL_ERROR "Please install the Boost libraries AND development packages")
388 ENDIF(Boost_FIND_REQUIRED)
389 ENDIF(Boost_FOUND)
391 # Under Windows, automatic linking is performed, so no need to specify the libraries.
392 IF (WIN32)
393 SET(Boost_LIBRARIES "")
394 ENDIF(WIN32)
396 # show the Boost_INCLUDE_DIRS AND Boost_LIBRARIES variables only in the advanced view
397 MARK_AS_ADVANCED(Boost_INCLUDE_DIRS
398 Boost_LIBRARIES
399 Boost_LIBRARY_DIRS
400 )
401 ENDIF(_boost_IN_CACHE)