Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/cmake/FindBoost.cmake @ 2077

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