A single header library to detect the OS at compile time.
You can download the sources.
Documentation and more detailed examples are hosted on Github Pages.
Using compiler predefined macros we can detect the operating system before compilation. To trigger conditional compilation in a readable way we can check for equality against macros exported for each operating system.
#include "detect.hpp"
#if PLATFORM_OS == PLATFORM_OS_LINUX
...
#endif
The exported macros are:
PLATFORM_OS_LINUX
PLATFORM_OS_SOLARIS
PLATFORM_OS_WINDOWS
PLATFORM_OS_BSD
PLATFORM_OS_MACOS
PLATFORM_OS_IOS
PLATFORM_OS_WATCHOS
PLATFORM_OS_TVOS
PLATFORM_OS_ANDROID
We can also detect if the operating system is compliant with the Unix and Posix standards or is for a mobile.
PLATFORM_UNIX
PLATFORM_POSIX
PLATFORM_MOBILE
These will be booleans rather than defined or undefined.
It is also useful to define compile time constants:
namespace platform {
enum OS {
Linux,
Solaris,
BSD,
Windows,
macOS,
iOS,
watchOS,
tvOS,
Android,
}
constexpr OS os
constexpr char sep
constexpr char devnull[]
constexpr bool unix
constexpr bool posix
constexpr bool mobile
}
To install dependencies:
yarn install
pip install .[all]
conan install .
To run tests:
scons test
To generate the documentation locally:
scons docs
To run linters:
scons lint
To run formatters:
scons format
Please read this repository's Code of Conduct which outlines our collaboration standards and the Changelog for details on breaking changes that have been made.
This repository adheres to semantic versioning standards. For more information on semantic versioning visit SemVer.
Bump2version is used to version and tag changes. For example:
bump2version patch
- Joel Lefkowitz - Initial work
Lots of love to the open source community!