Lagom: Change to shared library build for all Lagom code

Split the Lagom build into shared libraries to match the Serenity build.

This reduces the cognitive load when trying to edit the Lagom CMakeLists
significantly. It also reduces the amount of source files that must be
compiled to run each test or host program significantly.

Also re-organize all the build rules into sections. And reorganize the
CMakeLists file in general.
This commit is contained in:
Andrew Kaster 2021-07-25 19:37:27 -06:00 committed by Linus Groh
parent 38707f4a20
commit b6e5117f65
Notes: sideshowbarker 2024-07-18 07:47:00 +09:00
2 changed files with 406 additions and 276 deletions

View file

@ -1,45 +1,71 @@
cmake_minimum_required (VERSION 3.0)
project (Lagom)
cmake_minimum_required (VERSION 3.16)
project(
Lagom
VERSION 0.0.0
DESCRIPTION "Host build of SerenityOS libraries and applications"
HOMEPAGE_URL "https://github.com/SerenityOS/serenity"
LANGUAGES C CXX
)
# This is required for CMake (when invoked for a Lagom-only build) to
# ignore any files downloading during the build, e.g. UnicodeData.txt.
# https://cmake.org/cmake/help/latest/policy/CMP0058.html
cmake_policy(SET CMP0058 NEW)
include(../CMake/wasm_spec_tests.cmake)
get_filename_component(
SERENITY_PROJECT_ROOT "${PROJECT_SOURCE_DIR}/../.."
ABSOLUTE CACHE
)
if (NOT ENABLE_OSS_FUZZ)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -Wno-literal-suffix -O2 -Wall -Wextra -Werror -std=c++2a -fPIC -g -Wno-deprecated-copy")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a -fPIC -g -Wno-deprecated-copy")
find_package(Threads REQUIRED)
include(${SERENITY_PROJECT_ROOT}/Meta/CMake/wasm_spec_tests.cmake)
add_compile_options(-Wno-unknown-warning-option -Wno-literal-suffix -Wno-deprecated-copy)
add_compile_options(-O2)
add_compile_options(-Wall -Wextra -Werror)
add_compile_options(-fPIC -g)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# See slide 100 of the following ppt :^)
# https://crascit.com/wp-content/uploads/2019/09/Deep-CMake-For-Library-Authors-Craig-Scott-CppCon-2019.pdf
if (NOT APPLE)
set(CMAKE_INSTALL_RPATH $ORIGIN)
endif()
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if (ENABLE_ADDRESS_SANITIZER)
add_definitions(-fsanitize=address -fno-omit-frame-pointer)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=address")
endif()
if (ENABLE_MEMORY_SANITIZER)
add_definitions(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
add_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins")
endif()
if (ENABLE_UNDEFINED_SANITIZER)
add_definitions(-fsanitize=undefined -fno-sanitize=vptr -fno-omit-frame-pointer)
add_compile_options(-fsanitize=undefined -fno-sanitize=vptr -fno-omit-frame-pointer)
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=undefined -fno-sanitize=vptr")
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang$")
# Clang's default constexpr-steps limit is 1048576(2^20), GCC doesn't have one
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual -Wno-user-defined-literals -fconstexpr-steps=16777216")
add_compile_options(-Wno-overloaded-virtual -Wno-user-defined-literals -fconstexpr-steps=16777216)
if (ENABLE_FUZZER_SANITIZER)
add_definitions(-fsanitize=fuzzer -fno-omit-frame-pointer)
add_compile_options(-fsanitize=fuzzer -fno-omit-frame-pointer)
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=fuzzer")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-expansion-to-defined -Wno-literal-suffix")
add_compile_options(-Wno-expansion-to-defined)
endif()
# These are here to support Fuzzili builds further down the directory stack
@ -51,215 +77,377 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
# FIXME: This is a hack, because the lagom stuff can be built individually or
# in combination with the system, we generate two Debug.h files. One in
# Build/AK/Debug.h and the other in Build/Meta/Lagom/AK/Debug.h.
configure_file(../../AK/Debug.h.in AK/Debug.h @ONLY)
configure_file(../../Kernel/Debug.h.in Kernel/Debug.h @ONLY)
include_directories(../../)
include_directories(../../Userland/)
include_directories(../../Userland/Libraries/)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if (BUILD_LAGOM AND NOT ENABLE_OSS_FUZZ AND NOT ENABLE_FUZZER_SANITIZER)
if (CMAKE_SOURCE_DIR MATCHES ".*/Lagom")
set(write_if_different ${CMAKE_SOURCE_DIR}/../write-only-on-difference.sh)
add_subdirectory(../../Userland/Libraries/LibUnicode/CodeGenerators ${CMAKE_CURRENT_BINARY_DIR}/LibUnicode/CodeGenerators)
function(lagom_lib target_name fs_name)
cmake_parse_arguments(LAGOM_LIBRARY "" "" "SOURCES;LIBS" ${ARGN})
add_library(${target_name} SHARED ${LAGOM_LIBRARY_SOURCES})
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME lagom-${fs_name})
target_link_libraries(${target_name} ${LAGOM_LIBRARY_LIBS})
if (NOT ${target_name} STREQUAL "LagomCore")
target_link_libraries(${target_name} LagomCore)
endif()
# Don't install Lagom libs into the target Root/
# FIXME: Remove this for 4594
if (CMAKE_SOURCE_DIR MATCHES ".*/Lagom")
install(TARGETS ${target_name})
endif()
endfunction()
include(../../Userland/Libraries/LibUnicode/unicode_data.cmake)
function(lagom_test source)
cmake_parse_arguments(LAGOM_TEST "" "" "LIBS" ${ARGN})
get_filename_component(name ${source} NAME_WE)
add_executable(${name}_lagom ${source})
set_target_properties(${name}_lagom PROPERTIES OUTPUT_NAME ${name})
target_link_libraries(${name}_lagom LagomCore LagomTest LagomTestMain ${LAGOM_TEST_LIBS})
add_test(
NAME ${name}
COMMAND ${name}_lagom
)
endfunction()
# AK/Core
# Note: AK is included in LagomCore 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")
lagom_lib(LagomCore core
SOURCES ${AK_SOURCES} ${LIBCORE_SOURCES}
LIBS Threads::Threads
)
if (NOT APPLE)
target_link_libraries(LagomCore crypt) # Core::Account uses crypt() but it's not in libcrypt on macOS
endif()
file(GLOB AK_SOURCES CONFIGURE_DEPENDS "../../AK/*.cpp")
file(GLOB AK_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/AK/*.cpp")
file(GLOB LIBARCHIVE_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibArchive/*.cpp")
file(GLOB LIBAUDIO_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibAudio/*.cpp")
list(REMOVE_ITEM LIBAUDIO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibAudio/ClientConnection.cpp")
file(GLOB LIBREGEX_LIBC_SOURCES "../../Userland/Libraries/LibRegex/C/Regex.cpp")
file(GLOB LIBREGEX_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibRegex/*.cpp")
file(GLOB LIBREGEX_TESTS CONFIGURE_DEPENDS "../../Tests/LibRegex/*.cpp")
file(GLOB LIBCORE_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCore/*.cpp")
file(GLOB LIBELF_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibELF/*.cpp")
# There's no way we can reliably make this cross platform
list(REMOVE_ITEM LIBELF_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibELF/DynamicLinker.cpp")
file(GLOB LIBGEMINI_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGemini/*.cpp")
file(GLOB LIBGFX_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGfx/*.cpp")
file(GLOB LIBGUI_GML_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGUI/GML*.cpp")
list(REMOVE_ITEM LIBGUI_GML_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibGUI/GMLSyntaxHighlighter.cpp")
file(GLOB LIBHTTP_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibHTTP/*.cpp")
file(GLOB LIBIPC_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibIPC/*.cpp")
file(GLOB LIBLINE_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibLine/*.cpp")
file(GLOB LIBMARKDOWN_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibMarkdown/*.cpp")
file(GLOB LIBX86_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibX86/*.cpp")
file(GLOB LIBJS_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibJS/*.cpp")
file(GLOB LIBJS_SUBDIR_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibJS/*/*.cpp")
file(GLOB LIBJS_SUBSUBDIR_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibJS/*/*/*.cpp")
file(GLOB LIBCOMPRESS_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCompress/*.cpp")
file(GLOB LIBCOMPRESS_TESTS CONFIGURE_DEPENDS "../../Tests/LibCompress/*.cpp")
file(GLOB LIBCRYPTO_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCrypto/*.cpp")
file(GLOB LIBCRYPTO_SUBDIR_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCrypto/*/*.cpp")
file(GLOB LIBCRYPTO_SUBSUBDIR_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCrypto/*/*/*.cpp")
file(GLOB LIBTLS_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTLS/*.cpp")
file(GLOB LIBGFX_TTF_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGfx/TrueTypeFont/*.cpp")
file(GLOB LIBTEXTCODEC_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTextCodec/*.cpp")
file(GLOB SHELL_SOURCES CONFIGURE_DEPENDS "../../Userland/Shell/*.cpp")
file(GLOB SHELL_TESTS CONFIGURE_DEPENDS "../../Userland/Shell/Tests/*.sh")
list(FILTER SHELL_SOURCES EXCLUDE REGEX ".*main.cpp$")
file(GLOB_RECURSE LIBSQL_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibSQL/*.cpp")
list(REMOVE_ITEM LIBSQL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibSQL/AST/SyntaxHighlighter.cpp")
list(REMOVE_ITEM LIBSQL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibSQL/SQLClient.cpp")
file(GLOB LIBSQL_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibSQL/*.cpp")
file(GLOB LIBWASM_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibWasm/*/*.cpp")
file(GLOB LIBIMAP_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibIMAP/*.cpp")
file(GLOB LIBTEST_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTest/*.cpp")
list(FILTER LIBTEST_SOURCES EXCLUDE REGEX ".*Main.cpp$")
file(GLOB LIBTEST_MAIN CONFIGURE_DEPENDS "../../Userland/Libraries/LibTest/TestMain.cpp")
file(GLOB LIBCRYPTO_TESTS CONFIGURE_DEPENDS "../../Tests/LibCrypto/*.cpp")
file(GLOB LIBTLS_TESTS CONFIGURE_DEPENDS "../../Tests/LibTLS/*.cpp")
file(GLOB LIBUNICODE_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibUnicode/*.cpp")
set(LIBUNICODE_SOURCES ${LIBUNICODE_SOURCES} ${UNICODE_DATA_SOURCES})
file(GLOB LIBUNICODE_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibUnicode/*.cpp")
set(LAGOM_REGEX_SOURCES ${LIBREGEX_LIBC_SOURCES} ${LIBREGEX_SOURCES})
set(LAGOM_CORE_SOURCES ${AK_SOURCES} ${LIBCORE_SOURCES})
set(LAGOM_MORE_SOURCES ${LIBARCHIVE_SOURCES} ${LIBAUDIO_SOURCES} ${LIBELF_SOURCES} ${LIBIPC_SOURCES} ${LIBLINE_SOURCES} ${LIBJS_SOURCES} ${LIBJS_SUBDIR_SOURCES} ${LIBJS_SUBSUBDIR_SOURCES} ${LIBX86_SOURCES} ${LIBCRYPTO_SOURCES} ${LIBCOMPRESS_SOURCES} ${LIBCRYPTO_SUBDIR_SOURCES} ${LIBCRYPTO_SUBSUBDIR_SOURCES} ${LIBTLS_SOURCES} ${LIBGFX_TTF_SOURCES} ${LIBTEXTCODEC_SOURCES} ${LIBMARKDOWN_SOURCES} ${LIBGEMINI_SOURCES} ${LIBGFX_SOURCES} ${LIBGUI_GML_SOURCES} ${LIBHTTP_SOURCES} ${LAGOM_REGEX_SOURCES} ${SHELL_SOURCES} ${LIBSQL_SOURCES} ${LIBWASM_SOURCES} ${LIBIMAP_SOURCES} ${LIBUNICODE_SOURCES})
set(LAGOM_TEST_SOURCES ${LIBTEST_SOURCES})
# FIXME: This is a hack, because the lagom stuff can be build individually or
# in combination with the system, we generate two Debug.h files. One in
# Build/AK/Debug.h and the other in Build/Meta/Lagom/AK/Debug.h.
configure_file(../../AK/Debug.h.in AK/Debug.h @ONLY)
configure_file(../../Kernel/Debug.h.in Kernel/Debug.h @ONLY)
add_library(LagomCore ${LAGOM_CORE_SOURCES})
find_package(Threads REQUIRED)
target_link_libraries(LagomCore Threads::Threads)
if (BUILD_LAGOM)
add_library(Lagom $<TARGET_OBJECTS:LagomCore> ${LAGOM_MORE_SOURCES})
target_link_libraries(Lagom Threads::Threads)
# Lagom Libraries
# Archive
file(GLOB LIBARCHIVE_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibArchive/*.cpp")
lagom_lib(LagomArchive archive
SOURCES ${LIBARCHIVE_SOURCES}
)
# Audio
file(GLOB LIBAUDIO_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibAudio/*.cpp")
list(REMOVE_ITEM LIBAUDIO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibAudio/ClientConnection.cpp")
lagom_lib(LagomAudio audio
SOURCES ${LIBAUDIO_SOURCES}
)
# Compress
file(GLOB LIBCOMPRESS_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCompress/*.cpp")
lagom_lib(LagomCompress compress
SOURCES ${LIBCOMPRESS_SOURCES}
LIBS LagomCrypto
)
# Crypto
file(GLOB LIBCRYPTO_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCrypto/*.cpp")
file(GLOB LIBCRYPTO_SUBDIR_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCrypto/*/*.cpp")
file(GLOB LIBCRYPTO_SUBSUBDIR_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibCrypto/*/*/*.cpp")
lagom_lib(LagomCrypto crypto
SOURCES ${LIBCRYPTO_SOURCES} ${LIBCRYPTO_SUBDIR_SOURCES} ${LIBCRYPTO_SUBSUBDIR_SOURCES}
)
# ELF
file(GLOB LIBELF_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibELF/*.cpp")
# There's no way we can reliably make the dymamic loading classes cross platform
list(FILTER LIBELF_SOURCES EXCLUDE REGEX ".*Dynamic.*.cpp$")
lagom_lib(LagomELF elf
SOURCES ${LIBELF_SOURCES}
)
# Gemini
file(GLOB LIBGEMINI_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGemini/*.cpp")
lagom_lib(LagomGemini gemini
SOURCES ${LIBGEMINI_SOURCES}
LIBS LagomTLS
)
# GFX
file(GLOB LIBGFX_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGfx/*.cpp")
file(GLOB LIBGFX_TTF_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGfx/TrueTypeFont/*.cpp")
lagom_lib(LagomGfx gfx
SOURCES ${LIBGFX_SOURCES} ${LIBGFX_TTF_SOURCES}
LIBS m LagomCompress LagomTextCodec LagomIPC
)
# GUI-GML
file(GLOB LIBGUI_GML_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibGUI/GML*.cpp")
list(REMOVE_ITEM LIBGUI_GML_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibGUI/GMLSyntaxHighlighter.cpp")
lagom_lib(LagomGML gml
SOURCES ${LIBGUI_GML_SOURCES}
)
# HTTP
file(GLOB LIBHTTP_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibHTTP/*.cpp")
lagom_lib(LagomHTTP http
SOURCES ${LIBHTTP_SOURCES}
LIBS LagomCompress LagomTLS
)
# IMAP
file(GLOB LIBIMAP_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibIMAP/*.cpp")
lagom_lib(LagomIMAP imap
SOURCES ${LIBIMAP_SOURCES}
LIBS LagomTLS
)
# IPC
file(GLOB LIBIPC_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibIPC/*.cpp")
lagom_lib(LagomIPC ipc
SOURCES ${LIBIPC_SOURCES}
)
# JS
file(GLOB LIBJS_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibJS/*.cpp")
file(GLOB LIBJS_SUBDIR_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibJS/*/*.cpp")
file(GLOB LIBJS_SUBSUBDIR_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibJS/*/*/*.cpp")
list(REMOVE_ITEM LIBJS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibJS/SyntaxHighlighter.cpp")
lagom_lib(LagomJS js
SOURCES ${LIBJS_SOURCES} ${LIBJS_SUBDIR_SOURCES} ${LIBJS_SUBSUBDIR_SOURCES}
LIBS m LagomCrypto LagomRegex LagomUnicode
)
# Line
file(GLOB LIBLINE_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibLine/*.cpp")
lagom_lib(LagomLine line
SOURCES ${LIBLINE_SOURCES}
)
# Markdown
file(GLOB LIBMARKDOWN_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibMarkdown/*.cpp")
lagom_lib(LagomMarkdown markdown
SOURCES ${LIBMARKDOWN_SOURCES}
LIBS LagomJS
)
# Regex
file(GLOB LIBREGEX_LIBC_SOURCES "../../Userland/Libraries/LibRegex/C/Regex.cpp")
file(GLOB LIBREGEX_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibRegex/*.cpp")
lagom_lib(LagomRegex regex
SOURCES ${LIBREGEX_SOURCES} ${LIBREGEX_LIBC_SOURCES}
)
# Shell
file(GLOB SHELL_SOURCES CONFIGURE_DEPENDS "../../Userland/Shell/*.cpp")
list(REMOVE_ITEM SHELL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Shell/SyntaxHighlighter.cpp")
list(FILTER SHELL_SOURCES EXCLUDE REGEX ".*main.cpp$")
lagom_lib(LagomShell shell
SOURCES ${SHELL_SOURCES}
LIBS LagomLine LagomRegex
)
# SQL
file(GLOB_RECURSE LIBSQL_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibSQL/*.cpp")
list(REMOVE_ITEM LIBSQL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibSQL/AST/SyntaxHighlighter.cpp")
list(REMOVE_ITEM LIBSQL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibSQL/SQLClient.cpp")
lagom_lib(LagomSQL sql
SOURCES ${LIBSQL_SOURCES}
)
# TextCodec
file(GLOB LIBTEXTCODEC_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTextCodec/*.cpp")
lagom_lib(LagomTextCodec textcodec
SOURCES ${LIBTEXTCODEC_SOURCES}
)
# TLS
file(GLOB LIBTLS_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTLS/*.cpp")
lagom_lib(LagomTLS tls
SOURCES ${LIBTLS_SOURCES}
LIBS LagomCrypto
)
# Unicode
# We need to make sure not to build code generators for Fuzzer builds, as they already have their own main.cpp
if (NOT ENABLE_OSS_FUZZ AND NOT ENABLE_FUZZER_SANITIZER)
# FIXME: Make this logic smarter in 4594
if (NOT CMAKE_SOURCE_DIR STREQUAL SERENITY_PROJECT_ROOT)
set(write_if_different ${CMAKE_CURRENT_SOURCE_DIR}/../write-only-on-difference.sh)
add_subdirectory(../../Userland/Libraries/LibUnicode/CodeGenerators ${CMAKE_CURRENT_BINARY_DIR}/LibUnicode/CodeGenerators)
endif()
include(../../Userland/Libraries/LibUnicode/unicode_data.cmake)
endif()
file(GLOB LIBUNICODE_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibUnicode/*.cpp")
lagom_lib(LagomUnicode unicode
SOURCES ${LIBUNICODE_SOURCES} ${UNICODE_DATA_SOURCES}
)
# WASM
file(GLOB LIBWASM_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibWasm/*/*.cpp")
lagom_lib(LagomWasm wasm
SOURCES ${LIBWASM_SOURCES}
)
# x86
file(GLOB LIBX86_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibX86/*.cpp")
lagom_lib(LagomX86 x86
SOURCES ${LIBX86_SOURCES}
)
if (NOT ENABLE_OSS_FUZZ AND NOT ENABLE_FUZZER_SANITIZER)
enable_testing()
add_library(LagomTest $<TARGET_OBJECTS:LagomCore> ${LAGOM_TEST_SOURCES})
target_link_libraries(LagomTest Threads::Threads)
# Lagom Examples
add_executable(TestApp TestApp.cpp)
target_link_libraries(TestApp Lagom)
target_link_libraries(TestApp stdc++)
target_link_libraries(TestApp LagomCore)
add_executable(TestJson TestJson.cpp)
target_link_libraries(TestJson Lagom)
target_link_libraries(TestJson stdc++)
target_link_libraries(TestJson LagomCore)
# Lagom Utilities
add_executable(adjtime_lagom ../../Userland/Utilities/adjtime.cpp)
set_target_properties(adjtime_lagom PROPERTIES OUTPUT_NAME adjtime)
target_link_libraries(adjtime_lagom Lagom)
target_link_libraries(adjtime_lagom LagomCore)
add_executable(disasm_lagom ../../Userland/Utilities/disasm.cpp)
set_target_properties(disasm_lagom PROPERTIES OUTPUT_NAME disasm)
target_link_libraries(disasm_lagom LagomCore LagomELF LagomX86)
add_executable(gml-format_lagom ../../Userland/Utilities/gml-format.cpp)
set_target_properties(gml-format_lagom PROPERTIES OUTPUT_NAME gml-format)
target_link_libraries(gml-format_lagom LagomCore LagomGML)
add_executable(js_lagom ../../Userland/Utilities/js.cpp)
set_target_properties(js_lagom PROPERTIES OUTPUT_NAME js)
target_link_libraries(js_lagom Lagom)
target_link_libraries(js_lagom stdc++)
target_link_libraries(js_lagom pthread)
target_link_libraries(js_lagom LagomJS LagomLine Threads::Threads)
add_executable(ntpquery_lagom ../../Userland/Utilities/ntpquery.cpp)
set_target_properties(ntpquery_lagom PROPERTIES OUTPUT_NAME ntpquery)
target_link_libraries(ntpquery_lagom Lagom)
target_link_libraries(ntpquery_lagom LagomCore)
add_executable(shell_lagom ../../Userland/Shell/main.cpp)
set_target_properties(shell_lagom PROPERTIES OUTPUT_NAME shell)
target_link_libraries(shell_lagom LagomCore LagomShell)
add_executable(wasm_lagom ../../Userland/Utilities/wasm.cpp)
set_target_properties(wasm_lagom PROPERTIES OUTPUT_NAME wasm)
target_link_libraries(wasm_lagom LagomCore LagomWasm LagomLine)
enable_testing()
# LibTest
file(GLOB LIBTEST_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTest/*.cpp")
list(FILTER LIBTEST_SOURCES EXCLUDE REGEX ".*Main.cpp$")
add_library(
LagomTest
SHARED
${LIBTEST_SOURCES}
)
target_link_libraries(LagomTest LagomCore)
set_target_properties(LagomTest PROPERTIES OUTPUT_NAME lagom-test)
add_library(
LagomTestMain
OBJECT
"${SERENITY_PROJECT_ROOT}/Userland/Libraries/LibTest/TestMain.cpp"
)
# LibTest tests from Tests/
# AK
file(GLOB AK_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/AK/*.cpp")
foreach(source ${AK_TEST_SOURCES})
lagom_test(${source})
endforeach()
set_tests_properties(TestJSON PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/AK)
# Core
lagom_test(../../Tests/LibCore/TestLibCoreIODevice.cpp)
set_tests_properties(TestLibCoreIODevice PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibCore)
# Crypto
file(GLOB LIBCRYPTO_TESTS CONFIGURE_DEPENDS "../../Tests/LibCrypto/*.cpp")
foreach(source ${LIBCRYPTO_TESTS})
lagom_test(${source} LIBS LagomCrypto)
endforeach()
# Compress
file(GLOB LIBCOMPRESS_TESTS CONFIGURE_DEPENDS "../../Tests/LibCompress/*.cpp")
foreach(source ${LIBCOMPRESS_TESTS})
lagom_test(${source} LIBS LagomCompress)
endforeach()
# Regex
file(GLOB LIBREGEX_TESTS CONFIGURE_DEPENDS "../../Tests/LibRegex/*.cpp")
# RegexLibC test POSIX <regex.h> and contains many Serenity extensions
# It is therefore not reasonable to run it on Lagom
list(REMOVE_ITEM LIBREGEX_TESTS "${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibRegex/RegexLibC.cpp")
foreach(source ${LIBREGEX_TESTS})
lagom_test(${source} LIBS LagomRegex)
endforeach()
# SQL
file(GLOB LIBSQL_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibSQL/*.cpp")
foreach(source ${LIBSQL_TEST_SOURCES})
lagom_test(${source} LIBS LagomSQL)
endforeach()
# TLS
file(GLOB LIBTLS_TESTS CONFIGURE_DEPENDS "../../Tests/LibTLS/*.cpp")
foreach(source ${LIBTLS_TESTS})
lagom_test(${source} LIBS LagomTLS)
set_tests_properties(TestTLSHandshake PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibTLS)
endforeach()
# Unicode
file(GLOB LIBUNICODE_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibUnicode/*.cpp")
foreach(source ${LIBUNICODE_TEST_SOURCES})
lagom_test(${source} LIBS LagomUnicode)
endforeach()
# JavaScriptTestRunner + LibTest tests
# test-js
add_executable(test-js_lagom
../../Tests/LibJS/test-js.cpp
../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp)
set_target_properties(test-js_lagom PROPERTIES OUTPUT_NAME test-js)
target_link_libraries(test-js_lagom Lagom)
target_link_libraries(test-js_lagom stdc++)
target_link_libraries(test-js_lagom pthread)
target_link_libraries(test-js_lagom LagomCore LagomTest LagomJS)
add_test(
NAME JS
COMMAND test-js_lagom --show-progress=false
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set_tests_properties(JS PROPERTIES ENVIRONMENT SERENITY_SOURCE_DIR=${SERENITY_PROJECT_ROOT})
# test-wasm
add_executable(test-wasm_lagom
../../Tests/LibWasm/test-wasm.cpp
../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp)
set_target_properties(test-wasm_lagom PROPERTIES OUTPUT_NAME test-wasm)
target_link_libraries(test-wasm_lagom LagomCore LagomTest LagomWasm LagomJS)
add_test(
NAME WasmParser
COMMAND test-wasm_lagom --show-progress=false
)
set_tests_properties(WasmParser PROPERTIES
ENVIRONMENT SERENITY_SOURCE_DIR=${SERENITY_PROJECT_ROOT}
SKIP_RETURN_CODE 1)
# Tests that are not LibTest based
# test-crypto
add_executable(test-crypto_lagom ../../Userland/Utilities/test-crypto.cpp)
set_target_properties(test-crypto_lagom PROPERTIES OUTPUT_NAME test-crypto)
target_link_libraries(test-crypto_lagom Lagom)
target_link_libraries(test-crypto_lagom stdc++)
target_link_libraries(test-crypto_lagom LagomCore LagomTLS LagomCrypto LagomLine)
add_test(
NAME Crypto
COMMAND test-crypto_lagom test -t -s google.com --ca-certs-file ../../Base/etc/ca_certs.ini
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_executable(test-wasm_lagom
../../Tests/LibWasm/test-wasm.cpp
../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp)
set_target_properties(test-wasm_lagom PROPERTIES OUTPUT_NAME test-wasm)
target_link_libraries(test-wasm_lagom Lagom)
target_link_libraries(test-wasm_lagom stdc++)
target_link_libraries(test-wasm_lagom pthread)
add_test(
NAME WasmParser
COMMAND test-wasm_lagom --show-progress=false
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set_tests_properties(WasmParser PROPERTIES
ENVIRONMENT SERENITY_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/../..
SKIP_RETURN_CODE 1)
add_executable(disasm_lagom ../../Userland/Utilities/disasm.cpp)
set_target_properties(disasm_lagom PROPERTIES OUTPUT_NAME disasm)
target_link_libraries(disasm_lagom Lagom)
target_link_libraries(disasm_lagom stdc++)
add_executable(shell_lagom ../../Userland/Shell/main.cpp)
set_target_properties(shell_lagom PROPERTIES OUTPUT_NAME shell)
target_link_libraries(shell_lagom Lagom)
target_link_libraries(shell_lagom stdc++)
target_link_libraries(shell_lagom pthread)
add_executable(gml-format_lagom ../../Userland/Utilities/gml-format.cpp)
set_target_properties(gml-format_lagom PROPERTIES OUTPUT_NAME gml-format)
target_link_libraries(gml-format_lagom Lagom)
target_link_libraries(gml-format_lagom stdc++)
add_executable(test-iodevice ../../Tests/LibCore/TestLibCoreIODevice.cpp ${LIBTEST_MAIN})
set_target_properties(test-iodevice PROPERTIES OUTPUT_NAME test-iodevice)
target_link_libraries(test-iodevice Lagom)
target_link_libraries(test-iodevice LagomTest)
target_link_libraries(test-iodevice stdc++)
add_test(
NAME test-iodevice
COMMAND test-iodevice
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibCore
)
add_executable(wasm_lagom ../../Userland/Utilities/wasm.cpp)
set_target_properties(wasm_lagom PROPERTIES OUTPUT_NAME wasm)
target_link_libraries(wasm_lagom Lagom)
target_link_libraries(wasm_lagom stdc++)
foreach(source ${LIBCRYPTO_TESTS})
get_filename_component(name ${source} NAME_WE)
add_executable(${name}_lagom ${source} ${LIBCRYPTO_SOURCES} ${LIBTEST_MAIN})
target_link_libraries(${name}_lagom Lagom LagomTest)
add_test(
NAME ${name}_lagom
COMMAND ${name}_lagom
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endforeach()
foreach(source ${LIBTLS_TESTS})
get_filename_component(name ${source} NAME_WE)
add_executable(${name}_lagom ${source} ${LIBTLS_SOURCES} ${LIBTEST_MAIN})
target_link_libraries(${name}_lagom Lagom LagomTest)
add_test(
NAME ${name}_lagom
COMMAND ${name}_lagom
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibTLS
)
endforeach()
# Shell
file(GLOB SHELL_TESTS CONFIGURE_DEPENDS "../../Userland/Shell/Tests/*.sh")
foreach(TEST_PATH ${SHELL_TESTS})
get_filename_component(TEST_NAME ${TEST_PATH} NAME_WE)
add_test(
NAME "Shell-${TEST_NAME}"
COMMAND shell_lagom --skip-shellrc "${TEST_PATH}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Shell/Tests
WORKING_DIRECTORY ${SERENITY_PROJECT_ROOT}/Userland/Shell/Tests
)
set_tests_properties("Shell-${TEST_NAME}" PROPERTIES
TIMEOUT 10
@ -267,65 +455,7 @@ if (BUILD_LAGOM)
PASS_REGULAR_EXPRESSION "PASS"
)
endforeach()
foreach(source ${AK_TEST_SOURCES})
get_filename_component(name ${source} NAME_WE)
add_executable(${name}_lagom ${source} ${LIBTEST_MAIN})
target_link_libraries(${name}_lagom LagomTest)
add_test(
NAME ${name}_lagom
COMMAND ${name}_lagom
# FIXME: Only TestJSON needs this property
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/AK
)
endforeach()
foreach(source ${LIBREGEX_TESTS})
get_filename_component(name ${source} NAME_WE)
add_executable(${name}_lagom ${source} ${LAGOM_REGEX_SOURCES} ${LIBTEST_MAIN})
target_link_libraries(${name}_lagom LagomTest)
add_test(
NAME ${name}_lagom
COMMAND ${name}_lagom
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endforeach()
foreach(source ${LIBCOMPRESS_TESTS})
get_filename_component(name ${source} NAME_WE)
add_executable(${name}_lagom ${source} ${LIBCOMPRESS_SOURCES} ${LIBTEST_MAIN})
target_link_libraries(${name}_lagom Lagom LagomTest)
add_test(
NAME ${name}_lagom
COMMAND ${name}_lagom
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endforeach()
foreach(source ${LIBSQL_TEST_SOURCES})
get_filename_component(name ${source} NAME_WE)
add_executable(${name}_lagom ${source} ${LIBSQL_SOURCES} ${LIBTEST_MAIN})
target_link_libraries(${name}_lagom LagomTest)
add_test(
NAME ${name}_lagom
COMMAND ${name}_lagom
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endforeach()
foreach(source ${LIBUNICODE_TEST_SOURCES})
get_filename_component(name ${source} NAME_WE)
add_executable(${name}_lagom ${source} ${LIBUNICODE_SOURCES} ${LIBTEST_MAIN})
target_link_libraries(${name}_lagom LagomTest)
add_test(
NAME ${name}_lagom
COMMAND ${name}_lagom
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endforeach()
endif()
install(TARGETS Lagom LagomCore)
endif()
if (ENABLE_FUZZER_SANITIZER OR ENABLE_OSS_FUZZ)

View file

@ -3,60 +3,60 @@ function(add_simple_fuzzer name)
if (ENABLE_OSS_FUZZ)
target_link_libraries(${name}
PUBLIC Lagom)
PUBLIC {$ARGN} LagomCore)
else()
target_compile_options(${name}
PRIVATE $<$<CXX_COMPILER_ID:Clang>:-g -O1 -fsanitize=fuzzer>
)
target_link_libraries(${name}
PUBLIC Lagom
PUBLIC ${ARGN} LagomCore
PRIVATE $<$<CXX_COMPILER_ID:Clang>:-fsanitize=fuzzer>
)
endif()
endfunction()
add_simple_fuzzer(FuzzBMPLoader)
add_simple_fuzzer(FuzzCyrillicDecoder)
add_simple_fuzzer(FuzzDeflateCompression)
add_simple_fuzzer(FuzzDeflateDecompression)
add_simple_fuzzer(FuzzELF)
add_simple_fuzzer(FuzzFlacLoader)
add_simple_fuzzer(FuzzGemini)
add_simple_fuzzer(FuzzGIFLoader)
add_simple_fuzzer(FuzzGzipCompression)
add_simple_fuzzer(FuzzGzipDecompression)
add_simple_fuzzer(FuzzICOLoader)
add_simple_fuzzer(FuzzJPGLoader)
add_simple_fuzzer(FuzzMD5)
add_simple_fuzzer(FuzzPNGLoader)
add_simple_fuzzer(FuzzPBMLoader)
add_simple_fuzzer(FuzzPGMLoader)
add_simple_fuzzer(FuzzPPMLoader)
add_simple_fuzzer(FuzzQuotedPrintableParser)
add_simple_fuzzer(FuzzHebrewDecoder)
add_simple_fuzzer(FuzzHttpRequest)
add_simple_fuzzer(FuzzIMAPParser)
add_simple_fuzzer(FuzzJs)
add_simple_fuzzer(FuzzLatin1Decoder)
add_simple_fuzzer(FuzzLatin2Decoder)
add_simple_fuzzer(FuzzMarkdown)
add_simple_fuzzer(FuzzRegexECMA262)
add_simple_fuzzer(FuzzRegexPosixBasic)
add_simple_fuzzer(FuzzRegexPosixExtended)
add_simple_fuzzer(FuzzSHA1)
add_simple_fuzzer(FuzzSHA256)
add_simple_fuzzer(FuzzSHA384)
add_simple_fuzzer(FuzzSHA512)
add_simple_fuzzer(FuzzShell)
add_simple_fuzzer(FuzzSQLParser)
add_simple_fuzzer(FuzzTTF)
add_simple_fuzzer(FuzzBMPLoader LagomGfx)
add_simple_fuzzer(FuzzCyrillicDecoder LagomTextCodec)
add_simple_fuzzer(FuzzDeflateCompression LagomCompress)
add_simple_fuzzer(FuzzDeflateDecompression LagomCompress)
add_simple_fuzzer(FuzzELF LagomELF)
add_simple_fuzzer(FuzzFlacLoader LagomAudio)
add_simple_fuzzer(FuzzGemini LagomGemini)
add_simple_fuzzer(FuzzGIFLoader LagomGfx)
add_simple_fuzzer(FuzzGzipCompression LagomCompress)
add_simple_fuzzer(FuzzGzipDecompression LagomCompress)
add_simple_fuzzer(FuzzICOLoader LagomGfx)
add_simple_fuzzer(FuzzJPGLoader LagomGfx)
add_simple_fuzzer(FuzzMD5 LagomCrypto)
add_simple_fuzzer(FuzzPNGLoader LagomGfx)
add_simple_fuzzer(FuzzPBMLoader LagomGfx)
add_simple_fuzzer(FuzzPGMLoader LagomGfx)
add_simple_fuzzer(FuzzPPMLoader LagomGfx)
add_simple_fuzzer(FuzzQuotedPrintableParser LagomIMAP)
add_simple_fuzzer(FuzzHebrewDecoder LagomTextCodec)
add_simple_fuzzer(FuzzHttpRequest LagomHTTP)
add_simple_fuzzer(FuzzIMAPParser LagomIMAP)
add_simple_fuzzer(FuzzJs LagomJS)
add_simple_fuzzer(FuzzLatin1Decoder LagomTextCodec)
add_simple_fuzzer(FuzzLatin2Decoder LagomTextCodec)
add_simple_fuzzer(FuzzMarkdown LagomMarkdown)
add_simple_fuzzer(FuzzRegexECMA262 LagomRegex)
add_simple_fuzzer(FuzzRegexPosixBasic LagomRegex)
add_simple_fuzzer(FuzzRegexPosixExtended LagomRegex)
add_simple_fuzzer(FuzzSHA1 LagomCrypto)
add_simple_fuzzer(FuzzSHA256 LagomCrypto)
add_simple_fuzzer(FuzzSHA384 LagomCrypto)
add_simple_fuzzer(FuzzSHA512 LagomCrypto)
add_simple_fuzzer(FuzzShell LagomShell)
add_simple_fuzzer(FuzzSQLParser LagomSQL)
add_simple_fuzzer(FuzzTTF LagomGfx)
add_simple_fuzzer(FuzzURL)
add_simple_fuzzer(FuzzUTF16BEDecoder)
add_simple_fuzzer(FuzzRSAKeyParsing)
add_simple_fuzzer(FuzzWAVLoader)
add_simple_fuzzer(FuzzWasmParser)
add_simple_fuzzer(FuzzZip)
add_simple_fuzzer(FuzzZlibDecompression)
add_simple_fuzzer(FuzzUTF16BEDecoder LagomTextCodec)
add_simple_fuzzer(FuzzRSAKeyParsing LagomCrypto)
add_simple_fuzzer(FuzzWAVLoader LagomAudio)
add_simple_fuzzer(FuzzWasmParser LagomWasm)
add_simple_fuzzer(FuzzZip LagomArchive)
add_simple_fuzzer(FuzzZlibDecompression LagomCompress)
if (NOT ENABLE_OSS_FUZZ)
set(CMAKE_EXE_LINKER_FLAGS "${ORIGINAL_CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
@ -67,7 +67,7 @@ target_compile_options(FuzzilliJs
PRIVATE $<$<CXX_COMPILER_ID:Clang>:-g -O1 -fsanitize-coverage=trace-pc-guard>
)
target_link_libraries(FuzzilliJs
PUBLIC Lagom
PUBLIC LagomCore LagomJS
PRIVATE $<$<CXX_COMPILER_ID:Clang>:-fsanitize-coverage=trace-pc-guard>
)
endif()