cmake 在 /usr/include 中找不到单独的 Boost 组件

问题描述 投票:0回答:1

cmake
又让我发疯了。

我想使用一些Boost包。我想避免依赖所有的 Boost。

这有效:

cmake_minimum_required(VERSION 3.20)
project(YOMM2 LANGUAGES CXX VERSION 1.5.2)

find_package(Boost REQUIRED)
message(STATUS "Boost is here: ${Boost_INCLUDE_DIRS}")
$ cmake -S . -B build
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.81.0/BoostConfig.cmake (found version "1.81.0")  
-- Boost is here: /usr/include
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/jll/dev/fpp/build```

这不是:

cmake_minimum_required(VERSION 3.20)
project(YOMM2 LANGUAGES CXX VERSION 1.5.2)

find_package(Boost REQUIRED COMPONENTS mp11)
message(STATUS "Boost is here: ${Boost_INCLUDE_DIRS}")
$ cmake . -B build
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Boost-1.81.0/BoostConfig.cmake:141 (find_package):
  Could not find a package configuration file provided by "boost_mp11"
  (requested version 1.81.0) with any of the following names:

    boost_mp11Config.cmake
    boost_mp11-config.cmake

  Add the installation prefix of "boost_mp11" to CMAKE_PREFIX_PATH or set
  "boost_mp11_DIR" to a directory containing one of the above files.  If
  "boost_mp11" 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.81.0/BoostConfig.cmake:262 (boost_find_component)
  /usr/share/cmake-3.27/Modules/FindBoost.cmake:594 (find_package)
  CMakeLists.txt:5 (find_package)

但是,当我将

vcpkg
与此清单一起使用时:

{
  "name": "yomm2",
  "version": "1.5.3",
  "dependencies": [
    "boost-mp11"
  ]
}

然后就可以了:

$ cmake -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -S . -B build
-- Running vcpkg install
Detecting compiler hash for triplet x64-linux...
Compiler found: /usr/bin/c++
The following packages will be built and installed:
  * boost-cmake:[email protected]#1
...
-- Running vcpkg install - done
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /home/jll/dev/fpp/build/vcpkg_installed/x64-linux/share/boost/BoostConfig.cmake (found version "1.85.0") found components: mp11 
-- Boost is here: /home/jll/dev/fpp/build/vcpkg_installed/x64-linux/include
-- Configuring done (0.8s)
-- Generating done (0.0s)
-- Build files have been written to: /home/jll/dev/fpp/build

我在上面的例子中使用的

cmake
版本是3.27.4版本。

我相信(错觉?)

cmake
将查找包配置或标题(这就是doc似乎所说的)。我是不是做错了什么?

[更新] 嗯,我在跟踪中看到了这一点:

/usr/share/cmake-3.27/Modules/FindBoost.cmake(2218):  set(Boost_${UPPERCOMPONENT}_HEADER ON )
/usr/share/cmake-3.27/Modules/FindBoost.cmake(2219):  message(WARNING No header defined for ${COMPONENT}; skipping header check  (note: header-only libraries have no designated component) )
CMake Warning at /usr/share/cmake-3.27/Modules/FindBoost.cmake:2219 (message):
  No header defined for mp11; skipping header check (note: header-only
  libraries have no designated component)
Call Stack (most recent call first):
  /home/jll/dev/vcpkg/installed/x64-linux/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package)
  /home/jll/dev/vcpkg/scripts/buildsystems/vcpkg.cmake:811 (include)
  CMakeLists.txt:5 (find_package)
cmake boost
1个回答
0
投票

经过一番谷歌搜索后,我发现了this,usr1234567向我指出了this

对我来说,这看起来就像一个兔子洞,而且我开始认为我无论如何都在混淆两种不同的东西。

我想为开发人员(或 CI)提供一种快速构建我的 YOMM2 库的方法 - 这意味着,如果尚未安装 Boost,则无需构建所有 Boost 及其依赖项。所以我有两种可能的情况。

如果Boost安装在系统范围内,

cmake
只需要找到Boost即可。由开发人员或系统管理员来确保所需的库存在。很可能,Boost 的全部都会在那里。这就是我的开发机器和我用于 GitHub CI 的 docker 镜像中的情况。

或者开发人员可以使用包管理器。使用

vcpkg
,我可以指定单独的 Boost 库。
conan
仅提供整体Boost。不管怎样,在这种情况下,我的依赖项是由包管理器拉取的,
CMakeLists.txt
不需要费心。这是我在 Windows/MSVC 上使用的设置。

© www.soinside.com 2019 - 2024. All rights reserved.