gpt4 book ai didi

cmake - 如何使用 FetchContent_Declare 将 -Wno-dev 传播到 cmake?

转载 作者:行者123 更新时间:2023-12-04 01:50:04 40 4
gpt4 key购买 nike

我正在使用 FetchContent来自 CMake (3.12) 的功能并像这样声明它:

FetchContent_Declare(libsndfile
GIT_REPOSITORY ${LIBSNDFILE_GIT_REPO}
GIT_TAG ${LIBSNDFILE_GIT_TAG}
GIT_CONFIG advice.detachedHead=false
SOURCE_DIR "${CMAKE_BINARY_DIR}/libsndfile"
BINARY_DIR "${CMAKE_BINARY_DIR}/libsndfile-build"
CMAKE_ARGS "-Wno-dev"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

根据 CMake 文档:

FetchContent_Declare: The <contentOptions> can be any of the download or update/patch options that the ExternalProject_Add() command understands



并根据 ExternalProject_Add文档,“指定的参数被传递到 cmake 命令行”时使用 CMAKE_ARGS .
-Wno-dev选项似乎没有传递,因为我继续在输出中看到此警告消息:
CMake Warning (dev) at /Volumes/Vault/misc/src/libsndfile/CMakeLists.txt:446 (add_executable):
Policy CMP0063 is not set: Honor visibility properties for all target
types. Run "cmake --help-policy CMP0063" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.

Target "sndfile-interleave" of type "EXECUTABLE" has the following
visibility properties set for C:

C_VISIBILITY_PRESET

For compatibility CMake is not honoring them for this target.
This warning is for project developers. Use -Wno-dev to suppress it.

我相信我正在关注文档,但似乎我做错了什么。知道有什么问题吗?

编辑:根据评论中的要求,这是一个完整的示例:

文件 CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(self_contained_libsndfile_example)

set(CMAKE_CXX_STANDARD 14)

# This is in order to trigger the warnings in FetchContent
set(CMAKE_C_VISIBILITY_PRESET hidden)

include(FetchContent)

set(LIBSNDFILE_GIT_REPO "https://github.com/erikd/libsndfile" CACHE STRING "libsndfile git repository url" FORCE)
set(LIBSNDFILE_GIT_TAG b4bd397ca74f4c72b9cabaae66fef0c3d5a8c527 CACHE STRING "libsndfile git tag" FORCE)

FetchContent_Declare(libsndfile
GIT_REPOSITORY ${LIBSNDFILE_GIT_REPO}
GIT_TAG ${LIBSNDFILE_GIT_TAG}
GIT_CONFIG advice.detachedHead=false
SOURCE_DIR "${CMAKE_BINARY_DIR}/libsndfile"
BINARY_DIR "${CMAKE_BINARY_DIR}/libsndfile-build"
CMAKE_ARGS "-Wno-dev"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

FetchContent_GetProperties(libsndfile)

if(NOT libsndfile_POPULATED)
FetchContent_Populate(libsndfile)
endif()

set(LIBSNDFILE_ROOT_DIR ${libsndfile_SOURCE_DIR})
set(LIBSNDFILE_INCLUDE_DIR "${libsndfile_BINARY_DIR}/src")
add_subdirectory(${libsndfile_SOURCE_DIR} ${libsndfile_BINARY_DIR} EXCLUDE_FROM_ALL)
file(COPY "${libsndfile_SOURCE_DIR}/src/sndfile.hh" DESTINATION ${LIBSNDFILE_INCLUDE_DIR})

include_directories(${LIBSNDFILE_INCLUDE_DIR})

set(target self_contained_libsndfile_example)

add_executable(${target} main.cpp)
target_link_libraries(${target} PRIVATE sndfile)

最佳答案

这是对 CMake 文档的误解。 CMAKE_ARGSConfigure Step 的一部分选项不是 download or update/patch ExternalProject_Add() 的选项并被忽略。

查看 CMake (3.12) [ https://cmake.org/cmake/help/v3.12/module/FetchContent.html] 的文档

The contentOptions can be any of the download or update/patch options that the ExternalProject_Add() command understands. The configure, build, install and test steps are explicitly disabled and therefore options related to them will be ignored.



为了避免您看到的消息,您需要调用 cmake 作为 cmake -Wno-dev在构建项目时在命令行上。

关于cmake - 如何使用 FetchContent_Declare 将 -Wno-dev 传播到 cmake?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53562639/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com