Search code examples
c++windows-7windows-8visual-studio-2012cmake

How to check Windows version in CMake?


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

Is there any way to do this?


Solution

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