11

如何使用 CMake 检查我是否正在为 Windows 7 或 Windows 8 配置 Visual Studio 解决方案?

有没有办法做到这一点?

4

1 回答 1

12

您可以使用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()
于 2013-05-17T11:23:21.967 回答