1

I need to determine what version of MacOS the cmake file is running on.

if(BIGSUR)
     # do something
else()
    #  do something else
endif()

rTanna
  • 19
  • 3
  • Have you checked [CMAKE_HOST_SYSTEM_VERSION](https://cmake.org/cmake/help/latest/variable/CMAKE_HOST_SYSTEM_VERSION.html) variable? According to its description, you can use it for your purpose. – Tsyvarev Feb 12 '21 at 20:36
  • Yes that looks like exactly what I need. Thank you! – rTanna Feb 12 '21 at 21:06

1 Answers1

0

Depending on what you're doing, CMAKE_HOST_SYSTEM_VERSION might not be correct. You might instead want CMAKE_SYSTEM_VERSION which gives the version of the target system for which you are compiling. The wording in your question ("the cmake file is running on") suggests that you do want the HOST version, but I'm mentioning both for completeness.

Now, what you probably want is:

if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" 
    AND CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 20
    AND CMAKE_HOST_SYSTEM_VERSION VERSION_LESS 21)
    message(STATUS "Running on Big Sur")
endif ()

Note that Big Sur is the latest version of macOS and runs the Darwin kernel version 20.x. Each release of macOS has increased the Darwin major version by 1 since Jaguar in 2002 (Puma jumped from v1.4.1 to 5.1), so it's safe to assume that no release of Big Sur will have a Darwin version > 20.

Alex Reinking
  • 6,342
  • 2
  • 28
  • 47