FindBoost.cmake 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. # - Try to find Boost include dirs and libraries
  2. # Usage of this module as follows:
  3. #
  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 ... )
  7. #
  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.
  13. #
  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
  17. #
  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
  22. #
  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
  28. #
  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
  50. #
  51. # The last three variables are available also as environment variables
  52. #
  53. #
  54. # Variables defined by this module:
  55. #
  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.
  72. # For each component you list the following variables are set.
  73. # ATTENTION: The component names need to be in lower case, just as the boost
  74. # library names however the cmake variables use upper case for the component
  75. # part. So you'd get Boost_SERIALIZATION_FOUND for example.
  76. #
  77. # Boost_${COMPONENT}_FOUND True IF the Boost library "component" was found.
  78. # Boost_${COMPONENT}_LIBRARY The absolute path of the Boost library "component".
  79. # Boost_${COMPONENT}_LIBRARY_DEBUG The absolute path of the debug version of the
  80. # Boost library "component".
  81. # Boost_${COMPONENT}_LIBRARY_RELEASE The absolute path of the release version of the
  82. # Boost library "component"
  83. #
  84. # Copyright (c) 2006-2008 Andreas Schneider <[email protected]>
  85. # Copyright (c) 2007 Wengo
  86. # Copyright (c) 2007 Mike Jackson
  87. # Copyright (c) 2008 Andreas Pakulat <[email protected]>
  88. #
  89. # Redistribution AND use is allowed according to the terms of the New
  90. # BSD license.
  91. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  92. #
  93. OPTION(Boost_USE_MULTITHREADED
  94. "Use the multithreaded versions of the Boost libraries" ON)
  95. if (Boost_FIND_VERSION_EXACT)
  96. if (Boost_FIND_VERSION_PATCH)
  97. set( _boost_TEST_VERSIONS
  98. "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}.${Boost_FIND_VERSION_PATCH}")
  99. else (Boost_FIND_VERSION_PATCH)
  100. set( _boost_TEST_VERSIONS
  101. "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}.0"
  102. "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
  103. endif (Boost_FIND_VERSION_PATCH)
  104. else (Boost_FIND_VERSION_EXACT)
  105. set( _boost_TEST_VERSIONS ${Boost_ADDITIONAL_VERSIONS}
  106. "1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0"
  107. "1.34" "1.33.1" "1.33.0" "1.33" )
  108. endif (Boost_FIND_VERSION_EXACT)
  109. # The reason that we failed to find Boost. This will be set to a
  110. # user-friendly message when we fail to find some necessary piece of
  111. # Boost.
  112. set(Boost_ERROR_REASON)
  113. ############################################
  114. #
  115. # Check the existence of the libraries.
  116. #
  117. ############################################
  118. # This macro was taken directly from the FindQt4.cmake file that is included
  119. # with the CMake distribution. This is NOT my work. All work was done by the
  120. # original authors of the FindQt4.cmake file. Only minor modifications were
  121. # made to remove references to Qt and make this file more generally applicable
  122. #########################################################################
  123. MACRO (_Boost_ADJUST_LIB_VARS basename)
  124. IF (Boost_INCLUDE_DIR )
  125. IF (Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
  126. # if the generator supports configuration types then set
  127. # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
  128. IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
  129. SET(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
  130. ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
  131. # if there are no configuration types and CMAKE_BUILD_TYPE has no value
  132. # then just use the release libraries
  133. SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} )
  134. ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
  135. SET(Boost_${basename}_LIBRARIES optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
  136. ENDIF (Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
  137. # if only the release version was found, set the debug variable also to the release version
  138. IF (Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
  139. SET(Boost_${basename}_LIBRARY_DEBUG ${Boost_${basename}_LIBRARY_RELEASE})
  140. SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE})
  141. SET(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE})
  142. ENDIF (Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
  143. # if only the debug version was found, set the release variable also to the debug version
  144. IF (Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
  145. SET(Boost_${basename}_LIBRARY_RELEASE ${Boost_${basename}_LIBRARY_DEBUG})
  146. SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_DEBUG})
  147. SET(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_DEBUG})
  148. ENDIF (Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
  149. IF (Boost_${basename}_LIBRARY)
  150. SET(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY} CACHE FILEPATH "The Boost ${basename} library")
  151. GET_FILENAME_COMPONENT(Boost_LIBRARY_DIRS "${Boost_${basename}_LIBRARY}" PATH)
  152. SET(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIRS} CACHE FILEPATH "Boost library directory")
  153. SET(Boost_${basename}_FOUND ON CACHE INTERNAL "Whether the Boost ${basename} library found")
  154. ENDIF (Boost_${basename}_LIBRARY)
  155. ENDIF (Boost_INCLUDE_DIR )
  156. # Make variables changeble to the advanced user
  157. MARK_AS_ADVANCED(
  158. Boost_${basename}_LIBRARY
  159. Boost_${basename}_LIBRARY_RELEASE
  160. Boost_${basename}_LIBRARY_DEBUG
  161. )
  162. ENDMACRO (_Boost_ADJUST_LIB_VARS)
  163. #-------------------------------------------------------------------------------
  164. SET( _boost_IN_CACHE TRUE)
  165. IF(Boost_INCLUDE_DIR)
  166. FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
  167. STRING(TOUPPER ${COMPONENT} COMPONENT)
  168. IF(NOT Boost_${COMPONENT}_FOUND)
  169. SET( _boost_IN_CACHE FALSE)
  170. ENDIF(NOT Boost_${COMPONENT}_FOUND)
  171. ENDFOREACH(COMPONENT)
  172. ELSE(Boost_INCLUDE_DIR)
  173. SET( _boost_IN_CACHE FALSE)
  174. ENDIF(Boost_INCLUDE_DIR)
  175. IF (_boost_IN_CACHE)
  176. # in cache already
  177. SET(Boost_FOUND TRUE)
  178. FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
  179. STRING(TOUPPER ${COMPONENT} COMPONENT)
  180. _Boost_ADJUST_LIB_VARS( ${COMPONENT} )
  181. SET(Boost_LIBRARIES ${Boost_LIBRARIES} ${Boost_${COMPONENT}_LIBRARY})
  182. ENDFOREACH(COMPONENT)
  183. SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
  184. IF(Boost_VERSION AND NOT "${Boost_VERSION}" STREQUAL "0")
  185. MATH(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000")
  186. MATH(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000")
  187. MATH(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100")
  188. ENDIF(Boost_VERSION AND NOT "${Boost_VERSION}" STREQUAL "0")
  189. ELSE (_boost_IN_CACHE)
  190. # Need to search for boost
  191. IF(WIN32)
  192. # In windows, automatic linking is performed, so you do not have
  193. # to specify the libraries. If you are linking to a dynamic
  194. # runtime, then you can choose to link to either a static or a
  195. # dynamic Boost library, the default is to do a static link. You
  196. # can alter this for a specific library "whatever" by defining
  197. # BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to be
  198. # linked dynamically. Alternatively you can force all Boost
  199. # libraries to dynamic link by defining BOOST_ALL_DYN_LINK.
  200. # This feature can be disabled for Boost library "whatever" by
  201. # defining BOOST_WHATEVER_NO_LIB, or for all of Boost by defining
  202. # BOOST_ALL_NO_LIB.
  203. # If you want to observe which libraries are being linked against
  204. # then defining BOOST_LIB_DIAGNOSTIC will cause the auto-linking
  205. # code to emit a #pragma message each time a library is selected
  206. # for linking.
  207. SET(Boost_LIB_DIAGNOSTIC_DEFINITIONS
  208. "-DBOOST_LIB_DIAGNOSTIC" CACHE STRING "Boost diagnostic define")
  209. ENDIF(WIN32)
  210. SET(_boost_INCLUDE_SEARCH_DIRS
  211. C:/boost/include
  212. "C:/boost"
  213. "$ENV{ProgramFiles}/boost/boost_${Boost_FIND_VERSION_MAJOR}_${Boost_FIND_VERSION_MINOR}_${Boost_FIND_VERSION_PATCH}"
  214. "$ENV{ProgramFiles}/Boost"
  215. /sw/local/include
  216. )
  217. SET(_boost_LIBRARIES_SEARCH_DIRS
  218. C:/boost/lib
  219. "C:/boost"
  220. "$ENV{ProgramFiles}/boost/boost_${Boost_FIND_VERSION_MAJOR}_${Boost_FIND_VERSION_MINOR}_${Boost_FIND_VERSION_PATCH}/lib"
  221. "$ENV{ProgramFiles}/Boost"
  222. /sw/local/lib
  223. )
  224. # If BOOST_ROOT was defined in the environment, use it.
  225. if (NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
  226. set(BOOST_ROOT $ENV{BOOST_ROOT})
  227. endif(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
  228. # If BOOSTROOT was defined in the environment, use it.
  229. if (NOT BOOST_ROOT AND NOT $ENV{BOOSTROOT} STREQUAL "")
  230. set(BOOST_ROOT $ENV{BOOSTROOT})
  231. endif(NOT BOOST_ROOT AND NOT $ENV{BOOSTROOT} STREQUAL "")
  232. # If BOOST_INCLUDEDIR was defined in the environment, use it.
  233. IF( NOT $ENV{BOOST_INCLUDEDIR} STREQUAL "" )
  234. set(BOOST_INCLUDEDIR $ENV{BOOST_INCLUDEDIR})
  235. ENDIF( NOT $ENV{BOOST_INCLUDEDIR} STREQUAL "" )
  236. # If BOOST_LIBRARYDIR was defined in the environment, use it.
  237. IF( NOT $ENV{BOOST_LIBRARYDIR} STREQUAL "" )
  238. set(BOOST_LIBRARYDIR $ENV{BOOST_LIBRARYDIR})
  239. ENDIF( NOT $ENV{BOOST_LIBRARYDIR} STREQUAL "" )
  240. IF( BOOST_ROOT )
  241. file(TO_CMAKE_PATH ${BOOST_ROOT} BOOST_ROOT)
  242. SET(_boost_INCLUDE_SEARCH_DIRS
  243. ${BOOST_ROOT}/include
  244. ${BOOST_ROOT}
  245. ${_boost_INCLUDE_SEARCH_DIRS})
  246. SET(_boost_LIBRARIES_SEARCH_DIRS
  247. ${BOOST_ROOT}/lib
  248. ${BOOST_ROOT}/stage/lib
  249. ${_boost_LIBRARIES_SEARCH_DIRS})
  250. ENDIF( BOOST_ROOT )
  251. IF( BOOST_INCLUDEDIR )
  252. file(TO_CMAKE_PATH ${BOOST_INCLUDEDIR} BOOST_INCLUDEDIR)
  253. SET(_boost_INCLUDE_SEARCH_DIRS
  254. ${BOOST_INCLUDEDIR} ${_boost_INCLUDE_SEARCH_DIRS})
  255. ENDIF( BOOST_INCLUDEDIR )
  256. IF( BOOST_LIBRARYDIR )
  257. file(TO_CMAKE_PATH ${BOOST_LIBRARYDIR} BOOST_LIBRARYDIR)
  258. SET(_boost_LIBRARIES_SEARCH_DIRS
  259. ${BOOST_LIBRARYDIR} ${_boost_LIBRARIES_SEARCH_DIRS})
  260. ENDIF( BOOST_LIBRARYDIR )
  261. # Try to find Boost by stepping backwards through the Boost versions
  262. # we know about.
  263. FOREACH(_boost_VER ${_boost_TEST_VERSIONS})
  264. IF( NOT Boost_INCLUDE_DIR )
  265. # Add in a path suffix, based on the required version, ideally
  266. # we could read this from version.hpp, but for that to work we'd
  267. # need to know the include dir already
  268. if (WIN32 AND NOT CYGWIN)
  269. set(_boost_PATH_SUFFIX boost_${_boost_VER})
  270. else (WIN32 AND NOT CYGWIN)
  271. set(_boost_PATH_SUFFIX boost-${_boost_VER})
  272. endif (WIN32 AND NOT CYGWIN)
  273. IF(_boost_PATH_SUFFIX MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
  274. STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1_\\2_\\3"
  275. _boost_PATH_SUFFIX ${_boost_PATH_SUFFIX})
  276. ELSEIF(_boost_PATH_SUFFIX MATCHES "[0-9]+\\.[0-9]+")
  277. STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1_\\2"
  278. _boost_PATH_SUFFIX ${_boost_PATH_SUFFIX})
  279. ENDIF(_boost_PATH_SUFFIX MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
  280. FIND_PATH(Boost_INCLUDE_DIR
  281. NAMES boost/config.hpp
  282. HINTS ${_boost_INCLUDE_SEARCH_DIRS}
  283. PATH_SUFFIXES ${_boost_PATH_SUFFIX}
  284. )
  285. ENDIF( NOT Boost_INCLUDE_DIR )
  286. ENDFOREACH(_boost_VER)
  287. IF(Boost_INCLUDE_DIR)
  288. # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
  289. # Read the whole file:
  290. #
  291. SET(BOOST_VERSION 0)
  292. SET(BOOST_LIB_VERSION "")
  293. FILE(READ "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS)
  294. STRING(REGEX REPLACE ".*#define BOOST_VERSION ([0-9]+).*" "\\1" Boost_VERSION "${_boost_VERSION_HPP_CONTENTS}")
  295. STRING(REGEX REPLACE ".*#define BOOST_LIB_VERSION \"([0-9_]+)\".*" "\\1" Boost_LIB_VERSION "${_boost_VERSION_HPP_CONTENTS}")
  296. SET(Boost_LIB_VERSION ${Boost_LIB_VERSION} CACHE INTERNAL "The library version string for boost libraries")
  297. SET(Boost_VERSION ${Boost_VERSION} CACHE INTERNAL "The version number for boost libraries")
  298. IF(NOT "${Boost_VERSION}" STREQUAL "0")
  299. MATH(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000")
  300. MATH(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000")
  301. MATH(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100")
  302. set(Boost_ERROR_REASON
  303. "${Boost_ERROR_REASON}Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}\nBoost include path: ${Boost_INCLUDE_DIR}")
  304. ENDIF(NOT "${Boost_VERSION}" STREQUAL "0")
  305. ELSE(Boost_INCLUDE_DIR)
  306. set(Boost_ERROR_REASON
  307. "${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.")
  308. ENDIF(Boost_INCLUDE_DIR)
  309. # Setting some more suffixes for the library
  310. SET (Boost_LIB_PREFIX "")
  311. IF ( WIN32 AND Boost_USE_STATIC_LIBS )
  312. SET (Boost_LIB_PREFIX "lib")
  313. ENDIF ( WIN32 AND Boost_USE_STATIC_LIBS )
  314. SET (_boost_COMPILER "-gcc")
  315. IF (MSVC90)
  316. SET (_boost_COMPILER "-vc90")
  317. ELSEIF (MSVC80)
  318. SET (_boost_COMPILER "-vc80")
  319. ELSEIF (MSVC71)
  320. SET (_boost_COMPILER "-vc71")
  321. ENDIF(MSVC90)
  322. IF (MINGW)
  323. EXEC_PROGRAM(${CMAKE_CXX_COMPILER}
  324. ARGS -dumpversion
  325. OUTPUT_VARIABLE _boost_COMPILER_VERSION
  326. )
  327. STRING(REGEX REPLACE "([0-9])\\.([0-9])\\.[0-9]" "\\1\\2"
  328. _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION})
  329. SET (_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}")
  330. ENDIF(MINGW)
  331. IF (UNIX)
  332. IF (NOT CMAKE_COMPILER_IS_GNUCC)
  333. # We assume that we have the Intel compiler.
  334. SET (_boost_COMPILER "-il")
  335. ELSE (NOT CMAKE_COMPILER_IS_GNUCC)
  336. # Determine which version of GCC we have.
  337. EXEC_PROGRAM(${CMAKE_CXX_COMPILER}
  338. ARGS -dumpversion
  339. OUTPUT_VARIABLE _boost_COMPILER_VERSION
  340. )
  341. STRING(REGEX REPLACE "([0-9])\\.([0-9])\\.[0-9]" "\\1\\2"
  342. _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION})
  343. IF(APPLE)
  344. IF(Boost_MINOR_VERSION)
  345. IF(${Boost_MINOR_VERSION} GREATER 35)
  346. # In Boost 1.36.0 and newer, the mangled compiler name used
  347. # on Mac OS X/Darwin is "xgcc".
  348. SET(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}")
  349. ELSE(${Boost_MINOR_VERSION} GREATER 35)
  350. # In Boost <= 1.35.0, there is no mangled compiler name for
  351. # the Mac OS X/Darwin version of GCC.
  352. SET(_boost_COMPILER "")
  353. ENDIF(${Boost_MINOR_VERSION} GREATER 35)
  354. ELSE(Boost_MINOR_VERSION)
  355. # We don't know the Boost version, so assume it's
  356. # pre-1.36.0.
  357. SET(_boost_COMPILER "")
  358. ENDIF(Boost_MINOR_VERSION)
  359. ELSE()
  360. SET (_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}")
  361. ENDIF()
  362. ENDIF (NOT CMAKE_COMPILER_IS_GNUCC)
  363. ENDIF(UNIX)
  364. SET (_boost_MULTITHREADED "-mt")
  365. IF( NOT Boost_USE_MULTITHREADED )
  366. SET (_boost_MULTITHREADED "")
  367. ENDIF( NOT Boost_USE_MULTITHREADED )
  368. SET( _boost_STATIC_TAG "")
  369. IF (WIN32)
  370. IF(MSVC)
  371. SET (_boost_ABI_TAG "g")
  372. ENDIF(MSVC)
  373. IF( Boost_USE_STATIC_LIBS )
  374. SET( _boost_STATIC_TAG "-s")
  375. ENDIF( Boost_USE_STATIC_LIBS )
  376. ENDIF(WIN32)
  377. SET (_boost_ABI_TAG "${_boost_ABI_TAG}d")
  378. # ------------------------------------------------------------------------
  379. # Begin finding boost libraries
  380. # ------------------------------------------------------------------------
  381. FOREACH(COMPONENT ${Boost_FIND_COMPONENTS})
  382. STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
  383. SET( Boost_${UPPERCOMPONENT}_LIBRARY "Boost_${UPPERCOMPONENT}_LIBRARY-NOTFOUND" )
  384. SET( Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE "Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE-NOTFOUND" )
  385. SET( Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG "Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG-NOTFOUND")
  386. # Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
  387. IF( Boost_USE_STATIC_LIBS )
  388. SET( _boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  389. IF(WIN32)
  390. SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  391. ELSE(WIN32)
  392. SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  393. ENDIF(WIN32)
  394. ENDIF( Boost_USE_STATIC_LIBS )
  395. FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE
  396. NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${Boost_LIB_VERSION}
  397. ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}-${Boost_LIB_VERSION}
  398. ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}
  399. ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}
  400. ${Boost_LIB_PREFIX}boost_${COMPONENT}
  401. HINTS ${_boost_LIBRARIES_SEARCH_DIRS}
  402. )
  403. FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG
  404. NAMES ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}-${_boost_ABI_TAG}-${Boost_LIB_VERSION}
  405. ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}-${Boost_LIB_VERSION}
  406. ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}-${_boost_ABI_TAG}
  407. ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_STATIC_TAG}${_boost_ABI_TAG}
  408. ${Boost_LIB_PREFIX}boost_${COMPONENT}-${_boost_ABI_TAG}
  409. HINTS ${_boost_LIBRARIES_SEARCH_DIRS}
  410. )
  411. _Boost_ADJUST_LIB_VARS(${UPPERCOMPONENT})
  412. IF( Boost_USE_STATIC_LIBS )
  413. SET(CMAKE_FIND_LIBRARY_SUFFIXES ${_boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
  414. ENDIF( Boost_USE_STATIC_LIBS )
  415. ENDFOREACH(COMPONENT)
  416. # ------------------------------------------------------------------------
  417. # End finding boost libraries
  418. # ------------------------------------------------------------------------
  419. SET(Boost_INCLUDE_DIRS
  420. ${Boost_INCLUDE_DIR}
  421. )
  422. SET(Boost_FOUND FALSE)
  423. IF(Boost_INCLUDE_DIR)
  424. SET( Boost_FOUND TRUE )
  425. # Check the version of Boost against the requested version.
  426. if (Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR)
  427. 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")
  428. endif (Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR)
  429. if(Boost_MAJOR_VERSION LESS "${Boost_FIND_VERSION_MAJOR}" )
  430. set( Boost_FOUND FALSE )
  431. set(_Boost_VERSION_AGE "old")
  432. elseif(Boost_MAJOR_VERSION EQUAL "${Boost_FIND_VERSION_MAJOR}" )
  433. if(Boost_MINOR_VERSION LESS "${Boost_FIND_VERSION_MINOR}" )
  434. set( Boost_FOUND FALSE )
  435. set(_Boost_VERSION_AGE "old")
  436. elseif(Boost_MINOR_VERSION EQUAL "${Boost_FIND_VERSION_MINOR}" )
  437. if( Boost_FIND_VERSION_PATCH AND Boost_SUBMINOR_VERSION LESS "${Boost_FIND_VERSION_PATCH}" )
  438. set( Boost_FOUND FALSE )
  439. set(_Boost_VERSION_AGE "old")
  440. endif( Boost_FIND_VERSION_PATCH AND Boost_SUBMINOR_VERSION LESS "${Boost_FIND_VERSION_PATCH}" )
  441. endif( Boost_MINOR_VERSION LESS "${Boost_FIND_VERSION_MINOR}" )
  442. endif( Boost_MAJOR_VERSION LESS "${Boost_FIND_VERSION_MAJOR}" )
  443. if (Boost_FOUND AND Boost_FIND_VERSION_EXACT)
  444. # If the user requested an exact version of Boost, check
  445. # that. We already know that the Boost version we have is >= the
  446. # requested version.
  447. set(_Boost_VERSION_AGE "new")
  448. # If the user didn't specify a patchlevel, it's 0.
  449. if (NOT Boost_FIND_VERSION_PATCH)
  450. set(Boost_FIND_VERSION_PATCH 0)
  451. endif (NOT Boost_FIND_VERSION_PATCH)
  452. # We'll set Boost_FOUND true again if we have an exact version match.
  453. set(Boost_FOUND FALSE)
  454. if(Boost_MAJOR_VERSION EQUAL "${Boost_FIND_VERSION_MAJOR}" )
  455. if(Boost_MINOR_VERSION EQUAL "${Boost_FIND_VERSION_MINOR}" )
  456. if(Boost_SUBMINOR_VERSION EQUAL "${Boost_FIND_VERSION_PATCH}" )
  457. set( Boost_FOUND TRUE )
  458. endif(Boost_SUBMINOR_VERSION EQUAL "${Boost_FIND_VERSION_PATCH}" )
  459. endif( Boost_MINOR_VERSION EQUAL "${Boost_FIND_VERSION_MINOR}" )
  460. endif( Boost_MAJOR_VERSION EQUAL "${Boost_FIND_VERSION_MAJOR}" )
  461. endif (Boost_FOUND AND Boost_FIND_VERSION_EXACT)
  462. if(NOT Boost_FOUND)
  463. # State that we found a version of Boost that is too new or too old.
  464. set(Boost_ERROR_REASON
  465. "${Boost_ERROR_REASON}\nDetected version of Boost is too ${_Boost_VERSION_AGE}. Requested version was ${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
  466. if (Boost_FIND_VERSION_PATCH)
  467. set(Boost_ERROR_REASON
  468. "${Boost_ERROR_REASON}.${Boost_FIND_VERSION_PATCH}")
  469. endif (Boost_FIND_VERSION_PATCH)
  470. if (NOT Boost_FIND_VERSION_EXACT)
  471. set(Boost_ERROR_REASON "${Boost_ERROR_REASON} (or newer)")
  472. endif (NOT Boost_FIND_VERSION_EXACT)
  473. set(Boost_ERROR_REASON "${Boost_ERROR_REASON}.")
  474. endif (NOT Boost_FOUND)
  475. if (Boost_FOUND)
  476. set(_boost_CHECKED_COMPONENT FALSE)
  477. set(_Boost_MISSING_COMPONENTS)
  478. foreach(COMPONENT ${Boost_FIND_COMPONENTS})
  479. string(TOUPPER ${COMPONENT} COMPONENT)
  480. set(_boost_CHECKED_COMPONENT TRUE)
  481. if(NOT Boost_${COMPONENT}_FOUND)
  482. string(TOLOWER ${COMPONENT} COMPONENT)
  483. list(APPEND _Boost_MISSING_COMPONENTS ${COMPONENT})
  484. set( Boost_FOUND FALSE)
  485. endif(NOT Boost_${COMPONENT}_FOUND)
  486. endforeach(COMPONENT)
  487. endif (Boost_FOUND)
  488. if (_Boost_MISSING_COMPONENTS)
  489. # We were unable to find some libraries, so generate a sensible
  490. # error message that lists the libraries we were unable to find.
  491. set(Boost_ERROR_REASON
  492. "${Boost_ERROR_REASON}\nThe following Boost libraries could not be found:\n")
  493. foreach(COMPONENT ${_Boost_MISSING_COMPONENTS})
  494. set(Boost_ERROR_REASON
  495. "${Boost_ERROR_REASON} boost_${COMPONENT}\n")
  496. endforeach(COMPONENT)
  497. list(LENGTH Boost_FIND_COMPONENTS Boost_NUM_COMPONENTS_WANTED)
  498. list(LENGTH _Boost_MISSING_COMPONENTS Boost_NUM_MISSING_COMPONENTS)
  499. if (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS})
  500. set(Boost_ERROR_REASON
  501. "${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.")
  502. else (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS})
  503. set(Boost_ERROR_REASON
  504. "${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.")
  505. endif (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS})
  506. endif (_Boost_MISSING_COMPONENTS)
  507. IF( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT )
  508. # Compatibility Code for backwards compatibility with CMake
  509. # 2.4's FindBoost module.
  510. # Look for the boost library path.
  511. # Note that the user may not have installed any libraries
  512. # so it is quite possible the Boost_LIBRARY_PATH may not exist.
  513. SET(_boost_LIB_DIR ${Boost_INCLUDE_DIR})
  514. IF("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+")
  515. GET_FILENAME_COMPONENT(_boost_LIB_DIR ${_boost_LIB_DIR} PATH)
  516. ENDIF ("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+")
  517. IF("${_boost_LIB_DIR}" MATCHES "/include$")
  518. # Strip off the trailing "/include" in the path.
  519. GET_FILENAME_COMPONENT(_boost_LIB_DIR ${_boost_LIB_DIR} PATH)
  520. ENDIF("${_boost_LIB_DIR}" MATCHES "/include$")
  521. IF(EXISTS "${_boost_LIB_DIR}/lib")
  522. SET (_boost_LIB_DIR ${_boost_LIB_DIR}/lib)
  523. ELSE(EXISTS "${_boost_LIB_DIR}/lib")
  524. IF(EXISTS "${_boost_LIB_DIR}/stage/lib")
  525. SET(_boost_LIB_DIR ${_boost_LIB_DIR}/stage/lib)
  526. ELSE(EXISTS "${_boost_LIB_DIR}/stage/lib")
  527. SET(_boost_LIB_DIR "")
  528. ENDIF(EXISTS "${_boost_LIB_DIR}/stage/lib")
  529. ENDIF(EXISTS "${_boost_LIB_DIR}/lib")
  530. IF(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}")
  531. SET(Boost_LIBRARY_DIRS ${_boost_LIB_DIR} CACHE FILEPATH "Boost library directory")
  532. ENDIF(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}")
  533. ENDIF( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT )
  534. ELSE(Boost_INCLUDE_DIR)
  535. SET( Boost_FOUND FALSE)
  536. ENDIF(Boost_INCLUDE_DIR)
  537. IF (Boost_FOUND)
  538. IF (NOT Boost_FIND_QUIETLY)
  539. MESSAGE(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
  540. ENDIF(NOT Boost_FIND_QUIETLY)
  541. IF (NOT Boost_FIND_QUIETLY)
  542. MESSAGE(STATUS "Found the following Boost libraries:")
  543. ENDIF(NOT Boost_FIND_QUIETLY)
  544. FOREACH ( COMPONENT ${Boost_FIND_COMPONENTS} )
  545. STRING( TOUPPER ${COMPONENT} UPPERCOMPONENT )
  546. IF ( Boost_${UPPERCOMPONENT}_FOUND )
  547. IF (NOT Boost_FIND_QUIETLY)
  548. MESSAGE (STATUS " ${COMPONENT}")
  549. ENDIF(NOT Boost_FIND_QUIETLY)
  550. SET(Boost_LIBRARIES ${Boost_LIBRARIES} ${Boost_${UPPERCOMPONENT}_LIBRARY})
  551. ENDIF ( Boost_${UPPERCOMPONENT}_FOUND )
  552. ENDFOREACH(COMPONENT)
  553. ELSE (Boost_FOUND)
  554. IF (Boost_FIND_REQUIRED)
  555. message(SEND_ERROR "Unable to find the requested Boost libraries.\n${Boost_ERROR_REASON}")
  556. ENDIF(Boost_FIND_REQUIRED)
  557. ENDIF(Boost_FOUND)
  558. # Under Windows, automatic linking is performed, so no need to specify the libraries.
  559. IF (WIN32)
  560. IF (NOT MINGW)
  561. SET(Boost_LIBRARIES "")
  562. ENDIF (NOT MINGW)
  563. ENDIF(WIN32)
  564. # show the Boost_INCLUDE_DIRS AND Boost_LIBRARIES variables only in the advanced view
  565. MARK_AS_ADVANCED(Boost_INCLUDE_DIR
  566. Boost_INCLUDE_DIRS
  567. Boost_LIBRARY_DIRS
  568. Boost_USE_MULTITHREADED
  569. )
  570. ENDIF(_boost_IN_CACHE)