# Copyright (c) 2020 Egor Tensin # This file is part of the "cmake-common" project. # For details, see https://github.com/egor-tensin/cmake-common # Distributed under the MIT License. import argparse from enum import auto, StrEnum class Configuration(StrEnum): """Correspond to CMake's default CMAKE_BUILD_TYPE values.""" DEBUG = auto() MINSIZEREL = auto() RELWITHDEBINFO = auto() RELEASE = auto() @staticmethod def all(): return tuple(Configuration) @staticmethod def parse(s): try: return Configuration(s.lower()) except ValueError as e: raise argparse.ArgumentTypeError(f"invalid configuration: {s}") from e def b2_variant(self): """Roughly maps CMake's CMAKE_BUILD_TYPE to Boost's variant. AFAIK, Boost only supports debug/release, MinSizeRel and RelWithDebInfo are hence mapped to "release". The libraries will still reside in install_dir/PLATFORM/CONFIGURATION/lib, if CONFIGURATION is MinSizeRel/RelWithDebInfo. """ match self: case Configuration.MINSIZEREL | Configuration.RELWITHDEBINFO: return Configuration.RELEASE.b2_variant() case _: return self.lower() def b2_args(self): return [f"variant={self.b2_variant()}"] def cmake_args(self): return [f"-DCMAKE_BUILD_TYPE={self}"]