Lagrange
build.h
1/*
2 * Copyright 2023 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#define LAGRANGE_TARGET_OS(X) LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_##X()
15
16#if defined(_WIN32) || defined(_WIN64)
17 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_WINDOWS() 1
18 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_LINUX() 0
19 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_APPLE() 0
20 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_WASM() 0
21#elif defined(__APPLE__)
22 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_WINDOWS() 0
23 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_APPLE() 1
24 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_LINUX() 0
25 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_WASM() 0
26#elif defined(__linux__)
27 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_WINDOWS() 0
28 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_APPLE() 0
29 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_LINUX() 1
30 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_WASM() 0
31#elif defined(__wasm__)
32 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_WINDOWS() 0
33 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_APPLE() 0
34 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_LINUX() 0
35 #define LAGRANGE_TARGET_OS_PRIVATE_DEFINITION_WASM() 1
36#else
37 #error "Platform not supported"
38#endif
39
40#define LAGRANGE_TARGET_COMPILER(X) LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_##X()
41
42#if defined(__EMSCRIPTEN__)
43 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_MSVC() 0
44 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CYGWIN() 0
45 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CLANG() 0
46 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_GCC() 0
47 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_EMSCRIPTEN() 1
48#elif defined(_MSC_VER)
49 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_MSVC() 1
50 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CYGWIN() 0
51 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CLANG() 0
52 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_GCC() 0
53 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_EMSCRIPTEN() 0
54#elif defined(__CYGWIN__)
55 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_MSVC() 0
56 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CYGWIN() 1
57 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CLANG() 0
58 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_GCC() 0
59 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_EMSCRIPTEN() 0
60#elif defined(__clang__)
61 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_MSVC() 0
62 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CYGWIN() 0
63 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CLANG() 1
64 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_GCC() 0
65 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_EMSCRIPTEN() 0
66#elif defined(__GNUC__)
67 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_MSVC() 0
68 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CYGWIN() 0
69 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_CLANG() 0
70 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_GCC() 1
71 #define LAGRANGE_TARGET_COMPILER_PRIVATE_DEFINITION_EMSCRIPTEN() 0
72#else
73 #error "Compiler not supported"
74#endif
75
76#define LAGRANGE_TARGET_PLATFORM(X) LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_##X()
77
78#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \
79 defined(_M_X64) || defined(_M_AMD64)
80 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_x86_64() 1
81 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_arm64() 0
82#elif defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
83 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_x86_64() 0
84 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_arm64() 1
85#else
86 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_x86_64() 0
87 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_arm64() 0
88#endif
89
90#if defined(__wasm32__)
91 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_wasm32() 1
92 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_wasm64() 0
93#elif defined(__wasm64__)
94 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_wasm32() 0
95 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_wasm64() 1
96#else
97 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_wasm32() 0
98 #define LAGRANGE_TARGET_PLATFORM_PRIVATE_DEFINITION_wasm64() 0
99#endif
100
101#if !( \
102 LAGRANGE_TARGET_PLATFORM(x86_64) || LAGRANGE_TARGET_PLATFORM(arm64) || \
103 LAGRANGE_TARGET_PLATFORM(wasm32) || LAGRANGE_TARGET_PLATFORM(wasm64))
104 #error "Unexpected target platform setup"
105#endif
106
107#define LAGRANGE_TARGET_FEATURE(X) LAGRANGE_TARGET_FEATURE_PRIVATE_DEFINITION_##X()
108
109#if __clang__ && !__INTEL_COMPILER
110 #define LAGRANGE_ENABLE_RTTI __has_feature(cxx_rtti)
111#elif defined(_CPPRTTI)
112 #define LAGRANGE_ENABLE_RTTI 1
113#else
114 #define LAGRANGE_ENABLE_RTTI (__GXX_RTTI || __RTTI || __INTEL_RTTI__)
115#endif
116
117#if LAGRANGE_ENABLE_RTTI
118 #define LAGRANGE_TARGET_FEATURE_PRIVATE_DEFINITION_RTTI() 1
119#else
120 #define LAGRANGE_TARGET_FEATURE_PRIVATE_DEFINITION_RTTI() 0
121#endif