Search code examples
c++cmakeheader-files

CMake can find one Boost header file but not another


Since Boost libraries can be individually installed on some system (even though it's probably going to be rare) I want to make sure they are available.

I do that by checking for some of the header files I need:

check_include_file_cxx(boost/parameter/keyword.hpp HAVE_BOOST_PARAMETER_KEYWORD_HPP)
check_include_file_cxx(boost/asio/io_service.hpp HAVE_BOOST_ASIO_IO_SERVICE_HPP)

The problem I have is that CMake claims that it can find the boost/parameter/keyword.hpp header file but not the boost/asio/io_service.hpp header file:

-- Looking for C++ include boost/parameter/keyword.hpp
-- Looking for C++ include boost/parameter/keyword.hpp - found
-- Looking for C++ include boost/asio/io_service.hpp
-- Looking for C++ include boost/asio/io_service.hpp - not found

And yes the ASIO header file exists:

$ ls -l /usr/include/boost/asio/io_service.hpp
-rw-r--r-- 1 root root 861 nov 13 13:47 /usr/include/boost/asio/io_service.hpp

I have Boost 1.67 installed, and an using CMake version 3.12.3 on a Debian SID system (up to date).

Is this a bug in the check_include_file_cxx function or am I missing something?


Solution

  • Boost ASIO depends on the Boost System library, which is a link-library.

    Since the CMake function check_include_file_cxx does a full build (including linking, not only compiles) of the the test program, it will fail unless the Boost System library is added for the linking.

    That causes the test to fail, even though the header file is actually installed.

    To succeed the Boost System library must be linked when checking the header file:

    check_include_file_cxx(boost/asio/io_service.hpp HAVE_BOOST_ASIO_IO_SERVICE_HPP -lboost_system)