gpt4 book ai didi

cmake - 供应商项目中的静音 CMP0048 警告

转载 作者:行者123 更新时间:2023-12-03 14:45:21 25 4
gpt4 key购买 nike

我有带有 CMakeLists.txt 的 git 子模块由于 CMP0048 导致警告的文件。警告如下所示:

CMake Warning (dev) at submodule_directory/CMakeLists.txt:24 (project):
Policy CMP0048 is not set: project() command manages VERSION variables.
Run "cmake --help-policy CMP0048" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.

The following variable(s) would be set to empty:

PROJECT_VERSION
PROJECT_VERSION_MAJOR
PROJECT_VERSION_MINOR
PROJECT_VERSION_PATCH
This warning is for project developers. Use -Wno-dev to suppress it.

我不控制这些 CMakeLists.txt文件,我不想 fork ,所以对此没有什么可做的,我只想让 CMake 闭嘴。使用 cmake_policy(SET CMP0048 OLD)在添加子模块目录之前不能解决这个问题。 (我猜 project() 重置 cmake 策略?)。

对此我能做些什么吗?

最佳答案

如果您不关心启用策略,最简单的解决方案就是设置 CMAKE_POLICY_DEFAULT_CMP0048 NEW 在 CMake 命令行。以下答案显示了一种替代方法,可让您采取更零碎的方法。

在 CMake 3.15+ 中有一个更灵活的解决方案,使用 CMAKE_PROJECT_INCLUDE_BEFORE 多变的。在此处查看我的示例:

$ tree
.
├── CMakeLists.txt
├── cmake
│   └── EnableCMP0048.cmake
└── subproj
└── CMakeLists.txt
我假设 subproj/CMakeLists.txt包含这个:
cmake_minimum_required(VERSION 2.8.12) # Never do this
project(subproj)
cmake/EnableCMP0048.cmake , 放:
cmake_policy(SET CMP0048 NEW)
./CMakeLists.txt , 放:
cmake_minimum_required(VERSION 3.15)
project(test VERSION 1.0.0)

set(CMAKE_PROJECT_INCLUDE_BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/EnableCMP0048.cmake")
add_subdirectory(subproj)
unset(CMAKE_PROJECT_INCLUDE_BEFORE) # if you don't want to affect subsequent add_subdirectory calls.
现在这将启用 CMP0048并将清除子项目中提到的变量。鉴于在您的问题中,您尝试通过修改策略来解决此问题,我认为这没关系。但如果没有,您可以添加另一个脚本, cmake/RestoreProjectVars.cmake :
# Recall the top-level CMakeLists.txt had project(test).
set(PROJECT_VERSION "${test_VERSION}")
set(PROJECT_VERSION_MAJOR "${test_VERSION_MAJOR}")
set(PROJECT_VERSION_MINOR "${test_VERSION_MINOR}")
set(PROJECT_VERSION_PATCH "${test_VERSION_PATCH}")
然后 set(CMAKE_PROJECT_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/RestoreProjectVars.cmake")在调用 add_subdirectory 之前在调用后恢复这些变量。

关于cmake - 供应商项目中的静音 CMP0048 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37582508/

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