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

时间:2018-11-30 18:02:59

标签: cmake

我正在使用CMake(3.12)中的FetchContent功能,并这样声明:

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:可以是ExternalProject_Add()命令可以理解的任何下载或更新/补丁选项

根据ExternalProject_Add文档,当使用CMAKE_ARGS时,“ 指定的参数将传递给cmake命令行”。

在我继续在输出中看到此警告消息时,似乎没有传递-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)

2 个答案:

答案 0 :(得分:0)

这是对CMake文档的误解。 CMAKE_ARGSConfigure Step的{​​{1}}选项的download or update/patch选项的一部分,将被忽略。

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

的文档
  

contentOptions可以是任何下载或更新/补丁   ExternalProject_Add()命令可以理解的选项。的   配置,构建,安装和测试步骤已明确禁用,   因此与它们相关的选项将被忽略。

为避免看到这些消息,在构建项目时,需要在命令行上以ExternalProject_Add()的形式调用cmake。

答案 1 :(得分:0)

使用this CMake-issue的修复程序(该修复程序将进入CMake 3.17),您可以将变量private void BtnRight_Click(object sender, EventArgs e) { foreach(DataGridViewRow item in dgAvailabe.Rows) { DataGridViewCheckBoxCell chkchecking = item.Cells[0] as DataGridViewCheckBoxCell; if (Convert.ToBoolean(chkchecking.Value) == true) { int n = dgSelected.Rows.Add(); dgSelected.Rows[n].Cells[0].Value = item.Cells[1].Value.ToString(); dgSelected.Rows[n].Cells[1].Value = item.Cells[2].Value.ToString(); dgSelected.Rows[n].Cells[2].Value = item.Cells[3].Value.ToString(); dgSelected.Rows[n].Cells[3].Value = item.Cells[4].Value.ToString(); dgSelected.Rows[n].Cells[4].Value = item.Cells[5].Value.ToString(); } } } 指向一个文件,该文件将适当地设置CMake-policy CMP0063,并且该文件将自动包含在该文件中。呼叫CMAKE_PROJECT_sndfile_INCLUDE_BEFORE。结果,您将不会对您提取的项目收到此警告。