简体   繁体   中英

CMake check Windows version

How do I check with CMake whether I'm configuring a Visual Studio solution for Windows 7 or Windows 8?

Is there a way to do this?

You can use CMAKE_SYSTEM_NAME and CMAKE_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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM