c++ - 找不到时如何消除cmake的find_package的警告?
问题描述
这是我的 CMakeLists.txt 的一部分
find_package(Catch2)
if(TARGET Catch2::Catch2)
message("catch2 has been installed previously")
include(Catch)
else()
message("no target catch2")
include(FetchContent)
# Download and configure Catch2 for the tests
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG master
)
FetchContent_GetProperties(catch2)
if (NOT catch2_POPULATED)
FetchContent_Populate(catch2)
add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib)
include(Catch)
endif()
endif()
我想做的是如果catch2可用,则直接使用,否则,自动从github下载。它现在工作正常,除了这个烦人的警告:
CMake Warning at test/CMakeLists.txt:9 (find_package):
By not providing "FindCatch2.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Catch2", but
CMake did not find one.
Could not find a package configuration file provided by "Catch2" with any
of the following names:
Catch2Config.cmake
catch2-config.cmake
Add the installation prefix of "Catch2" to CMAKE_PREFIX_PATH or set
"Catch2_DIR" to a directory containing one of the above files. If "Catch2"
provides a separate development package or SDK, be sure it has been
installed.
那么,如何消除这个警告呢?
解决方案
只需使用QUIET
,如下所示:
find_package(PackageName QUIET)
如果找不到包配置文件,除非指定 QUIET 参数,否则 CMake 将生成描述问题的错误。
https://cmake.org/cmake/help/v3.8/command/find_package.html?highlight=i
推荐阅读
- asp.net-core - 为什么我的原点在 asp net core 3 中为空,而不是 localhost
- javascript - CORS BLOCKED 'Access-Control-Allow-Origin' Firebase 功能不允许
- javascript - Three.js - 用线条连接粒子 - 如何更高效?
- django - 如何在Django中测试一个实例是否有一个ForeignKey指向它的子类?
- mysql - Django 我想传递多个 id 并获取他们的数据。场景:社交网络系统
- ios - 即使方向被锁定,我如何检测设备方向
- sql - 更改现有数据的序列号列
- java - 列出的选项的正确 xpath 是什么?
- amazon-web-services - 如何使用 Terraform 进行 CloudFront 源故障转移?
- linux - 为 GNU Radio 3.8 编译 gr-gsm 时出错