From: Wolfgang Bangerth Date: Thu, 27 Feb 2025 22:00:15 +0000 (-0700) Subject: Provide a way to query debug/release status as a C++ variable. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec530b752e8c572d708783d2b0c1b7435fd79d51;p=dealii.git Provide a way to query debug/release status as a C++ variable. --- diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index 6b47a6fbdc..799dbf6ccb 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -32,6 +32,57 @@ #define DEAL_II_VERSION_MINOR @DEAL_II_VERSION_MINOR@ #define DEAL_II_VERSION_SUBMINOR @DEAL_II_VERSION_SUBMINOR@ +/*********************************************************************** + * Two macro names that we put at the top and bottom of all deal.II files + * and that will be expanded to "namespace dealii {" and "}". + */ + +#define DEAL_II_NAMESPACE_OPEN namespace dealii { +#define DEAL_II_NAMESPACE_CLOSE } + +/*********************************************************************** + * A variable that can be used to query whether we are compiling in + * debug or release mode. + */ + +DEAL_II_NAMESPACE_OPEN + +/** + * An enum type that is used to describe what kind of build has + * been used to compile the deal.II library: Namely, whether it is + * a debug or a release build. + */ +enum class LibraryBuildMode +{ + debug, + release +}; + +/** + * A variable that can be queried to determine whether the deal.II + * library you are trying to compile against is a debug or a release + * mode build. + */ +constexpr LibraryBuildMode library_build_mode +#ifdef DEBUG + = LibraryBuildMode::debug; +#else + = LibraryBuildMode::release; +#endif + + +/** + * A function that returns whether we are currently compiling for a debug + * build (rather than a release build). + */ +constexpr bool running_in_debug_mode() +{ + return (library_build_mode == LibraryBuildMode::debug); +} + + +DEAL_II_NAMESPACE_CLOSE + /*********************************************************************** * Configured deal.II features: @@ -514,14 +565,6 @@ #cmakedefine DEAL_II_MPI_WITH_DEVICE_SUPPORT -/*********************************************************************** - * Two macro names that we put at the top and bottom of all deal.II files - * and that will be expanded to "namespace dealii {" and "}". - */ - -#define DEAL_II_NAMESPACE_OPEN namespace dealii { -#define DEAL_II_NAMESPACE_CLOSE } - /*********************************************************************** * Two macros to guard external header includes. *