mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-08 00:01:09 +00:00
* Add Missing Includes Across src/libslic3r Every libslic3r source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, with libslic3r headers spelled libslic3r/... so they resolve outside the library's private include paths. MultiMaterialSegmentation.hpp, Support/SupportParameters.hpp and Format/STEP.hpp are made self-contained by hand. * Make the libslic3r Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Left out: I18N.hpp, which errors on purpose when included from GUI code, and VoxelizeCSGMesh.hpp and SLA/bicubic.h, which nothing includes and which no longer compile at all. * Add the Includes Missing From the Hand-Fixed libslic3r Headers clang-tidy would not edit these headers while they failed to compile on their own, so the first pass skipped them. With the headers now self-contained, a second pass adds the rest. * Keep Windows Setup Ahead of the Added libslic3r Includes Print.cpp and Thread.cpp open with a _WIN32 block that has to come first; without the precompiled header, Print.cpp otherwise reaches windows.h through OCCT with NONLS defined and boost/regex fails. OpenVDBUtils.cpp and SLA/SupportTreeBuilder.cpp had includes inside #ifndef NOMINMAX, which libslic3r defines on Windows, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory. * Re-Add libslic3r Includes After the Clipper2 2.0.1 Migration Rebasing onto main took main's version of the files the Clipper2 migration rewrote, so their added includes are restored here, along with includes for main's new code. Clipper2's individual headers are now ignored by clang-tidy: they only build the Z variant through clipper2_z.hpp, which defines USINGZ first, so including clipper.core.h and the like directly broke ClipperZUtils.cpp.
178 lines
5.6 KiB
C++
178 lines
5.6 KiB
C++
#include "Platform.hpp"
|
|
|
|
#include <boost/log/trivial.hpp>
|
|
#include <boost/filesystem/operations.hpp>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
#include <cassert>
|
|
|
|
#if defined(__APPLE__)
|
|
#include <sys/types.h>
|
|
#include <sys/sysctl.h>
|
|
#include <mach/machine.h>
|
|
#endif
|
|
|
|
namespace Slic3r {
|
|
|
|
static auto s_platform = Platform::Uninitialized;
|
|
static auto s_platform_flavor = PlatformFlavor::Uninitialized;
|
|
|
|
void detect_platform()
|
|
{
|
|
#if defined(_WIN32)
|
|
BOOST_LOG_TRIVIAL(info) << "Platform: Windows";
|
|
s_platform = Platform::Windows;
|
|
s_platform_flavor = PlatformFlavor::Generic;
|
|
#elif defined(__APPLE__)
|
|
BOOST_LOG_TRIVIAL(info) << "Platform: OSX";
|
|
s_platform = Platform::OSX;
|
|
s_platform_flavor = PlatformFlavor::GenericOSX;
|
|
{
|
|
cpu_type_t type = 0;
|
|
size_t size = sizeof(type);
|
|
if (sysctlbyname("hw.cputype", &type, &size, NULL, 0) == 0) {
|
|
type &= ~CPU_ARCH_MASK;
|
|
if (type == CPU_TYPE_X86) {
|
|
int proc_translated = 0;
|
|
size = sizeof(proc_translated);
|
|
// Detect if native CPU is really X86 or PrusaSlicer runs through Rosetta.
|
|
if (sysctlbyname("sysctl.proc_translated", &proc_translated, &size, NULL, 0) == -1) {
|
|
if (errno == ENOENT) {
|
|
// Native CPU is X86, and property sysctl.proc_translated doesn't exist.
|
|
s_platform_flavor = PlatformFlavor::OSXOnX86;
|
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: OSXOnX86";
|
|
}
|
|
} else if (proc_translated == 1) {
|
|
// Native CPU is ARM and PrusaSlicer runs through Rosetta.
|
|
s_platform_flavor = PlatformFlavor::OSXOnArm;
|
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: OSXOnArm";
|
|
} else {
|
|
// Native CPU is X86.
|
|
s_platform_flavor = PlatformFlavor::OSXOnX86;
|
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: OSXOnX86";
|
|
}
|
|
} else if (type == CPU_TYPE_ARM) {
|
|
// Native CPU is ARM
|
|
s_platform_flavor = PlatformFlavor::OSXOnArm;
|
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: OSXOnArm";
|
|
}
|
|
}
|
|
}
|
|
#elif defined(__linux__)
|
|
BOOST_LOG_TRIVIAL(info) << "Platform: 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)) {
|
|
if (strstr(buf, "Chromium OS") != nullptr) {
|
|
s_platform_flavor = PlatformFlavor::LinuxOnChromium;
|
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: LinuxOnChromium";
|
|
} else if (strstr(buf, "microsoft") != nullptr || strstr(buf, "Microsoft") != nullptr) {
|
|
if (boost::filesystem::exists("/run/WSL") && getenv("WSL_INTEROP") != nullptr) {
|
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: WSL2";
|
|
s_platform_flavor = PlatformFlavor::WSL2;
|
|
} else {
|
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: WSL";
|
|
s_platform_flavor = PlatformFlavor::WSL;
|
|
}
|
|
}
|
|
}
|
|
::fclose(f);
|
|
}
|
|
}
|
|
#elif defined(__OpenBSD__)
|
|
BOOST_LOG_TRIVIAL(info) << "Platform: OpenBSD";
|
|
s_platform = Platform::BSDUnix;
|
|
s_platform_flavor = PlatformFlavor::OpenBSD;
|
|
#else
|
|
// This should not happen.
|
|
BOOST_LOG_TRIVIAL(info) << "Platform: Unknown";
|
|
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;
|
|
}
|
|
|
|
std::string platform_os_type()
|
|
{
|
|
#if defined(_WIN32)
|
|
return "win";
|
|
#elif defined(__APPLE__)
|
|
return "macos";
|
|
#elif defined(__linux__) || defined(__LINUX__)
|
|
return "linux";
|
|
#else
|
|
return "unknown";
|
|
#endif
|
|
}
|
|
|
|
std::string platform_architecture()
|
|
{
|
|
#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
|
|
return "arm64";
|
|
#elif defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64) || defined(_M_X64) || defined(_M_AMD64)
|
|
return "x86_64";
|
|
#elif defined(__i386__) || defined(__i386) || defined(i386) || defined(_M_IX86)
|
|
return "i386";
|
|
#else
|
|
return "unknown";
|
|
#endif
|
|
}
|
|
|
|
|
|
|
|
std::string platform_to_string(Platform platform)
|
|
{
|
|
switch (platform) {
|
|
case Platform::Uninitialized: return "Unitialized";
|
|
case Platform::Unknown : return "Unknown";
|
|
case Platform::Windows : return "Windows";
|
|
case Platform::OSX : return "OSX";
|
|
case Platform::Linux : return "Linux";
|
|
case Platform::BSDUnix : return "BSDUnix";
|
|
}
|
|
assert(false);
|
|
return "";
|
|
}
|
|
|
|
|
|
|
|
std::string platform_flavor_to_string(PlatformFlavor pf)
|
|
{
|
|
switch (pf) {
|
|
case PlatformFlavor::Uninitialized : return "Unitialized";
|
|
case PlatformFlavor::Unknown : return "Unknown";
|
|
case PlatformFlavor::Generic : return "Generic";
|
|
case PlatformFlavor::GenericLinux : return "GenericLinux";
|
|
case PlatformFlavor::LinuxOnChromium : return "LinuxOnChromium";
|
|
case PlatformFlavor::WSL : return "WSL";
|
|
case PlatformFlavor::WSL2 : return "WSL2";
|
|
case PlatformFlavor::OpenBSD : return "OpenBSD";
|
|
case PlatformFlavor::GenericOSX : return "GenericOSX";
|
|
case PlatformFlavor::OSXOnX86 : return "OSXOnX86";
|
|
case PlatformFlavor::OSXOnArm : return "OSXOnArm";
|
|
}
|
|
assert(false);
|
|
return "";
|
|
}
|
|
|
|
|
|
} // namespace Slic3r
|