Something went wrong on our end
-
Martin Beseda authoredMartin Beseda authored
FindBoost.cmake 5.20 KiB
# This file is NOT an original FindBoost.cmake module provided by KitWare!
#
# It's a simplified version whose only purpose is to be used in a software
# library lib4neuro and it does NOT provide a full funcionality of the original,
# as it only works with the system-layout-named libraries (e.g. libboost_system.so).
# Optional user-defined variables
# (can be passed directly to CMake or exported as environmental variables
#
# * BOOST_LIBRARYDIR - The path to the folder containing Boost libraries
# * BOOST_INCLUDEDIR - The path to the folder containing Boost header files
# "External" used variables
#
# * DEPENDENCIES_LINK_TYPE - TODO
# "Output" variables set after running this script
# * Boost_FOUND - TODO
# * Boost_INCLUDE_DIRS - TODO
# * Boost_LIBRARY_DIRS - TODO
# * Boost_LIBRARIES - TODO
# Module usage
# TODO
message("FindBoost starting...")
# Check if needed Boost components were specified
if(NOT Boost_FIND_COMPONENTS)
message(FATAL_ERROR "No Boost components were specified! Please, set them correctly with flag COMPONENTS (see Module Usage section in this script).")
else()
message("Required Boost components: ${Boost_FIND_COMPONENTS}")
endif()
# Look for a standard boost header file.
set(Boost_INCLUDE_DIRS "Boost_INCLUDE_DIRS-NOTFOUND")
find_path(
Boost_INCLUDE_DIRS
NAMES
config.hpp
HINTS
$ENV{BOOST_ROOT}
$ENV{BOOST_ROOT}/boost
${BOOST_INCLUDEDIR}
$ENV{BOOST_INCLUDEDIR}
${CMAKE_CURRENT_LIST_DIR}/external_dependencies/boost
PATHS
/usr/include
PATH_SUFFIXES
boost
include
)
# Add path without "boost" include sub-directory to include path,
# as Boost headers are supposed to be included like
# #include<boost/...> according to the documentation
set(TMP "")
string(REPLACE "/boost/boost" "/boost" TMP ${Boost_INCLUDE_DIRS})
list(APPEND Boost_INCLUDE_DIRS ${TMP})
if(NOT Boost_INCLUDE_DIRS)
message(FATAL_ERROR "Boost include directory was not found! Please, set variable BOOST_INCLUDEDIR to the correct path.")
else()
message("Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
endif()
# Create a list of requested Boost libraries with "system" names
if(NOT DEPENDENCIES_LINK_TYPE)
message(FATAL_ERROR "Variable DEPENDENCIES_LINK_TYPE is not set! Set it to 'static' or 'shared'.")
endif()
set(LIB_PREFIX "lib")
set(LIB_SUFFIX "a") # suffix for Linux static libraries
if("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared" AND WIN32)
set(LIB_PREFIX "")
set(LIB_SUFFIX "dll")
elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "static" AND WIN32)
set(LIB_SUFFIX "lib")
elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared")
set(LIB_SUFFIX "so")
endif()
set(REQUESTED_BOOST_LIBS "")
foreach(COMPONENT ${Boost_FIND_COMPONENTS})
list(APPEND REQUESTED_BOOST_LIBS "${LIB_PREFIX}boost_${COMPONENT}.${LIB_SUFFIX}")
endforeach()
message("REQUESTED_BOOST_LIBS: ${REQUESTED_BOOST_LIBS}")
# Look for libraries specified by COMPONENTS flag
set(Boost_LIBRARY_DIRS "Boost_LIBRARY_DIRS-NOTFOUND")
find_path(
Boost_LIBRARY_DIRS
NAMES
${REQUESTED_BOOST_LIBS}
HINTS
$ENV{BOOST_ROOT}
$ENV{BOOST_ROOT}/stage
$ENV{BOOST_ROOT}/stage/lib
${BOOST_LIBRARYDIR}
$ENV{BOOST_LIBRARYDIR}
${CMAKE_CURRENT_LIST_DIR}/external_dependencies/boost
${CMAKE_CURRENT_LIST_DIR}/external_dependencies/boost/stage
${CMAKE_CURRENT_LIST_DIR}/external_dependencies/boost/stage/lib
PATHS
/usr/lib/boost
/usr/lib/x86_64-linux-gnu
PATH_SUFFIXES
lib
)
if(NOT Boost_LIBRARY_DIRS)
message(FATAL_ERROR "Boost library directory was not found! Please, set variable BOOST_LIBRARYDIR to the correct path.")
else()
message("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
endif()
# Construct list of libraries' names and make them
# targets, so they may be linked
set(Boost_LIBRARIES "")
foreach(LIBNAME ${REQUESTED_BOOST_LIBS})
message("Looking for ${LIBNAME}...")
set(${LIBNAME} "${LIBNAME}-NOTFOUND")
find_library(
${LIBNAME}
NAMES
${LIBNAME}
PATHS
${Boost_LIBRARY_DIRS}
PATH_SUFFIXES
stage/lib
lib
NO_DEFAULT_PATH
)
message("${LIBNAME} ${${LIBNAME}}")
# Check, if the Boost component was found
if("${${LIBNAME}}" STREQUAL "${LIBNAME}-NOTFOUND")
message(FATAL_ERROR "Boost library ${LIBNAME} was NOT found!\
Please, set variable BOOST_LIBRARYDIR to the correct path and check the library names\
format in your Boost installation.")
else()
message("${LIBNAME} was found: ${${LIBNAME}}")
endif()
list(APPEND Boost_LIBRARIES ${${LIBNAME}})
endforeach()
if(NOT Boost_LIBRARY_DIRS)
message(FATAL_ERROR "Boost library directory was not found! Please, set variable BOOST_LIBRARYDIR to the correct path.")
endif()
# Set Boost_FOUND
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
Boost
FAIL_MESSAGE
"Boost was NOT found!"
REQUIRED_VARS
Boost_INCLUDE_DIRS
Boost_LIBRARY_DIRS
)
message("Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message("Boost_LIBRARIES: ${Boost_LIBRARIES}")