我的CMakeLists.txt以以下方式包含boost
库:
cmake_minimum_required(VERSION 3.28)
set(BOOST_INCLUDE_LIBRARIES filesystem iostreams log program_options system)
set(BOOST_ENABLE_CMAKE ON)
include(FetchContent)
FetchContent_Declare(
Boost
URL https://github.com/boostorg/boost/releases/download/boost-1.83.0/boost-1.83.0.7z
USES_TERMINAL_DOWNLOAD TRUE
DOWNLOAD_NO_EXTRACT FALSE
FIND_PACKAGE_ARGS COMPONENTS ${BOOST_INCLUDE_LIBRARIES}
)
FetchContent_MakeAvailable(Boost)
字符串
这样,我得到以下错误:
CMake Error at _deps/boost-src/libs/headers/CMakeLists.txt:11 (add_library):
add_library cannot create ALIAS target "Boost::headers" because another
target with the same name already exists.
型
我做错了什么?
1条答案
按热度按时间tmb3ates1#
我无法复制它:
字符串
docker build .
打印:(点击查看完整分辨率)x1c 0d1x的数据
project(ProjectName)
型
更新
在评论添加context to reproduce问题后,我找到了原因。
原因是
FETCHCONTENT_TRY_FIND_PACKAGE_MODE
默认为OPT_IN
,这意味着find_package
被调用,因为FIND_PACKAGE_ARGS
存在。这会找到声明::headerstarget的系统Boost包。 有两种方法可以解决这个问题: 1.删除
FIND_PACKAGE_ARGS,参考[docs](https://cmake.org/cmake/help/latest/module/FetchContent.html): 此选项适用于
FetchContent_MakeAvailable()命令可能首先尝试调用
find_package()以满足
的依赖关系的情况 1.在内容声明之前将
FETCHCONTENT_TRY_FIND_PACKAGE_MODE设置为
NEVER`:型
注意事项:
find_package
在fetchcontent包填充之前找到Boost,则添加OVERRIDE_FIND_PACKAGE
不会执行任何操作-例如,此操作失败:https://coliru.stacked-crooked.com/a/55451090f10cffa7FetchContents_Declare
**点处FETCHCONTENT_TRY_FIND_PACKAGE_MODE
**的值是重要的更多的文档在集成FindPackage