Is there a way to check if specific boost header-only libraries are installed? I am aware of the COMPONENTS option in the find_package(Boost ...) command, but it only works for compiled libraries.
I am particularly interested in checking if the user has boost/multiprecision/mpc.hpp and boost/multiprecision/mpfr.hpp installed.
Checking if (EXISTS "${Boost_INCLUDE_DIR}/…") is probably the only reliable way. Having a component per header library would be nice. Their issue tracker would be the place to ask though.
Thank you for your comment. It turns out I was tackling the problem in the wrong way. The reason I was looking for specific headers is that in Ubuntu 18.04, only mpfr.hpp is included, but the reason for this is that mpc.hpp is relatively new, so what I should have done is check if the Boost version is recent enough, which can be easily done with find_package.
Still, before realizing that, I found a solution using the check_include_file_cxx macro, which I paste below from Stack Overflow for future reference.
The macro check_include_file_cxx not only checks if the required header is available, but also tries to compile a small test program. For that, it also needs to link to libraries (-lmpfr for boost/multiprecision/mpfr.hpp and -lmpfr -lmpc for boost/multiprecision/mpc.hpp).
This did the trick for me.
find_package(Boost REQUIRED
VERSION 1.69)
if ( Boost_FOUND )
include_directories(${Boost_INCLUDE_DIRS})
endif()
include(CheckIncludeFileCXX)
cmake_policy(SET CMP0075 NEW) # Required for specifying CMAKE_REQUIRED_LIBRARIES
set(CMAKE_REQUIRED_INCLUDES "${Boost_INCLUDE_DIRS}")
set(CMAKE_REQUIRED_LIBRARIES "mpfr" "mpc" "gmp")
set(REQUIRED_BOOST_HEADERS
"boost/multiprecision/mpfr.hpp;boost/multiprecision/mpc.hpp"
)
foreach(HEADER ${REQUIRED_BOOST_HEADERS})
check_include_file_cxx("${HEADER}" ${HEADER}_FOUND)
if (NOT ${HEADER}_FOUND)
message(FATAL_ERROR "HEADER ${HEADER} NOT FOUND")
endif()
endforeach()