gpt4 book ai didi

cmake - 查找引入了哪个 CMake 版本的功能

转载 作者:行者123 更新时间:2023-12-04 12:17:55 24 4
gpt4 key购买 nike

我想针对比我自己使用的版本旧的特定版本的 CMake(与 this question 相关,即正确使用 cmake_minimum_required() ),并且能够确定哪些功能要远离会很好从,例如。

是否可以找到在 CMake 中引入某个特性(变量、函数、属性等)的第一个版本?

据我所知,CMake 文档不直接包含此信息(通过发行说明间接包含的信息除外)。一个很好的例子是 Qt API 文档(例如,参见 QCryptographicHash 的文档)。

编辑 :我使用 Florian 提供的解决方案的修改版本创建了一个 git repo:https://github.com/mbitsnbites/cmake-minver

最佳答案

阅读这里的评论后是我的CMake命令/属性/等的版本。检查器:

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.5)

function(version_required_by)
set(_keywords ${ARGN})
set(_temp_file "${CMAKE_CURRENT_BINARY_DIR}/download.txt")
foreach(_ver IN ITEMS 2.6 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.8.10 2.8.11 2.8.12 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7)
message(STATUS "Check version required: ${_ver}")
if (_ver VERSION_LESS 2.8)
set(_url "https://cmake.org/cmake/help/cmake${_ver}docs.html")
elseif (_ver VERSION_LESS 3.0)
set(_url "https://cmake.org/cmake/help/v${_ver}/cmake.html")
else()
set(_url "https://cmake.org/cmake/help/latest/release/${_ver}.html")
endif()
file(DOWNLOAD "${_url}" "${_temp_file}")
file(READ "${_temp_file}" _help_text)
foreach(_keyword IN LISTS _keywords)
string(FIND "${_help_text}" "${_keyword}" _found)
if (NOT _found EQUAL -1)
message(STATUS "${_keyword} -> v${_ver}")
list(REMOVE_ITEM _keywords "${_keyword}")
endif()
endforeach()
if (NOT _keywords)
message("cmake_minimum_required(VERSION ${_ver} FATAL_ERROR)")
if (NOT CMAKE_MINIMUM_REQUIRED_VERSION)
cmake_minimum_required(VERSION ${_ver} FATAL_ERROR)
endif()
break()
endif()
endforeach()
if (_keywords)
message(FATAL_ERROR "Check version required error: Not found ${_keywords}")
endif()
endfunction()

if (CMAKE_SCRIPT_MODE_FILE)
foreach(_i RANGE 3 ${CMAKE_ARGC})
list(APPEND _args "${CMAKE_ARGV${_i}}")
endforeach()
else()
list(
APPEND _args
"string(FIND"
"target_include_directories"
"BUILDSYSTEM_TARGETS"
)
endif()
version_required_by(${_args})

会给出我用来测试它的那些例子:
-- Check version required: 2.6
...
-- Check version required: 2.8.5
-- string(FIND -> v2.8.5
...
-- Check version required: 2.8.11
-- target_include_directories -> v2.8.11
...
-- Check version required: 3.7
-- BUILDSYSTEM_TARGETS -> v3.7
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)

编辑:或者如果你例如在脚本模式下运行上面的:
> cmake -P CMakeLists.txt target_include_directories
-- Check version required: 2.6
...
-- Check version required: 2.8.11
-- target_include_directories -> v2.8.11
cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)

引用
  • https://github.com/mbitsnbites/cmake-minver 找到最新的脚本/命令行版本
  • 关于cmake - 查找引入了哪个 CMake 版本的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40844358/

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