From 9f25dc6b09ce76d1ab2a92d454c1387600515612 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 7 Jun 2024 15:41:53 -0600 Subject: [PATCH] CMake+CI: Remove BUILD_LAGOM=OFF option in favor of LAGOM_TOOLS_ONLY=ON The far more common configuration for Ladybird is to always build the Lagom libraries. --- .github/workflows/lagom-template.yml | 2 +- .github/workflows/wasm.yml | 3 +- Documentation/AdvancedBuildInstructions.md | 5 +- Documentation/RunningTests.md | 5 +- Ladybird/cmake/EnableLagom.cmake | 2 - Meta/CMake/lagom_options.cmake | 2 +- Meta/Lagom/BuildFuzzers.sh | 5 +- Meta/Lagom/CMakeLists.txt | 467 +++++++++++---------- 8 files changed, 245 insertions(+), 246 deletions(-) diff --git a/.github/workflows/lagom-template.yml b/.github/workflows/lagom-template.yml index b691b90e664..241c085aace 100644 --- a/.github/workflows/lagom-template.yml +++ b/.github/workflows/lagom-template.yml @@ -98,7 +98,7 @@ jobs: set -e cmake -GNinja -S Meta/Lagom -B ${{ github.workspace }}/tools-build \ - -DBUILD_LAGOM=OFF \ + -DLAGOM_TOOLS_ONLY=ON \ -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/tool-install \ -DSERENITY_CACHE_DIR=${{ github.workspace }}/Build/caches \ -DCMAKE_C_COMPILER=gcc-13 \ diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index e90d2e1d512..aacd76b57f7 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -50,7 +50,7 @@ jobs: cmake -GNinja \ -B ${{ github.workspace }}/Build/lagom-tools \ -S ${{ github.workspace }}/Meta/Lagom \ - -DBUILD_LAGOM=OFF \ + -DLAGOM_TOOLS_ONLY=ON -DSERENITY_CACHE_DIR=${{ github.workspace }}/Build/caches \ -DCMAKE_C_COMPILER=gcc-13 \ -DCMAKE_CXX_COMPILER=g++-13 \ @@ -66,7 +66,6 @@ jobs: -B ${{ github.workspace }}/Build/wasm \ -S ${{ github.workspace }}/Meta/Lagom \ -DLagomTools_DIR=${{ github.workspace }}/Build/lagom-tools/share/LagomTools \ - -DBUILD_LAGOM=ON \ -DSERENITY_CACHE_DIR=${{ github.workspace }}/Build/caches \ -DBUILD_SHARED_LIBS=OFF env: diff --git a/Documentation/AdvancedBuildInstructions.md b/Documentation/AdvancedBuildInstructions.md index a86d745e75b..893dca22051 100644 --- a/Documentation/AdvancedBuildInstructions.md +++ b/Documentation/AdvancedBuildInstructions.md @@ -25,11 +25,10 @@ There are some optional features that can be enabled during compilation that are - `ENABLE_FUZZERS_OSSFUZZ`: builds OSS-Fuzz compatible [fuzzers](../Meta/Lagom/ReadMe.md#fuzzing) for various parts of the system. - `ENABLE_ALL_THE_DEBUG_MACROS`: used for checking whether debug code compiles on CI. This should not be set normally, as it clutters the console output and makes the system run very slowly. Instead, enable only the needed debug macros, as described below. - `ENABLE_COMPILETIME_FORMAT_CHECK`: checks for the validity of `std::format`-style format string during compilation. Enabled by default. -- `BUILD_LAGOM`: builds [Lagom](../Meta/Lagom/ReadMe.md), which makes various SerenityOS libraries and programs available on the host system. -- `ENABLE_MOLD_LINKER`: builds the userland with the [`mold` linker](https://github.com/rui314/mold). `mold` can be built by running `Toolchain/BuildMold.sh`. +- `LAGOM_TOOLS_ONLY`: Skips building libraries, utiltis and tests for [Lagom](../Meta/Lagom/ReadMe.md). Mostly only useful for cross-compilation. - `INCLUDE_WASM_SPEC_TESTS`: downloads and includes the WebAssembly spec testsuite tests. In order to use this option, you will need to install `prettier` and `wabt`. wabt version 1.0.23 or higher is required to pre-process the WebAssembly spec testsuite. - `INCLUDE_FLAC_SPEC_TESTS`: downloads and includes the xiph.org FLAC test suite. -- `SERENITY_CACHE_DIR`: sets the location of a shared cache of downloaded files. Should not need to be set unless managing a distribution package. +- `SERENITY_CACHE_DIR`: sets the location of a shared cache of downloaded files. Should not need to be set manually unless managing a distribution package. - `ENABLE_NETWORK_DOWNLOADS`: allows downloading files from the internet during the build. Default on, turning off enables offline builds. For offline builds, the structure of the SERENITY_CACHE_DIR must be set up the way that the build expects. - `ENABLE_ACCELERATED_GRAPHICS`: builds features that use accelerated graphics APIs to speed up painting and drawing using native graphics libraries. diff --git a/Documentation/RunningTests.md b/Documentation/RunningTests.md index 987c2dafec9..262733947d1 100644 --- a/Documentation/RunningTests.md +++ b/Documentation/RunningTests.md @@ -11,10 +11,9 @@ ctest --preset default ``` If you want to avoid building and running LibWeb tests, you can use a Lagom-only build. -For a Lagom-only build, pass the Lagom source directory to CMake. The `BUILD_LAGOM` CMake option is required. ```sh -cmake -GNinja -S Meta/Lagom -B Build/lagom -DBUILD_LAGOM=ON +cmake -GNinja -S Meta/Lagom -B Build/lagom ``` The tests can be run via ninja after doing a build. Note that `test-js` requires the `LADYBIRD_SOURCE_DIR` environment variable to be set @@ -63,7 +62,7 @@ The Sanitizer test preset already sets these environment variables. ```sh export ASAN_OPTIONS='strict_string_checks=1:check_initialization_order=1:strict_init_order=1:detect_stack_use_after_return=1:allocator_may_return_null=1' export UBSAN_OPTIONS='print_stacktrace=1:print_summary=1:halt_on_error=1' -cmake -GNinja -S Meta/Lagom -B Build/lagom -DBUILD_LAGOM=ON -DENABLE_ADDRESS_SANITIZER=ON -DENABLE_UNDEFINED_SANITIZER=ON +cmake -GNinja -S Meta/Lagom -B Build/lagom -DENABLE_ADDRESS_SANITIZER=ON -DENABLE_UNDEFINED_SANITIZER=ON cd Build/lagom ninja CTEST_OUTPUT_ON_FAILURE=1 LADYBIRD_SOURCE_DIR=${PWD}/../.. ninja test diff --git a/Ladybird/cmake/EnableLagom.cmake b/Ladybird/cmake/EnableLagom.cmake index 1e219251274..d99046038da 100644 --- a/Ladybird/cmake/EnableLagom.cmake +++ b/Ladybird/cmake/EnableLagom.cmake @@ -2,8 +2,6 @@ # # SPDX-License-Identifier: MIT -set(BUILD_LAGOM ON CACHE INTERNAL "Build all Lagom targets") - set(LAGOM_SOURCE_DIR "${LADYBIRD_SOURCE_DIR}/Meta/Lagom") set(LAGOM_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/Lagom") diff --git a/Meta/CMake/lagom_options.cmake b/Meta/CMake/lagom_options.cmake index cddcc9a034b..be16e578cc0 100644 --- a/Meta/CMake/lagom_options.cmake +++ b/Meta/CMake/lagom_options.cmake @@ -10,7 +10,7 @@ serenity_option(ENABLE_MEMORY_SANITIZER OFF CACHE BOOL "Enable memory sanitizer serenity_option(ENABLE_FUZZERS OFF CACHE BOOL "Build fuzzing targets") serenity_option(ENABLE_FUZZERS_LIBFUZZER OFF CACHE BOOL "Build fuzzers using Clang's libFuzzer") serenity_option(ENABLE_FUZZERS_OSSFUZZ OFF CACHE BOOL "Build OSS-Fuzz compatible fuzzers") -serenity_option(BUILD_LAGOM OFF CACHE BOOL "Build parts of the system targeting the host OS for fuzzing/testing") +serenity_option(LAGOM_TOOLS_ONLY OFF CACHE BOOL "Don't build libraries, utilities and tests, only host build tools") serenity_option(ENABLE_LAGOM_CCACHE ON CACHE BOOL "Enable ccache for Lagom builds") serenity_option(LAGOM_USE_LINKER "" CACHE STRING "The linker to use (e.g. lld, mold) instead of the system default") serenity_option(ENABLE_LAGOM_COVERAGE_COLLECTION OFF CACHE STRING "Enable code coverage instrumentation for lagom binaries in clang") diff --git a/Meta/Lagom/BuildFuzzers.sh b/Meta/Lagom/BuildFuzzers.sh index 0f01928da42..05012302888 100755 --- a/Meta/Lagom/BuildFuzzers.sh +++ b/Meta/Lagom/BuildFuzzers.sh @@ -53,7 +53,7 @@ fi # FIXME: Replace these CMake invocations with a CMake superbuild? echo "Building Lagom Tools..." cmake -GNinja -B Build/tools \ - -DBUILD_LAGOM=OFF \ + -DLAGOM_TOOLS_ONLY=ON \ -DCMAKE_CXX_FLAGS="$CXXFLAGS" \ -DCMAKE_INSTALL_PREFIX=Build/tool-install \ -Dpackage=LagomTools @@ -69,7 +69,6 @@ echo "Building Lagom Fuzzers..." if [ "$#" -gt "0" ] && [ "--oss-fuzz" = "$1" ] ; then echo "Building for oss-fuzz configuration..." cmake -GNinja -B Build/fuzzers \ - -DBUILD_LAGOM=ON \ -DBUILD_SHARED_LIBS=OFF \ -DENABLE_FUZZERS_OSSFUZZ=ON \ -DFUZZER_DICTIONARY_DIRECTORY="$OUT" \ @@ -83,7 +82,6 @@ if [ "$#" -gt "0" ] && [ "--oss-fuzz" = "$1" ] ; then elif [ "$#" -gt "0" ] && [ "--standalone" = "$1" ] ; then echo "Building for standalone fuzz configuration..." cmake -GNinja -B Build/lagom-fuzzers-standalone \ - -DBUILD_LAGOM=ON \ -DENABLE_FUZZERS=ON \ -DCMAKE_PREFIX_PATH=Build/tool-install ninja -C Build/lagom-fuzzers-standalone @@ -91,7 +89,6 @@ else echo "Building for local fuzz configuration..." pick_clang cmake -GNinja -B Build/lagom-fuzzers \ - -DBUILD_LAGOM=ON \ -DENABLE_FUZZERS_LIBFUZZER=ON \ -DENABLE_ADDRESS_SANITIZER=ON \ -DENABLE_UNDEFINED_SANITIZER=ON \ diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index e00a907ec67..33f39741169 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -390,238 +390,245 @@ if (BUILD_LAGOM_TOOLS) add_subdirectory(Tools) endif() -if (BUILD_LAGOM) - # Lagom Libraries - set(lagom_standard_libraries - AccelGfx - Archive - Audio - Compress - Crypto - Diff - Gfx - HTTP - ImageDecoderClient - IPC - JS - Line - Locale - Protocol - Regex - RIFF - Syntax - TextCodec - Threading - TLS - Video - Wasm - Web - WebSocket - WebView - XML - ) - - compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/RequestServer/RequestClient.ipc Userland/Services/RequestServer/RequestClientEndpoint.h) - compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/RequestServer/RequestServer.ipc Userland/Services/RequestServer/RequestServerEndpoint.h) - compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebContentServer.ipc Userland/Services/WebContent/WebContentServerEndpoint.h) - compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebContentClient.ipc Userland/Services/WebContent/WebContentClientEndpoint.h) - compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebDriverClient.ipc Userland/Services/WebContent/WebDriverClientEndpoint.h) - compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebDriverServer.ipc Userland/Services/WebContent/WebDriverServerEndpoint.h) - - foreach(lib IN LISTS lagom_standard_libraries) - add_serenity_subdirectory("Userland/Libraries/Lib${lib}") - endforeach() - - # FIXME: Why is this not in LibLocale/CMakeLists.txt? - target_link_libraries(LibLocale PRIVATE LibTimeZone) - - if (NOT ENABLE_FUZZERS AND NOT ENABLE_COMPILER_EXPLORER_BUILD AND NOT ANDROID AND NOT IOS) - # Lagom Utilities - lagom_utility(abench SOURCES ../../Userland/Utilities/abench.cpp LIBS LibMain LibFileSystem LibAudio) - lagom_utility(aconv SOURCES ../../Userland/Utilities/aconv.cpp LIBS LibMain LibFileSystem LibAudio) - - lagom_utility(animation SOURCES ../../Userland/Utilities/animation.cpp LIBS LibGfx LibMain) - - lagom_utility(gzip SOURCES ../../Userland/Utilities/gzip.cpp LIBS LibCompress LibMain) - - find_package(SDL2 QUIET) - if (SDL2_FOUND) - add_serenity_subdirectory(Meta/Lagom/Contrib/VideoPlayerSDL) - endif() - - lagom_utility(icc SOURCES ../../Userland/Utilities/icc.cpp LIBS LibGfx LibMain LibURL) - lagom_utility(image SOURCES ../../Userland/Utilities/image.cpp LIBS LibGfx LibMain) - lagom_utility(isobmff SOURCES ../../Userland/Utilities/isobmff.cpp LIBS LibGfx LibMain) - lagom_utility(ttfdisasm SOURCES ../../Userland/Utilities/ttfdisasm.cpp LIBS LibGfx LibMain) - lagom_utility(js SOURCES ../../Userland/Utilities/js.cpp LIBS LibCrypto LibJS LibLine LibLocale LibMain LibTextCodec Threads::Threads) - - if (EMSCRIPTEN) - lagom_utility(libjs SOURCES Wasm/js_repl.cpp LIBS LibJS LibLocale LibTimeZone LibUnicode) - target_link_options(libjs PRIVATE - -sEXPORTED_FUNCTIONS=_initialize_repl,_execute - -sEXPORTED_RUNTIME_METHODS=allocateUTF8 - -sERROR_ON_UNDEFINED_SYMBOLS=0 - -sENVIRONMENT=web) - endif() - - lagom_utility(lzcat SOURCES ../../Userland/Utilities/lzcat.cpp LIBS LibCompress LibMain) - - lagom_utility(tar SOURCES ../../Userland/Utilities/tar.cpp LIBS LibArchive LibCompress LibFileSystem LibMain) - lagom_utility(test262-runner SOURCES ../../Tests/LibJS/test262-runner.cpp LIBS LibJS LibFileSystem) - - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - include(CheckCSourceCompiles) - # Check for musl's declaration of __assert_fail - check_c_source_compiles( - " - #include - __attribute__((__noreturn__)) void __assert_fail(char const* assertion, char const* file, int line, char const* function) {} - int main() {} - " - ASSERT_FAIL_HAS_INT - ) - endif() - - if (ASSERT_FAIL_HAS_INT OR EMSCRIPTEN) - target_compile_definitions(test262-runner PRIVATE ASSERT_FAIL_HAS_INT) - endif() - - lagom_utility(wasm SOURCES ../../Userland/Utilities/wasm.cpp LIBS LibFileSystem LibWasm LibLine LibMain LibJS) - lagom_utility(xml SOURCES ../../Userland/Utilities/xml.cpp LIBS LibFileSystem LibMain LibXML LibURL) - lagom_utility(xzcat SOURCES ../../Userland/Utilities/xzcat.cpp LIBS LibCompress LibMain) - - enable_testing() - # LibTest - file(GLOB LIBTEST_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTest/*.cpp") - list(FILTER LIBTEST_SOURCES EXCLUDE REGEX ".*Main.cpp$") - add_library( - LibTest - ${LIBTEST_SOURCES} - ) - target_link_libraries(LibTest PRIVATE AK LibCore LibFileSystem) - set_target_properties(LibTest PROPERTIES OUTPUT_NAME lagom-test) - add_library( - LibTestMain - OBJECT - "${SERENITY_PROJECT_ROOT}/Userland/Libraries/LibTest/TestMain.cpp" - ) - target_link_libraries(LibTest PUBLIC GenericClangPlugin) - target_link_libraries(LibTestMain PUBLIC GenericClangPlugin) - - # LibTest tests from Tests/ - set(TEST_DIRECTORIES - AK - LibCrypto - LibCompress - LibGfx - LibLocale - LibTest - LibTextCodec - LibTTF - LibTimeZone - LibUnicode - LibVideo - LibWeb - LibWebView - LibXML - ) - - if (ENABLE_CLANG_PLUGINS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$") - list(APPEND TEST_DIRECTORIES ClangPlugins) - endif() - - foreach (dir IN LISTS TEST_DIRECTORIES) - add_serenity_subdirectory("Tests/${dir}") - endforeach() - - # LibTLS needs a special working directory to find cacert.pem - lagom_test(../../Tests/LibTLS/TestTLSHandshake.cpp LibTLS LIBS LibTLS LibCrypto) - lagom_test(../../Tests/LibTLS/TestTLSCertificateParser.cpp LibTLS LIBS LibTLS LibCrypto) - - # The FLAC tests need a special working directory to find the test files - lagom_test(../../Tests/LibAudio/TestFLACSpec.cpp LIBS LibAudio WORKING_DIRECTORY "${FLAC_TEST_PATH}/..") - - lagom_test(../../Tests/LibAudio/TestPlaybackStream.cpp LIBS LibAudio) - if (HAVE_PULSEAUDIO) - target_compile_definitions(TestPlaybackStream PRIVATE HAVE_PULSEAUDIO=1) - endif() - - # LibCore - lagom_test(../../Tests/LibCore/TestLibCoreArgsParser.cpp) - - if ((LINUX OR APPLE) AND NOT EMSCRIPTEN) - lagom_test(../../Tests/LibCore/TestLibCoreFileWatcher.cpp) - lagom_test(../../Tests/LibCore/TestLibCorePromise.cpp LIBS LibThreading) - endif() - - lagom_test(../../Tests/LibCore/TestLibCoreDateTime.cpp LIBS LibTimeZone) - - # RegexLibC test POSIX and contains many Serenity extensions - # It is therefore not reasonable to run it on Lagom, and we only run the Regex test - lagom_test(../../Tests/LibRegex/Regex.cpp LIBS LibRegex WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibRegex) - - # test-jpeg-roundtrip - add_executable(test-jpeg-roundtrip - ../../Userland/Utilities/test-jpeg-roundtrip.cpp) - target_link_libraries(test-jpeg-roundtrip AK LibGfx LibMain) - - # JavaScriptTestRunner + LibTest tests - # test-js - add_executable(test-js - ../../Tests/LibJS/test-js.cpp - ../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp) - target_link_libraries(test-js AK LibCore LibFileSystem LibTest LibJS) - add_test( - NAME JS - COMMAND test-js --show-progress=false - ) - set_tests_properties(JS PROPERTIES ENVIRONMENT LADYBIRD_SOURCE_DIR=${SERENITY_PROJECT_ROOT}) - - # Extra tests from Tests/LibJS - lagom_test(../../Tests/LibJS/test-invalid-unicode-js.cpp LIBS LibJS) - lagom_test(../../Tests/LibJS/test-value-js.cpp LIBS LibJS) - - # test-wasm - add_executable(test-wasm - ../../Tests/LibWasm/test-wasm.cpp - ../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp) - target_link_libraries(test-wasm AK LibCore LibFileSystem LibTest LibWasm LibJS LibCrypto) - add_test( - NAME WasmParser - COMMAND test-wasm --show-progress=false ${CMAKE_CURRENT_BINARY_DIR}/Userland/Libraries/LibWasm/Tests - ) - set_tests_properties(WasmParser PROPERTIES - SKIP_RETURN_CODE 1 - ENVIRONMENT LADYBIRD_SOURCE_DIR=${SERENITY_PROJECT_ROOT} - ) - - # FIXME: When we are using CMake >= 3.21, the library installations can be replaced with RUNTIME_DEPENDENCIES. - # https://cmake.org/cmake/help/latest/command/install.html - include(get_linked_lagom_libraries.cmake) - get_linked_lagom_libraries(js js_libraries) - - install(TARGETS js ${js_libraries} COMPONENT js) - - set(CPACK_GENERATOR "TGZ") - set(CPACK_STRIP_FILES TRUE) - set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) - set(CPACK_COMPONENTS_ALL js) - if (APPLE) - if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES AND "x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES) - set(CPACK_SYSTEM_NAME "macOS-universal2") - else() - set(CPACK_SYSTEM_NAME "macOS-${CMAKE_SYSTEM_PROCESSOR}") - endif() - else() - set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") - endif() - - set(CPACK_ARCHIVE_JS_FILE_NAME "serenity-js-${CPACK_SYSTEM_NAME}") - set(CPACK_PACKAGE_FILE_NAME "serenity-js-${CPACK_SYSTEM_NAME}") - include(CPack) - endif() +if (LAGOM_TOOLS_ONLY) + return() endif() +# Lagom Libraries +set(lagom_standard_libraries + AccelGfx + Archive + Audio + Compress + Crypto + Diff + Gfx + HTTP + ImageDecoderClient + IPC + JS + Line + Locale + Protocol + Regex + RIFF + Syntax + TextCodec + Threading + TLS + Video + Wasm + Web + WebSocket + WebView + XML +) + +compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/RequestServer/RequestClient.ipc Userland/Services/RequestServer/RequestClientEndpoint.h) +compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/RequestServer/RequestServer.ipc Userland/Services/RequestServer/RequestServerEndpoint.h) +compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebContentServer.ipc Userland/Services/WebContent/WebContentServerEndpoint.h) +compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebContentClient.ipc Userland/Services/WebContent/WebContentClientEndpoint.h) +compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebDriverClient.ipc Userland/Services/WebContent/WebDriverClientEndpoint.h) +compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebDriverServer.ipc Userland/Services/WebContent/WebDriverServerEndpoint.h) + +foreach(lib IN LISTS lagom_standard_libraries) + add_serenity_subdirectory("Userland/Libraries/Lib${lib}") +endforeach() + +# FIXME: Why is this not in LibLocale/CMakeLists.txt? +target_link_libraries(LibLocale PRIVATE LibTimeZone) + if (ENABLE_FUZZERS) add_subdirectory(Fuzzers) endif() + +# No utilities or tests in these configs +if (ENABLE_FUZZERS OR ENABLE_COMPILER_EXPLORER_BUILD OR ANDROID OR IOS) + return() +endif() + +# Lagom Utilities +lagom_utility(abench SOURCES ../../Userland/Utilities/abench.cpp LIBS LibMain LibFileSystem LibAudio) +lagom_utility(aconv SOURCES ../../Userland/Utilities/aconv.cpp LIBS LibMain LibFileSystem LibAudio) + +lagom_utility(animation SOURCES ../../Userland/Utilities/animation.cpp LIBS LibGfx LibMain) + +lagom_utility(gzip SOURCES ../../Userland/Utilities/gzip.cpp LIBS LibCompress LibMain) + +find_package(SDL2 QUIET) +if (SDL2_FOUND) + add_serenity_subdirectory(Meta/Lagom/Contrib/VideoPlayerSDL) +endif() + +lagom_utility(icc SOURCES ../../Userland/Utilities/icc.cpp LIBS LibGfx LibMain LibURL) +lagom_utility(image SOURCES ../../Userland/Utilities/image.cpp LIBS LibGfx LibMain) +lagom_utility(isobmff SOURCES ../../Userland/Utilities/isobmff.cpp LIBS LibGfx LibMain) +lagom_utility(ttfdisasm SOURCES ../../Userland/Utilities/ttfdisasm.cpp LIBS LibGfx LibMain) +lagom_utility(js SOURCES ../../Userland/Utilities/js.cpp LIBS LibCrypto LibJS LibLine LibLocale LibMain LibTextCodec Threads::Threads) + +if (EMSCRIPTEN) + lagom_utility(libjs SOURCES Wasm/js_repl.cpp LIBS LibJS LibLocale LibTimeZone LibUnicode) + target_link_options(libjs PRIVATE + -sEXPORTED_FUNCTIONS=_initialize_repl,_execute + -sEXPORTED_RUNTIME_METHODS=allocateUTF8 + -sERROR_ON_UNDEFINED_SYMBOLS=0 + -sENVIRONMENT=web) +endif() + +lagom_utility(lzcat SOURCES ../../Userland/Utilities/lzcat.cpp LIBS LibCompress LibMain) + +lagom_utility(tar SOURCES ../../Userland/Utilities/tar.cpp LIBS LibArchive LibCompress LibFileSystem LibMain) +lagom_utility(test262-runner SOURCES ../../Tests/LibJS/test262-runner.cpp LIBS LibJS LibFileSystem) + +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + include(CheckCSourceCompiles) + # Check for musl's declaration of __assert_fail + check_c_source_compiles( + " + #include + __attribute__((__noreturn__)) void __assert_fail(char const* assertion, char const* file, int line, char const* function) {} + int main() {} + " + ASSERT_FAIL_HAS_INT + ) +endif() + +if (ASSERT_FAIL_HAS_INT OR EMSCRIPTEN) + target_compile_definitions(test262-runner PRIVATE ASSERT_FAIL_HAS_INT) +endif() + +lagom_utility(wasm SOURCES ../../Userland/Utilities/wasm.cpp LIBS LibFileSystem LibWasm LibLine LibMain LibJS) +lagom_utility(xml SOURCES ../../Userland/Utilities/xml.cpp LIBS LibFileSystem LibMain LibXML LibURL) +lagom_utility(xzcat SOURCES ../../Userland/Utilities/xzcat.cpp LIBS LibCompress LibMain) + +include(CTest) +if (BUILD_TESTING) + # LibTest + file(GLOB LIBTEST_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTest/*.cpp") + list(FILTER LIBTEST_SOURCES EXCLUDE REGEX ".*Main.cpp$") + add_library( + LibTest + ${LIBTEST_SOURCES} + ) + target_link_libraries(LibTest PRIVATE AK LibCore LibFileSystem) + set_target_properties(LibTest PROPERTIES OUTPUT_NAME lagom-test) + add_library( + LibTestMain + OBJECT + "${SERENITY_PROJECT_ROOT}/Userland/Libraries/LibTest/TestMain.cpp" + ) + target_link_libraries(LibTest PUBLIC GenericClangPlugin) + target_link_libraries(LibTestMain PUBLIC GenericClangPlugin) + + # LibTest tests from Tests/ + set(TEST_DIRECTORIES + AK + LibCrypto + LibCompress + LibGfx + LibLocale + LibTest + LibTextCodec + LibTTF + LibTimeZone + LibUnicode + LibVideo + LibWeb + LibWebView + LibXML + ) + + if (ENABLE_CLANG_PLUGINS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$") + list(APPEND TEST_DIRECTORIES ClangPlugins) + endif() + + foreach (dir IN LISTS TEST_DIRECTORIES) + add_serenity_subdirectory("Tests/${dir}") + endforeach() + + # LibTLS needs a special working directory to find cacert.pem + lagom_test(../../Tests/LibTLS/TestTLSHandshake.cpp LibTLS LIBS LibTLS LibCrypto) + lagom_test(../../Tests/LibTLS/TestTLSCertificateParser.cpp LibTLS LIBS LibTLS LibCrypto) + + # The FLAC tests need a special working directory to find the test files + lagom_test(../../Tests/LibAudio/TestFLACSpec.cpp LIBS LibAudio WORKING_DIRECTORY "${FLAC_TEST_PATH}/..") + + lagom_test(../../Tests/LibAudio/TestPlaybackStream.cpp LIBS LibAudio) + if (HAVE_PULSEAUDIO) + target_compile_definitions(TestPlaybackStream PRIVATE HAVE_PULSEAUDIO=1) + endif() + + # LibCore + lagom_test(../../Tests/LibCore/TestLibCoreArgsParser.cpp) + + if ((LINUX OR APPLE) AND NOT EMSCRIPTEN) + lagom_test(../../Tests/LibCore/TestLibCoreFileWatcher.cpp) + lagom_test(../../Tests/LibCore/TestLibCorePromise.cpp LIBS LibThreading) + endif() + + lagom_test(../../Tests/LibCore/TestLibCoreDateTime.cpp LIBS LibTimeZone) + + # RegexLibC test POSIX and contains many Serenity extensions + # It is therefore not reasonable to run it on Lagom, and we only run the Regex test + lagom_test(../../Tests/LibRegex/Regex.cpp LIBS LibRegex WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibRegex) + + # test-jpeg-roundtrip + add_executable(test-jpeg-roundtrip + ../../Userland/Utilities/test-jpeg-roundtrip.cpp) + target_link_libraries(test-jpeg-roundtrip AK LibGfx LibMain) + + # JavaScriptTestRunner + LibTest tests + # test-js + add_executable(test-js + ../../Tests/LibJS/test-js.cpp + ../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp) + target_link_libraries(test-js AK LibCore LibFileSystem LibTest LibJS) + add_test( + NAME JS + COMMAND test-js --show-progress=false + ) + set_tests_properties(JS PROPERTIES ENVIRONMENT LADYBIRD_SOURCE_DIR=${SERENITY_PROJECT_ROOT}) + + # Extra tests from Tests/LibJS + lagom_test(../../Tests/LibJS/test-invalid-unicode-js.cpp LIBS LibJS) + lagom_test(../../Tests/LibJS/test-value-js.cpp LIBS LibJS) + + # test-wasm + add_executable(test-wasm + ../../Tests/LibWasm/test-wasm.cpp + ../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp) + target_link_libraries(test-wasm AK LibCore LibFileSystem LibTest LibWasm LibJS LibCrypto) + add_test( + NAME WasmParser + COMMAND test-wasm --show-progress=false ${CMAKE_CURRENT_BINARY_DIR}/Userland/Libraries/LibWasm/Tests + ) + set_tests_properties(WasmParser PROPERTIES + SKIP_RETURN_CODE 1 + ENVIRONMENT LADYBIRD_SOURCE_DIR=${SERENITY_PROJECT_ROOT} + ) +endif() + +# FIXME: When we are using CMake >= 3.21, the library installations can be replaced with RUNTIME_DEPENDENCIES. +# https://cmake.org/cmake/help/latest/command/install.html +include(get_linked_lagom_libraries.cmake) +get_linked_lagom_libraries(js js_libraries) + +install(TARGETS js ${js_libraries} COMPONENT js) + +set(CPACK_GENERATOR "TGZ") +set(CPACK_STRIP_FILES TRUE) +set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) +set(CPACK_COMPONENTS_ALL js) +if (APPLE) + if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES AND "x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES) + set(CPACK_SYSTEM_NAME "macOS-universal2") + else() + set(CPACK_SYSTEM_NAME "macOS-${CMAKE_SYSTEM_PROCESSOR}") + endif() +else() + set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") +endif() + +set(CPACK_ARCHIVE_JS_FILE_NAME "serenity-js-${CPACK_SYSTEM_NAME}") +set(CPACK_PACKAGE_FILE_NAME "serenity-js-${CPACK_SYSTEM_NAME}") +include(CPack)