Skip to content

Commit

Permalink
Begin reorg of native code directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Mar 15, 2024
1 parent 0a2b695 commit bad8d15
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 130 deletions.
129 changes: 128 additions & 1 deletion build-tools/cmake/xa_common.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,128 @@
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

include("${CMAKE_ANDROID_NDK}/build/cmake/abis.cmake")

option(ENABLE_CLANG_ASAN "Enable the clang AddressSanitizer support" OFF)
option(ENABLE_CLANG_UBSAN "Enable the clang UndefinedBehaviorSanitizer support" OFF)

if(ENABLE_CLANG_ASAN OR ENABLE_CLANG_UBSAN)
set(STRIP_DEBUG_DEFAULT OFF)
set(ANALYZERS_ENABLED ON)
else()
set(STRIP_DEBUG_DEFAULT ON)
set(ANALYZERS_ENABLED OFF)
endif()

option(COMPILER_DIAG_COLOR "Show compiler diagnostics/errors in color" ON)
option(STRIP_DEBUG "Strip debugging information when linking" ${STRIP_DEBUG_DEFAULT})
option(DISABLE_DEBUG "Disable the built-in debugging code" OFF)
option(USE_CCACHE "Use ccache, if found, to speed up recompilation" ON)

if(USE_CCACHE)
if(CMAKE_CXX_COMPILER MATCHES "/ccache/")
message(STATUS "ccache: compiler already uses ccache")
else()
find_program(CCACHE ccache)
if(CCACHE)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE}")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE}")
message(STATUS "ccache: compiler will be lauched with ${CCACHE}")
endif()
endif()
endif()

if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(DEBUG_BUILD True)
else()
set(DEBUG_BUILD False)
endif()

if(ANDROID_STL STREQUAL none)
set(USES_LIBSTDCPP False)
else()
set(USES_LIBSTDCPP True)
endif()

#
# General config
#
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
set(IS_LINUX True)
else()
set(IS_LINUX False)
endif()

if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
set(IS_MACOS True)
else()
set(IS_MACOS False)
endif()

set(XA_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/Build${XA_BUILD_CONFIGURATION}")
include("${XA_BUILD_DIR}/xa_build_configuration.cmake")

#
# Paths
#
if(ANDROID_ABI MATCHES "^arm64-v8a")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_ARM64}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_arm64-v8a_TRIPLE}")
elseif(ANDROID_ABI MATCHES "^armeabi-v7a")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_ARM}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_armeabi-v7a_TRIPLE}")
elseif(ANDROID_ABI MATCHES "^x86_64")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_X86_64}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_x86_64_TRIPLE}")
elseif(ANDROID_ABI MATCHES "^x86")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_X86}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_x86_TRIPLE}")
else()
message(FATAL "${ANDROID_ABI} is not supported for .NET 6+ builds")
endif()

file(REAL_PATH "../../" REPO_ROOT_DIR)
set(EXTERNAL_DIR "${REPO_ROOT_DIR}/external")
set(JAVA_INTEROP_SRC_PATH "${EXTERNAL_DIR}/Java.Interop/src/java-interop")
set(SHARED_SOURCES_DIR "${REPO_ROOT_DIR}/src/native/shared")
set(TRACING_SOURCES_DIR "${REPO_ROOT_DIR}/src/native/tracing")
#
# Include directories
#
include_directories(SYSTEM ${CMAKE_SYSROOT}/usr/include/c++/v1/)
include_directories(SYSTEM "${NET_RUNTIME_DIR}/native/include/mono-2.0")
include_directories("${JAVA_INTEROP_SRC_PATH}")
include_directories("${SHARED_SOURCES_DIR}")
include_directories("${TRACING_SOURCES_DIR}")

#
# Compiler defines
#
add_compile_definitions(XA_VERSION="${XA_VERSION}")
add_compile_definitions(_REENTRANT)
add_compile_definitions(PLATFORM_ANDROID)

if(DEBUG_BUILD AND NOT DISABLE_DEBUG)
add_compile_definitions(DEBUG)
endif()

if(ANDROID_ABI MATCHES "^(arm64-v8a|x86_64)")
add_compile_definitions(ANDROID64)
endif()

if (ANDROID_NDK_MAJOR LESS 20)
add_compile_definitions(__ANDROID_API_Q__=29)
endif()

#
# Shared sources
#
set(XA_SHARED_SOURCES
${SHARED_SOURCES_DIR}/helpers.cc
${SHARED_SOURCES_DIR}/new_delete.cc
)
7 changes: 7 additions & 0 deletions build-tools/cmake/xa_preamble.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12)

#
# Read product version
#
file(STRINGS "../../Directory.Build.props" XA_PRODUCT_VERSION_XML REGEX "^[ \t]*<ProductVersion>(.*)</ProductVersion>")
string(REGEX REPLACE "^[ \t]*<ProductVersion>(.*)</ProductVersion>" "\\1" XA_VERSION "${XA_PRODUCT_VERSION_XML}")
150 changes: 21 additions & 129 deletions src/monodroid/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,76 +1,24 @@
cmake_minimum_required(VERSION 3.18.1)
cmake_minimum_required(VERSION 3.19)

#
# MUST be included before project()!
#
include("../../build-tools/cmake/xa_common.cmake")

#
# Read product version
#
file(STRINGS "../../Directory.Build.props" XA_PRODUCT_VERSION_XML REGEX "^[ \t]*<ProductVersion>(.*)</ProductVersion>")
string(REGEX REPLACE "^[ \t]*<ProductVersion>(.*)</ProductVersion>" "\\1" XA_VERSION "${XA_PRODUCT_VERSION_XML}")
include("../../build-tools/cmake/xa_preamble.cmake")

project(
monodroid
VERSION ${XA_VERSION}
DESCRIPTION "Xamarin.Android native runtime"
HOMEPAGE_URL "https://github.com/xamarin/xamarin-android"
LANGUAGES CXX C
)

include("${CMAKE_ANDROID_NDK}/build/cmake/abis.cmake")

option(COMPILER_DIAG_COLOR "Show compiler diagnostics/errors in color" ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

option(ENABLE_CLANG_ASAN "Enable the clang AddressSanitizer support" OFF)
option(ENABLE_CLANG_UBSAN "Enable the clang UndefinedBehaviorSanitizer support" OFF)
)

if(ENABLE_CLANG_ASAN OR ENABLE_CLANG_UBSAN)
set(STRIP_DEBUG_DEFAULT OFF)
set(ANALYZERS_ENABLED ON)
else()
set(STRIP_DEBUG_DEFAULT ON)
set(ANALYZERS_ENABLED OFF)
endif()
#
# MUST be included after project()!
#
include("../../build-tools/cmake/xa_common.cmake")

option(ENABLE_TIMING "Build with timing support" OFF)
option(STRIP_DEBUG "Strip debugging information when linking" ${STRIP_DEBUG_DEFAULT})
option(DISABLE_DEBUG "Disable the built-in debugging code" OFF)
option(USE_CCACHE "Use ccache, if found, to speed up recompilation" ON)

if(USE_CCACHE)
if(CMAKE_CXX_COMPILER MATCHES "/ccache/")
message(STATUS "ccache: compiler already uses ccache")
else()
find_program(CCACHE ccache)
if(CCACHE)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE}")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE}")
message(STATUS "ccache: compiler will be lauched with ${CCACHE}")
endif()
endif()
endif()

if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(DEBUG_BUILD True)
else()
set(DEBUG_BUILD False)
endif()

if(ANDROID_STL STREQUAL none)
set(USES_LIBSTDCPP False)
else()
set(USES_LIBSTDCPP True)
endif()

# Environment checks

Expand Down Expand Up @@ -109,50 +57,15 @@ endif()
include(CheckIncludeFile)
include(CheckCXXSymbolExists)

# General config

if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
set(IS_LINUX True)
else()
set(IS_LINUX False)
endif()

if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
set(IS_MACOS True)
else()
set(IS_MACOS False)
endif()

# Paths

set(EXTERNAL_DIR "../../external")
set(JAVA_INTEROP_SRC_PATH "${EXTERNAL_DIR}/Java.Interop/src/java-interop")
set(SOURCES_DIR ${CMAKE_SOURCE_DIR}/jni)
set(BIONIC_SOURCES_DIR "../../src-ThirdParty/bionic")
set(BIONIC_SOURCES_DIR "${REPO_ROOT_DIR}/src-ThirdParty/bionic")
set(LZ4_SRC_DIR "${EXTERNAL_DIR}/lz4/lib")
set(LZ4_INCLUDE_DIR ${LZ4_SRC_DIR})
set(XA_BIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/${XA_BUILD_CONFIGURATION}")
set(XA_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/Build${XA_BUILD_CONFIGURATION}")
set(XA_BIN_DIR "${REPO_ROOT_DIR}/bin/${XA_BUILD_CONFIGURATION}")
set(ROBIN_MAP_DIR "${EXTERNAL_DIR}/robin-map")

include("${XA_BUILD_DIR}/xa_build_configuration.cmake")

if(ANDROID_ABI MATCHES "^arm64-v8a")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_ARM64}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_arm64-v8a_TRIPLE}")
elseif(ANDROID_ABI MATCHES "^armeabi-v7a")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_ARM}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_armeabi-v7a_TRIPLE}")
elseif(ANDROID_ABI MATCHES "^x86_64")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_X86_64}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_x86_64_TRIPLE}")
elseif(ANDROID_ABI MATCHES "^x86")
set(NET_RUNTIME_DIR "${NETCORE_APP_RUNTIME_DIR_X86}")
set(TOOLCHAIN_TRIPLE "${NDK_ABI_x86_TRIPLE}")
else()
message(FATAL "${ANDROID_ABI} is not supported for .NET 6+ builds")
endif()

set(LZ4_SOURCES
"${LZ4_SRC_DIR}/lz4.c"
)
Expand All @@ -163,9 +76,8 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/ ${CMAKE_SOURCE_DIR}/inc
# The SYSTEM which will make clang skip warnings for the headers there. Since we can't do
# much about them, we can just as well avoid cluttered build output.
include_directories(SYSTEM ${ROBIN_MAP_DIR}/include)
include_directories(SYSTEM ${CMAKE_SYSROOT}/usr/include/c++/v1/)
include_directories(SYSTEM ${LZ4_INCLUDE_DIR})
include_directories(SYSTEM "${NET_RUNTIME_DIR}/native/include/mono-2.0")

include_directories("jni")
include_directories("${XA_BIN_DIR}/include")
include_directories("${XA_BIN_DIR}/include/${ANDROID_ABI}/eglib")
Expand All @@ -174,7 +86,6 @@ include_directories("${XA_BIN_DIR}/include/${ANDROID_ABI}/eglib")
include_directories("../../bin/${CONFIGURATION}/include")
include_directories("../../bin/${CONFIGURATION}/include/${ANDROID_ABI}/eglib")
include_directories("${MONO_PATH}/mono/eglib")
include_directories("${JAVA_INTEROP_SRC_PATH}")

# Common preparation code
include("../../build-tools/cmake/xa_macros.cmake")
Expand All @@ -184,33 +95,18 @@ xa_macos_prepare_arm64()

# Compiler defines

add_compile_definitions(XA_VERSION="${XA_VERSION}")
add_compile_definitions(TSL_NO_EXCEPTIONS)
add_compile_definitions(HAVE_CONFIG_H)
add_compile_definitions(_REENTRANT)
add_compile_definitions(JI_DLL_EXPORT)
add_compile_definitions(MONO_DLL_EXPORT)
add_compile_definitions(NET)
add_compile_definitions(JI_NO_VISIBILITY)

if(DEBUG_BUILD AND NOT DISABLE_DEBUG)
add_compile_definitions(DEBUG)
endif()

if (ENABLE_TIMING)
add_compile_definitions(MONODROID_TIMING)
endif()

add_compile_definitions(HAVE_LZ4)
add_compile_definitions(PLATFORM_ANDROID)

if(ANDROID_ABI MATCHES "^(arm64-v8a|x86_64)")
add_compile_definitions(ANDROID64)
endif()

if (ANDROID_NDK_MAJOR LESS 20)
add_compile_definitions(__ANDROID_API_Q__=29)
endif()

# Compiler and linker flags
set(LINK_LIBS
Expand Down Expand Up @@ -370,6 +266,7 @@ set(XAMARIN_MONODROID_SOURCES
${JAVA_INTEROP_SRC_PATH}/java-interop-util.cc
${JAVA_INTEROP_SRC_PATH}/java-interop.cc
${LZ4_SOURCES}
${XA_SHARED_SOURCES}
${SOURCES_DIR}/android-system.cc
${SOURCES_DIR}/basic-android-system.cc
${SOURCES_DIR}/basic-utilities.cc
Expand All @@ -379,15 +276,13 @@ set(XAMARIN_MONODROID_SOURCES
${SOURCES_DIR}/embedded-assemblies-zip.cc
${SOURCES_DIR}/embedded-assemblies.cc
${SOURCES_DIR}/globals.cc
${SOURCES_DIR}/helpers.cc
${SOURCES_DIR}/jni-remapping.cc
${SOURCES_DIR}/logger.cc
${SOURCES_DIR}/mono-log-adapter.cc
${SOURCES_DIR}/monodroid-glue.cc
${SOURCES_DIR}/monodroid-networkinfo.cc
${SOURCES_DIR}/monodroid-tracing.cc
${SOURCES_DIR}/monovm-properties.cc
${SOURCES_DIR}/new_delete.cc
${SOURCES_DIR}/osbridge.cc
${SOURCES_DIR}/pinvoke-override-api.cc
${SOURCES_DIR}/shared-constants.cc
Expand All @@ -406,25 +301,23 @@ endif()
if(NOT USES_LIBSTDCPP)
list(APPEND XAMARIN_MONODROID_SOURCES
${BIONIC_SOURCES_DIR}/cxa_guard.cc
${SOURCES_DIR}/cxx-abi/string.cc
${SOURCES_DIR}/cxx-abi/terminate.cc
${SHARED_SOURCES_DIR}/cxx-abi/string.cc
${SHARED_SOURCES_DIR}/cxx-abi/terminate.cc
)
endif()

set(NATIVE_TRACING_SOURCES
${SOURCES_DIR}/cxx-abi/string.cc
# ${SOURCES_DIR}/cxx-abi/terminate.cc
${SOURCES_DIR}/helpers.cc
${SOURCES_DIR}/native-tracing.cc
${SOURCES_DIR}/new_delete.cc
${SHARED_SOURCES_DIR}/cxx-abi/string.cc
# ${SHARED_SOURCES_DIR}/cxx-abi/terminate.cc
${TRACING_SOURCES_DIR}/native-tracing.cc
${XA_SHARED_SOURCES}
)

set(MARSHAL_METHODS_TRACING_SOURCES
${SOURCES_DIR}/cxx-abi/string.cc
${SOURCES_DIR}/cxx-abi/terminate.cc
${SOURCES_DIR}/helpers.cc
${SHARED_SOURCES_DIR}/cxx-abi/string.cc
${SHARED_SOURCES_DIR}/cxx-abi/terminate.cc
${SOURCES_DIR}/marshal-methods-tracing.cc
${SOURCES_DIR}/new_delete.cc
${XA_SHARED_SOURCES}
)

set(XAMARIN_APP_STUB_SOURCES
Expand All @@ -436,9 +329,8 @@ set(XAMARIN_DEBUG_APP_HELPER_SOURCES
${SOURCES_DIR}/basic-utilities.cc
${SOURCES_DIR}/cpu-arch-detect.cc
${SOURCES_DIR}/debug-app-helper.cc
${SOURCES_DIR}/helpers.cc
${SOURCES_DIR}/new_delete.cc
${SOURCES_DIR}/shared-constants.cc
${XA_SHARED_SOURCES}
)

set(XAMARIN_STUB_LIB_SOURCES
Expand Down
Loading

0 comments on commit bad8d15

Please sign in to comment.