如何在CMake中检查Windows版本

How to check Windows version in CMake?

本文关键字:检查 Windows 版本 CMake      更新时间:2023-10-16

我如何与CMake检查我是否正在配置Visual Studio解决方案,例如Windows 7或Windows 8?

有什么办法可以做到吗?

您可以使用CMAKE_SYSTEM_NAMECMAKE_SYSTEM_VERSION

## Check for Windows ##
if( WIN32 ) # true if windows (32 and 64 bit)
    ## Check for Version ##
    if( ${CMAKE_SYSTEM_VERSION} EQUAL 6.1 ) # Windows 7
        # Do something here
    elseif( ${CMAKE_SYSTEM_VERSION} EQUAL 6.2 ) # Windows 8
        # Do something here
    else() # Some other Windows
        # Do something here
    endif()
endif()