1 // Copyright 2017 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef COMMON_PLATFORM_H_ 16 #define COMMON_PLATFORM_H_ 17 18 #if defined(_WIN32) || defined(_WIN64) 19 # include <winapifamily.h> 20 # define DAWN_PLATFORM_WINDOWS 1 21 # if WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP 22 # define DAWN_PLATFORM_WIN32 1 23 # elif WINAPI_FAMILY == WINAPI_FAMILY_PC_APP 24 # define DAWN_PLATFORM_WINUWP 1 25 # else 26 # error "Unsupported Windows platform." 27 # endif 28 29 #elif defined(__linux__) 30 # define DAWN_PLATFORM_LINUX 1 31 # define DAWN_PLATFORM_POSIX 1 32 # if defined(__ANDROID__) 33 # define DAWN_PLATFORM_ANDROID 1 34 # endif 35 36 #elif defined(__APPLE__) 37 # define DAWN_PLATFORM_APPLE 1 38 # define DAWN_PLATFORM_POSIX 1 39 # include <TargetConditionals.h> 40 # if TARGET_OS_IPHONE 41 # define DAWN_PLATFORM_IOS 42 # elif TARGET_OS_MAC 43 # define DAWN_PLATFORM_MACOS 44 # else 45 # error "Unsupported Apple platform." 46 # endif 47 48 #elif defined(__Fuchsia__) 49 # define DAWN_PLATFORM_FUCHSIA 1 50 # define DAWN_PLATFORM_POSIX 1 51 52 #elif defined(__EMSCRIPTEN__) 53 # define DAWN_PLATFORM_EMSCRIPTEN 1 54 # define DAWN_PLATFORM_POSIX 1 55 56 #else 57 # error "Unsupported platform." 58 #endif 59 60 // Distinguish mips32. 61 #if defined(__mips__) && (_MIPS_SIM == _ABIO32) && !defined(__mips32__) 62 # define __mips32__ 63 #endif 64 65 // Distinguish mips64. 66 #if defined(__mips__) && (_MIPS_SIM == _ABI64) && !defined(__mips64__) 67 # define __mips64__ 68 #endif 69 70 #if defined(_WIN64) || defined(__aarch64__) || defined(__x86_64__) || defined(__mips64__) || \ 71 defined(__s390x__) || defined(__PPC64__) 72 # define DAWN_PLATFORM_64_BIT 1 73 static_assert(sizeof(sizeof(char)) == 8, "Expect sizeof(size_t) == 8"); 74 #elif defined(_WIN32) || defined(__arm__) || defined(__i386__) || defined(__mips32__) || \ 75 defined(__s390__) || defined(__EMSCRIPTEN__) 76 # define DAWN_PLATFORM_32_BIT 1 77 static_assert(sizeof(sizeof(char)) == 4, "Expect sizeof(size_t) == 4"); 78 #else 79 # error "Unsupported platform" 80 #endif 81 82 #endif // COMMON_PLATFORM_H_ 83