ENH: fix uppercase version so defines are not upper as well
[cmake.git] / Modules / FindBoost.cmake
blobec5d1c3c8c0d6cb4237b7c4ee1c813866b8344a8
1 # - Try to find Boost include dirs and libraries
2 # Usage of this module as follows:
4 #     SET(Boost_USE_STATIC_LIBS ON)
5 #     SET(Boost_USE_MULTITHREAD OFF)
6 #     FIND_PACKAGE( Boost 1.34.1 COMPONENTS date_time filesystem iostreams ... )
8 # The Boost_ADDITIONAL_VERSIONS variable can be used to specify a list of
9 # boost version numbers that should be taken into account when searching
10 # for the libraries. Unfortunately boost puts the version number into the
11 # actual filename for the libraries, so this might be needed in the future
12 # when new Boost versions are released.
14 # Currently this module searches for the following version numbers:
15 # 1.33, 1.33.0, 1.33.1, 1.34, 1.34.0, 1.34.1, 1.35, 1.35.0, 1.35.1, 1.36, 
16 # 1.36.0, 1.36.1
18 # The components list needs to be the actual names of boost libraries, that is
19 # the part of the actual library files that differ on different libraries. So
20 # its "date_time" for "libboost_date_time...". Anything else will result in
21 # errors
23 # You can provide a minimum version number that should be used. If you provide this 
24 # version number and specify the REQUIRED attribute, this module will fail if it
25 # can't find the specified or a later version. If you specify a version number this is
26 # automatically put into the considered list of version numbers and thus doesn't need
27 # to be specified in the Boost_ADDITIONAL_VERSIONS variable
29 # Variables used by this module, they can change the default behaviour and need to be set
30 # before calling find_package:
31 #  Boost_USE_MULTITHREAD         Can be set to OFF to use the non-multithreaded
32 #                                boost libraries. Defaults to ON.
33 #  Boost_USE_STATIC_LIBS         Can be set to ON to force the use of the static
34 #                                boost libraries. Defaults to OFF.
35 #  Boost_ADDITIONAL_VERSIONS     A list of version numbers to use for searching
36 #                                the boost include directory. The default list
37 #                                of version numbers is:
38 #                                1.33, 1.33.0, 1.33.1, 1.34, 1.34.0, 1.34.1, 
39 #                                1.35, 1.35.0, 1.35.1, 1.36, 1.36.0, 1.36.1
40 #                                If you want to look for an older or newer
41 #                                version set this variable to a list of
42 #                                strings, where each string contains a number, i.e.
43 #                                SET(Boost_ADDITIONAL_VERSIONS "0.99.0" "1.35.0")
44 #  BOOST_ROOT or BOOSTROOT       Preferred installation prefix for searching for Boost,
45 #                                set this if the module has problems finding the proper Boost installation
46 #  BOOST_INCLUDEDIR              Set this to the include directory of Boost, if the
47 #                                module has problems finding the proper Boost installation
48 #  BOOST_LIBRARYDIR              Set this to the lib directory of Boost, if the
49 #                                module has problems finding the proper Boost installation
51 #  The last three variables are available also as environment variables
54 # Variables defined by this module:
56 #  Boost_FOUND                          System has Boost, this means the include dir was found,
57 #                                       as well as all the libraries specified in the COMPONENTS list
58 #  Boost_INCLUDE_DIRS                   Boost include directories, not cached
59 #  Boost_INCLUDE_DIR                    This is almost the same as above, but this one is cached and may be
60 #                                       modified by advanced users
61 #  Boost_LIBRARIES                      Link these to use the Boost libraries that you specified, not cached
62 #  Boost_LIBRARY_DIRS                   The path to where the Boost library files are.
63 #  Boost_VERSION                        The version number of the boost libraries that have been found,
64 #                                       same as in version.hpp from Boost
65 #  Boost_LIB_VERSION                    The version number in filename form as its appended to the library filenames
66 #  Boost_MAJOR_VERSION                  major version number of boost
67 #  Boost_MINOR_VERSION                  minor version number of boost
68 #  Boost_SUBMINOR_VERSION               subminor version number of boost
69 #  Boost_LIB_DIAGNOSTIC_DEFINITIONS     Only set on windows. Can be used with add_definitions 
70 #                                       to print diagnostic information about the automatic 
71 #                                       linking done on windows.
73 # For each component you list the following variables are set.
74 # ATTENTION: The component names need to be in lower case, just as the boost
75 # library names however the cmake variables use upper case for the component
76 # part. So you'd get Boost_SERIALIZATION_FOUND for example.
78 #  Boost_${COMPONENT}_FOUND             True IF the Boost library "component" was found.
79 #  Boost_${COMPONENT}_LIBRARY           The absolute path of the Boost library "component".
80 #  Boost_${COMPONENT}_LIBRARY_DEBUG     The absolute path of the debug version of the
81 #                                       Boost library "component".
82 #  Boost_${COMPONENT}_LIBRARY_RELEASE   The absolute path of the release version of the
83 #                                       Boost library "component"
85 #  Copyright (c) 2006-2008 Andreas Schneider <mail@cynapses.org>
86 #  Copyright (c) 2007      Wengo
87 #  Copyright (c) 2007      Mike Jackson
88 #  Copyright (c) 2008      Andreas Pakulat <apaku@gmx.de>
90 #  Redistribution AND use is allowed according to the terms of the New
91 #  BSD license.
92 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
94 OPTION(Boost_USE_MULTITHREADED 
95   "Use the multithreaded versions of the Boost libraries" ON)
97 if(Boost_FIND_VERSION_EXACT)
98   # The version may appear in a directory with or without the patch
99   # level, even when the patch level is non-zero.
100   set(_boost_TEST_VERSIONS
101     "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}.${Boost_FIND_VERSION_PATCH}"
102     "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
103 else(Boost_FIND_VERSION_EXACT)
104   # The user has not requested an exact version.  Among known
105   # versions, find those that are acceptable to the user request.
106   set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS}
107     "1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0"
108     "1.34" "1.33.1" "1.33.0" "1.33")
109   set(_boost_TEST_VERSIONS)
110   if(Boost_FIND_VERSION)
111     set(_Boost_FIND_VERSION_SHORT "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
112     # Select acceptable versions.
113     foreach(version ${_Boost_KNOWN_VERSIONS})
114       if(NOT "${version}" VERSION_LESS "${Boost_FIND_VERSION}")
115         # This version is high enough.
116         list(APPEND _boost_TEST_VERSIONS "${version}")
117       elseif("${version}.99" VERSION_EQUAL "${_Boost_FIND_VERSION_SHORT}.99")
118         # This version is a short-form for the requested version with
119         # the patch level dropped.
120         list(APPEND _boost_TEST_VERSIONS "${version}")
121       endif()
122     endforeach(version)
123   else(Boost_FIND_VERSION)
124     # Any version is acceptable.
125     set(_boost_TEST_VERSIONS "${_Boost_KNOWN_VERSIONS}")
126   endif(Boost_FIND_VERSION)
127 endif(Boost_FIND_VERSION_EXACT)
129 # The reason that we failed to find Boost. This will be set to a
130 # user-friendly message when we fail to find some necessary piece of
131 # Boost.
132 set(Boost_ERROR_REASON)
134 ############################################
136 # Check the existence of the libraries.
138 ############################################
139 # This macro was taken directly from the FindQt4.cmake file that is included
140 # with the CMake distribution. This is NOT my work. All work was done by the
141 # original authors of the FindQt4.cmake file. Only minor modifications were
142 # made to remove references to Qt and make this file more generally applicable
143 #########################################################################
145 MACRO (_Boost_ADJUST_LIB_VARS basename)
146   IF (Boost_INCLUDE_DIR )
147     IF (Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
148       # if the generator supports configuration types then set
149       # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
150       IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
151         SET(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
152       ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
153         # if there are no configuration types and CMAKE_BUILD_TYPE has no value
154         # then just use the release libraries
155         SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} )
156       ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
157       SET(Boost_${basename}_LIBRARIES optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
158     ENDIF (Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
160     # if only the release version was found, set the debug variable also to the release version
161     IF (Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
162       SET(Boost_${basename}_LIBRARY_DEBUG ${Boost_${basename}_LIBRARY_RELEASE})
163       SET(Boost_${basename}_LIBRARY       ${Boost_${basename}_LIBRARY_RELEASE})
164       SET(Boost_${basename}_LIBRARIES     ${Boost_${basename}_LIBRARY_RELEASE})
165     ENDIF (Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
167     # if only the debug version was found, set the release variable also to the debug version
168     IF (Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
169       SET(Boost_${basename}_LIBRARY_RELEASE ${Boost_${basename}_LIBRARY_DEBUG})
170       SET(Boost_${basename}_LIBRARY         ${Boost_${basename}_LIBRARY_DEBUG})
171       SET(Boost_${basename}_LIBRARIES       ${Boost_${basename}_LIBRARY_DEBUG})
172     ENDIF (Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
173     
174     IF (Boost_${basename}_LIBRARY)
175       SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY} CACHE FILEPATH "The Boost ${basename} library")
176       GET_FILENAME_COMPONENT(Boost_LIBRARY_DIRS "${Boost_${basename}_LIBRARY}" PATH)
177       SET(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIRS} CACHE FILEPATH "Boost library directory")
178       SET(Boost_${basename}_FOUND ON CACHE INTERNAL "Whether the Boost ${basename} library found")
179     ENDIF (Boost_${basename}_LIBRARY)
181   ENDIF (Boost_INCLUDE_DIR )
182   # Make variables changeble to the advanced user
183   MARK_AS_ADVANCED(
184       Boost_${basename}_LIBRARY
185       Boost_${basename}_LIBRARY_RELEASE
186       Boost_${basename}_LIBRARY_DEBUG
187   )
188 ENDMACRO (_Boost_ADJUST_LIB_VARS)
190 #-------------------------------------------------------------------------------
193 SET( _boost_IN_CACHE TRUE)
194 IF(Boost_INCLUDE_DIR)
195   FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
196     STRING(TOUPPER ${COMPONENT} COMPONENT)
197     IF(NOT Boost_${COMPONENT}_FOUND)
198       SET( _boost_IN_CACHE FALSE)
199     ENDIF(NOT Boost_${COMPONENT}_FOUND)
200   ENDFOREACH(COMPONENT)
201 ELSE(Boost_INCLUDE_DIR)
202   SET( _boost_IN_CACHE FALSE)
203 ENDIF(Boost_INCLUDE_DIR)
205 IF (_boost_IN_CACHE)
206   # in cache already
207   SET(Boost_FOUND TRUE)
208   FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
209     STRING(TOUPPER ${COMPONENT} COMPONENT)
210     _Boost_ADJUST_LIB_VARS( ${COMPONENT} )
211     SET(Boost_LIBRARIES ${Boost_LIBRARIES} ${Boost_${COMPONENT}_LIBRARY})
212   ENDFOREACH(COMPONENT)
213   SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
214   IF(Boost_VERSION AND NOT "${Boost_VERSION}" STREQUAL "0")
215     MATH(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000")
216     MATH(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000")
217     MATH(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100")
218   ENDIF(Boost_VERSION AND NOT "${Boost_VERSION}" STREQUAL "0")
219 ELSE (_boost_IN_CACHE)
220   # Need to search for boost
222   IF(WIN32)
223     # In windows, automatic linking is performed, so you do not have
224     # to specify the libraries.  If you are linking to a dynamic
225     # runtime, then you can choose to link to either a static or a
226     # dynamic Boost library, the default is to do a static link.  You
227     # can alter this for a specific library "whatever" by defining
228     # BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to be
229     # linked dynamically.  Alternatively you can force all Boost
230     # libraries to dynamic link by defining BOOST_ALL_DYN_LINK.
231   
232     # This feature can be disabled for Boost library "whatever" by
233     # defining BOOST_WHATEVER_NO_LIB, or for all of Boost by defining
234     # BOOST_ALL_NO_LIB.
235   
236     # If you want to observe which libraries are being linked against
237     # then defining BOOST_LIB_DIAGNOSTIC will cause the auto-linking
238     # code to emit a #pragma message each time a library is selected
239     # for linking.
240     SET(Boost_LIB_DIAGNOSTIC_DEFINITIONS 
241       "-DBOOST_LIB_DIAGNOSTIC" CACHE STRING "Boost diagnostic define")
242   ENDIF(WIN32)
244   SET(_boost_INCLUDE_SEARCH_DIRS
245     C:/boost/include
246     "C:/boost"
247     "$ENV{ProgramFiles}/boost/boost_${Boost_FIND_VERSION_MAJOR}_${Boost_FIND_VERSION_MINOR}_${Boost_FIND_VERSION_PATCH}"
248     "$ENV{ProgramFiles}/Boost"
249     /sw/local/include
250   )
252   SET(_boost_LIBRARIES_SEARCH_DIRS
253     C:/boost/lib
254     "C:/boost"
255     "$ENV{ProgramFiles}/boost/boost_${Boost_FIND_VERSION_MAJOR}_${Boost_FIND_VERSION_MINOR}_${Boost_FIND_VERSION_PATCH}/lib"
256     "$ENV{ProgramFiles}/Boost"
257     /sw/local/lib
258   )
260   # If BOOST_ROOT was defined in the environment, use it.
261   if (NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
262     set(BOOST_ROOT $ENV{BOOST_ROOT})
263   endif(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
265   # If BOOSTROOT was defined in the environment, use it.
266   if (NOT BOOST_ROOT AND NOT $ENV{BOOSTROOT} STREQUAL "")
267     set(BOOST_ROOT $ENV{BOOSTROOT})
268   endif(NOT BOOST_ROOT AND NOT $ENV{BOOSTROOT} STREQUAL "")
270   # If BOOST_INCLUDEDIR was defined in the environment, use it.
271   IF( NOT $ENV{BOOST_INCLUDEDIR} STREQUAL "" )
272     set(BOOST_INCLUDEDIR $ENV{BOOST_INCLUDEDIR})
273   ENDIF( NOT $ENV{BOOST_INCLUDEDIR} STREQUAL "" )
275   # If BOOST_LIBRARYDIR was defined in the environment, use it.
276   IF( NOT $ENV{BOOST_LIBRARYDIR} STREQUAL "" )
277     set(BOOST_LIBRARYDIR $ENV{BOOST_LIBRARYDIR})
278   ENDIF( NOT $ENV{BOOST_LIBRARYDIR} STREQUAL "" )
280   IF( BOOST_ROOT )
281     file(TO_CMAKE_PATH ${BOOST_ROOT} BOOST_ROOT)
282     SET(_boost_INCLUDE_SEARCH_DIRS 
283       ${BOOST_ROOT}/include 
284       ${BOOST_ROOT}
285       ${_boost_INCLUDE_SEARCH_DIRS})
286     SET(_boost_LIBRARIES_SEARCH_DIRS 
287       ${BOOST_ROOT}/lib 
288       ${BOOST_ROOT}/stage/lib 
289       ${_boost_LIBRARIES_SEARCH_DIRS})
290   ENDIF( BOOST_ROOT )
292   IF( BOOST_INCLUDEDIR )
293     file(TO_CMAKE_PATH ${BOOST_INCLUDEDIR} BOOST_INCLUDEDIR)
294     SET(_boost_INCLUDE_SEARCH_DIRS 
295       ${BOOST_INCLUDEDIR} ${_boost_INCLUDE_SEARCH_DIRS})
296   ENDIF( BOOST_INCLUDEDIR )
298   IF( BOOST_LIBRARYDIR )
299     file(TO_CMAKE_PATH ${BOOST_LIBRARYDIR} BOOST_LIBRARYDIR)
300     SET(_boost_LIBRARIES_SEARCH_DIRS 
301       ${BOOST_LIBRARYDIR} ${_boost_LIBRARIES_SEARCH_DIRS})
302   ENDIF( BOOST_LIBRARYDIR )
304   # Try to find Boost by stepping backwards through the Boost versions
305   # we know about.
306   IF( NOT Boost_INCLUDE_DIR )
307     # Build a list of path suffixes for each version.
308     SET(_boost_PATH_SUFFIXES)
309     FOREACH(_boost_VER ${_boost_TEST_VERSIONS})
310       # Add in a path suffix, based on the required version, ideally
311       # we could read this from version.hpp, but for that to work we'd
312       # need to know the include dir already
313       if (WIN32 AND NOT CYGWIN)
314         set(_boost_PATH_SUFFIX boost_${_boost_VER})
315       else (WIN32 AND NOT CYGWIN)
316         set(_boost_PATH_SUFFIX boost-${_boost_VER})
317       endif (WIN32 AND NOT CYGWIN)
319       IF(_boost_PATH_SUFFIX MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
320           STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1_\\2_\\3" 
321             _boost_PATH_SUFFIX ${_boost_PATH_SUFFIX})
322       ELSEIF(_boost_PATH_SUFFIX MATCHES "[0-9]+\\.[0-9]+")
323           STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1_\\2" 
324             _boost_PATH_SUFFIX ${_boost_PATH_SUFFIX})
325       ENDIF(_boost_PATH_SUFFIX MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
326       LIST(APPEND _boost_PATH_SUFFIXES "${_boost_PATH_SUFFIX}")
327     ENDFOREACH(_boost_VER)
329     # Look for a standard boost header file.
330     FIND_PATH(Boost_INCLUDE_DIR
331       NAMES         boost/config.hpp
332       HINTS         ${_boost_INCLUDE_SEARCH_DIRS}
333       PATH_SUFFIXES ${_boost_PATH_SUFFIXES}
334       )
335   ENDIF( NOT Boost_INCLUDE_DIR )
337   IF(Boost_INCLUDE_DIR)
338     # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
339     # Read the whole file:
340     #
341     SET(BOOST_VERSION 0)
342     SET(BOOST_LIB_VERSION "")
343     FILE(READ "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS)
344   
345     STRING(REGEX REPLACE ".*#define BOOST_VERSION ([0-9]+).*" "\\1" Boost_VERSION "${_boost_VERSION_HPP_CONTENTS}")
346     STRING(REGEX REPLACE ".*#define BOOST_LIB_VERSION \"([0-9_]+)\".*" "\\1" Boost_LIB_VERSION "${_boost_VERSION_HPP_CONTENTS}")
347   
348     SET(Boost_LIB_VERSION ${Boost_LIB_VERSION} CACHE INTERNAL "The library version string for boost libraries")
349     SET(Boost_VERSION ${Boost_VERSION} CACHE INTERNAL "The version number for boost libraries")
350     
351     IF(NOT "${Boost_VERSION}" STREQUAL "0")
352       MATH(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000")
353       MATH(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000")
354       MATH(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100")
356       set(Boost_ERROR_REASON
357           "${Boost_ERROR_REASON}Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}\nBoost include path: ${Boost_INCLUDE_DIR}")
358     ENDIF(NOT "${Boost_VERSION}" STREQUAL "0")
359   ELSE(Boost_INCLUDE_DIR)
360     set(Boost_ERROR_REASON
361       "${Boost_ERROR_REASON}Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.")
362   ENDIF(Boost_INCLUDE_DIR)
364   # Setting some more suffixes for the library
365   SET (Boost_LIB_PREFIX "")
366   IF ( WIN32 AND Boost_USE_STATIC_LIBS )
367     SET (Boost_LIB_PREFIX "lib")
368   ENDIF ( WIN32 AND Boost_USE_STATIC_LIBS )
369   SET (_boost_COMPILER "-gcc")
370   IF (MSVC90)
371     SET (_boost_COMPILER "-vc90")
372   ELSEIF (MSVC80)
373     SET (_boost_COMPILER "-vc80")
374   ELSEIF (MSVC71)
375     SET (_boost_COMPILER "-vc71")
376   ENDIF(MSVC90)
377   IF (MINGW)
378     EXEC_PROGRAM(${CMAKE_CXX_COMPILER}
379       ARGS -dumpversion
380       OUTPUT_VARIABLE _boost_COMPILER_VERSION
381       )
382     STRING(REGEX REPLACE "([0-9])\\.([0-9])\\.[0-9]" "\\1\\2"
383       _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION})
384     SET (_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}")
385   ENDIF(MINGW)
386   IF (UNIX)
387     IF (NOT CMAKE_COMPILER_IS_GNUCC)
388       # We assume that we have the Intel compiler.
389       SET (_boost_COMPILER "-il")
390     ELSE (NOT CMAKE_COMPILER_IS_GNUCC)
391       # Determine which version of GCC we have.
392       EXEC_PROGRAM(${CMAKE_CXX_COMPILER}
393         ARGS -dumpversion
394         OUTPUT_VARIABLE _boost_COMPILER_VERSION
395         )
396       STRING(REGEX REPLACE "([0-9])\\.([0-9])\\.[0-9]" "\\1\\2"
397         _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION})
398       IF(APPLE)
399         IF(Boost_MINOR_VERSION)
400           IF(${Boost_MINOR_VERSION} GREATER 35)
401             # In Boost 1.36.0 and newer, the mangled compiler name used
402             # on Mac OS X/Darwin is "xgcc".
403             SET(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}")
404           ELSE(${Boost_MINOR_VERSION} GREATER 35)
405             # In Boost <= 1.35.0, there is no mangled compiler name for
406             # the Mac OS X/Darwin version of GCC.
407             SET(_boost_COMPILER "")
408           ENDIF(${Boost_MINOR_VERSION} GREATER 35)
409         ELSE(Boost_MINOR_VERSION)
410           # We don't know the Boost version, so assume it's
411           # pre-1.36.0.
412           SET(_boost_COMPILER "")
413         ENDIF(Boost_MINOR_VERSION)
414       ELSE()
415         SET (_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}")
416       ENDIF()
417     ENDIF (NOT CMAKE_COMPILER_IS_GNUCC)
418   ENDIF(UNIX)
420   SET (_boost_MULTITHREADED "-mt")
422   IF( NOT Boost_USE_MULTITHREADED )
423     SET (_boost_MULTITHREADED "")
424   ENDIF( NOT Boost_USE_MULTITHREADED )
426   SET( _boost_STATIC_TAG "")
427   IF (WIN32)
428     IF(MSVC)
429       SET (_boost_ABI_TAG "g")
430     ENDIF(MSVC)
431     IF( Boost_USE_STATIC_LIBS )
432       SET( _boost_STATIC_TAG "-s")
433     ENDIF( Boost_USE_STATIC_LIBS )
434   ENDIF(WIN32)
435   SET (_boost_ABI_TAG "${_boost_ABI_TAG}d")
437   # ------------------------------------------------------------------------
438   #  Begin finding boost libraries
439   # ------------------------------------------------------------------------
440   FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
441     STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
442     SET( Boost_${UPPERCOMPONENT}_LIBRARY "Boost_${UPPERCOMPONENT}_LIBRARY-NOTFOUND" )
443     SET( Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE "Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE-NOTFOUND" )
444     SET( Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG "Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG-NOTFOUND")
446     # Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
447     IF( Boost_USE_STATIC_LIBS )
448       SET( _boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
449       IF(WIN32)
450         SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
451       ELSE(WIN32)
452         SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
453       ENDIF(WIN32)
454     ENDIF( Boost_USE_STATIC_LIBS )
456     FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE
457         NAMES  ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${Boost_LIB_VERSION}
458                ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}-${Boost_LIB_VERSION}
459                ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}
460                ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}
461                ${Boost_LIB_PREFIX}boost_${COMPONENT}
462         HINTS  ${_boost_LIBRARIES_SEARCH_DIRS}
463     )
465     FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG
466         NAMES  ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${_boost_ABI_TAG}-${Boost_LIB_VERSION}
467                ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}-${Boost_LIB_VERSION}
468                ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}-${_boost_ABI_TAG}
469                ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}
470                ${Boost_LIB_PREFIX}boost_${COMPONENT}-${_boost_ABI_TAG}
471         HINTS  ${_boost_LIBRARIES_SEARCH_DIRS}
472     )
474     _Boost_ADJUST_LIB_VARS(${UPPERCOMPONENT})
475     IF( Boost_USE_STATIC_LIBS )
476       SET(CMAKE_FIND_LIBRARY_SUFFIXES ${_boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
477     ENDIF( Boost_USE_STATIC_LIBS )
478   ENDFOREACH(COMPONENT)
479   # ------------------------------------------------------------------------
480   #  End finding boost libraries
481   # ------------------------------------------------------------------------
483   SET(Boost_INCLUDE_DIRS
484     ${Boost_INCLUDE_DIR}
485   )
487   SET(Boost_FOUND FALSE)
488   IF(Boost_INCLUDE_DIR)
489     SET( Boost_FOUND TRUE )
491     # Check the version of Boost against the requested version.
492     if (Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR)
493       message(SEND_ERROR "When requesting a specific version of Boost, you must provide at least the major and minor version numbers, e.g., 1.34")
494     endif (Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR)
495     if(Boost_MAJOR_VERSION LESS "${Boost_FIND_VERSION_MAJOR}" )
496       set( Boost_FOUND FALSE )
497       set(_Boost_VERSION_AGE "old")
498     elseif(Boost_MAJOR_VERSION EQUAL "${Boost_FIND_VERSION_MAJOR}" )
499       if(Boost_MINOR_VERSION LESS "${Boost_FIND_VERSION_MINOR}" )
500         set( Boost_FOUND FALSE )
501         set(_Boost_VERSION_AGE "old")
502       elseif(Boost_MINOR_VERSION EQUAL "${Boost_FIND_VERSION_MINOR}" )
503         if( Boost_FIND_VERSION_PATCH AND Boost_SUBMINOR_VERSION LESS "${Boost_FIND_VERSION_PATCH}" )
504           set( Boost_FOUND FALSE )
505           set(_Boost_VERSION_AGE "old")
506         endif( Boost_FIND_VERSION_PATCH AND Boost_SUBMINOR_VERSION LESS "${Boost_FIND_VERSION_PATCH}" )
507       endif( Boost_MINOR_VERSION LESS "${Boost_FIND_VERSION_MINOR}" )
508     endif( Boost_MAJOR_VERSION LESS "${Boost_FIND_VERSION_MAJOR}" )
510     if (Boost_FOUND AND Boost_FIND_VERSION_EXACT)
511       # If the user requested an exact version of Boost, check
512       # that. We already know that the Boost version we have is >= the
513       # requested version.
514       set(_Boost_VERSION_AGE "new")
516       # If the user didn't specify a patchlevel, it's 0.
517       if (NOT Boost_FIND_VERSION_PATCH)
518         set(Boost_FIND_VERSION_PATCH 0)
519       endif (NOT Boost_FIND_VERSION_PATCH)
520       
521       # We'll set Boost_FOUND true again if we have an exact version match.
522       set(Boost_FOUND FALSE)
523       if(Boost_MAJOR_VERSION EQUAL "${Boost_FIND_VERSION_MAJOR}" )
524         if(Boost_MINOR_VERSION EQUAL "${Boost_FIND_VERSION_MINOR}" )
525           if(Boost_SUBMINOR_VERSION EQUAL "${Boost_FIND_VERSION_PATCH}" )
526             set( Boost_FOUND TRUE )
527           endif(Boost_SUBMINOR_VERSION EQUAL "${Boost_FIND_VERSION_PATCH}" )
528         endif( Boost_MINOR_VERSION EQUAL "${Boost_FIND_VERSION_MINOR}" )
529       endif( Boost_MAJOR_VERSION EQUAL "${Boost_FIND_VERSION_MAJOR}" )
530     endif (Boost_FOUND AND Boost_FIND_VERSION_EXACT)
532     if(NOT Boost_FOUND)
533       # State that we found a version of Boost that is too new or too old.
534       set(Boost_ERROR_REASON
535         "${Boost_ERROR_REASON}\nDetected version of Boost is too ${_Boost_VERSION_AGE}. Requested version was ${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
536       if (Boost_FIND_VERSION_PATCH)
537         set(Boost_ERROR_REASON 
538           "${Boost_ERROR_REASON}.${Boost_FIND_VERSION_PATCH}")
539       endif (Boost_FIND_VERSION_PATCH)
540       if (NOT Boost_FIND_VERSION_EXACT)
541         set(Boost_ERROR_REASON "${Boost_ERROR_REASON} (or newer)")
542       endif (NOT Boost_FIND_VERSION_EXACT)
543       set(Boost_ERROR_REASON "${Boost_ERROR_REASON}.")
544     endif (NOT Boost_FOUND)
546     if (Boost_FOUND)
547       set(_boost_CHECKED_COMPONENT FALSE)
548       set(_Boost_MISSING_COMPONENTS)
549       foreach(COMPONENT ${Boost_FIND_COMPONENTS})
550         string(TOUPPER ${COMPONENT} COMPONENT)
551         set(_boost_CHECKED_COMPONENT TRUE)
552         if(NOT Boost_${COMPONENT}_FOUND)
553           string(TOLOWER ${COMPONENT} COMPONENT)
554           list(APPEND _Boost_MISSING_COMPONENTS ${COMPONENT})
555           set( Boost_FOUND FALSE)
556         endif(NOT Boost_${COMPONENT}_FOUND)
557       endforeach(COMPONENT)
558     endif (Boost_FOUND)
560     if (_Boost_MISSING_COMPONENTS)
561       # We were unable to find some libraries, so generate a sensible
562       # error message that lists the libraries we were unable to find.
563       set(Boost_ERROR_REASON
564         "${Boost_ERROR_REASON}\nThe following Boost libraries could not be found:\n")
565       foreach(COMPONENT ${_Boost_MISSING_COMPONENTS})
566         set(Boost_ERROR_REASON
567           "${Boost_ERROR_REASON}        boost_${COMPONENT}\n")
568       endforeach(COMPONENT)
570       list(LENGTH Boost_FIND_COMPONENTS Boost_NUM_COMPONENTS_WANTED)
571       list(LENGTH _Boost_MISSING_COMPONENTS Boost_NUM_MISSING_COMPONENTS)
572       if (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS})
573         set(Boost_ERROR_REASON
574           "${Boost_ERROR_REASON}No Boost libraries were found. You may need to set Boost_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.")
575       else (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS})
576         set(Boost_ERROR_REASON
577           "${Boost_ERROR_REASON}Some (but not all) of the required Boost libraries were found. You may need to install these additional Boost libraries. Alternatively, set Boost_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.")
578       endif (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS})
579     endif (_Boost_MISSING_COMPONENTS)
581     IF( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT )
582       # Compatibility Code for backwards compatibility with CMake
583       # 2.4's FindBoost module.
585       # Look for the boost library path.
586       # Note that the user may not have installed any libraries
587       # so it is quite possible the Boost_LIBRARY_PATH may not exist.
588       SET(_boost_LIB_DIR ${Boost_INCLUDE_DIR})
589     
590       IF("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+")
591         GET_FILENAME_COMPONENT(_boost_LIB_DIR ${_boost_LIB_DIR} PATH)
592       ENDIF ("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+")
593     
594       IF("${_boost_LIB_DIR}" MATCHES "/include$")
595         # Strip off the trailing "/include" in the path.
596         GET_FILENAME_COMPONENT(_boost_LIB_DIR ${_boost_LIB_DIR} PATH)
597       ENDIF("${_boost_LIB_DIR}" MATCHES "/include$")
598     
599       IF(EXISTS "${_boost_LIB_DIR}/lib")
600         SET (_boost_LIB_DIR ${_boost_LIB_DIR}/lib)
601       ELSE(EXISTS "${_boost_LIB_DIR}/lib")
602         IF(EXISTS "${_boost_LIB_DIR}/stage/lib")
603           SET(_boost_LIB_DIR ${_boost_LIB_DIR}/stage/lib)
604         ELSE(EXISTS "${_boost_LIB_DIR}/stage/lib")
605           SET(_boost_LIB_DIR "")
606         ENDIF(EXISTS "${_boost_LIB_DIR}/stage/lib")
607       ENDIF(EXISTS "${_boost_LIB_DIR}/lib")
608     
609       IF(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}")
610         SET(Boost_LIBRARY_DIRS ${_boost_LIB_DIR} CACHE FILEPATH "Boost library directory")
611       ENDIF(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}")
613     ENDIF( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT )
615   ELSE(Boost_INCLUDE_DIR)
616     SET( Boost_FOUND FALSE)
617   ENDIF(Boost_INCLUDE_DIR)
619   IF (Boost_FOUND)
620       IF (NOT Boost_FIND_QUIETLY)
621         MESSAGE(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
622       ENDIF(NOT Boost_FIND_QUIETLY)
623       IF (NOT Boost_FIND_QUIETLY)
624         MESSAGE(STATUS "Found the following Boost libraries:")
625       ENDIF(NOT Boost_FIND_QUIETLY)
626       FOREACH ( COMPONENT  ${Boost_FIND_COMPONENTS} )
627         STRING( TOUPPER ${COMPONENT} UPPERCOMPONENT )
628         IF ( Boost_${UPPERCOMPONENT}_FOUND )
629           IF (NOT Boost_FIND_QUIETLY)
630             MESSAGE (STATUS "  ${COMPONENT}")
631           ENDIF(NOT Boost_FIND_QUIETLY)
632           SET(Boost_LIBRARIES ${Boost_LIBRARIES} ${Boost_${UPPERCOMPONENT}_LIBRARY})
633         ENDIF ( Boost_${UPPERCOMPONENT}_FOUND )
634       ENDFOREACH(COMPONENT)
635   ELSE (Boost_FOUND)
636       IF (Boost_FIND_REQUIRED)
637         message(SEND_ERROR "Unable to find the requested Boost libraries.\n${Boost_ERROR_REASON}")
638       ENDIF(Boost_FIND_REQUIRED)
639   ENDIF(Boost_FOUND)
641   # Under Windows, automatic linking is performed, so no need to specify the libraries.
642   IF (WIN32)
643     IF (NOT MINGW)
644       SET(Boost_LIBRARIES "")
645     ENDIF (NOT MINGW)
646   ENDIF(WIN32)
648   # show the Boost_INCLUDE_DIRS AND Boost_LIBRARIES variables only in the advanced view
649   MARK_AS_ADVANCED(Boost_INCLUDE_DIR
650       Boost_INCLUDE_DIRS
651       Boost_LIBRARY_DIRS
652       Boost_USE_MULTITHREADED
653   )
654 ENDIF(_boost_IN_CACHE)