diff --git a/src/slic3r/Utils/Platform.cpp b/src/slic3r/Utils/Platform.cpp new file mode 100644 index 000000000..d30f30fc8 --- /dev/null +++ b/src/slic3r/Utils/Platform.cpp @@ -0,0 +1,59 @@ +#include "Platform.hpp" + + +// For starting another PrusaSlicer instance on OSX. +// Fails to compile on Windows on the build server. + +#include + +namespace Slic3r { +namespace GUI { + +static auto s_platform = Platform::Uninitialized; +static auto s_platform_flavor = PlatformFlavor::Uninitialized; + +void detect_platform() +{ +#if defined(_WIN32) + s_platform = Platform::Windows; + s_platform_flavor = PlatformFlavor::Generic; +#elif defined(__APPLE__) + s_platform = Platform::OSX; + s_platform_flavor = PlatformFlavor::Generic; +#elif defined(__linux__) + s_platform = Platform::Linux; + s_platform_flavor = PlatformFlavor::GenericLinux; + // Test for Chromium. + { + FILE *f = ::fopen("/proc/version", "rt"); + if (f) { + char buf[4096]; + // Read the 1st line. + if (::fgets(buf, 4096, f) && strstr(buf, "Chromium OS") != nullptr) + s_platform_flavor = LinuxOnChromium; + ::fclose(f); + } + } +#elif defined(__OpenBSD__) + s_platform = Platform::BSD; + s_platform_flavor = PlatformFlavor::OpenBSD; +#else + // This should not happen. + static_assert(false, "Unknown platform detected"); + s_platform = Platform::Unknown; + s_platform_flavor = PlatformFlavor::Unknown; +#endif +} + +Platform platform() +{ + return s_platform; +} + +PlatformFlavor platform_flavor() +{ + return s_platform_flavor; +} + +} // namespace GUI +} // namespace Slic3r diff --git a/src/slic3r/Utils/Platform.hpp b/src/slic3r/Utils/Platform.hpp new file mode 100644 index 000000000..e11bde412 --- /dev/null +++ b/src/slic3r/Utils/Platform.hpp @@ -0,0 +1,40 @@ +#ifndef SLIC3R_GUI_Utils_Platform_HPP +#define SLIC3R_GUI_Utils_Platform_HPP + +namespace Slic3r { +namespace GUI { + +enum class Platform +{ + Uninitialized, + Unknown, + Windows, + OSX, + Linux, + BSD, +}; + +enum class PlatformFlavor +{ + Uninitialized, + Unknown, + // For Windows and OSX, until we need to be more specific. + Generic, + // For Platform::Linux + GenericLinux, + LinuxOnChromium, + // For Platform::BSD + OpenBSD, +}; + +// To be called on program start-up. +void detect_platform(); + +Platform platform(); +PlatformFlavor platform_flavor(); + + +} // namespace GUI +} // namespace Slic3r + +#endif // SLIC3R_GUI_Utils_Platform_HPP