FindBoost: Only successfull after second cmake run
I have the weird situation that my initial CMake run fails because FindBoost was unable to find my installed Boost version, but when I rerun CMake a second time it succeeds.
- I am using the latest version of CMake built from
master
(version 3.18.20200916) and am trying to find the latest Boost version (1.74.0). - I am providing values for
BOOST_ROOT
,BOOST_INCLUDEDIR
andBOOST_LIBRARYDIR
. The values for the latter two are list-values with multiple possible locations for the installed Boost headers/libraries. (One of these locations is always the exact path to the Boost headers/libraries directory.) - Additionally, I am also setting
Boost_NO_BOOST_CMAKE
toFALSE
in order to allow FindBoost possibly finding my Boost libs using thefind_package
CONFIG mode. - For simpler debugging I also set
Boost_DEBUG
andBoost_DETAILED_FAILURE_MSG
.
I was expecting FindBoost to find my Boost libs (via the CMake scripts coming with Boost itself).
However, on the first run it fails with the following:
-- The C compiler identification is GNU 8.4.0
-- The CXX compiler identification is GNU 8.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc-8 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++-8 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1489 ] _boost_TEST_VERSIONS = <unset>
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1490 ] Boost_USE_MULTITHREADED = "TRUE"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1491 ] Boost_USE_STATIC_LIBS = "FALSE"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1492 ] Boost_USE_STATIC_RUNTIME = "FALSE"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1493 ] Boost_ADDITIONAL_VERSIONS = "1.69.0;1.69;1.68.0;1.68;1.67.0;1.67;1.58.1"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1494 ] Boost_NO_SYSTEM_PATHS = "TRUE"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1526 ] BOOST_ROOT = "/opt"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1527 ] ENV{BOOST_ROOT} = <unset>
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1528 ] BOOST_INCLUDEDIR = "/opt/include/x86_64-linux-gnu;/opt/include;/opt/include/x86_64-linux-gnu;/opt/include"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1529 ] ENV{BOOST_INCLUDEDIR} = <unset>
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1530 ] BOOST_LIBRARYDIR = "/opt/lib/x86_64-linux-gnu;/opt/lib;/opt/lib/x86_64-linux-gnu;/opt/lib"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1531 ] ENV{BOOST_LIBRARYDIR} = <unset>
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1603 ] _boost_INCLUDE_SEARCH_DIRS = "/opt/include/x86_64-linux-gnu;/opt/include;/opt/include/x86_64-linux-gnu;/opt/include;/opt/include;/opt;NO_CMAKE_SYSTEM_PATH;NO_SYSTEM_ENVIRONMENT_PATH"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1604 ] _boost_PATH_SUFFIXES = <unset>
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1689 ] Boost_LIB_PREFIX = ""
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1690 ] Boost_NAMESPACE = "boost"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1712 ] _boost_COMPILER = "-gcc8" (user-specified via Boost_COMPILER)
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1726 ] _boost_MULTITHREADED = "-mt"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1777 ] _boost_ARCHITECTURE_TAG = "-x64" (user-specified via Boost_ARCHITECTURE)
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1807 ] _boost_RELEASE_ABI_TAG = "-"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1808 ] _boost_DEBUG_ABI_TAG = "-d"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1868 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "/opt/lib/x86_64-linux-gnu;/opt/lib;/opt/lib/x86_64-linux-gnu;/opt/lib;/opt/lib;/opt/stage/lib;Boost_INCLUDE_DIR-NOTFOUND/lib;Boost_INCLUDE_DIR-NOTFOUND/../lib;Boost_INCLUDE_DIR-NOTFOUND/stage/lib;NO_CMAKE_SYSTEM_PATH;NO_SYSTEM_ENVIRONMENT_PATH"
-- [ /tmp/build/cmake/Modules/FindBoost.cmake:1869 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "/opt/lib/x86_64-linux-gnu;/opt/lib;/opt/lib/x86_64-linux-gnu;/opt/lib;/opt/lib;/opt/stage/lib;Boost_INCLUDE_DIR-NOTFOUND/lib;Boost_INCLUDE_DIR-NOTFOUND/../lib;Boost_INCLUDE_DIR-NOTFOUND/stage/lib;NO_CMAKE_SYSTEM_PATH;NO_SYSTEM_ENVIRONMENT_PATH"
CMake Error at /tmp/build/cmake/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR) (Required is at least
version "1.74.0")
Call Stack (most recent call first):
/tmp/build/cmake/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
/tmp/build/cmake/Modules/FindBoost.cmake:2175 (find_package_handle_standard_args)
CMake/UseBoost.cmake:59 (find_package)
CMake/DefaultSettings.cmake:168 (include)
CMakeLists.txt:70 (include)
-- Configuring incomplete, errors occurred!
But when I then rerun CMake it succeeds with the following output:
-- Using value of CMake-variable "CMAKE_CXX_COMPILER" as C++ compiler executable: /usr/bin/g++-8
-- Found Boost 1.74.0 at /opt/lib/x86_64-linux-gnu/cmake/Boost-1.74.0
-- Requested configuration: QUIET REQUIRED
-- BoostConfig: find_package(boost_headers 1.74.0 EXACT CONFIG REQUIRED QUIET HINTS /opt/lib/x86_64-linux-gnu/cmake)
-- Found boost_headers 1.74.0 at /opt/lib/x86_64-linux-gnu/cmake/boost_headers-1.74.0
-- Found Boost: /opt/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found suitable version "1.74.0", minimum required is "1.74.0")
...
...
...
-- Found Boost 1.74.0 at /opt/lib/x86_64-linux-gnu/cmake/Boost-1.74.0
-- Requested configuration: QUIET REQUIRED COMPONENTS filesystem;system
-- BoostConfig: find_package(boost_headers 1.74.0 EXACT CONFIG REQUIRED QUIET HINTS /opt/lib/x86_64-linux-gnu/cmake)
-- BoostConfig: find_package(boost_filesystem 1.74.0 EXACT CONFIG REQUIRED QUIET HINTS /opt/lib/x86_64-linux-gnu/cmake)
-- Found boost_filesystem 1.74.0 at /opt/lib/x86_64-linux-gnu/cmake/boost_filesystem-1.74.0
-- Boost toolset is gcc8 (GNU 8.4.0)
-- Scanning /opt/lib/x86_64-linux-gnu/cmake/boost_filesystem-1.74.0/libboost_filesystem-variant*.cmake
-- Including /opt/lib/x86_64-linux-gnu/cmake/boost_filesystem-1.74.0/libboost_filesystem-variant-gcc8-mt-x64-1_74-shared.cmake
-- [x] libboost_filesystem-gcc8-mt-x64-1_74.so.1.74.0
-- Including /opt/lib/x86_64-linux-gnu/cmake/boost_filesystem-1.74.0/libboost_filesystem-variant-gcc8-mt-x64-1_74-static.cmake
-- [ ] libboost_filesystem-gcc8-mt-x64-1_74.a
-- Adding boost_filesystem dependencies: headers
-- BoostConfig: find_package(boost_system 1.74.0 EXACT CONFIG REQUIRED QUIET HINTS /opt/lib/x86_64-linux-gnu/cmake)
-- Found boost_system 1.74.0 at /opt/lib/x86_64-linux-gnu/cmake/boost_system-1.74.0
-- Boost toolset is gcc8 (GNU 8.4.0)
-- Scanning /opt/lib/x86_64-linux-gnu/cmake/boost_system-1.74.0/libboost_system-variant*.cmake
-- Including /opt/lib/x86_64-linux-gnu/cmake/boost_system-1.74.0/libboost_system-variant-gcc8-mt-x64-1_74-shared.cmake
-- [x] libboost_system-gcc8-mt-x64-1_74.so.1.74.0
-- Including /opt/lib/x86_64-linux-gnu/cmake/boost_system-1.74.0/libboost_system-variant-gcc8-mt-x64-1_74-static.cmake
-- [ ] libboost_system-gcc8-mt-x64-1_74.a
-- Adding boost_system dependencies: headers
-- Found Boost: /opt/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found suitable version "1.74.0", minimum required is "1.74.0") found components: filesystem system
By looking at this second output it should be obvious that FindBoost found the CMake config-file provided by Boost and then used that to find all the Boost libraries and headers.
But why not already at the first CMake run?
I also tried editing the FindBoost.cmake
script locally to output the value of Boost_DIR
and ENV{Boost_DIR}
before and after the internal find_package(Boost QUIET NO_MODULE)
call (in line 448).
- On the first run these variables are not set before the call and after the call only
Boost_DIR
is set toBoost_DIR-NOTFOUND
, whileENV{Boost_DIR}
is still not set. - On the second run
ENV{Boost_DIR}
is still never set, butBoost_DIR
is set toBoost_DIR-NOTFOUND
before and to the correct path (/opt/lib/x86_64-linux-gnu/cmake/Boost-1.74.0
) after the call.
Of course, if I provide the correct value for CMake variable Boost_DIR
before calling find_package(Boost)
on the first run, FindBoost succeeds on the first run, too.