Add a "--buildInfo" argument to print the compiler and optimization options used when building

This commit is contained in:
Username404-59 2021-10-20 17:06:02 +02:00
parent 0ce02ea77f
commit 88d22e6183
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 27 additions and 3 deletions

View File

@ -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)

View File

@ -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<const char*> 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

View File

@ -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);