From 9c2211f246b54de2cdc751b2713c998f7acaefac Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 11 Jul 2022 01:07:47 -0600 Subject: [PATCH] Meta: Add Android cross-compile support to Lagom This is a start to properly letting us cross-compile Lagom where both the Tools and the BUILD_LAGOM=ON build are using Lagom CMakeLists. The initial cut allows an Android build to succeed, more or less. But there are issues with namespace clashes when using FetchContent with this approach. --- Meta/Azure/Lagom.yml | 3 ++- Meta/Lagom/BuildFuzzers.sh | 3 ++- Meta/Lagom/CMakeLists.txt | 13 ++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Meta/Azure/Lagom.yml b/Meta/Azure/Lagom.yml index 431b8561d8..d754527d29 100644 --- a/Meta/Azure/Lagom.yml +++ b/Meta/Azure/Lagom.yml @@ -48,7 +48,8 @@ jobs: cmake -GNinja -B tools-build \ -DBUILD_LAGOM=OFF \ -DENABLE_LAGOM_CCACHE=ON \ - -DCMAKE_INSTALL_PREFIX=tool-install + -DCMAKE_INSTALL_PREFIX=tool-install \ + -Dpackage=LagomTools ninja -C tools-build install cmake -GNinja -B Build \ -DBUILD_LAGOM=ON \ diff --git a/Meta/Lagom/BuildFuzzers.sh b/Meta/Lagom/BuildFuzzers.sh index 3db5ad6951..9b83b68f1f 100755 --- a/Meta/Lagom/BuildFuzzers.sh +++ b/Meta/Lagom/BuildFuzzers.sh @@ -46,7 +46,8 @@ export AFL_NOOPT=1 echo "Building Lagom Tools..." cmake -GNinja -B Build/tools \ -DBUILD_LAGOM=OFF \ - -DCMAKE_INSTALL_PREFIX=Build/tool-install + -DCMAKE_INSTALL_PREFIX=Build/tool-install \ + -Dpackage=LagomTools ninja -C Build/tools install # Restore flags for oss-fuzz diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index c74cbf7ba2..8a65912a11 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -148,7 +148,7 @@ include_directories(${CMAKE_BINARY_DIR}/Services) include(CMakePackageConfigHelpers) # find_package() call for consumers to find this project -set(package Lagom) +set(package Lagom CACHE STRING "") # Allow package maintainers to freely override the path for the configs set(Lagom_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/${package}" @@ -176,7 +176,7 @@ function(lagom_lib library fs_name) # Don't make alias when we're going to import a previous build for Tools # FIXME: Is there a better way to write this? - if (NOT ENABLE_FUZZERS) + if (NOT ENABLE_FUZZERS AND NOT CMAKE_CROSSCOMPILING) # alias for parity with exports add_library(Lagom::${library} ALIAS ${target_name}) endif() @@ -260,11 +260,14 @@ endif() # Note: AK is included in LibCore for the host build instead of LibC per the target build file(GLOB AK_SOURCES CONFIGURE_DEPENDS "../../AK/*.cpp") file(GLOB LIBCORE_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCore/*.cpp") +if (ANDROID) + list(REMOVE_ITEM LIBCORE_SOURCES "${CMAKE_CURRENT_LIST_DIR}/../../Userland/Libraries/LibCore/Account.cpp") +endif() lagom_lib(Core core SOURCES ${AK_SOURCES} ${LIBCORE_SOURCES} LIBS Threads::Threads ) -if (NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") +if (NOT APPLE AND NOT ANDROID AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") target_link_libraries(LibCore crypt) # LibCore::Account uses crypt() but it's not in libcrypt on macOS endif() @@ -298,8 +301,8 @@ install( # Code Generators and other host tools # We need to make sure not to build code generators for Fuzzer builds, as they already have their own main.cpp # Instead, we import them from a previous install of Lagom. This mandates a two-stage build for fuzzers. -if (ENABLE_FUZZERS) - find_package(Lagom REQUIRED) +if (ENABLE_FUZZERS OR CMAKE_CROSSCOMPILING) + find_package(LagomTools REQUIRED) else() add_subdirectory(Tools) endif()