Newer
Older
# 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
# "Output" variables set after running this script
# * Boost_FOUND - TODO
# * Boost_INCLUDE_DIRS - TODO
# * Boost_LIBRARY_DIRS - TODO
# * Boost_LIBRARIES - TODO
# 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
HINTS
${BOOST_INCLUDEDIR}
$ENV{BOOST_INCLUDEDIR}
${CMAKE_CURRENT_LIST_DIR}/external_dependencies/boost
if(NOT Boost_INCLUDE_DIRS)
message(FATAL_ERROR "Boost include directory was not found! Please, set variable BOOST_INCLUDEDIR to the correct path.")
# 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'.")
set(LIB_SUFFIX "a") # suffix for Linux static libraries
if("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared" AND WIN32)
set(LIB_SUFFIX "dll")
elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "static" AND WIN32)
elseif("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared")
set(LIB_SUFFIX "so")
foreach(COMPONENT ${Boost_FIND_COMPONENTS})
list(APPEND REQUESTED_BOOST_LIBS "${LIB_PREFIX}boost_${COMPONENT}.${LIB_SUFFIX}")
endforeach()
# 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
${BOOST_LIBRARYDIR}
$ENV{BOOST_LIBRARYDIR}
${CMAKE_CURRENT_LIST_DIR}/external_dependencies/boost
PATHS
/usr/lib/boost
/usr/lib/x86_64-linux-gnu
PATH_SUFFIXES
stage/lib
lib
# Construct list of libraries' names and make them
# targets, so they may be linked
set(Boost_LIBRARIES "")
foreach(LIBNAME ${REQUESTED_BOOST_LIBS})
set(${LIBNAME} "${LIBNAME}-NOTFOUND")
find_library(
${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.")
# Make the target of the same name as the library
#add_library(${LIBNAME}_tar STATIC IMPORTED)
get_filename_component(TMP ${${LIBNAME}} ABSOLUTE)
#set_property(TARGET ${LIBNAME}_tar PROPERTY IMPORTED_LOCATION ${TMP})
if(NOT Boost_LIBRARY_DIRS)
message(FATAL_ERROR "Boost library directory was not found! Please, set variable BOOST_LIBRARYDIR to the correct path.")
# 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}")