gpt4 book ai didi

cmake - 如何强制cmake使用新版CMP0077(允许从变量中设置选项)

转载 作者:行者123 更新时间:2023-12-04 16:38:11 29 4
gpt4 key购买 nike

我正在尝试将 Howard Hinnant 的 date 库添加为我的构建的子目录。这是简单的设置:

$ git clone https://github.com/HowardHinnant/date.git
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
project(date_test)

set(BUILD_TZ_LIB ON)
set(USE_SYSTEM_TZ_DB ON)
set(ENABLE_DATE_TESTING OFF)
add_subdirectory(date)

这里没有太多事情发生。当我尝试使用 cmake 3.18.3 按原样配置此构建时,我得到一堆输出,例如:

CMake Warning (dev) at date/CMakeLists.txt:30 (option):
Policy CMP0077 is not set: option() honors normal variables. Run "cmake
--help-policy CMP0077" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.

For compatibility with older versions of CMake, option is clearing the
normal variable 'USE_SYSTEM_TZ_DB'.
This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at date/CMakeLists.txt:34 (option):
Policy CMP0077 is not set: option() honors normal variables. Run "cmake
--help-policy CMP0077" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.

For compatibility with older versions of CMake, option is clearing the
normal variable 'ENABLE_DATE_TESTING'.
This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at date/CMakeLists.txt:37 (option):
Policy CMP0077 is not set: option() honors normal variables. Run "cmake
--help-policy CMP0077" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.

For compatibility with older versions of CMake, option is clearing the
normal variable 'BUILD_TZ_LIB'.
This warning is for project developers. Use -Wno-dev to suppress it.

# date: USE_SYSTEM_TZ_DB OFF
# date: MANUAL_TZ_DB OFF
# date: USE_TZ_DB_IN_DOT OFF
# date: BUILD_SHARED_LIBS OFF
# date: ENABLE_DATE_TESTING OFF
# date: DISABLE_STRING_VIEW OFF

值得注意的是,我的变量被忽略了(当我希望 USE_SYSTEM_TZ_DBOFF 时,我希望它为 ON)。

如果我按照错误所说的做,并添加 cmake_policy(SET CMP0077 NEW),那么...我得到完全相同的东西。有关该策略的相同警告消息。同样忽略我设置的变量。

有没有办法设置这些变量并将它们传播到 date 构建中,或者我是否将它们声明为 CACHE INTERNAL 变量?

最佳答案

在调用 add_subdirectory 之前,通过 set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) 设置该策略的默认值以将日期库添加到您的项目可以解决问题。

根据documentation ,

Commands cmake_minimum_required(VERSION) and cmake_policy(VERSION) by default leave policies introduced after the given version unset. Set CMAKE_POLICY_DEFAULT_CMP to OLD or NEW to specify the default for policy CMP, where is the policy number.

CMAKE_POLICY_DEFAULT_CMP0077 未设置时,日期库的 CMakeLists.txt 中的 cmake_minimum_required(VERSION 3.7) 调用会重置值该政策对旧行为的影响。如果 CMake 不这样做,如果父项目更新其 CMakeLists.txt 以需要更新版本,则通过 FetchContent 或 git 子模块包含的子项目的构建很容易中断。

关于cmake - 如何强制cmake使用新版CMP0077(允许从变量中设置选项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66340703/

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