Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/cmake/FindBoost.cmake @ 1307

Last change on this file since 1307 was 1230, checked in by landauf, 17 years ago

added a tcl-thread, but there are still some bugs and problems

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