Bill, If you think it is generally OK and useful to people, tell me what improvements are needed before it would be eligible for inclusion in the modules directory of CMake.
 
I have had a go at writing a FindBoost.cmake file (attached). It tries to find where the boost includes are using "educated guesses" and then tries to determine the path to the library files. The problem with windows is that there is no "default" library path.
 
Is there a better way of doing this for both windows and linux? I have searched the web but most examples are just for linux and only seem to do part of the job.
 
The rationale for my solution is outlined below.
 
I think my solution is a bit rough around the edges but pointing in the right direction. For example:
If I have a path like /usr/local/include/boost-1_33_1/boost
How can I get the /usr/local part so I can append /lib to it?
 
The problem is that I could have a paths like:
 /user/local/include/boost
 /user/include/boost-1_33_1/boost
 /user/local/include/boost
 C:\boost\include\boost
 C:\boost\include\boost\boost-1_33_1\boost
 
My problem is that I want to set up a BOOST_INCLUDE_PATH (easy, just look for a file like config.hpp).
The hard part is determining the library path it is either:
${BOOST_INCLUDE_PATH}/../../../lib
or
${BOOST_INCLUDE_PATH}/../../lib

 You can see from the attached code that I used a series of IF ( EXISTS ...

Is this the best way to do this?
 
If people have comments or can improve on it, I would welcome any input!
 
Andrew

--

___________________________________________
Andrew J. P. Maclean
Centre for Autonomous Systems
The Rose Street Building J04
The University of Sydney  2006  NSW
AUSTRALIA
Ph: +61 2 9351 3283
Fax: +61 2 9351 7474
URL: http://www.cas.edu.au/
___________________________________________
 
#-----------------------------------------------------------------------------
# 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 )


_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to