Reputation: 31
I need to determine what version of MacOS the cmake file is running on.
if(BIGSUR)
# do something
else()
# do something else
endif()
Upvotes: 1
Views: 1628
Reputation: 19816
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.
Upvotes: 1