cmake find_package: 为什么在 boost 中找不到某些组件

cmake find_package: why cannot find some components in boost

Find_package 命令对我来说是一场噩梦。 我正在尝试将一些指定的组件包含在我的项目中。 对于不同的错误,使用 find_package 命令无法找到某些组件。 谁能帮忙解释一下报告的错误?

案例 1:

cmake_minimum_required(VERSION 3.15)
project(tryBoost)

set(CMAKE_CXX_STANDARD 14)

set(BOOST_ROOT "D:\cygwin64\home\yubo\boost_1_62_0") # either set it here or from the command line
find_package(Boost 1.62.0 REQUIRED COMPONENTS json) # header only libraries must not be added here
add_executable(tryBoost main.cpp)

我尝试查找json,但是报错: 没有为 json 定义 header;跳过 header 检查

案例 2:

cmake_minimum_required(VERSION 3.15)
project(tryBoost)

set(CMAKE_CXX_STANDARD 14)

set(BOOST_ROOT "D:\cygwin64\home\yubo\boost_1_62_0") # either set it here or from the command line
find_package(Boost 1.62.0 REQUIRED COMPONENTS system) # header only libraries must not be added here
add_executable(tryBoost main.cpp)

我尝试查找系统,但是报错: 找不到 Boost(缺少:Boost_INCLUDE_DIR 系统)

boost 如何在子目录中组织其组件? find_package 命令在扫描 boost root 目录时如何工作?为什么“header 只有库不能在此处添加”。

谢谢。

请参考以下CMakeList.txt。

cmake_minimum_required(VERSION 3.15)
project(tryBoost)

set(CMAKE_CXX_STANDARD 14)
#set(Boost_DEBUG ON)

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)

set(BOOST_ROOT "/home/yubo/boost_1_78_0")

add_executable(tryBoost main.cpp)


set(Boost_NO_BOOST_CMAKE FALSE CACHE BOOL "" FORCE)
find_package(Boost 1.78.0 REQUIRED COMPONENTS json)
message("${Boost_FOUND}")

message("Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
target_include_directories(tryBoost PUBLIC ${Boost_INCLUDE_DIRS})

message("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
message("Boost_LIBRARIES: ${Boost_LIBRARIES}")
target_link_libraries(tryBoost  ${Boost_LIBRARIES})