platform.cpp (2457B)
1 /* ReaPack: Package manager for REAPER 2 * Copyright (C) 2015-2025 Christian Fillion 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #include "platform.hpp" 19 20 #include <cstring> 21 #include <utility> 22 23 const Platform::Enum Platform::Current = Platform:: 24 #ifdef __APPLE__ 25 # ifdef __x86_64__ 26 Darwin_x86_64 27 # elif __i386__ 28 Darwin_i386 29 # elif __arm64__ 30 Darwin_arm64 31 # else 32 Unknown 33 # endif 34 35 #elif __linux__ 36 # ifdef __x86_64__ 37 Linux_x86_64 38 # elif __i686__ 39 Linux_i686 40 # elif __ARM_ARCH_7A__ 41 Linux_armv7l 42 # elif __aarch64__ 43 Linux_aarch64 44 # else 45 Unknown 46 # endif 47 48 #elif _WIN32 49 # ifdef _M_ARM64EC 50 Windows_arm64ec 51 # elif _M_X64 52 Windows_x64 53 # else 54 Windows_x86 55 # endif 56 57 #else 58 Unknown 59 #endif 60 ; 61 62 static_assert(Platform::Current != Platform::Unknown, 63 "The current operating system or architecture is not supported."); 64 65 auto Platform::parse(const char *platform, const bool hasArm64Ec) -> Enum 66 { 67 constexpr std::pair<const char *, Enum> map[] { 68 { "all", Generic }, 69 70 { "darwin", Darwin_Any }, 71 { "darwin32", Darwin_i386 }, 72 { "darwin64", Darwin_x86_64 }, 73 { "darwin-arm64", Darwin_arm64 }, 74 75 { "linux", Linux_Any }, 76 { "linux32", Linux_i686 }, 77 { "linux64", Linux_x86_64 }, 78 { "linux-armv7l", Linux_armv7l }, 79 { "linux-aarch64", Linux_aarch64 }, 80 81 { "windows", Windows_Any }, 82 { "win32", Windows_x86 }, 83 { "win64", Windows_x64 }, 84 { "windows-arm64ec", Windows_arm64ec }, 85 }; 86 87 for(auto &[key, value] : map) { 88 if(!strcmp(platform, key)) { 89 if(!hasArm64Ec && value == Windows_x64) 90 return Windows_x64_arm64ec; 91 return value; 92 } 93 } 94 95 return Unknown; 96 } 97 98 bool Platform::test() const 99 { 100 return (m_value & Current) != Unknown; 101 }