1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CHRE_TOOLCHAIN_H_ 18 #define CHRE_TOOLCHAIN_H_ 19 20 /** 21 * @file 22 * Compiler/build toolchain-specific macros used by the CHRE API 23 */ 24 25 #if defined(__GNUC__) || defined(__clang__) 26 // For GCC and clang 27 28 #define CHRE_DEPRECATED(message) \ 29 __attribute__((deprecated(message))) 30 31 // Enable printf-style compiler warnings for mismatched format string and args 32 #define CHRE_PRINTF_ATTR(formatPos, argStart) \ 33 __attribute__((format(printf, formatPos, argStart))) 34 35 #define CHRE_BUILD_ERROR(message) CHRE_DO_PRAGMA(GCC error message) 36 #define CHRE_DO_PRAGMA(message) _Pragma(#message) 37 38 #elif defined(__ICCARM__) || defined(__CC_ARM) 39 // For IAR ARM and Keil MDK-ARM compilers 40 41 #define CHRE_PRINTF_ATTR(formatPos, argStart) 42 43 #elif defined(_MSC_VER) 44 // For Microsoft Visual Studio 45 46 #define CHRE_PRINTF_ATTR(formatPos, argStart) 47 48 #else // if !defined(__GNUC__) && !defined(__clang__) 49 50 #error Need to add support for new compiler 51 52 #endif 53 54 // For platforms that don't support error pragmas, utilize the best method of 55 // showing an error depending on the platform support. 56 #ifndef CHRE_BUILD_ERROR 57 #ifdef __cplusplus // C++11 or greater assumed 58 #define CHRE_BUILD_ERROR(message) static_assert(0, message) 59 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L 60 #define CHRE_BUILD_ERROR(message) _Static_assert(0, message) 61 #else 62 #define CHRE_BUILD_ERROR(message) char buildError[-1] = message 63 #endif 64 #endif 65 66 #endif // CHRE_TOOLCHAIN_H_ 67