From 1a06e53c58c18ec853ea3f7bf799582ec4d661ec Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 31 Jan 2016 19:06:44 -0700 Subject: [PATCH] Add some compiler identification info to build --- include/chaiscript/chaiscript_defines.hpp | 32 +++++++++++++++++ .../chaiscript/language/chaiscript_engine.hpp | 35 +++++++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index c2ba4ae..87f3eeb 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -8,11 +8,14 @@ #define CHAISCRIPT_DEFINES_HPP_ #ifdef _MSC_VER +#define CHAISCRIPT_COMPILER_VERSION #_MSC_FULL_VER #define CHAISCRIPT_MSVC _MSC_VER #define CHAISCRIPT_HAS_DECLSPEC #if _MSC_VER <= 1800 #define CHAISCRIPT_MSVC_12 #endif +#else +#define CHAISCRIPT_COMPILER_VERSION __VERSION__ #endif #ifndef CHAISCRIPT_MSVC_12 @@ -29,6 +32,25 @@ #define CHAISCRIPT_WINDOWS #endif +#if defined(_WIN32) +#if defined(__llvm__) +#define CHAISCRIPT_COMPILER_NAME "clang(windows)" +#elif defined(__GNUC__) +#define CHAISCRIPT_COMPILER_NAME "gcc(mingw)" +#else +#define CHAISCRIPT_COMPILER_NAME "msvc" +#endif +#else +#if defined(__llvm__) +#define CHAISCRIPT_COMPILER_NAME "clang" +#elif defined(__GNUC__) +#define CHAISCRIPT_COMPILER_NAME "gcc" +#else +#define CHAISCRIPT_COMPILER_NAME "unknown" +#endif +#endif + + #if (defined(__GNUC__) && __GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || (defined(__llvm__) && !defined(CHAISCRIPT_LIBCPP)) /// Currently only g++>=4.8 supports this natively /// \todo Make this support other compilers when possible @@ -64,6 +86,12 @@ #define CHAISCRIPT_CONSTEXPR constexpr #endif +#ifdef _DEBUG +#define CHAISCRIPT_DEBUG true +#else +#define CHAISCRIPT_DEBUG false +#endif + #include namespace chaiscript { @@ -71,6 +99,10 @@ namespace chaiscript { static const int version_minor = 7; static const int version_patch = 2; + static const char *compiler_version = CHAISCRIPT_COMPILER_VERSION; + static const char *compiler_name = CHAISCRIPT_COMPILER_NAME; + static const bool debug_build = CHAISCRIPT_DEBUG; + template inline std::shared_ptr make_shared(Arg && ... arg) { diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 3e58116..fba4f8f 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -398,6 +398,10 @@ namespace chaiscript m_engine.add(fun(&ChaiScript::version_minor), "version_minor"); m_engine.add(fun(&ChaiScript::version_patch), "version_patch"); m_engine.add(fun(&ChaiScript::version), "version"); + m_engine.add(fun(&ChaiScript::compiler_version), "compiler_version"); + m_engine.add(fun(&ChaiScript::compiler_name), "compiler_name"); + m_engine.add(fun(&ChaiScript::compiler_id), "compiler_id"); + m_engine.add(fun(&ChaiScript::debug_build), "debug_build"); m_engine.add(fun([this](const Boxed_Value &t_bv, const std::string &t_name){ add_global_const(t_bv, t_name); }), "add_global_const"); m_engine.add(fun([this](const Boxed_Value &t_bv, const std::string &t_name){ add_global(t_bv, t_name); }), "add_global"); @@ -552,11 +556,36 @@ namespace chaiscript static std::string version() { - std::stringstream ss; - ss << version_major() << "." << version_minor() << "." << version_patch(); - return ss.str(); + return std::to_string(version_major()) + '.' + std::to_string(version_minor()) + '.' + std::to_string(version_patch()); } + static std::string compiler_id() + { + return compiler_name() + '-' + compiler_version(); + } + + static std::string build_id() + { + return compiler_id() + (debug_build()?"-Debug":"-Release"); + } + + static std::string compiler_version() + { + return chaiscript::compiler_version; + } + + static std::string compiler_name() + { + return chaiscript::compiler_name; + } + + static bool debug_build() + { + return chaiscript::debug_build; + } + + + std::string get_type_name(const Type_Info &ti) const { return m_engine.get_type_name(ti);