I want to try and build a source file only if I'm on a POSIX system (let's ignore cross-building for the sake of this question). I know how to check that I'm on a UNIX system; I know how to check for the presence of header files; but - how do I check for full POSIX conformance?
Notes:
- For the sake of specificity, I want to check for POSIX.1-2008 and POSIX.1c.
- I care about conformance in practice, not official certification.
- You may assume CMake 3.25 or later (but if you can avoid that assumption, that's also nice).
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)):You can look at the doc comment in
Modules/CMakeDetermineSystem.cmaketo 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 seeAIX,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 -sfor "z/OS USS" givesOS/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: