One way basic way to do this is just check CMAKE_HOST_SYSTEM_NAME
(assuming you really want the host system name and not the target system name (CMAKE_HOST_NAME
)):
Name of the OS CMake is running on.
On systems that have the uname command, this variable is set to the output of uname -s
. Linux, Windows, and Darwin for macOS are the values found on the big three operating systems.
You can look at the doc comment in Modules/CMakeDetermineSystem.cmake
to see the list of possible values.
The list of well-known operating systems that are POSIX certified is pretty short (https://en.wikipedia.org/wiki/POSIX#POSIX-certified). Of those that are listed in the Wikipedia page and the CMakeDetermineSystem.cmake
, I see AIX
, HP-UX
, Darwin
(macOS), SCO_SV
(OpenServer 5), UnixWare
,
I don't see INTEGRITY, VxWorks, or z/OS in the list of documented possible values, but that might just be a lapse in documentation and not necessarily that they aren't supported. From https://en.wikipedia.org/wiki/Uname#Examples, I see that uname -s
for "z/OS USS" gives OS/390
. That table doesn't have info for INTEGRITY or VxWare though.
Related on the point of there not being a lot of POSIX-certified OSes: Why are most Linux distributions not POSIX-compliant?
Something like this:
set(POSIX_SYSTEM_NAMES "AIX;HP-UX;Darwin;SCO_SV;UnixWare;OS/360")
if(NOT ("${CMAKE_HOST_SYSTEM_NAME}" IN_LIST POSIX_SYSTEM_NAMES))
message(FATAL_ERROR "This system is not a fully POSIX compliant system")
endif()