Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/merger/cmake/FindBoost.cmake @ 330

Last change on this file since 330 was 294, checked in by nicolasc, 17 years ago

added FindENet and FindBoost
FindBoost does not work (yet)

File size: 10.2 KB
RevLine 
[294]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#  Boost_<library>_FOUND        - True if the Boost <library> is found.
9#  Boost_<library>_INCLUDE_DIRS - The include path for Boost <library>.
10#  Boost_<library>_LIBRARIES    - The libraries to link to to use Boost <library>.
11#  Boost_LIBRARIES              - The libraries to link to to use all Boost libraries.
12#
13# The following variables can be set to configure how Boost is found:
14#  Boost_LIB_PREFIX             - Look for Boost libraries prefixed with this, e.g. "lib"
15#  Boost_LIB_SUFFIX             - Look for Boost libraries ending with this, e.g. "vc80-mt"
16#  Boost_LIB_SUFFIX_DEBUG       - As for Boost_LIB_SUFFIX but for debug builds, e.g. "vs80-mt-gd"
17
18# ----------------------------------------------------------------------------
19# If you have installed Boost in a non-standard location or you have
20# just staged the boost files using bjam then you have three
21# options. In the following comments, it is assumed that <Your Path>
22# points to the root directory of the include directory of Boost. e.g
23# If you have put boost in C:\development\Boost then <Your Path> is
24# "C:/development/Boost" and in this directory there will be two
25# directories called "include" and "lib".
26# 1) After CMake runs, set Boost_INCLUDE_DIR to <Your Path>/include/boost<-version>
27# 2) Use CMAKE_INCLUDE_PATH to set a path to <Your Path>/include. This will allow FIND_PATH()
28#    to locate Boost_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g.
29#    SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include")
30# 3) Set an environment variable called ${BOOST_ROOT} that points to the root of where you have
31#    installed Boost, e.g. <Your Path>. It is assumed that there is at least a subdirectory called
32#    include in this path.
33#
34# Note:
35#  1) If you are just using the boost headers, then you do not need to use
36#     Boost_LIBRARY_DIRS in your CMakeLists.txt file.
37#  2) If Boost has not been installed, then when setting Boost_LIBRARY_DIRS
38#     the script will look for /lib first and, if this fails, then for /stage/lib.
39#
40# Usage:
41# In your CMakeLists.txt file do something like this:
42# ...
43# # Boost
44# FIND_PACKAGE(Boost)
45# ...
46# INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
47# LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
48#
49# In Windows, we make the assumption that, if the Boost files are installed, the default directory
50# will be C:\boost.
51
52#
53# TODO:
54#
55# 1) Automatically find the Boost library files and eliminate the need
56#    to use Link Directories.
57#
58
59IF(WIN32)
60# In windows, automatic linking is performed, so you do not have to specify the libraries.
61# If you are linking to a dynamic runtime, then you can choose to link to either a static or a
62# dynamic Boost library, the default is to do a static link.  You can alter this for a specific
63# library "whatever" by defining BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to
64# be linked dynamically.  Alternatively you can force all Boost libraries to dynamic link by
65# defining BOOST_ALL_DYN_LINK.
66
67# This feature can be disabled for Boost library "whatever" by defining BOOST_WHATEVER_NO_LIB,
68# or for all of Boost by defining BOOST_ALL_NO_LIB.
69
70# If you want to observe which libraries are being linked against then defining
71# BOOST_LIB_DIAGNOSTIC will cause the auto-linking code to emit a #pragma message each time
72# a library is selected for linking.
73  SET(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC")
74ENDIF(WIN32)
75
76
77SET(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")
78
79SET(BOOST_DIR_MESSAGE "Set the Boost_INCLUDE_DIR cmake cache entry to the ${BOOST_INCLUDE_PATH_DESCRIPTION}")
80
81SET(BOOST_DIR_SEARCH $ENV{BOOST_ROOT})
82IF(BOOST_DIR_SEARCH)
83  FILE(TO_CMAKE_PATH ${BOOST_DIR_SEARCH} BOOST_DIR_SEARCH)
84  SET(BOOST_DIR_SEARCH ${BOOST_DIR_SEARCH}/include)
85ENDIF(BOOST_DIR_SEARCH)
86
87IF(WIN32)
88  SET(BOOST_DIR_SEARCH
89    ${BOOST_DIR_SEARCH}
90    C:/boost/include
91    D:/boost/include
92  )
93ENDIF(WIN32)
94
95# Add in some path suffixes. These will have to be updated whenever a new Boost version comes out.
96SET(SUFFIX_FOR_PATH
97 boost-1_34_1
98 boost-1_34_0
99 boost-1_34
100 boost-1_33_1
101 boost-1_33_0
102)
103
104#
105# Look for an installation.
106#
107FIND_PATH(Boost_INCLUDE_DIR NAMES boost/config.hpp PATH_SUFFIXES ${SUFFIX_FOR_PATH} PATHS
108
109# Look in other places.
110  ${BOOST_DIR_SEARCH}
111
112# Help the user find it if we cannot.
113  DOC "The ${BOOST_INCLUDE_PATH_DESCRIPTION}"
114)
115
116# Assume we didn't find it.
117SET(Boost_FOUND 0)
118
119# Now try to get the include and library path.
120IF(Boost_INCLUDE_DIR)
121
122# Look for the boost library path.
123# Note that the user may not have installed any libraries
124# so it is quite possible the Boost_LIBRARY_PATH may not exist.
125  SET(Boost_LIBRARY_DIR ${Boost_INCLUDE_DIR})
126
127  IF("${Boost_LIBRARY_DIR}" MATCHES "boost-[0-9]+")
128    GET_FILENAME_COMPONENT(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR} PATH)
129  ENDIF ("${Boost_LIBRARY_DIR}" MATCHES "boost-[0-9]+")
130
131  IF("${Boost_LIBRARY_DIR}" MATCHES "/include$")
132# Strip off the trailing "/include" in the path.
133    GET_FILENAME_COMPONENT(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR} PATH)
134  ENDIF("${Boost_LIBRARY_DIR}" MATCHES "/include$")
135
136  IF(EXISTS "${Boost_LIBRARY_DIR}/lib")
137    SET (Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR}/lib)
138  ELSE(EXISTS "${Boost_LIBRARY_DIR}/lib")
139    IF(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
140      SET(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR}/stage/lib)
141    ELSE(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
142      SET(Boost_LIBRARY_DIR "")
143    ENDIF(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
144  ENDIF(EXISTS "${Boost_LIBRARY_DIR}/lib")
145
146  IF(EXISTS "${Boost_INCLUDE_DIR}")
147    SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
148# We have found boost. It is possible that the user has not
149# compiled any libraries so we set Boost_FOUND to be true here.
150    SET(Boost_FOUND 1)
151    MARK_AS_ADVANCED(Boost_INCLUDE_DIR)
152  ENDIF(EXISTS "${Boost_INCLUDE_DIR}")
153
154  IF(Boost_LIBRARY_DIR AND EXISTS "${Boost_LIBRARY_DIR}")
155    SET(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR})
156  ENDIF(Boost_LIBRARY_DIR AND EXISTS "${Boost_LIBRARY_DIR}")
157ENDIF(Boost_INCLUDE_DIR)
158
159#
160# Find boost libraries
161#
162
163# List of library suffixes to search, e.g. libboost_date_time-gcc
164SET(BOOST_SUFFIX_SEARCH
165  gcc
166  il
167)
168
169# List of all boost libraries
170SET(BOOST_ALL_LIBRARIES
171  date_time
172  filesystem
173  graph
174  iostreams
175  program_options
176  python
177  regex
178  serialization
179  signals
180  unit_test_framework
181  thread
182  wave
183)
184
185# Macro to find boost library called name
186MACRO(BOOST_FIND_LIBRARY name)
187
188# User can specify a particular build variant via the variables:
189#   Boost_LIB_PREFIX, Boost_LIB_SUFFIX, Boost_LIB_SUFFIX_DEBUG
190# otherwise we'll search the BOOST_SUFFIX_SEARCH list
191  SET(BOOST_LIB_NAMES ${Boost_LIB_PREFIX}boost_${name}-${Boost_LIB_SUFFIX})
192  IF(NOT Boost_LIB_SUFFIX)
193    FOREACH(suffix ${BOOST_SUFFIX_SEARCH})
194      SET(BOOST_LIB_NAMES ${BOOST_LIB_NAMES} ${Boost_LIB_PREFIX}boost_${name}-${suffix})
195    ENDFOREACH(suffix)
196  ENDIF(NOT Boost_LIB_SUFFIX)
197
198# Find the library in the Boost_LIBRARY_DIRS
199  FIND_LIBRARY(Boost_${name}_LIBRARY
200    NAMES ${BOOST_LIB_NAMES}
201    PATHS ${Boost_LIBRARY_DIRS})
202
203# For MSVC builds find debug library
204  IF(WIN32 AND MSVC AND Boost_${name}_LIBRARY)
205    FIND_LIBRARY(Boost_${name}_LIBRARY_DEBUG ${Boost_LIB_PREFIX}boost_${name}-${Boost_LIB_SUFFIX_DEBUG})
206
207    IF(MSVC_IDE)
208      IF(Boost_${name}_LIBRARY AND Boost_${name}_LIBRARY_DEBUG)
209        SET(Boost_${name}_LIBRARIES debug ${Boost_${name}_LIBRARY_DEBUG} optimized ${Boost_${name}_LIBRARY})
210      ELSE(Boost_${name}_LIBRARY AND Boost_${name}_LIBRARY_DEBUG)
211        MESSAGE(FATAL_ERROR "Could not find the debug and release version of Boost ${name} library.")
212      ENDIF(Boost_${name}_LIBRARY AND Boost_${name}_LIBRARY_DEBUG)
213    ELSE(MSVC_IDE)
214      STRING(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER)
215      IF(CMAKE_BUILD_TYPE_TOLOWER MATCHES debug)
216        SET(Boost_${name}_LIBRARIES ${Boost_${name}_LIBRARY_DEBUG})
217      ELSE(CMAKE_BUILD_TYPE_TOLOWER MATCHES debug)
218        SET(Boost_${name}_LIBRARIES ${Boost_${name}_LIBRARY})
219      ENDIF(CMAKE_BUILD_TYPE_TOLOWER MATCHES debug)
220    ENDIF(MSVC_IDE)
221  ELSE(WIN32 AND MSVC AND Boost_${name}_LIBRARY)
222    SET(Boost_${name}_LIBRARIES ${Boost_${name}_LIBRARY})
223  ENDIF(WIN32 AND MSVC AND Boost_${name}_LIBRARY)
224
225# If we've got it setup appropriate variables or issue error message
226  IF(Boost_${name}_LIBRARY)
227    SET(Boost_${name}_FOUND 1)
228    SET(Boost_${name}_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
229    MARK_AS_ADVANCED(Boost_${name}_LIBRARY Boost_${name}_LIBRARY_DEBUG)
230  ELSE(Boost_${name}_LIBRARY)
231    IF(NOT Boost_FIND_QUIETLY)
232      MESSAGE(STATUS "Boost ${name} library was not found.")
233    ELSE(NOT Boost_FIND_QUIETLY)
234      IF(Boost_FIND_REQUIRED_${name})
235        MESSAGE(FATAL_ERROR "Could NOT find required Boost ${name} library.")
236      ENDIF(Boost_FIND_REQUIRED_${name})
237    ENDIF(NOT Boost_FIND_QUIETLY)
238  ENDIF(Boost_${name}_LIBRARY)
239ENDMACRO(BOOST_FIND_LIBRARY)
240
241IF(Boost_LIBRARY_DIRS)
242
243# If the user specified required components e.g. via
244# FIND_PACKAGE(Boost REQUIRED date_time regex)
245# find (just) those libraries. Otherwise find all libraries.
246  IF(Boost_FIND_COMPONENTS)
247    SET(Boost_FIND_LIBRARIES ${Boost_FIND_COMPONENTS})
248  ELSE(Boost_FIND_COMPONENTS)
249    SET(Boost_FIND_LIBRARIES ${BOOST_ALL_LIBRARIES})
250  ENDIF(Boost_FIND_COMPONENTS)
251
252  SET(Boost_LIBRARIES)
253  FOREACH(library ${Boost_FIND_LIBRARIES})
254    BOOST_FIND_LIBRARY(${library})
255    IF(Boost_${library}_FOUND)
256      SET(Boost_LIBRARIES ${Boost_LIBRARIES} ${Boost_${library}_LIBRARIES})
257    ENDIF(Boost_${library}_FOUND)
258  ENDFOREACH(library)
259ENDIF(Boost_LIBRARY_DIRS)
260
261IF(NOT Boost_FOUND)
262  IF(NOT Boost_FIND_QUIETLY)
263    MESSAGE(STATUS "Boost was not found. ${BOOST_DIR_MESSAGE}")
264  ELSE(NOT Boost_FIND_QUIETLY)
265    IF(Boost_FIND_REQUIRED)
266      MESSAGE(FATAL_ERROR "Boost was not found. ${BOOST_DIR_MESSAGE}")
267    ENDIF(Boost_FIND_REQUIRED)
268  ENDIF(NOT Boost_FIND_QUIETLY)
269ENDIF(NOT Boost_FOUND)
Note: See TracBrowser for help on using the repository browser.