|
1 | | -set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12) |
| 1 | +set(CMAKE_CXX_STANDARD 20) |
| 2 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 3 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 4 | + |
| 5 | +set(CMAKE_C_STANDARD 11) |
| 6 | +set(CMAKE_C_STANDARD_REQUIRED ON) |
| 7 | +set(CMAKE_C_EXTENSIONS OFF) |
| 8 | + |
| 9 | +include("${CMAKE_ANDROID_NDK}/build/cmake/abis.cmake") |
| 10 | + |
| 11 | +if(CMAKE_BUILD_TYPE STREQUAL Debug) |
| 12 | + set(DEBUG_BUILD True) |
| 13 | +else() |
| 14 | + set(DEBUG_BUILD False) |
| 15 | +endif() |
| 16 | + |
| 17 | +set(XA_NO_INLINE "$ENV{XA_NO_INLINE}") |
| 18 | +if(XA_NO_INLINE) |
| 19 | + set(DONT_INLINE_DEFAULT ON) |
| 20 | +else() |
| 21 | + set(DONT_INLINE_DEFAULT OFF) |
| 22 | +endif() |
| 23 | + |
| 24 | +set(XA_NO_STRIP "$ENV{XA_NO_STRIP}") |
| 25 | +if(XA_NO_STRIP OR DEBUG_BUILD) |
| 26 | + set(STRIP_DEBUG_DEFAULT OFF) |
| 27 | +endif() |
| 28 | + |
| 29 | +option(ENABLE_CLANG_ASAN "Enable the clang AddressSanitizer support" OFF) |
| 30 | +option(ENABLE_CLANG_UBSAN "Enable the clang UndefinedBehaviorSanitizer support" OFF) |
| 31 | + |
| 32 | +if(ENABLE_CLANG_ASAN OR ENABLE_CLANG_UBSAN) |
| 33 | + set(STRIP_DEBUG_DEFAULT OFF) |
| 34 | + set(ANALYZERS_ENABLED ON) |
| 35 | +else() |
| 36 | + if(NOT XA_NO_STRIP) |
| 37 | + set(STRIP_DEBUG_DEFAULT ON) |
| 38 | + endif() |
| 39 | + set(ANALYZERS_ENABLED OFF) |
| 40 | +endif() |
| 41 | + |
| 42 | +option(COMPILER_DIAG_COLOR "Show compiler diagnostics/errors in color" ON) |
| 43 | +option(STRIP_DEBUG "Strip debugging information when linking" ${STRIP_DEBUG_DEFAULT}) |
| 44 | +option(DISABLE_DEBUG "Disable the built-in debugging code" OFF) |
| 45 | +option(USE_CCACHE "Use ccache, if found, to speed up recompilation" ON) |
| 46 | +option(DONT_INLINE "Do not inline any functions which are usually inlined, to get better stack traces" ${DONT_INLINE_DEFAULT}) |
| 47 | + |
| 48 | +if(USE_CCACHE) |
| 49 | + if(CMAKE_CXX_COMPILER MATCHES "/ccache/") |
| 50 | + message(STATUS "ccache: compiler already uses ccache") |
| 51 | + else() |
| 52 | + find_program(CCACHE ccache) |
| 53 | + if(CCACHE) |
| 54 | + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE}") |
| 55 | + set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE}") |
| 56 | + message(STATUS "ccache: compiler will be lauched with ${CCACHE}") |
| 57 | + endif() |
| 58 | + endif() |
| 59 | +endif() |
| 60 | + |
| 61 | +if(ANDROID_STL STREQUAL none) |
| 62 | + set(USES_LIBSTDCPP False) |
| 63 | +else() |
| 64 | + set(USES_LIBSTDCPP True) |
| 65 | +endif() |
| 66 | + |
| 67 | +# |
| 68 | +# General config |
| 69 | +# |
| 70 | +if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) |
| 71 | + set(IS_LINUX True) |
| 72 | +else() |
| 73 | + set(IS_LINUX False) |
| 74 | +endif() |
| 75 | + |
| 76 | +if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) |
| 77 | + set(IS_MACOS True) |
| 78 | +else() |
| 79 | + set(IS_MACOS False) |
| 80 | +endif() |
| 81 | + |
| 82 | +set(XA_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/Build${XA_BUILD_CONFIGURATION}") |
| 83 | +include("${XA_BUILD_DIR}/xa_build_configuration.cmake") |
| 84 | + |
| 85 | +# |
| 86 | +# Paths |
| 87 | +# |
| 88 | +if(ANDROID_ABI MATCHES "^arm64-v8a") |
| 89 | + set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_ARM64}") |
| 90 | + set(TOOLCHAIN_TRIPLE "${NDK_ABI_arm64-v8a_TRIPLE}") |
| 91 | +elseif(ANDROID_ABI MATCHES "^armeabi-v7a") |
| 92 | + set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_ARM}") |
| 93 | + set(TOOLCHAIN_TRIPLE "${NDK_ABI_armeabi-v7a_TRIPLE}") |
| 94 | +elseif(ANDROID_ABI MATCHES "^x86_64") |
| 95 | + set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_X86_64}") |
| 96 | + set(TOOLCHAIN_TRIPLE "${NDK_ABI_x86_64_TRIPLE}") |
| 97 | +elseif(ANDROID_ABI MATCHES "^x86") |
| 98 | + set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_X86}") |
| 99 | + set(TOOLCHAIN_TRIPLE "${NDK_ABI_x86_TRIPLE}") |
| 100 | +else() |
| 101 | + message(FATAL "${ANDROID_ABI} is not supported for .NET 6+ builds") |
| 102 | +endif() |
| 103 | + |
| 104 | +file(REAL_PATH "../../" REPO_ROOT_DIR) |
| 105 | +set(EXTERNAL_DIR "${REPO_ROOT_DIR}/external") |
| 106 | +set(JAVA_INTEROP_SRC_PATH "${EXTERNAL_DIR}/Java.Interop/src/java-interop") |
| 107 | +set(SHARED_SOURCES_DIR "${REPO_ROOT_DIR}/src/native/shared") |
| 108 | +set(TRACING_SOURCES_DIR "${REPO_ROOT_DIR}/src/native/tracing") |
| 109 | +# |
| 110 | +# Include directories |
| 111 | +# |
| 112 | +include_directories(SYSTEM ${CMAKE_SYSROOT}/usr/include/c++/v1/) |
| 113 | +include_directories(SYSTEM "${NET_RUNTIME_DIR}/native/include/mono-2.0") |
| 114 | +include_directories("${JAVA_INTEROP_SRC_PATH}") |
| 115 | +include_directories("${SHARED_SOURCES_DIR}") |
| 116 | +include_directories("${TRACING_SOURCES_DIR}") |
| 117 | + |
| 118 | +# |
| 119 | +# Compiler defines |
| 120 | +# |
| 121 | +add_compile_definitions(XA_VERSION="${XA_VERSION}") |
| 122 | +add_compile_definitions(_REENTRANT) |
| 123 | +add_compile_definitions(PLATFORM_ANDROID) |
| 124 | + |
| 125 | +if(DEBUG_BUILD AND NOT DISABLE_DEBUG) |
| 126 | + add_compile_definitions(DEBUG) |
| 127 | +endif() |
| 128 | + |
| 129 | +if(ANDROID_ABI MATCHES "^(arm64-v8a|x86_64)") |
| 130 | + add_compile_definitions(ANDROID64) |
| 131 | +endif() |
| 132 | + |
| 133 | +if (ANDROID_NDK_MAJOR LESS 20) |
| 134 | + add_compile_definitions(__ANDROID_API_Q__=29) |
| 135 | +endif() |
| 136 | + |
| 137 | +# |
| 138 | +# Shared sources |
| 139 | +# |
| 140 | +set(XA_SHARED_SOURCES |
| 141 | + ${SHARED_SOURCES_DIR}/helpers.cc |
| 142 | + ${SHARED_SOURCES_DIR}/new_delete.cc |
| 143 | +) |
0 commit comments