build_config.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. // Copyright (c) 2018, libnumaapi authors
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to
  5. // deal in the Software without restriction, including without limitation the
  6. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  7. // sell copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  19. // IN THE SOFTWARE.
  20. //
  21. // Author: Sergey Sharybin (sergey.vfx@gmail.com)
  22. #ifndef __BUILD_CONFIG_H__
  23. #define __BUILD_CONFIG_H__
  24. #include <limits.h>
  25. #include <stdint.h>
  26. // Initially is based on Chromium's build_config.h, with tweaks and extensions
  27. // needed for this project.
  28. //
  29. // NOTE: All commonly used symbols (which are checked on a "top" level, from
  30. // outside of any platform-specific ifdef block) are to be explicitly defined
  31. // to 0 when they are not "active". This is extra lines of code in this file,
  32. // but is not being edited that often. Such approach helps catching cases when
  33. // one attempted to access build configuration variable without including the
  34. // header by simply using -Wundef compiler attribute.
  35. //
  36. // NOTE: Not having things explicitly defined to 0 is harmless (in terms it
  37. // follows same rules as Google projects) and will simply cause compiler to
  38. // become more noisy, which is simple to correct.
  39. ////////////////////////////////////////////////////////////////////////////////
  40. // A set of macros to use for platform detection.
  41. #if defined(__native_client__)
  42. // __native_client__ must be first, so that other OS_ defines are not set.
  43. # define OS_NACL 1
  44. #elif defined(_AIX)
  45. # define OS_AIX 1
  46. #elif defined(ANDROID)
  47. # define OS_ANDROID 1
  48. #elif defined(__APPLE__)
  49. // Only include TargetConditions after testing ANDROID as some android builds
  50. // on mac don't have this header available and it's not needed unless the target
  51. // is really mac/ios.
  52. # include <TargetConditionals.h>
  53. # define OS_MACOSX 1
  54. # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
  55. # define OS_IOS 1
  56. # endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
  57. #elif defined(__HAIKU__)
  58. # define OS_HAIKU 1
  59. #elif defined(__hpux)
  60. # define OS_HPUX 1
  61. #elif defined(__linux__)
  62. # define OS_LINUX 1
  63. // Include a system header to pull in features.h for glibc/uclibc macros.
  64. # include <unistd.h>
  65. # if defined(__GLIBC__) && !defined(__UCLIBC__)
  66. // We really are using glibc, not uClibc pretending to be glibc.
  67. # define LIBC_GLIBC 1
  68. # endif
  69. #elif defined(__sgi)
  70. # define OS_IRIX 1
  71. #elif defined(_WIN32)
  72. # define OS_WIN 1
  73. #elif defined(__FreeBSD__)
  74. # define OS_FREEBSD 1
  75. #elif defined(__NetBSD__)
  76. # define OS_NETBSD 1
  77. #elif defined(__OpenBSD__)
  78. # define OS_OPENBSD 1
  79. #elif defined(__sun)
  80. # define OS_SOLARIS 1
  81. #elif defined(__QNXNTO__)
  82. # define OS_QNX 1
  83. #else
  84. # error Please add support for your platform in build_config.h
  85. #endif
  86. #if !defined(OS_AIX)
  87. # define OS_AIX 0
  88. #endif
  89. #if !defined(OS_NACL)
  90. # define OS_NACL 0
  91. #endif
  92. #if !defined(OS_ANDROID)
  93. # define OS_ANDROID 0
  94. #endif
  95. #if !defined(OS_MACOSX)
  96. # define OS_MACOSX 0
  97. #endif
  98. #if !defined(OS_IOS)
  99. # define OS_IOS 0
  100. #endif
  101. #if !defined(OS_HAIKU)
  102. # define OS_HAIKU 0
  103. #endif
  104. #if !defined(OS_HPUX)
  105. # define OS_HPUX 0
  106. #endif
  107. #if !defined(OS_IRIX)
  108. # define OS_IRIX 0
  109. #endif
  110. #if !defined(OS_LINUX)
  111. # define OS_LINUX 0
  112. #endif
  113. #if !defined(LIBC_GLIBC)
  114. # define LIBC_GLIBC 0
  115. #endif
  116. #if !defined(OS_WIN)
  117. # define OS_WIN 0
  118. #endif
  119. #if !defined(OS_FREEBSD)
  120. # define OS_FREEBSD 0
  121. #endif
  122. #if !defined(OS_NETBSD)
  123. # define OS_NETBSD 0
  124. #endif
  125. #if !defined(OS_OPENBSD)
  126. # define OS_OPENBSD 0
  127. #endif
  128. #if !defined(OS_SOLARIS)
  129. # define OS_SOLARIS 0
  130. #endif
  131. #if !defined(OS_QNX)
  132. # define OS_QNX 0
  133. #endif
  134. ////////////////////////////////////////////////////////////////////////////////
  135. // *BSD OS family detection.
  136. //
  137. // For access to standard BSD features, use OS_BSD instead of a
  138. // more specific macro.
  139. #if OS_FREEBSD || OS_OPENBSD || OS_NETBSD
  140. # define OS_BSD 1
  141. #else
  142. # define OS_BSD 0
  143. #endif
  144. ////////////////////////////////////////////////////////////////////////////////
  145. // POSIX system detection.
  146. //
  147. // For access to standard POSIXish features use OS_POSIX instead of a
  148. // more specific macro.
  149. #if OS_MACOSX || OS_LINUX || OS_BSD || OS_SOLARIS ||OS_ANDROID || OS_NACL || \
  150. OS_QNX || OS_HAIKU || OS_AIX || OS_HPUX || OS_IRIX
  151. # define OS_POSIX 1
  152. #else
  153. # define OS_POSIX 0
  154. #endif
  155. ////////////////////////////////////////////////////////////////////////////////
  156. // Compiler detection, including its capabilities.
  157. #if defined(__clang__)
  158. # define COMPILER_CLANG 1
  159. #elif defined(__GNUC__)
  160. # define COMPILER_GCC 1
  161. # define COMPILER_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
  162. #elif defined(_MSC_VER)
  163. # define COMPILER_MSVC 1
  164. # define COMPILER_MSVC_VERSION (_MSC_VER)
  165. #elif defined(__MINGW32__)
  166. # define COMPILER_MINGW32 1
  167. #elif defined(__MINGW64__)
  168. # define COMPILER_MINGW64 1
  169. #else
  170. # error Please add support for your compiler in build_config.h
  171. #endif
  172. #if !defined(COMPILER_CLANG)
  173. # define COMPILER_CLANG 0
  174. #endif
  175. #if !defined(COMPILER_GCC)
  176. # define COMPILER_GCC 0
  177. #endif
  178. #if !defined(COMPILER_MSVC)
  179. # define COMPILER_MSVC 0
  180. #endif
  181. #if !defined(COMPILER_MINGW32)
  182. # define COMPILER_MINGW32 0
  183. #endif
  184. #if !defined(COMPILER_MINGW64)
  185. # define COMPILER_MINGW64 0
  186. #endif
  187. // Compiler is any of MinGW family.
  188. #if COMPILER_MINGW32 || COMPILER_MINGW64
  189. # define COMPILER_MINGW 1
  190. #else
  191. # define COMPILER_MINGW 0
  192. #endif
  193. // Check what is the latest C++ specification the compiler supports.
  194. //
  195. // NOTE: Use explicit definition here to avoid expansion-to-defined warning from
  196. // being geenrated. While this will most likely a false-positive warning in this
  197. // particular case, that warning might be helpful to catch errors elsewhere.
  198. // C++11 check.
  199. #if ((defined(__cplusplus) && (__cplusplus > 199711L)) || \
  200. (defined(_MSC_VER) && (_MSC_VER >= 1800)))
  201. # define COMPILER_SUPPORTS_CXX11 1
  202. #else
  203. # define COMPILER_SUPPORTS_CXX11 0
  204. #endif
  205. // C++14 check.
  206. #if (defined(__cplusplus) && (__cplusplus > 201311L))
  207. # define COMPILER_SUPPORTS_CXX14 1
  208. #else
  209. # define COMPILER_SUPPORTS_CXX14 0
  210. #endif
  211. // C++17 check.
  212. #if (defined(__cplusplus) && (__cplusplus > 201611L))
  213. # define COMPILER_SUPPORTS_CXX17 1
  214. #else
  215. # define COMPILER_SUPPORTS_CXX17 0
  216. #endif
  217. // C++20 check.
  218. #if (defined(__cplusplus) && (__cplusplus > 201911L))
  219. # define COMPILER_SUPPORTS_CXX20 1
  220. #else
  221. # define COMPILER_SUPPORTS_CXX20 0
  222. #endif
  223. // COMPILER_USE_ADDRESS_SANITIZER is defined when program is detected that
  224. // compilation happened wit haddress sanitizer enabled. This allows to give
  225. // tips to sanitizer, or maybe work around some known issues with third party
  226. // libraries.
  227. #if !defined(COMPILER_USE_ADDRESS_SANITIZER)
  228. # if defined(__has_feature)
  229. # define COMPILER_USE_ADDRESS_SANITIZER 1
  230. # elif defined(__SANITIZE_ADDRESS__)
  231. # define COMPILER_USE_ADDRESS_SANITIZER 1
  232. # endif
  233. #endif
  234. #if !defined(COMPILER_USE_ADDRESS_SANITIZER)
  235. # define COMPILER_USE_ADDRESS_SANITIZER 0
  236. #endif
  237. ////////////////////////////////////////////////////////////////////////////////
  238. // Processor architecture detection.
  239. //
  240. // For more info on what's defined, see:
  241. //
  242. // http://msdn.microsoft.com/en-us/library/b0084kay.aspx
  243. // http://www.agner.org/optimize/calling_conventions.pdf
  244. //
  245. // or with gcc, run: "echo | gcc -E -dM -"
  246. #if defined(_M_X64) || defined(__x86_64__)
  247. # define ARCH_CPU_X86_FAMILY 1
  248. # define ARCH_CPU_X86_64 1
  249. # define ARCH_CPU_64_BITS 1
  250. # define ARCH_CPU_LITTLE_ENDIAN 1
  251. #elif defined(_M_IX86) || defined(__i386__)
  252. # define ARCH_CPU_X86_FAMILY 1
  253. # define ARCH_CPU_X86 1
  254. # define ARCH_CPU_32_BITS 1
  255. # define ARCH_CPU_LITTLE_ENDIAN 1
  256. #elif defined(__ARMEL__)
  257. # define ARCH_CPU_ARM_FAMILY 1
  258. # define ARCH_CPU_ARMEL 1
  259. # define ARCH_CPU_32_BITS 1
  260. # define ARCH_CPU_LITTLE_ENDIAN 1
  261. #elif defined(__aarch64__)
  262. # define ARCH_CPU_ARM_FAMILY 1
  263. # define ARCH_CPU_ARM64 1
  264. # define ARCH_CPU_64_BITS 1
  265. # define ARCH_CPU_LITTLE_ENDIAN 1
  266. #elif defined(__pnacl__)
  267. # define ARCH_CPU_32_BITS 1
  268. # define ARCH_CPU_LITTLE_ENDIAN 1
  269. #elif defined(__MIPSEL__)
  270. # if defined(__LP64__)
  271. # define ARCH_CPU_MIPS64_FAMILY 1
  272. # define ARCH_CPU_MIPS64EL 1
  273. # define ARCH_CPU_64_BITS 1
  274. # define ARCH_CPU_LITTLE_ENDIAN 1
  275. # else
  276. # define ARCH_CPU_MIPS_FAMILY 1
  277. # define ARCH_CPU_MIPSEL 1
  278. # define ARCH_CPU_32_BITS 1
  279. # define ARCH_CPU_LITTLE_ENDIAN 1
  280. # endif
  281. #elif defined(__MIPSEB__)
  282. # if defined(__LP64__)
  283. # define ARCH_CPU_MIPS64_FAMILY 1
  284. # define ARCH_CPU_MIPS64EB 1
  285. # define ARCH_CPU_64_BITS 1
  286. # define ARCH_CPU_BIG_ENDIAN 1
  287. # else
  288. # define ARCH_CPU_MIPS_FAMILY 1
  289. # define ARCH_CPU_MIPSEB 1
  290. # define ARCH_CPU_32_BITS 1
  291. # define ARCH_CPU_BIG_ENDIAN 1
  292. # endif
  293. #else
  294. # error Please add support for your architecture in build_config.h
  295. #endif
  296. #if !defined(ARCH_CPU_LITTLE_ENDIAN)
  297. # define ARCH_CPU_LITTLE_ENDIAN 0
  298. #endif
  299. #if !defined(ARCH_CPU_BIG_ENDIAN)
  300. # define ARCH_CPU_BIG_ENDIAN 0
  301. #endif
  302. #if !defined(ARCH_CPU_32_BITS)
  303. # define ARCH_CPU_32_BITS 0
  304. #endif
  305. #if !defined(ARCH_CPU_64_BITS)
  306. # define ARCH_CPU_64_BITS 0
  307. #endif
  308. #if !defined(ARCH_CPU_X86_FAMILY)
  309. # define ARCH_CPU_X86_FAMILY 0
  310. #endif
  311. #if !defined(ARCH_CPU_ARM_FAMILY)
  312. # define ARCH_CPU_ARM_FAMILY 0
  313. #endif
  314. #if !defined(ARCH_CPU_MIPS_FAMILY)
  315. # define ARCH_CPU_MIPS_FAMILY 0
  316. #endif
  317. #if !defined(ARCH_CPU_MIPS64_FAMILY)
  318. # define ARCH_CPU_MIPS64_FAMILY 0
  319. #endif
  320. ////////////////////////////////////////////////////////////////////////////////
  321. // Sizes of platform-dependent types.
  322. #if defined(__SIZEOF_POINTER__)
  323. # define PLATFORM_SIZEOF_PTR __SIZEOF_POINTER__
  324. #elif defined(UINTPTR_MAX)
  325. # if (UINTPTR_MAX == 0xffffffff)
  326. # define PLATFORM_SIZEOF_PTR 4
  327. # elif (UINTPTR_MAX == 0xffffffffffffffff) // NOLINT
  328. # define PLATFORM_SIZEOF_PTR 8
  329. # endif
  330. #elif defined(__WORDSIZE)
  331. # if (__WORDSIZE == 32)
  332. # define PLATFORM_SIZEOF_PTR 4
  333. # else if (__WORDSIZE == 64)
  334. # define PLATFORM_SIZEOF_PTR 8
  335. # endif
  336. #endif
  337. #if !defined(PLATFORM_SIZEOF_PTR)
  338. # error "Cannot find pointer size"
  339. #endif
  340. #if (UINT_MAX == 0xffffffff)
  341. # define PLATFORM_SIZEOF_INT 4
  342. #elif (UINT_MAX == 0xffffffffffffffff) // NOLINT
  343. # define PLATFORM_SIZEOF_INT 8
  344. #else
  345. # error "Cannot find int size"
  346. #endif
  347. #if (USHRT_MAX == 0xffffffff)
  348. # define PLATFORM_SIZEOF_SHORT 4
  349. #elif (USHRT_MAX == 0xffff) // NOLINT
  350. # define PLATFORM_SIZEOF_SHORT 2
  351. #else
  352. # error "Cannot find short size"
  353. #endif
  354. #endif // __BUILD_CONFIG_H__