From 816d6e521d59532fc6dbc194c79351e52585f77e Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Thu, 15 Apr 2021 20:40:34 +0200 Subject: [PATCH] support user conf file --- .ci/build-cs | 2 ++ include/cubescript/cubescript/state.hh | 1 - include/cubescript/cubescript/util.hh | 1 - include/cubescript/cubescript_conf.hh | 42 +++++++++++++++++++++----- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/.ci/build-cs b/.ci/build-cs index 649bd87..a2f846a 100755 --- a/.ci/build-cs +++ b/.ci/build-cs @@ -12,6 +12,8 @@ current_triplet=`$CC -dumpmachine` if [ "$CC" = "clang" ]; then export CXX="clang++" export CXXFLAGS="-stdlib=libc++" +elif [ "$CC" = "gcc" ]; then + export CXX="g++" else export CXX="g++-10" fi diff --git a/include/cubescript/cubescript/state.hh b/include/cubescript/cubescript/state.hh index 5059627..94e47fa 100644 --- a/include/cubescript/cubescript/state.hh +++ b/include/cubescript/cubescript/state.hh @@ -12,7 +12,6 @@ #define LIBCUBESCRIPT_CUBESCRIPT_STATE_HH #include -#include #include #include diff --git a/include/cubescript/cubescript/util.hh b/include/cubescript/cubescript/util.hh index c59d175..fc95b31 100644 --- a/include/cubescript/cubescript/util.hh +++ b/include/cubescript/cubescript/util.hh @@ -14,7 +14,6 @@ #include #include -#include #include #include "ident.hh" diff --git a/include/cubescript/cubescript_conf.hh b/include/cubescript/cubescript_conf.hh index 5358a04..c06faff 100644 --- a/include/cubescript/cubescript_conf.hh +++ b/include/cubescript/cubescript_conf.hh @@ -2,13 +2,10 @@ * * @brief Library configuration. * - * This is the one file you are allowed to touch as a user - it contains - * settings that are used when building the library, notably the integer - * and floating point types used and their formats (used for conversions). - * - * Usually you will not want to touch this, but occasionally you might want - * to, e.g. to make a build of the library that uses double precision floats - * or larger integers. + * While you can technically modify this directly, it is better if you use + * a custom file `cubescript_conf_user.hh` in the same location. Most of the + * time you will not want to override anything, but should you need to change + * the integer, float or span types for a specific purpose, this allows you to. * * @copyright See COPYING.md in the project tree for further information. */ @@ -18,13 +15,18 @@ #include +#if __has_include("cubescript_conf_user.hh") +# include "cubescript_conf_user.hh" +#endif + #if __has_include() # include -#else +#elif !defined(LIBCUBESCRIPT_CONF_USER_SPAN) # error "This implementation does not provide an std::span." #endif namespace cubescript { +#if !defined(LIBCUBESCRIPT_CONF_USER_INTEGER) /** @brief The integer type used. * * While Cubescript is a stringly typed language, it uses integers and @@ -35,35 +37,50 @@ namespace cubescript { * 32-bit signed integer on most platforms. Keep in mind that is is * necessary for this type to be a signed integer type. * + * Define `LIBCUBESCRIPT_CONF_USER_INTEGER` in your custom conf file + * to disable the builtin. + * * @see float_type * @see INTEGER_FORMAT */ using integer_type = int; +#endif +#if !defined(LIBCUBESCRIPT_CONF_USER_FLOAT) /** @brief The floating point type used. * * By default, this is `float`, which is on most platforms an IEEE754 * binary32 data type. * + * Define `LIBCUBESCRIPT_CONF_USER_FLOAT` in your custom conf file + * to disable the builtin. + * * @see integer_type * @see FLOAT_FORMAT * @see ROUND_FLOAT_FORMAT */ using float_type = float; +#endif +#if !defined(LIBCUBESCRIPT_CONF_USER_SPAN) #if __has_include() || defined(LIBCS_GENERATING_DOC) /** @brief The span type used. * * By default, this is `std::span`. You will almost never want to override * this, but an alternative implementation can be supplied if your standard * library does not support it. + * + * Define `LIBCUBESCRIPT_CONF_USER_SPAN` in your custom conf file to + * disable the builtin. */ template using span_type = std::span; #else using span_type = void; #endif +#endif +#if !defined(LIBCUBESCRIPT_CONF_USER_INTEGER) /** @brief The integer format used. * * This is a formatting specifier as in `printf`, corresponding to the @@ -74,11 +91,16 @@ namespace cubescript { * There are no special restrictions imposed on the floating point type * other than that it actually has to be floating point. * + * Define `LIBCUBESCRIPT_CONF_USER_INTEGER` in your custom conf file + * to disable the builtin. + * * @see integer_type * @see FLOAT_FORMAT */ constexpr auto const INTEGER_FORMAT = "%d"; +#endif +#if !defined(LIBCUBESCRIPT_CONF_USER_FLOAT) /** @brief The float format used. * * This is a formatting specifier as in `printf`, corresponding to the @@ -88,6 +110,9 @@ namespace cubescript { * When the floating point value is equivalent to its integer value (i.e. * it has no decimal point), ROUND_FLOAT_FORMAT is used. * + * Define `LIBCUBESCRIPT_CONF_USER_FLOAT` in your custom conf file + * to disable the builtin. + * * @see float_type * @see ROUND_FLOAT_FORMAT * @see INTEGER_FORMAT @@ -104,6 +129,7 @@ namespace cubescript { * @see FLOAT_FORMAT */ constexpr auto const ROUND_FLOAT_FORMAT = "%.1f"; +#endif } /* namespace cubescript */ /* conf verification */