如何避免使用FetchContent下载的外部库中的clang整洁警告。是把它们当作系统库来处理的简单方法。
在过去,我使用我自己的标题库(我想忽略它)做过这件事,使用:
target_include_directories(${target} SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}<path_to_dir>)但即使加上这一点也不起作用
target_include_directories(test SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/build/_deps/spdlog-src/include)示例CMake:
cmake_minimum_required(VERSION 3.14)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(test)
option(ENABLE_CLANG_TIDY "Build the unit tests" OFF)
find_program(CLANGTIDY clang-tidy)
if(CLANGTIDY)
set(CMAKE_CXX_CLANG_TIDY clang-tidy; -header-filter=.;
-warnings-as-errors=*; --extra-arg-before=-std=c++17)
else()
message(SEND_ERROR "clang-tidy exe not found")
endif()
include(FetchContent)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.10.0
)
FetchContent_MakeAvailable(spdlog)
add_executable(test main.cpp)
target_include_directories(test SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/build/_deps/spdlog-src/include)
target_link_libraries(test spdlog::spdlog_header_only)示例源文件:
#include <spdlog/spdlog.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <string>
int main()
{
auto _logger{spdlog::basic_logger_mt("default_logger", "logger.txt")};
_logger->flush_on(spdlog::level::info);
spdlog::set_default_logger(_logger);
spdlog::set_level(spdlog::level::info);
spdlog::info("hello world");
}发布于 2022-04-15 10:39:52
通过执行以下操作,设法解决了这个问题:
include(FetchContent)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.10.0
)
FetchContent_GetProperties(spdlog)
if(NOT spdlog_POPULATED)
FetchContent_Populate(spdlog)
# create a header only library
add_library(spdlog INTERFACE)
add_library(spdlog::libspdlog ALIAS spdlog)
target_include_directories(
spdlog
SYSTEM INTERFACE
${spdlog_SOURCE_DIR}/include)
endif() https://stackoverflow.com/questions/71873622
复制相似问题