Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/cmake/FindBoost.cmake @ 480

Last change on this file since 480 was 418, checked in by bknecht, 17 years ago

cool fix for boost compiling

File size: 10.5 KB
Line 
1# THIS FILE HAS BEEN MODIFIED TO WORK ON TARDIS
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")
78ENDIF(WIN32)
79
80
81SET(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")
82
83SET(BOOST_DIR_MESSAGE "Set the Boost_INCLUDE_DIR cmake cache entry to the ${BOOST_INCLUDE_PATH_DESCRIPTION}")
84
85SET(BOOST_DIR_SEARCH $ENV{BOOST_ROOT})
86IF(BOOST_DIR_SEARCH)
87  FILE(TO_CMAKE_PATH ${BOOST_DIR_SEARCH} BOOST_DIR_SEARCH)
88  SET(BOOST_DIR_SEARCH ${BOOST_DIR_SEARCH}/include)
89ENDIF(BOOST_DIR_SEARCH)
90
91IF(WIN32)
92  SET(BOOST_DIR_SEARCH
93    ${BOOST_DIR_SEARCH}
94    C:/boost/include
95    D:/boost/include
96  )
97ENDIF(WIN32)
98
99# Add in some path suffixes. These will have to be updated whenever a new Boost version comes out.
100SET(SUFFIX_FOR_PATH
101 boost-1_34_1
102 boost-1_34_0
103 boost-1_34
104 boost-1_33_1
105 boost-1_33_0
106)
107
108#
109# Look for an installation.
110#
111FIND_PATH(Boost_INCLUDE_DIR NAMES boost/config.hpp PATH_SUFFIXES ${SUFFIX_FOR_PATH} PATHS
112
113# Look in other places.
114  ${BOOST_DIR_SEARCH}
115
116# Help the user find it if we cannot.
117  DOC "The ${BOOST_INCLUDE_PATH_DESCRIPTION}"
118)
119
120# Assume we didn't find it.
121SET(Boost_FOUND 0)
122
123# Now try to get the include and library path.
124IF(Boost_INCLUDE_DIR)
125
126# Look for the boost library path.
127# Note that the user may not have installed any libraries
128# so it is quite possible the Boost_LIBRARY_PATH may not exist.
129  SET(Boost_LIBRARY_DIR ${Boost_INCLUDE_DIR})
130
131  IF("${Boost_LIBRARY_DIR}" MATCHES "boost-[0-9]+")
132    GET_FILENAME_COMPONENT(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR} PATH)
133  ENDIF ("${Boost_LIBRARY_DIR}" MATCHES "boost-[0-9]+")
134
135  IF("${Boost_LIBRARY_DIR}" MATCHES "/include$")
136# Strip off the trailing "/include" in the path.
137    GET_FILENAME_COMPONENT(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR} PATH)
138  ENDIF("${Boost_LIBRARY_DIR}" MATCHES "/include$")
139
140  IF(EXISTS "${Boost_LIBRARY_DIR}/lib")
141    SET (Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR}/lib)
142  ELSE(EXISTS "${Boost_LIBRARY_DIR}/lib")
143    IF(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
144      SET(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR}/stage/lib)
145    ELSE(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
146      IF(EXISTS "${Boost_LIBRARY_DIR}/../../lib")
147        SET(Boost_LIBRARY_DIR "${Boost_LIBRARY_DIR}/../../lib")
148      ELSE(EXISTS "${Boost_LIBRARY_DIR}/../../lib")
149        SET(Boost_LIBRARY_DIR "")
150      ENDIF(EXISTS "${Boost_LIBRARY_DIR}/../../lib")
151    ENDIF(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
152  ENDIF(EXISTS "${Boost_LIBRARY_DIR}/lib")
153
154  IF(EXISTS "${Boost_INCLUDE_DIR}")
155    SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
156# We have found boost. It is possible that the user has not
157# compiled any libraries so we set Boost_FOUND to be true here.
158    SET(Boost_FOUND 1)
159    MARK_AS_ADVANCED(Boost_INCLUDE_DIR)
160  ENDIF(EXISTS "${Boost_INCLUDE_DIR}")
161
162  IF(Boost_LIBRARY_DIR AND EXISTS "${Boost_LIBRARY_DIR}")
163    SET(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR})
164  ENDIF(Boost_LIBRARY_DIR AND EXISTS "${Boost_LIBRARY_DIR}")
165ENDIF(Boost_INCLUDE_DIR)
166
167#
168# Find boost libraries
169#
170
171# List of library suffixes to search, e.g. libboost_date_time-gcc
172SET(BOOST_SUFFIX_SEARCH
173  mt
174  gcc41-mt
175  gcc
176  il
177)
178
179# List of all boost libraries
180SET(BOOST_ALL_LIBRARIES
181  date_time
182  filesystem
183  graph
184  iostreams
185  program_options
186  regex
187  serialization
188  signals
189  unit_test_framework
190  thread
191  wave
192)
193
194# Macro to find boost library called name
195MACRO(BOOST_FIND_LIBRARY name)
196
197# User can specify a particular build variant via the variables:
198#   Boost_LIB_PREFIX, Boost_LIB_SUFFIX, Boost_LIB_SUFFIX_DEBUG
199# otherwise we'll search the BOOST_SUFFIX_SEARCH list
200
201  SET(BOOST_LIB_NAMES ${Boost_LIB_PREFIX}boost_${name}-${Boost_LIB_SUFFIX})
202  IF(NOT Boost_LIB_SUFFIX)
203    FOREACH(suffix ${BOOST_SUFFIX_SEARCH})
204      SET(BOOST_LIB_NAMES ${BOOST_LIB_NAMES} ${Boost_LIB_PREFIX}boost_${name}-${suffix})
205    ENDFOREACH(suffix)
206  ENDIF(NOT Boost_LIB_SUFFIX)
207
208# Find the library in the Boost_LIBRARY_DIRS
209  FIND_LIBRARY(Boost_${name}_LIBRARY
210    NAMES ${BOOST_LIB_NAMES}
211    PATHS ${Boost_LIBRARY_DIRS})
212
213# For MSVC builds find debug library
214  IF(WIN32 AND MSVC AND Boost_${name}_LIBRARY)
215    FIND_LIBRARY(Boost_${name}_LIBRARY_DEBUG ${Boost_LIB_PREFIX}boost_${name}-${Boost_LIB_SUFFIX_DEBUG})
216
217    IF(MSVC_IDE)
218      IF(Boost_${name}_LIBRARY AND Boost_${name}_LIBRARY_DEBUG)
219        SET(Boost_${name}_LIBRARIES debug ${Boost_${name}_LIBRARY_DEBUG} optimized ${Boost_${name}_LIBRARY})
220      ELSE(Boost_${name}_LIBRARY AND Boost_${name}_LIBRARY_DEBUG)
221        MESSAGE(FATAL_ERROR "Could not find the debug and release version of Boost ${name} library.")
222      ENDIF(Boost_${name}_LIBRARY AND Boost_${name}_LIBRARY_DEBUG)
223    ELSE(MSVC_IDE)
224      STRING(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER)
225      IF(CMAKE_BUILD_TYPE_TOLOWER MATCHES debug)
226        SET(Boost_${name}_LIBRARIES ${Boost_${name}_LIBRARY_DEBUG})
227      ELSE(CMAKE_BUILD_TYPE_TOLOWER MATCHES debug)
228        SET(Boost_${name}_LIBRARIES ${Boost_${name}_LIBRARY})
229      ENDIF(CMAKE_BUILD_TYPE_TOLOWER MATCHES debug)
230    ENDIF(MSVC_IDE)
231  ELSE(WIN32 AND MSVC AND Boost_${name}_LIBRARY)
232    SET(Boost_${name}_LIBRARIES ${Boost_${name}_LIBRARY})
233  ENDIF(WIN32 AND MSVC AND Boost_${name}_LIBRARY)
234
235# If we've got it setup appropriate variables or issue error message
236  IF(Boost_${name}_LIBRARY)
237    SET(Boost_${name}_FOUND 1)
238    SET(Boost_${name}_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
239    MARK_AS_ADVANCED(Boost_${name}_LIBRARY Boost_${name}_LIBRARY_DEBUG)
240  ELSE(Boost_${name}_LIBRARY)
241    MESSAGE(STATUS "sdfds")
242    IF(NOT Boost_FIND_QUIETLY)
243      MESSAGE(STATUS "Boost ${name} library was not found.")
244    ELSE(NOT Boost_FIND_QUIETLY)
245      IF(Boost_FIND_REQUIRED_${name})
246        MESSAGE(FATAL_ERROR "Could NOT find required Boost ${name} library.")
247      ENDIF(Boost_FIND_REQUIRED_${name})
248    ENDIF(NOT Boost_FIND_QUIETLY)
249  ENDIF(Boost_${name}_LIBRARY)
250ENDMACRO(BOOST_FIND_LIBRARY)
251
252IF(Boost_LIBRARY_DIRS)
253
254# If the user specified required components e.g. via
255# FIND_PACKAGE(Boost REQUIRED date_time regex)
256# find (just) those libraries. Otherwise find all libraries.
257  IF(Boost_FIND_COMPONENTS)
258    SET(Boost_FIND_LIBRARIES ${Boost_FIND_COMPONENTS})
259  ELSE(Boost_FIND_COMPONENTS)
260    SET(Boost_FIND_LIBRARIES ${BOOST_ALL_LIBRARIES})
261  ENDIF(Boost_FIND_COMPONENTS)
262
263  SET(Boost_LIBRARIES)
264  FOREACH(library ${Boost_FIND_LIBRARIES})
265    BOOST_FIND_LIBRARY(${library})
266    IF(Boost_${library}_FOUND)
267      SET(Boost_LIBRARIES ${Boost_LIBRARIES} ${Boost_${library}_LIBRARIES})
268    ENDIF(Boost_${library}_FOUND)
269  ENDFOREACH(library)
270ENDIF(Boost_LIBRARY_DIRS)
271
272IF(NOT Boost_FOUND)
273  IF(NOT Boost_FIND_QUIETLY)
274    MESSAGE(STATUS "Boost was not found. ${BOOST_DIR_MESSAGE}")
275  ELSE(NOT Boost_FIND_QUIETLY)
276    IF(Boost_FIND_REQUIRED)
277      MESSAGE(FATAL_ERROR "Boost was not found. ${BOOST_DIR_MESSAGE}")
278    ENDIF(Boost_FIND_REQUIRED)
279  ENDIF(NOT Boost_FIND_QUIETLY)
280ENDIF(NOT Boost_FOUND)
Note: See TracBrowser for help on using the repository browser.