Определяем препроцессором Windows, Linux, MacOS, FreeBSD, Android, Solaris, SunOS, QNX.
Остальные операционные системы пока не интересуют.
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#define OS_NAME "Windows"
#elif defined(__linux__)
#define OS_NAME "Linux"
#elif defined(__APPLE__) || defined(__MACH__)
#define OS_NAME "Mac OS X"
#elif defined(__FreeBSD__)
#define OS_NAME "FreeBSD"
#elif defined(__ANDROID__)
#define OS_NAME "Android"
#elif defined(sun) || defined(__sun)
#if defined(__SVR4) || defined(__svr4__)
#define OS_NAME "Solaris"
#else
#define OS_NAME "SunOS"
#endif
#elif defined(__QNX__) || defined(__QNXNTO__)
#define OS_NAME "QNX"
#else
#error Unknown OS
#endif