diff --git a/src/cli/src/main.cpp b/src/cli/src/main.cpp index c96b3ab..3135efe 100644 --- a/src/cli/src/main.cpp +++ b/src/cli/src/main.cpp @@ -122,6 +122,9 @@ int main(int argc, char *argv[]) { "version", { "--version" }, "Print version and exit", 0 }, + { + "platform", { "--platform" }, + "Print platform information and exit", 0 }, { "no-timing", { "--no-timing" }, "Do not print out timing measurements", 0 }, @@ -183,6 +186,12 @@ int main(int argc, char *argv[]) exit(0); } + if (args["platform"]) + { + stdutils::platform::print_platform_info(std::cout); + exit(0); + } + const bool validation_mode = args["validation-mode"]; const bool verbose_mode = args["verbose"]; const std::chrono::seconds timeout_duration(args["timeout"].as(0u)); diff --git a/src/stdutils/include/stdutils/platform.h b/src/stdutils/include/stdutils/platform.h index fd107a8..6a8b46c 100644 --- a/src/stdutils/include/stdutils/platform.h +++ b/src/stdutils/include/stdutils/platform.h @@ -11,6 +11,17 @@ namespace stdutils namespace platform { +enum class OS +{ + UNKNOWN = 0, + LINUX, + MACOS, + WINDOWS +}; + +constexpr OS os(); +std::ostream& operator<<(std::ostream& out, OS os); + enum class Compiler { UNKNOWN = 0, @@ -35,11 +46,13 @@ enum class Arch constexpr Arch architecture(); std::ostream& operator<<(std::ostream& out, Arch arch); +void print_os(std::ostream& out); void print_cpp_standard(std::ostream& out); void print_compiler_info(std::ostream& out); void print_compilation_date(std::ostream& out); +void print_platform_info(std::ostream& out); void print_compiler_all_info(std::ostream& out); } -} \ No newline at end of file +} diff --git a/src/stdutils/src/platform.cpp b/src/stdutils/src/platform.cpp index 7aed5b3..2e58c75 100644 --- a/src/stdutils/src/platform.cpp +++ b/src/stdutils/src/platform.cpp @@ -11,6 +11,48 @@ namespace stdutils namespace platform { +constexpr OS os() +{ + // See: https://github.com/cpredef/predef/blob/master/OperatingSystems.md + #if defined(__linux__) + return OS::LINUX; + #elif defined(__APPLE__) + return OS::MACOS; + #elif defined(_WIN32) + return OS::WINDOWS; + #else + return OS::UNKNOWN; + #endif +} + +std::ostream& operator<<(std::ostream& out, OS os) +{ + switch(os) + { + case OS::UNKNOWN: + out << "Unknown"; + break; + + case OS::LINUX: + out << "linux"; + break; + + case OS::MACOS: + out << "macos"; + break; + + case OS::WINDOWS: + out << "windows"; + break; + + default: + assert(0); + out << "Unknown enum"; + break; + } + return out; +} + constexpr Compiler compiler() { // NB: Test __GNUC__ last, because that macro is sometimes defined by other compilers than the "true" GCC @@ -53,7 +95,7 @@ std::ostream& operator<<(std::ostream& out, Compiler compiler) default: assert(0); - out << "Unknown Id"; + out << "Unknown enum"; break; } return out; @@ -94,7 +136,7 @@ std::string compiler_version() default: assert(0); - out << "Unknown Id"; + out << "Unknown enum"; break; } return out.str(); @@ -136,12 +178,18 @@ std::ostream& operator<<(std::ostream& out, Arch arch) default: assert(0); - out << "Unknown Id"; + out << "Unknown enum"; break; } return out; } +void print_os(std::ostream& out) +{ + constexpr auto os_id = os(); + out << "OS: " << os_id << std::endl; +} + void print_cpp_standard(std::ostream& out) { out << "C++ Standard: " << __cplusplus << std::endl; @@ -167,13 +215,21 @@ void print_compilation_date(std::ostream& out) out << "Compilation date: " << __DATE__ << " " << __TIME__ << std::endl; } -void print_compiler_all_info(std::ostream& out) +void print_platform_info(std::ostream& out) { - print_cpp_standard(out); + print_os(out); + print_architecture_info(out); print_compiler_info(out); +} + +void print_compiler_all_info(std::ostream& out) +{ + print_os(out); print_architecture_info(out); + print_compiler_info(out); + print_cpp_standard(out); print_compilation_date(out); } } // namespace platform -} // namespace stdutils \ No newline at end of file +} // namespace stdutils