From 88d22e618325d5e50fadfa196b9ffa17ef0ec55c Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Wed, 20 Oct 2021 17:06:02 +0200 Subject: [PATCH] Add a "--buildInfo" argument to print the compiler and optimization options used when building --- CMakeLists.txt | 1 + src/headers/Yerbacon.hpp | 15 +++++++++++++++ src/main.cpp | 14 +++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc4ad00..a401998 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ elseif(${IS_CLANG}) endif() set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=full -fwhole-program-vtables -fstrict-vtable-pointers") endif() +add_definitions(-DYBCON_FLAGS="${CMAKE_CXX_FLAGS_RELEASE}" -DYBCON_COMPILER="${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") if (MINGW OR MSVC) if (UNIX) diff --git a/src/headers/Yerbacon.hpp b/src/headers/Yerbacon.hpp index a7d56a5..3c5ad2d 100644 --- a/src/headers/Yerbacon.hpp +++ b/src/headers/Yerbacon.hpp @@ -6,6 +6,14 @@ #define YBCON_VERSION "UNKNOWN" #endif +#ifndef YBCON_FLAGS +#define YBCON_FLAGS "none" +#endif + +#ifndef YBCON_COMPILER +#define YBCON_COMPILER "unknown" +#endif + #ifdef __STDC_NO_THREADS__ #error "A valid std::threads implementation is required" #endif @@ -27,6 +35,11 @@ namespace Yerbacon { consteval const char* getVersion() noexcept { return YBCON_VERSION; } + consteval const char* getBuildInfo() noexcept { return + "Build info:\n" + " Optimization flags: " YBCON_FLAGS "\n" + " Compiler: " YBCON_COMPILER; + } static void exit(const std::initializer_list reason) { std::for_each(reason.begin(), reason.end(), [](const char* current_string){ std::cout << current_string; @@ -48,4 +61,6 @@ namespace Yerbacon { } #undef YBCON_VERSION +#undef YBCON_FLAGS +#undef YBCON_COMPILER #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 6300b0c..2cd12af 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,8 +18,7 @@ int main(int argc, char* argv[]) { for (signed int i = 1; i < argc; ++i) { const string_view currentArg (argv[i]); - if ((argc == 2) && (currentArg == Argument("version"))) { cout << Yerbacon::getVersion() << endl; exit(EXIT_SUCCESS); } - else if (currentArg == ArgumentShort("printresult")) printResult = true; + if (currentArg == ArgumentShort("printresult")) printResult = true; else if (currentArg == ArgumentAssignable("target")) { const string_view value = ArgumentAssignable::getValueFor(currentArg); if (not value.empty()) (target = '.') += value; @@ -28,7 +27,16 @@ int main(int argc, char* argv[]) { else if (currentArg == Argument("parallel")) parallel = true; else if (currentArg == Argument("newlinesoff")) newLines = false; else if (currentArg.ends_with(".ybcon")) files.insert(currentArg); - else Yerbacon::exit({"\"", currentArg.data(), "\" is not a valid argument."}); + else { + if (argc == 2) { + if (currentArg == Argument("version")) { + cout << Yerbacon::getVersion(); + } else if (currentArg == Argument("buildInfo")) { + cout << Yerbacon::getBuildInfo() ; + } else goto invalid_argument; + cout << endl; exit(EXIT_SUCCESS); + } else invalid_argument: Yerbacon::exit({"\"", currentArg.data(), "\" is not a valid argument."}); + } } const auto compile = [&target, &newLines](string_view name) -> string { string transpiledString = transpile(parseString(getFileContent(name.data())), target, newLines);