Marco A.
Marco A.

Reputation: 43662

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?

Upvotes: 11

Views: 13906

Answers (1)

ollo
ollo

Reputation: 25340

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

Upvotes: 12

Related Questions