Skip to content

A single header library to detect the OS at compile time.

License

Notifications You must be signed in to change notification settings

JoelLefkowitz/detect

Repository files navigation

Detect

A single header library to detect the OS at compile time.

Review Quality

Installing

You can download the sources.

Documentation

Documentation and more detailed examples are hosted on Github Pages.

Usage

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
}

Tooling

Dependencies

To install dependencies:

yarn install
pip install .[all]
conan install .

Tests

To run tests:

scons test

Documentation

To generate the documentation locally:

scons docs

Linters

To run linters:

scons lint

Formatters

To run formatters:

scons format

Contributing

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

Contributors

Remarks

Lots of love to the open source community!

Be kind to your mind Love each other It's ok to have a bad day

About

A single header library to detect the OS at compile time.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published