FindBoost.cmake 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # - Find the Boost includes and libraries.
  2. # The following variables are set if Boost is found. If Boost is not
  3. # found, Boost_FOUND is set to false.
  4. # Boost_FOUND - True when the Boost include directory is found.
  5. # Boost_INCLUDE_DIRS - the path to where the boost include files are.
  6. # Boost_LIBRARY_DIRS - The path to where the boost library files are.
  7. # Boost_LIB_DIAGNOSTIC_DEFINITIONS - Only set if using Windows.
  8. # ----------------------------------------------------------------------------
  9. # If you have installed Boost in a non-standard location or you have
  10. # just staged the boost files using bjam then you have three
  11. # options. In the following comments, it is assumed that <Your Path>
  12. # points to the root directory of the include directory of Boost. e.g
  13. # If you have put boost in C:\development\Boost then <Your Path> is
  14. # "C:/development/Boost" and in this directory there will be two
  15. # directories called "include" and "lib".
  16. # 1) After CMake runs, set Boost_INCLUDE_DIR to <Your Path>/include/boost<-version>
  17. # 2) Use CMAKE_INCLUDE_PATH to set a path to <Your Path>/include. This will allow FIND_PATH()
  18. # to locate Boost_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g.
  19. # SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include")
  20. # 3) Set an environment variable called ${BOOST_ROOT} that points to the root of where you have
  21. # installed Boost, e.g. <Your Path>. It is assumed that there is at least a subdirectory called
  22. # include in this path.
  23. #
  24. # Note:
  25. # 1) If you are just using the boost headers, then you do not need to use
  26. # Boost_LIBRARY_DIRS in your CMakeLists.txt file.
  27. # 2) If Boost has not been installed, then when setting Boost_LIBRARY_DIRS
  28. # the script will look for /lib first and, if this fails, then for /stage/lib.
  29. #
  30. # Usage:
  31. # In your CMakeLists.txt file do something like this:
  32. # ...
  33. # # Boost
  34. # FIND_PACKAGE(Boost)
  35. # ...
  36. # INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
  37. # LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
  38. #
  39. # In Windows, we make the assumption that, if the Boost files are installed, the default directory
  40. # will be C:\boost.
  41. #
  42. # TODO:
  43. #
  44. # 1) Automatically find the Boost library files and eliminate the need
  45. # to use Link Directories.
  46. #
  47. IF(WIN32)
  48. # In windows, automatic linking is performed, so you do not have to specify the libraries.
  49. # If you are linking to a dynamic runtime, then you can choose to link to either a static or a
  50. # dynamic Boost library, the default is to do a static link. You can alter this for a specific
  51. # library "whatever" by defining BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to
  52. # be linked dynamically. Alternatively you can force all Boost libraries to dynamic link by
  53. # defining BOOST_ALL_DYN_LINK.
  54. # This feature can be disabled for Boost library "whatever" by defining BOOST_WHATEVER_NO_LIB,
  55. # or for all of Boost by defining BOOST_ALL_NO_LIB.
  56. # If you want to observe which libraries are being linked against then defining
  57. # BOOST_LIB_DIAGNOSTIC will cause the auto-linking code to emit a #pragma message each time
  58. # a library is selected for linking.
  59. SET(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC")
  60. ENDIF(WIN32)
  61. SET(BOOST_INCLUDE_PATH_DESCRIPTION "directory containing the boost include files. E.g /usr/local/include/boost-1_33_1 or c:\\boost\\include\\boost-1_33_1")
  62. SET(BOOST_DIR_MESSAGE "Set the Boost_INCLUDE_DIR cmake cache entry to the ${BOOST_INCLUDE_PATH_DESCRIPTION}")
  63. SET(BOOST_DIR_SEARCH $ENV{BOOST_ROOT})
  64. IF(BOOST_DIR_SEARCH)
  65. FILE(TO_CMAKE_PATH ${BOOST_DIR_SEARCH} BOOST_DIR_SEARCH)
  66. SET(BOOST_DIR_SEARCH ${BOOST_DIR_SEARCH}/include)
  67. ENDIF(BOOST_DIR_SEARCH)
  68. IF(WIN32)
  69. SET(BOOST_DIR_SEARCH
  70. ${BOOST_DIR_SEARCH}
  71. C:/boost/include
  72. D:/boost/include
  73. )
  74. ENDIF(WIN32)
  75. # Add in some path suffixes. These will have to be updated whenever a new Boost version comes out.
  76. SET(SUFFIX_FOR_PATH
  77. boost-1_34_1
  78. boost-1_34_0
  79. boost-1_33_1
  80. boost-1_33_0
  81. )
  82. #
  83. # Look for an installation.
  84. #
  85. FIND_PATH(Boost_INCLUDE_DIR NAMES boost/config.hpp PATH_SUFFIXES ${SUFFIX_FOR_PATH} PATHS
  86. # Look in other places.
  87. ${BOOST_DIR_SEARCH}
  88. # Help the user find it if we cannot.
  89. DOC "The ${BOOST_INCLUDE_PATH_DESCRIPTION}"
  90. )
  91. # Assume we didn't find it.
  92. SET(Boost_FOUND 0)
  93. # Now try to get the include and library path.
  94. IF(Boost_INCLUDE_DIR)
  95. # Look for the boost library path.
  96. # Note that the user may not have installed any libraries
  97. # so it is quite possible the Boost_LIBRARY_PATH may not exist.
  98. SET(Boost_LIBRARY_DIR ${Boost_INCLUDE_DIR})
  99. IF("${Boost_LIBRARY_DIR}" MATCHES "boost-[0-9]+")
  100. GET_FILENAME_COMPONENT(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR} PATH)
  101. ENDIF ("${Boost_LIBRARY_DIR}" MATCHES "boost-[0-9]+")
  102. IF("${Boost_LIBRARY_DIR}" MATCHES "/include$")
  103. # Strip off the trailing "/include" in the path.
  104. GET_FILENAME_COMPONENT(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR} PATH)
  105. ENDIF("${Boost_LIBRARY_DIR}" MATCHES "/include$")
  106. IF(EXISTS "${Boost_LIBRARY_DIR}/lib")
  107. SET (Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR}/lib)
  108. ELSE(EXISTS "${Boost_LIBRARY_DIR}/lib")
  109. IF(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
  110. SET(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR}/stage/lib)
  111. ELSE(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
  112. SET(Boost_LIBRARY_DIR "")
  113. ENDIF(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
  114. ENDIF(EXISTS "${Boost_LIBRARY_DIR}/lib")
  115. IF(EXISTS "${Boost_INCLUDE_DIR}")
  116. SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
  117. # We have found boost. It is possible that the user has not
  118. # compiled any libraries so we set Boost_FOUND to be true here.
  119. SET(Boost_FOUND 1)
  120. ENDIF(EXISTS "${Boost_INCLUDE_DIR}")
  121. IF(Boost_LIBRARY_DIR AND EXISTS "${Boost_LIBRARY_DIR}")
  122. SET(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR})
  123. ENDIF(Boost_LIBRARY_DIR AND EXISTS "${Boost_LIBRARY_DIR}")
  124. ENDIF(Boost_INCLUDE_DIR)
  125. IF(NOT Boost_FOUND)
  126. IF(NOT Boost_FIND_QUIETLY)
  127. MESSAGE(STATUS "Boost was not found. ${BOOST_DIR_MESSAGE}")
  128. ELSE(NOT Boost_FIND_QUIETLY)
  129. IF(Boost_FIND_REQUIRED)
  130. MESSAGE(FATAL_ERROR "Boost was not found. ${BOOST_DIR_MESSAGE}")
  131. ENDIF(Boost_FIND_REQUIRED)
  132. ENDIF(NOT Boost_FIND_QUIETLY)
  133. ENDIF(NOT Boost_FOUND)