1 # - Try to find Boost include dirs and libraries
2 # Usage of this module as follows:
4 # FIND_PACKAGE( Boost COMPONENTS date_time filesystem iostreams ... )
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.
12 # The components list needs to be the actual names of boost libraries, that is
13 # the part of the actual library files that differ on different libraries. So
14 # its "date_time" for "libboost_date_time...". Anything else will result in
17 # Component "filesystem" will automatically also enable "system" on 1.35 and
18 # later versions, where it depends on that.
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
23 # Boost_ADDITIONAL_VERSIONS A list of version numbers to use for searching
24 # the boost include directory. If you want to look
25 # for an older or newer version set this variable
26 # to a list of strings, where each string
27 # contains a number, i.e.
28 # SET(Boost_ADDITIONAL_VERSIONS "0.99.0" "1.35.0")
29 # Boost_ROOT Preferred installation prefix for searching for Boost,
30 # set this if the module has problems finding the proper Boost installation
31 # Boost_INCLUDEDIR Set this to the include directory of Boost, if the
32 # module has problems finding the proper Boost installation
33 # Boost_LIBRARYDIR Set this to the lib directory of Boost, if the
34 # module has problems finding the proper Boost installation
36 # The last three variables are available also as environment variables
39 # Variables defined by this module:
41 # Boost_FOUND System has Boost, this means the include dir was found,
42 # as well as all the libraries specified in the COMPONENTS list
43 # Boost_INCLUDE_DIRS Boost include directories, not cached
44 # Boost_INCLUDE_DIR This is almost the same as above, but this one is cached and may be
45 # modified by advanced users
46 # Boost_LIBRARIES Link these to use the Boost libraries that you specified, not cached
47 # Boost_LIBRARY_DIRS The path to where the Boost library files are.
48 # Boost_VERSION The version number of the boost libraries that have been found,
49 # same as in version.hpp from Boost
50 # Boost_LIB_VERSION The version number in filename form as its appended to the library filenames
51 # Boost_MAJOR_VERSION major version number of boost
52 # Boost_MINOR_VERSION minor version number of boost
53 # Boost_SUBMINOR_VERSION subminor version number of boost
55 # For each component you list the following variables are set.
56 # ATTENTION: The component names need to be in lower case, just as the boost
57 # library names however the cmake variables use upper case for the component
58 # part. So you'd get Boost_SERIALIZATION_FOUND for example.
60 # Boost_${COMPONENT}_FOUND True IF the Boost library "component" was found.
61 # Boost_${COMPONENT}_LIBRARY The absolute path of the Boost library "component".
62 # Boost_${COMPONENT}_LIBRARY_DEBUG The absolute path of the debug version of the
63 # Boost library "component".
64 # Boost_${COMPONENT}_LIBRARY_RELEASE The absolute path of the release version of the
65 # Boost library "component"
67 # Copyright (c) 2006-2008 Andreas Schneider <mail@cynapses.org>
68 # Copyright (c) 2007 Wengo
69 # Copyright (c) 2007 Mike Jackson
70 # Copyright (c) 2008 Andreas Pakulat <apaku@gmx.de>
72 # Redistribution AND use is allowed according to the terms of the New
74 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
77 # MESSAGE(STATUS "Finding Boost libraries.... ")
79 SET( _boost_TEST_VERSIONS ${Boost_ADDITIONAL_VERSIONS} "1.37.0" "1.37" "1.36.0" "1.36" "1.34.1" "1.34.0" "1.34" "1.33.1" "1.33.0" "1.33")
81 ############################################
83 # Check the existence of the libraries.
85 ############################################
86 # This macro was taken directly from the FindQt4.cmake file that is included
87 # with the CMake distribution. This is NOT my work. All work was done by the
88 # original authors of the FindQt4.cmake file. Only minor modifications were
89 # made to remove references to Qt and make this file more generally applicable
90 #########################################################################
92 MACRO (_Boost_ADJUST_LIB_VARS basename)
93 IF (Boost_INCLUDE_DIR )
94 #MESSAGE(STATUS "Adjusting ${basename} ")
96 IF (Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
97 # if the generator supports configuration types then set
98 # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
99 IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
100 SET(Boost_${basename}_LIBRARY ${Boost_SYSTEM_LIBRARY} ${Boost_${basename}_LIBRARY_RELEASE} )
101 ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
102 IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
103 SET(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
104 ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
105 # if there are no configuration types and CMAKE_BUILD_TYPE has no value
106 # then just use the release libraries
107 SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} )
108 ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
109 ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
110 SET(Boost_${basename}_LIBRARIES optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
111 ENDIF (Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
113 # if only the release version was found, set the debug variable also to the release version
114 IF (Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
115 SET(Boost_${basename}_LIBRARY_DEBUG ${Boost_${basename}_LIBRARY_RELEASE})
116 SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE})
117 SET(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE})
118 ENDIF (Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
120 # if only the debug version was found, set the release variable also to the debug version
121 IF (Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
122 SET(Boost_${basename}_LIBRARY_RELEASE ${Boost_${basename}_LIBRARY_DEBUG})
123 SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_DEBUG})
124 SET(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_DEBUG})
125 ENDIF (Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
127 IF (Boost_${basename}_LIBRARY)
128 SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY} CACHE FILEPATH "The Boost ${basename} library")
129 GET_FILENAME_COMPONENT(Boost_LIBRARY_DIRS "${Boost_${basename}_LIBRARY}" PATH)
130 SET(Boost_${basename}_FOUND 1)
131 ENDIF (Boost_${basename}_LIBRARY)
133 ENDIF (Boost_INCLUDE_DIR )
134 # Make variables changeble to the advanced user
136 Boost_${basename}_LIBRARY
137 Boost_${basename}_LIBRARY_RELEASE
138 Boost_${basename}_LIBRARY_DEBUG
140 ENDMACRO (_Boost_ADJUST_LIB_VARS)
142 #-------------------------------------------------------------------------------
145 SET( _boost_IN_CACHE TRUE)
147 IF(Boost_INCLUDE_DIR)
148 FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
149 STRING(TOUPPER ${COMPONENT} COMPONENT)
150 IF(NOT Boost_${COMPONENT}_FOUND)
151 SET( _boost_IN_CACHE FALSE)
152 ENDIF(NOT Boost_${COMPONENT}_FOUND)
153 ENDFOREACH(COMPONENT)
154 ELSE(Boost_INCLUDE_DIR)
155 SET( _boost_IN_CACHE FALSE)
156 ENDIF(Boost_INCLUDE_DIR)
160 SET(Boost_FOUND TRUE)
161 FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
162 _Boost_ADJUST_LIB_VARS( ${COMPONENT} )
163 ENDFOREACH(COMPONENT)
164 SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
165 ELSE (_boost_IN_CACHE)
166 # Need to search for boost
168 SET(_boost_INCLUDE_SEARCH_DIRS
170 "C:/Program Files/boost/boost_${Boost_REQUIRED_VERSION}"
171 # D: is very often the cdrom drive, IF you don't have a
172 # cdrom inserted it will popup a very annoying dialog
178 SET(_boost_LIBRARIES_SEARCH_DIRS
180 "C:/Program Files/boost/boost_${Boost_REQUIRED_VERSION}/lib"
185 IF( NOT $ENV{Boost_ROOT} STREQUAL "" )
186 SET(_boost_INCLUDE_SEARCH_DIRS $ENV{Boost_ROOT}/include ${_boost_INCLUDE_SEARCH_DIRS})
187 SET(_boost_LIBRARIES_SEARCH_DIRS $ENV{Boost_ROOT}/lib ${_boost_INCLUDE_SEARCH_DIRS})
188 ENDIF( NOT $ENV{Boost_ROOT} STREQUAL "" )
190 IF( NOT $ENV{Boost_INCLUDEDIR} STREQUAL "" )
191 SET(_boost_INCLUDE_SEARCH_DIRS $ENV{Boost_INCLUDEDIR} ${_boost_INCLUDE_SEARCH_DIRS})
192 ENDIF( NOT $ENV{Boost_INCLUDEDIR} STREQUAL "" )
194 IF( NOT $ENV{Boost_LIBRARYDIR} STREQUAL "" )
195 SET(_boost_LIBRARIES_SEARCH_DIRS $ENV{Boost_LIBRARYDIR} ${_boost_LIBRARIES_SEARCH_DIRS})
196 ENDIF( NOT $ENV{Boost_LIBRARYDIR} STREQUAL "" )
199 SET(_boost_INCLUDE_SEARCH_DIRS ${Boost_ROOT}/include)
200 SET(_boost_LIBRARIES_SEARCH_DIRS ${Boost_ROOT}/lib)
203 IF( Boost_INCLUDEDIR )
204 SET(_boost_INCLUDE_SEARCH_DIRS ${Boost_INCLUDEDIR})
205 ENDIF( Boost_INCLUDEDIR )
207 IF( Boost_LIBRARYDIR )
208 SET(_boost_LIBRARIES_SEARCH_DIRS ${Boost_LIBRARYDIR})
209 ENDIF( Boost_LIBRARYDIR )
211 # Search for include/boost_VERSION/boost/config.hpp (all these must be done first)
212 FOREACH(_boost_VER ${_boost_TEST_VERSIONS})
213 IF( NOT Boost_INCLUDE_DIR )
215 # Add in a path suffix, based on the required version, ideally we could
216 # read this from version.hpp, but for that to work we'd need to know the include
218 SET(_boost_PATH_SUFFIX
221 STRING(REGEX REPLACE "\\." "_" _boost_PATH_SUFFIX ${_boost_PATH_SUFFIX})
223 FIND_PATH(Boost_INCLUDE_DIR
224 NAMES ${_boost_PATH_SUFFIX}/boost/config.hpp
225 PATHS ${_boost_INCLUDE_SEARCH_DIRS}
228 # Add boost_VERSION to the path
229 IF( Boost_INCLUDE_DIR )
230 SET(Boost_INCLUDE_DIR "${Boost_INCLUDE_DIR}/${_boost_PATH_SUFFIX}" CACHE PATH "The Boost include path" FORCE)
231 ENDIF( Boost_INCLUDE_DIR )
233 ENDIF( NOT Boost_INCLUDE_DIR )
234 ENDFOREACH(_boost_VER)
236 # Search for include/boost/config.hpp
237 FOREACH(_boost_VER ${_boost_TEST_VERSIONS})
238 IF( NOT Boost_INCLUDE_DIR )
240 # Add in a path suffix, based on the required version, ideally we could
241 # read this from version.hpp, but for that to work we'd need to know the include
243 SET(_boost_PATH_SUFFIX
246 STRING(REGEX REPLACE "\\." "_" _boost_PATH_SUFFIX ${_boost_PATH_SUFFIX})
248 FIND_PATH(Boost_INCLUDE_DIR
249 NAMES boost/config.hpp
250 PATHS ${_boost_INCLUDE_SEARCH_DIRS}
252 ENDIF( NOT Boost_INCLUDE_DIR )
253 ENDFOREACH(_boost_VER)
255 IF( Boost_INCLUDE_DIR )
256 # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
257 # Read the whole file:
259 FILE(READ "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS)
261 STRING(REGEX REPLACE ".*#define BOOST_VERSION ([0-9]+).*" "\\1" Boost_VERSION_NUMERIC "${_boost_VERSION_HPP_CONTENTS}")
262 STRING(REGEX REPLACE ".*#define BOOST_LIB_VERSION \"([0-9_]+)\".*" "\\1" Boost_LIB_VERSION "${_boost_VERSION_HPP_CONTENTS}")
264 IF(Boost_VERSION_NUMERIC GREATER 0)
265 MATH(EXPR Boost_MAJOR_VERSION "${Boost_VERSION_NUMERIC} / 100000")
266 MATH(EXPR Boost_MINOR_VERSION "${Boost_VERSION_NUMERIC} / 100 % 1000")
267 MATH(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION_NUMERIC} % 100")
268 SET(Boost_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
269 ENDIF(Boost_VERSION_NUMERIC GREATER 0)
270 ENDIF( Boost_INCLUDE_DIR )
271 #Setting some more suffixes for the library
272 SET (Boost_LIB_PREFIX "")
274 SET (Boost_LIB_PREFIX "lib")
276 SET (_boost_COMPILER "-gcc")
278 SET (_boost_COMPILER "-vc71")
281 SET (_boost_COMPILER "-vc80")
284 SET (_boost_COMPILER "-mgw")
287 SET (_boost_COMPILER "-gcc")
291 SET (_boost_COMPILER "")
293 IF (NOT CMAKE_COMPILER_IS_GNUCC)
294 # This is for the intel compiler
295 SET (_boost_COMPILER "-il")
296 ELSE (NOT CMAKE_COMPILER_IS_GNUCC)
297 #find out the version of gcc being used.
298 EXEC_PROGRAM(${CMAKE_CXX_COMPILER}
300 OUTPUT_VARIABLE _boost_COMPILER_VERSION
302 STRING(REGEX REPLACE ".* ([0-9])\\.([0-9])\\.[0-9] .*" "\\1\\2"
303 _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION})
304 SET (_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}")
305 ENDIF (NOT CMAKE_COMPILER_IS_GNUCC)
309 SET (_boost_MULTITHREADED "-mt")
311 IF( Boost_USE_NONMULTITHREADED )
312 SET (_boost_MULTITHREADED "")
313 ENDIF( Boost_USE_NONMULTITHREADED )
315 SET( _boost_STATIC_TAG "")
317 SET (_boost_ABI_TAG "g")
318 SET( _boost_STATIC_TAG "-s")
320 SET (_boost_ABI_TAG "${_boost_ABI_TAG}d")
322 # The filesystem library depends on system library on 1.35 and later versions
323 IF(Boost_MAJOR_VERSION EQUAL 1 AND Boost_MINOR_VERSION GREATER 34 AND Boost_FIND_COMPONENTS MATCHES filesystem)
324 SET(Boost_FIND_COMPONENTS ${Boost_FIND_COMPONENTS} system)
325 ENDIF(Boost_MAJOR_VERSION EQUAL 1 AND Boost_MINOR_VERSION GREATER 34 AND Boost_FIND_COMPONENTS MATCHES filesystem)
327 # ------------------------------------------------------------------------
328 # Begin finding boost libraries
329 # ------------------------------------------------------------------------
330 FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
331 SET( Boost_{COMPONENT}_LIBRARY FALSE)
332 SET( Boost_{COMPONENT}_LIBRARY_RELEASE FALSE)
333 SET( Boost_{COMPONENT}_LIBRARY_DEBUG FALSE)
334 FIND_LIBRARY(Boost_${COMPONENT}_LIBRARY_RELEASE
335 NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${Boost_LIB_VERSION}
336 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}-${Boost_LIB_VERSION}
337 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}
338 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}
339 ${Boost_LIB_PREFIX}boost_${COMPONENT}
340 PATHS ${_boost_LIBRARIES_SEARCH_DIRS}
344 IF( NOT ${Boost_${COMPONENT}_LIBRARY_RELEASE} )
345 FIND_LIBRARY(Boost_${COMPONENT}_LIBRARY_RELEASE
346 NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${Boost_LIB_VERSION}
347 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}-${Boost_LIB_VERSION}
348 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}
349 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}
350 ${Boost_LIB_PREFIX}boost_${COMPONENT}
352 ENDIF( NOT ${Boost_${COMPONENT}_LIBRARY_RELEASE} )
354 FIND_LIBRARY(Boost_${COMPONENT}_LIBRARY_DEBUG
355 NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${_boost_ABI_TAG}-${Boost_LIB_VERSION}
356 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}-${Boost_LIB_VERSION}
357 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}-${_boost_ABI_TAG}
358 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}
359 ${Boost_LIB_PREFIX}boost_${COMPONENT}-${_boost_ABI_TAG}
360 PATHS ${_boost_LIBRARIES_SEARCH_DIRS}
364 IF( NOT ${Boost_${COMPONENT}_LIBRARY_DEBUG} )
365 FIND_LIBRARY(Boost_${COMPONENT}_LIBRARY_DEBUG
366 NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${_boost_ABI_TAG}-${Boost_LIB_VERSION}
367 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}-${Boost_LIB_VERSION}
368 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}-${_boost_ABI_TAG}
369 ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}
370 ${Boost_LIB_PREFIX}boost_${COMPONENT}-${_boost_ABI_TAG}
372 ENDIF( NOT ${Boost_${COMPONENT}_LIBRARY_DEBUG} )
373 _Boost_ADJUST_LIB_VARS(${COMPONENT})
374 ENDFOREACH(COMPONENT)
375 # ------------------------------------------------------------------------
376 # End finding boost libraries
377 # ------------------------------------------------------------------------
379 # libfind_process setup variables
380 SET(Boost_PROCESS_INCLUDES Boost_INCLUDE_DIR)
382 FOREACH ( COMPONENT ${Boost_FIND_COMPONENTS} )
383 SET(Boost_PROCESS_LIBS ${Boost_PROCESS_LIBS} Boost_${COMPONENT}_LIBRARY)
384 ENDFOREACH(COMPONENT)
386 INCLUDE(LibFindMacros)
388 # Check that everything was found correctly and do other processing
389 libfind_process(Boost)
391 # MESSAGE(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
392 # MESSAGE(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
394 # Under Windows, automatic linking is performed, so no need to specify the libraries.
396 SET(Boost_LIBRARIES "")
399 ENDIF(_boost_IN_CACHE)