[CMake] Finding Boost for Windows and Linux.
Andrew Maclean
andrew.amaclean at gmail.com
Mon Jun 19 02:56:50 EDT 2006
Skipped content of type multipart/alternative-------------- next part --------------
#-----------------------------------------------------------------------------
# Find the Boost includes and libraries.
# The following variables are set if Boost is found. If Boost is not
# found, BOOST_FOUND is set to false.
# BOOST_FOUND - Set to true when Boost is found.
# BOOST_INCLUDE_PATH - the path to where the boost include files are.
# BOOST_LIBRARY_PATH - The path to where the boost library files are.
#
# Note:
# 1) If you are just using the boost headers, then you do not need to use
# BOOST_LIBRARY_PATH in your CMakeLists.txt file.
# 2) If you are using Linux, and the boost libraries are in the default
# system library paths then you do not need to use BOOST_LIBRARY_PATH.
#
# Usage:
# In your CMakeLists.txt file do something like this:
# ...
# # Boost
# INCLUDE(FindBoost.cmake)
# ...
# INCLUDE_DIRECTORIES (${BOOST_INCLUDE_PATH})
# ...
# #-----------------------------------------------------------------------------
# # Paths to library files.
# IF ( WIN32 )
# LINK_DIRECTORIES (
# ${BOOST_LIB_PATH}
# )
#ELSE ( WIN32 )
# If your boost libraries are not in the system path, add them to a LINK_DIRECTORIES statement here:
#ENDIF ( WIN32 )
#
# Method:
# We are finding a particular boost include file and then assuming that
# the directory structure follows something like this:
# ${BOOST_PATH}/include/boost-x-y-z/boost
# ${BOOST_PATH}/lib
#or:
# ${BOOST_PATH}/include/boost-x-y-z/boost
# ${BOOST_PATH}/lib
# Where ${BOOST_PATH} is defined by ${BOOST_DIR_SEARCH1} below.
# Construct consistent error messages for use below.
SET(BOOST_INCLUDE_PATH_DESCRIPTION "directory containing the boost include files was not found. This could mean that Boost is not installed.")
# Search these directories.
SET(BOOST_DIR_SEARCH1
/usr;
/usr/local;
)
IF ( WIN32 )
# Assume this path exists.
SET ( BOOST_DIR_SEARCH1
${BOOST_DIR_SEARCH1}
";C:/boost"
)
ENDIF ( WIN32 )
STRING(REGEX REPLACE "/;" ";" BOOST_DIR_SEARCH2 "${BOOST_DIR_SEARCH1}")
# Construct a set of paths relative to the system search path.
SET(BOOST_DIR_SEARCH "")
FOREACH(dir ${BOOST_DIR_SEARCH2})
SET(BOOST_DIR_SEARCH ${BOOST_DIR_SEARCH}
${dir}/include/boost-1_33_2/boost
${dir}/include/boost-1_33_1/boost
${dir}/include/boost-1_33/boost
${dir}/include/boost
)
ENDFOREACH(dir)
#
# Look for an installation or build tree.
#
FIND_PATH(BOOST_INCLUDE_PATH config.hpp
# Look in places relative to the system executable search path.
${BOOST_DIR_SEARCH}
# Look in standard UNIX install locations.
/usr/local/include/boost
/usr/include/boost
# Help the user find it if we cannot.
DOC "The ${BOOST_INCLUDE_PATH_DESCRIPTION}"
)
SET(BOOST_FOUND NOTFOUND)
IF ( BOOST_INCLUDE_PATH )
# The user may not have installed any libraries.
SET (BOOST_FOUND "1" )
GET_FILENAME_COMPONENT(BOOST_LIBRARY_PATH ${BOOST_INCLUDE_PATH} PATH)
GET_FILENAME_COMPONENT(BOOST_LIBRARY_PATH ${BOOST_LIBRARY_PATH} PATH)
IF ( EXISTS ${BOOST_LIBRARY_PATH}/lib )
SET ( BOOST_LIBRARY_PATH ${BOOST_LIBRARY_PATH}/lib CACHE PATH "The path to the Boost library files." )
ELSE ( EXISTS ${BOOST_LIBRARY_PATH}/lib )
GET_FILENAME_COMPONENT(BOOST_LIBRARY_PATH ${BOOST_LIBRARY_PATH} PATH)
IF ( EXISTS ${BOOST_LIBRARY_PATH}/lib )
SET ( BOOST_LIBRARY_PATH ${BOOST_LIBRARY_PATH}/lib CACHE PATH "The path to the Boost library files." )
ELSE ( EXISTS ${BOOST_LIBRARY_PATH}/lib )
SET ( BOOST_LIBRARY_PATH "" CACHE PATH "The path to the Boost library files." )
ENDIF ( EXISTS ${BOOST_LIBRARY_PATH}/lib )
ENDIF ( EXISTS ${BOOST_LIBRARY_PATH}/lib )
ENDIF ( BOOST_INCLUDE_PATH )
IF ( WIN32 )
# In windows, automatic linking is performed, so you do not have to specify the libraries.
# If you are linking to a dynamic runtime, then you can choose to link to either a static or a
# dynamic Boost library, the default is to do a static link. You can alter this for a specific
# library "whatever" by defining BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to
# be linked dynamically. Alternatively you can force all Boost libraries to dynamic link by
# defining BOOST_ALL_DYN_LINK.
# This feature can be disabled for Boost library "whatever" by defining BOOST_WHATEVER_NO_LIB,
# or for all of Boost by defining BOOST_ALL_NO_LIB.
# If you want to observe which libraries are being linked against then defining
# BOOST_LIB_DIAGNOSTIC will cause the auto-linking code to emit a #pragma message each time
# a library is selected for linking.
ADD_DEFINITIONS(-DBOOST_LIB_DIAGNOSTIC )
ENDIF ( WIN32 )
More information about the CMake
mailing list