dev-cafe / cmake-cookbook

CMake Cookbook recipes.
Other
2.71k stars 696 forks source link

chapter-08 recipe-02 Could not find a package configuration file provided by "boost_filesystem" #522

Open Becheler opened 4 years ago

Becheler commented 4 years ago

Running the recipe leads to an error.

Expected Behavior

Running cmake should lead to no error.

Current Behavior

Somehow, the system boost version (1.71) seems to be detected, and raises an error.

Steps to Reproduce (for bugs)

$ cmake .. -DCMAKE_DISABLE_FIND_PACKAGE_Boost=ON
-- recipe-02 staged install: /home/becheler/dev/cmake-cookbook/chapter-08/recipe-02/cxx-example/build/stage
-- Boost 1.61 could not be located, Building Boost 1.61.0 instead.
--   Libraries to be built: filesystem, system
-- Configuring done
-- Generating done
-- Build files have been written to: /home/becheler/dev/cmake-cookbook/chapter-08/recipe-02/cxx-example/build
$ cmake --build .
[ 50%] Built target boost_external
[ 56%] Performing configure step for 'recipe-02_core'
loading initial cache file /home/becheler/dev/cmake-cookbook/chapter-08/recipe-02/cxx-example/build/subprojects/tmp/recipe-02_core/recipe-02_core-cache-.cmake
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:117 (find_package):
  Could not find a package configuration file provided by "boost_filesystem"
  (requested version 1.71.0) with any of the following names:

    boost_filesystemConfig.cmake
    boost_filesystem-config.cmake

  Add the installation prefix of "boost_filesystem" to CMAKE_PREFIX_PATH or
  set "boost_filesystem_DIR" to a directory containing one of the above
  files.  If "boost_filesystem" provides a separate development package or
  SDK, be sure it has been installed.
Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:182 (boost_find_component)
  /snap/cmake/487/share/cmake-3.18/Modules/FindBoost.cmake:448 (find_package)
  CMakeLists.txt:5 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/becheler/dev/cmake-cookbook/chapter-08/recipe-02/cxx-example/build/subprojects/Build/recipe-02_core/CMakeFiles/CMakeOutput.log".
make[2]: *** [CMakeFiles/recipe-02_core.dir/build.make:129: subprojects/Stamp/recipe-02_core/recipe-02_core-configure] Error 1
make[1]: *** [CMakeFiles/Makefile2:133: CMakeFiles/recipe-02_core.dir/all] Error 2
make: *** [Makefile:103: all] Error 2

Possible solution

Something along Boost_NO_BOOST_CMAKE ? I don't really know how to use it though, but the following works in the cxx-example/src/CMakelists.txt :

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-02_core LANGUAGES CXX)
set(Boost_NO_BOOST_CMAKE ON)
find_package(Boost 1.61 REQUIRED COMPONENTS filesystem)

add_executable(path-info path-info.cpp)

target_link_libraries(path-info
  PUBLIC
    Boost::filesystem
  )

Context

I am reusing this Superbuild pattern in my own projects, but they stopped working when I upgraded my ubuntu version. It is weird, because I expected the local version of boost (1.61) to always work, when apparently the system version (1.71) is detected.

Your Environment

Distributor ID: Ubuntu Description: Ubuntu 20.04 LTS Release: 20.04 Codename: focal

snap list Name Version Rev Tracking Publisher Notes cmake 3.18.0 487 latest/stable crascit✓ classic

bast commented 4 years ago

Dear Arnaud, thanks a lot for reporting this and sorry for the long silence. Soon I will schedule a "sprint" on this repo to resolve some long standing issues.

bored17 commented 2 years ago

always link system lib help