Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Modules / FindBoost.cmake
blob2de8239c77dabfa85de18dec139157c50bd86417
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.
9 # ----------------------------------------------------------------------------
10 # If you have installed Boost in a non-standard location or you have
11 # just staged the boost files using bjam then you have three
12 # options. In the following comments, it is assumed that <Your Path>
13 # points to the root directory of the include directory of Boost. e.g
14 # If you have put boost in C:\development\Boost then <Your Path> is
15 # "C:/development/Boost" and in this directory there will be two
16 # directories called "include" and "lib".
17 # 1) After CMake runs, set Boost_INCLUDE_DIR to <Your Path>/include/boost<-version>
18 # 2) Use CMAKE_INCLUDE_PATH to set a path to <Your Path>/include. This will allow FIND_PATH()
19 #    to locate Boost_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g.
20 #    SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include")
21 # 3) Set an environment variable called ${BOOST_ROOT} that points to the root of where you have
22 #    installed Boost, e.g. <Your Path>. It is assumed that there is at least a subdirectory called
23 #    include in this path.
25 # Note:
26 #  1) If you are just using the boost headers, then you do not need to use
27 #     Boost_LIBRARY_DIRS in your CMakeLists.txt file.
28 #  2) If Boost has not been installed, then when setting Boost_LIBRARY_DIRS
29 #     the script will look for /lib first and, if this fails, then for /stage/lib.
31 # Usage:
32 # In your CMakeLists.txt file do something like this:
33 # ...
34 # # Boost
35 # FIND_PACKAGE(Boost)
36 # ...
37 # INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
38 # LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
40 # In Windows, we make the assumption that, if the Boost files are installed, the default directory
41 # will be C:\boost.
44 # TODO:
46 # 1) Automatically find the Boost library files and eliminate the need
47 #    to use Link Directories.
50 IF(WIN32)
51   # In windows, automatic linking is performed, so you do not have to specify the libraries.
52   # If you are linking to a dynamic runtime, then you can choose to link to either a static or a
53   # dynamic Boost library, the default is to do a static link.  You can alter this for a specific
54   # library "whatever" by defining BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to
55   # be linked dynamically.  Alternatively you can force all Boost libraries to dynamic link by
56   # defining BOOST_ALL_DYN_LINK.
58   # This feature can be disabled for Boost library "whatever" by defining BOOST_WHATEVER_NO_LIB,
59   # or for all of Boost by defining BOOST_ALL_NO_LIB.
61   # If you want to observe which libraries are being linked against then defining
62   # BOOST_LIB_DIAGNOSTIC will cause the auto-linking code to emit a #pragma message each time
63   # a library is selected for linking.
64   SET(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC")
65 ENDIF(WIN32)
68 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")
70 SET(BOOST_DIR_MESSAGE "Set the Boost_INCLUDE_DIR cmake cache entry to the ${BOOST_INCLUDE_PATH_DESCRIPTION}")
72 SET(BOOST_DIR_SEARCH $ENV{BOOST_ROOT})
73 IF(BOOST_DIR_SEARCH)
74   FILE(TO_CMAKE_PATH ${BOOST_DIR_SEARCH} BOOST_DIR_SEARCH)
75   SET(BOOST_DIR_SEARCH ${BOOST_DIR_SEARCH} ${BOOST_DIR_SEARCH}/include)
76 ENDIF(BOOST_DIR_SEARCH)
78 IF(WIN32)
79   SET(BOOST_DIR_SEARCH
80     ${BOOST_DIR_SEARCH}
81     C:/boost/include
82     D:/boost/include
83   )
84 ENDIF(WIN32)
86 # Add in some path suffixes. These will have to be updated whenever a new Boost version comes out.
87 SET(SUFFIX_FOR_PATH
88  boost-1_34_1
89  boost-1_34_0
90  boost-1_34
91  boost-1_33_1
92  boost-1_33_0
96 # Look for an installation.
98 FIND_PATH(Boost_INCLUDE_DIR NAMES boost/config.hpp PATH_SUFFIXES ${SUFFIX_FOR_PATH} PATHS
100   # Look in other places.
101   ${BOOST_DIR_SEARCH}
103   # Help the user find it if we cannot.
104   DOC "The ${BOOST_INCLUDE_PATH_DESCRIPTION}"
107 SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
109 # Now try to get the include and library path.
110 IF(Boost_INCLUDE_DIR)
112   # Look for the boost library path.
113   # Note that the user may not have installed any libraries
114   # so it is quite possible the Boost_LIBRARY_PATH may not exist.
115   SET(Boost_LIBRARY_DIR ${Boost_INCLUDE_DIR})
117   IF("${Boost_LIBRARY_DIR}" MATCHES "boost-[0-9]+")
118     GET_FILENAME_COMPONENT(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR} PATH)
119   ENDIF ("${Boost_LIBRARY_DIR}" MATCHES "boost-[0-9]+")
121   IF("${Boost_LIBRARY_DIR}" MATCHES "/include$")
122     # Strip off the trailing "/include" in the path.
123     GET_FILENAME_COMPONENT(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR} PATH)
124   ENDIF("${Boost_LIBRARY_DIR}" MATCHES "/include$")
126   IF(EXISTS "${Boost_LIBRARY_DIR}/lib")
127     SET (Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR}/lib)
128   ELSE(EXISTS "${Boost_LIBRARY_DIR}/lib")
129     IF(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
130       SET(Boost_LIBRARY_DIR ${Boost_LIBRARY_DIR}/stage/lib)
131     ELSE(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
132       SET(Boost_LIBRARY_DIR "")
133     ENDIF(EXISTS "${Boost_LIBRARY_DIR}/stage/lib")
134   ENDIF(EXISTS "${Boost_LIBRARY_DIR}/lib")
136   IF(Boost_LIBRARY_DIR AND EXISTS "${Boost_LIBRARY_DIR}")
137     SET(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR})
138   ENDIF(Boost_LIBRARY_DIR AND EXISTS "${Boost_LIBRARY_DIR}")
139 ENDIF(Boost_INCLUDE_DIR)
141 # We have found boost. It is possible that the user has not
142 # compiled any libraries so we set Boost_FOUND to be true here.
143 # handle the QUIETLY and REQUIRED arguments and set BOOST_FOUND to TRUE if 
144 # all listed variables are TRUE
145 INCLUDE(FindPackageHandleStandardArgs)
146 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Boost "Boost was not found. ${BOOST_DIR_MESSAGE}" Boost_INCLUDE_DIR )
147 SET(Boost_FOUND ${BOOST_FOUND})
149 MARK_AS_ADVANCED(Boost_INCLUDE_DIR)