Skip to content

Instantly share code, notes, and snippets.

@rpavlik
Created November 14, 2014 16:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpavlik/586f1fda6e32777623e1 to your computer and use it in GitHub Desktop.
Save rpavlik/586f1fda6e32777623e1 to your computer and use it in GitHub Desktop.
Script to help CMake find Boost from the new installers
# Original author: Ryan Pavlik <ryan@sensics.com> <ryan.pavlik@gmail.com
# Released with the same license as needed to integrate into CMake.
# Help CMake find recent Boost MSVC binaries without manual configuration.
if(MSVC AND (NOT Boost_INCLUDE_DIR OR NOT Boost_LIBRARY_DIR))
math(EXPR _vs_ver "${MSVC_VERSION} / 100 - 6")
if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
set(_libdir "lib64-msvc-${_vs_ver}.0")
else()
set(_libdir "lib32-msvc-${_vs_ver}.0")
endif()
set(_haslibs)
if(EXISTS "c:/local")
file(GLOB _possibilities "c:/local/boost*")
list(REVERSE _possibilities)
foreach(DIR ${_possibilities})
if(EXISTS "${DIR}/${_libdir}")
list(APPEND _haslibs "${DIR}")
endif()
endforeach()
if(_haslibs)
list(APPEND CMAKE_PREFIX_PATH ${_haslibs})
find_package(Boost QUIET)
if(Boost_FOUND AND NOT Boost_LIBRARY_DIR)
set(BOOST_ROOT "${Boost_INCLUDE_DIR}" CACHE PATH "")
set(BOOST_LIBRARYDIR "${Boost_INCLUDE_DIR}/${_libdir}" CACHE PATH "")
endif()
endif()
endif()
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment