/detect

Detect the OS at compile time.

Primary LanguageC++MIT LicenseMIT

Detect

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

Review Quality

Installing

conan search detect

You can also 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. This allows us to conditionally compile code:

#include <detect/macros.hpp>

#if PLATFORM_LINUX
...
#endif

If we can check this at runtime then constants are more flexible:

#include <detect/constants.hpp>

if (platform::os == platform::linux) {
  ...
}

The exported macros are:

  • PLATFORM_LINUX
  • PLATFORM_SOLARIS
  • PLATFORM_WINDOWS
  • PLATFORM_BSD
  • PLATFORM_MACOS
  • PLATFORM_IOS
  • PLATFORM_WATCHOS
  • PLATFORM_TVOS
  • PLATFORM_ANDROID
  • PLATFORM_UNIX
  • PLATFORM_POSIX
  • PLATFORM_MOBILE

The compile time constants are contained in the platform namesapce:

namespace platform {
    enum OS {
        Linux,
        Solaris,
        BSD,
        Windows,
        macOS,
        iOS,
        watchOS,
        tvOS,
        Android,
    }

    constexpr OS os

    constexpr bool unix
    constexpr bool posix
    constexpr bool mobile

    constexpr char sep
    constexpr char devnull[]
}

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