查找引入了哪个功能的CMake版本 [英] Finding which CMake version a feature was introduced in

查看:113
本文介绍了查找引入了哪个功能的CMake版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想针对特定版本的CMake,该版本比我自己使用的版本更旧(与这个问题,即正确使用 cmake_minimum_required()),并且能够确定要远离哪些功能

I would like to target a specific version of CMake that is older than the version I am using myself (related to this question, i.e. correctly using cmake_minimum_required()), and it would be nice to be able to determine which features to stay away from, for instance.

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

Is it possible to find the first version that a certain feature (variable, function, property, ...) was introduced in CMake?

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

As far as I can tell, the CMake documentation does not directly include this information (except for indirectly via the release notes). A great example of how this could work is the Qt API documentation (e.g. see the documentation for QCryptographicHash).

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

EDIT: I created a git repo with a modified version of the solution provided by Florian: https://github.com/mbitsnbites/cmake-minver

推荐答案

在阅读注释后,这里是我的 CMake 版本的命令/属性/等。检查器:

After reading the comments here is my CMake version of a command/property/etc. checker:

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})

将给出我用于测试的示例:

Would give for those examples I used for testing it:

-- 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)

编辑:或者,例如在脚本模式下运行以上代码:

Or if you e.g. run the above in script mode:

> 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)

参考

  • Find the latest script/command line version at https://github.com/mbitsnbites/cmake-minver

这篇关于查找引入了哪个功能的CMake版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆