Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 894
Marco A. Avatar asked May 17 '13 09:05

Marco A.


People also ask

Is CMake installed on Windows?

C++ CMake tools for Windows is installed as part of the Desktop development with C++ and Linux Development with C++ workloads. Both C++ CMake tools for Windows and Linux Development with C++ are required for cross-platform CMake development.

How do I know if CMake is working?

To check if cmake is installed in your windows PC using command line, try to run the cmake command in a prompt: if you have the error you quoted in your question, it's not installed. Note that it doesn't mean cmake isn't effectively installed.

How do I open a CMake file in Windows?

Running CMake for Windows / Microsoft Visual C++ (MSVC)Run cmake-gui.exe, which should be in your Start menu under Program Files, there may also be a shortcut on your desktop, or if you built from source, it will be in the build directory.


1 Answers

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()
like image 196
ollo Avatar answered Oct 08 '22 20:10

ollo