ladybird/CMakeLists.txt

271 lines
10 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.16)
project(SerenityOS C CXX ASM)
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
message(FATAL_ERROR
": Don't use CMAKE_BUILD_TYPE when building serenity.\n"
"The default build type is optimized with debug info and asserts enabled,\n"
"and that's all there is.")
endif()
set(CMAKE_INSTALL_MESSAGE NEVER)
enable_testing()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(SERENITY_ARCH "i686" CACHE STRING "Target architecture for SerenityOS.")
# Central location for all custom options used in the Serenity build.
option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer testing in gcc/clang" OFF)
option(ENABLE_KERNEL_ADDRESS_SANITIZER "Enable kernel address sanitizer testing in gcc/clang" OFF)
option(ENABLE_MEMORY_SANITIZER "Enable memory sanitizer testing in gcc/clang" OFF)
option(ENABLE_UNDEFINED_SANITIZER "Enable undefined behavior sanitizer testing in gcc/clang" OFF)
option(ENABLE_FUZZER_SANITIZER "Enable fuzzer sanitizer testing in clang" OFF)
option(ENABLE_EXTRA_KERNEL_DEBUG_SYMBOLS "Enable -Og and -ggdb3 options for Kernel code for easier debugging" OFF)
option(ENABLE_ALL_THE_DEBUG_MACROS "Enable all debug macros to validate they still compile" OFF)
option(ENABLE_ALL_DEBUG_FACILITIES "Enable all noisy debug symbols and options. Not recommended for normal developer use" OFF)
option(ENABLE_COMPILETIME_FORMAT_CHECK "Enable compiletime format string checks" ON)
option(ENABLE_PCI_IDS_DOWNLOAD "Enable download of the pci.ids database at build time" ON)
option(BUILD_LAGOM "Build parts of the system targeting the host OS for fuzzing/testing" OFF)
option(ENABLE_KERNEL_LTO "Build the kernel with link-time optimization" OFF)
include(Meta/CMake/wasm_spec_tests.cmake)
add_custom_target(run
COMMAND ${CMAKE_SOURCE_DIR}/Meta/run.sh
USES_TERMINAL
)
# This can currently only be implemented by ordered commands
# as cmake doesn't support inter dependency ordering, and we
# would like to avoid inject dependencies on the existing
# custom commands to allow people to run commands adhoc with
# out forcing re-builds when they might not want them.
add_custom_target(setup-and-run
COMMAND ${CMAKE_MAKE_PROGRAM} install
COMMAND ${CMAKE_MAKE_PROGRAM} image
COMMAND ${CMAKE_MAKE_PROGRAM} run
USES_TERMINAL
)
add_custom_target(image
DEPENDS qemu-image
)
add_custom_target(qemu-image
COMMAND ${CMAKE_COMMAND} -E env "SERENITY_SOURCE_DIR=${CMAKE_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" ${CMAKE_SOURCE_DIR}/Meta/build-image-qemu.sh
BYPRODUCTS ${CMAKE_BINARY_DIR}/_disk_image
USES_TERMINAL
)
2020-05-27 00:51:18 +03:00
add_custom_target(grub-image
COMMAND ${CMAKE_COMMAND} -E env "SERENITY_SOURCE_DIR=${CMAKE_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" ${CMAKE_SOURCE_DIR}/Meta/build-image-grub.sh
BYPRODUCTS ${CMAKE_BINARY_DIR}/grub_disk_image
2020-05-27 00:51:18 +03:00
USES_TERMINAL
)
add_custom_target(extlinux-image
COMMAND ${CMAKE_COMMAND} -E env "SERENITY_SOURCE_DIR=${CMAKE_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" ${CMAKE_SOURCE_DIR}/Meta/build-image-extlinux.sh
BYPRODUCTS ${CMAKE_BINARY_DIR}/extlinux_disk_image
USES_TERMINAL
)
2020-05-27 00:51:18 +03:00
add_custom_target(lint-shell-scripts
COMMAND ${CMAKE_SOURCE_DIR}/Meta/lint-shell-scripts.sh
USES_TERMINAL
)
add_custom_target(check-style
COMMAND ${CMAKE_SOURCE_DIR}/Meta/check-style.sh
USES_TERMINAL
)
add_custom_target(install-ports
COMMAND ${CMAKE_COMMAND} -E env "SERENITY_SOURCE_DIR=${CMAKE_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" ${CMAKE_SOURCE_DIR}/Meta/install-ports-tree.sh
USES_TERMINAL
)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_compile_options(-Wno-literal-suffix)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fconcepts)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang$")
add_compile_options(-Wno-overloaded-virtual -Wno-user-defined-literals)
endif()
if (ENABLE_ALL_DEBUG_FACILITIES)
set(ENABLE_ALL_THE_DEBUG_MACROS ON)
set(ENABLE_EXTRA_KERNEL_DEBUG_SYMBOLS ON)
endif()
if (ENABLE_ALL_THE_DEBUG_MACROS)
include(${CMAKE_SOURCE_DIR}/Meta/CMake/all_the_debug_macros.cmake)
endif(ENABLE_ALL_THE_DEBUG_MACROS)
configure_file(AK/Debug.h.in AK/Debug.h @ONLY)
Meta: Split debug defines into multiple headers. The following script was used to make these changes: #!/bin/bash set -e tmp=$(mktemp -d) echo "tmp=$tmp" find Kernel \( -name '*.cpp' -o -name '*.h' \) | sort > $tmp/Kernel.files find . \( -path ./Toolchain -prune -o -path ./Build -prune -o -path ./Kernel -prune \) -o \( -name '*.cpp' -o -name '*.h' \) -print | sort > $tmp/EverythingExceptKernel.files cat $tmp/Kernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/Kernel.macros cat $tmp/EverythingExceptKernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/EverythingExceptKernel.macros comm -23 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/Kernel.unique comm -1 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/EverythingExceptKernel.unique cat $tmp/Kernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/Kernel.header cat $tmp/EverythingExceptKernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/EverythingExceptKernel.header for macro in $(cat $tmp/Kernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.new-includes ||: done cat $tmp/Kernel.new-includes | sort > $tmp/Kernel.new-includes.sorted for macro in $(cat $tmp/EverythingExceptKernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.old-includes ||: done cat $tmp/Kernel.old-includes | sort > $tmp/Kernel.old-includes.sorted comm -23 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.new comm -13 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.old comm -12 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.mixed for file in $(cat $tmp/Kernel.includes.new) do sed -i -E 's/#include <AK\/Debug\.h>/#include <Kernel\/Debug\.h>/' $file done for file in $(cat $tmp/Kernel.includes.mixed) do echo "mixed include in $file, requires manual editing." done
2021-01-25 18:07:10 +03:00
configure_file(Kernel/Debug.h.in Kernel/Debug.h @ONLY)
2021-01-12 14:17:30 +03:00
include_directories(Userland/Libraries)
include_directories(.)
include_directories(${CMAKE_BINARY_DIR})
add_subdirectory(Meta/Lagom)
if (ENABLE_UNDEFINED_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
endif()
2021-01-12 14:18:55 +03:00
add_subdirectory(Userland/DevTools/IPCCompiler)
DevTools: Add StateMachineGenerator utility This program turns a description of a state machine that takes its input byte-by-byte into C++ code. The state machine is described in a custom format as specified below: ``` // Comments are started by two slashes, and cause the rest of the line // to be ignored @name ExampleStateMachine // sets the name of the generated class @namespace Test // sets the namespace (optional) @begin Begin // sets the state the parser will start in // The rest of the file contains one or more states and an optional // @anywhere directive. Each of these is a curly bracket delimited set // of state transitions. State transitions contain a selector, the // literal "=>" and a (new_state, action) tuple. Examples: // 0x0a => (Begin, PrintLine) // [0x00..0x1f] => (_, Warn) // '_' means no change // [0x41..0x5a] => (BeginWord, _) // '_' means no action // Rules common to all states. These take precedence over rules in the // specific states. @anywhere { 0x0a => (Begin, PrintLine) [0x00..0x1f] => (_, Warn) } Begin { [0x41..0x5a] => (Word, _) [0x61..0x7a] => (Word, _) // For missing values, the transition (_, _) is implied } Word { // The entry action is run when we transition to this state from a // *different* state. @anywhere can't have this @entry IncreaseWordCount 0x09 => (Begin, _) 0x20 => (Begin, _) // The exit action is run before we transition to any *other* state // from here. @anywhere can't have this @exit EndOfWord } ``` The generated code consists of a single class which takes a `Function<Action, u8>` as a parameter in its constructor. This gets called whenever an action is to be done. This is because some input might not produce an action, but others might produce up to 3 (exit, state transition, entry). The actions allow us to build a more advanced parser over the simple state machine. The sole public method, `void advance(u8)`, handles the input byte-by-byte, managing the state changes and requesting the appropriate Action from the handler. Internally, the state transitions are resolved via a lookup table. This is a bit wasteful for more complex state machines, therefore the generator is designed to be easily extendable with a switch-based resolver; only the private `lookup_state_transition` method needs to be re-implemented. My goal for this tool is to use it for implementing a standard-compliant ANSI escape sequence parser for LibVT, as described on <https://vt100.net/emu/dec_ansi_parser>
2021-05-08 10:53:49 +03:00
add_subdirectory(Userland/DevTools/StateMachineGenerator)
2021-01-12 14:17:30 +03:00
add_subdirectory(Userland/Libraries/LibWeb/CodeGenerators)
set(write_if_different ${CMAKE_SOURCE_DIR}/Meta/write-only-on-difference.sh)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
unset(CMAKE_SYSROOT)
set(CMAKE_STAGING_PREFIX ${CMAKE_BINARY_DIR}/Root)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/Root)
set(CMAKE_INSTALL_DATAROOTDIR ${CMAKE_BINARY_DIR}/Root/res)
set(GCC_VERSION 11.1.0)
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES SerenityOS)
message("Good job on building cmake!")
else()
set(TOOLCHAIN_ROOT ${CMAKE_SOURCE_DIR}/Toolchain/Local/${SERENITY_ARCH}/)
set(TOOLCHAIN_PATH ${TOOLCHAIN_ROOT}/bin)
set(TOOLCHAIN_PREFIX ${TOOLCHAIN_PATH}/${SERENITY_ARCH}-pc-serenity-)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}gcc-ranlib)
set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}strip)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}gcc-ar)
endif()
foreach(lang ASM C CXX OBJC OBJCXX)
unset(CMAKE_${lang}_OSX_COMPATIBILITY_VERSION_FLAG)
unset(CMAKE_${lang}_OSX_CURRENT_VERSION_FLAG)
unset(CMAKE_${lang}_LINK_FLAGS)
unset(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS)
unset(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS)
unset(CMAKE_SHARED_MODULE_LOADER_${lang}_FLAG )
unset(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG)
unset(CMAKE_${lang}_SYSROOT_FLAG)
if (CMAKE_SYSTEM_NAME MATCHES Darwin)
## macOS workaround. Use GNU ld flags for SONAMEs.
set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
"<CMAKE_${lang}_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> <LINK_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,-soname,")
endif()
endforeach()
set(CMAKE_INSTALL_NAME_TOOL "")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-shared -Wl,--hash-style=gnu,-z,relro,-z,now,-z,noexecstack")
set(CMAKE_CXX_LINK_FLAGS "-Wl,--hash-style=gnu,-z,relro,-z,now,-z,noexecstack")
# We disable it completely because it makes cmake very spammy.
# This will need to be revisited when the Loader supports RPATH/RUN_PATH.
set(CMAKE_SKIP_RPATH TRUE)
add_compile_options(-Wformat=2)
add_compile_options(-fdiagnostics-color=always)
if (NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES SerenityOS)
2021-03-28 17:43:05 +03:00
# FIXME: Something makes this go crazy and flag unused variables that aren't flagged as such when building with the toolchain.
# Disable -Werror for now.
add_compile_options(-Werror)
2021-03-28 17:43:05 +03:00
endif()
add_compile_options(-Wall)
add_compile_options(-Wextra)
# The following warnings are sorted by the "base" name (the part excluding the initial Wno or W).
add_compile_options(-Wno-address-of-packed-member)
add_compile_options(-Wcast-align)
add_compile_options(-Wcast-qual)
add_compile_options(-Wno-deprecated-copy)
add_compile_options(-Wduplicated-cond)
add_compile_options(-Wdouble-promotion)
add_compile_options(-Wno-expansion-to-defined)
add_compile_options(-Wformat=2)
add_compile_options(-Wimplicit-fallthrough)
add_compile_options(-Wlogical-op)
add_compile_options(-Wmisleading-indentation)
add_compile_options(-Wmissing-declarations)
add_compile_options(-Wno-nonnull-compare)
add_compile_options(-Wnon-virtual-dtor)
add_compile_options(-Wno-unknown-warning-option)
add_compile_options(-Wundef)
add_compile_options(-Wunused)
add_compile_options(-Wwrite-strings)
add_compile_options(-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.)
add_compile_options(-fno-exceptions)
add_compile_options(-fstack-protector-strong)
add_compile_options(-g1)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fstack-clash-protection)
endif()
add_compile_definitions(DEBUG SANITIZE_PTRS)
set(CMAKE_CXX_FLAGS_STATIC "${CMAKE_CXX_FLAGS} -static")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pie -fpic")
if (ENABLE_COMPILETIME_FORMAT_CHECK)
add_compile_definitions(ENABLE_COMPILETIME_FORMAT_CHECK)
endif()
add_link_options(--sysroot ${CMAKE_BINARY_DIR}/Root)
2021-01-12 14:17:30 +03:00
include_directories(Userland/Libraries/LibC)
include_directories(Userland/Libraries/LibCrypt)
2021-01-12 14:17:30 +03:00
include_directories(Userland/Libraries/LibM)
include_directories(Userland/Libraries/LibPthread)
include_directories(Userland/Libraries/LibSystem)
2021-01-12 14:23:01 +03:00
include_directories(Userland/Services)
2021-01-12 13:53:14 +03:00
include_directories(Userland)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
2021-01-12 14:23:01 +03:00
include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland/Services)
2021-01-12 14:17:30 +03:00
include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland/Libraries)
2021-01-12 13:53:14 +03:00
include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland)
# FIXME: vptr sanitizing requires.. intense ABI wrangling of std::type_info
# And would be better served by porting ubsan_type_hash_itanium.cpp from compiler-rt
# We don't set this along with the original fsanitize=undefined because for host tools, we can rely on
# the host's libubsan to provide the ABI-specific vptr type cache.
# This is not a problem for the Kernel, because it does not have RTTI enabled :^)
if (ENABLE_UNDEFINED_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize=vptr")
endif()
add_subdirectory(AK)
add_subdirectory(Kernel)
add_subdirectory(Userland)
add_subdirectory(Tests)
set(PCI_IDS_GZ_URL https://pci-ids.ucw.cz/v2.2/pci.ids.gz)
set(PCI_IDS_GZ_PATH ${CMAKE_BINARY_DIR}/pci.ids.gz)
set(PCI_IDS_PATH ${CMAKE_BINARY_DIR}/pci.ids)
set(PCI_IDS_INSTALL_PATH ${CMAKE_INSTALL_DATAROOTDIR}/pci.ids)
if(ENABLE_PCI_IDS_DOWNLOAD AND NOT EXISTS ${PCI_IDS_GZ_PATH})
message(STATUS "Downloading PCI ID database from ${PCI_IDS_GZ_URL}...")
file(DOWNLOAD ${PCI_IDS_GZ_URL} ${PCI_IDS_GZ_PATH} INACTIVITY_TIMEOUT 10)
endif()
if(EXISTS ${PCI_IDS_GZ_PATH} AND NOT EXISTS ${PCI_IDS_INSTALL_PATH})
message(STATUS "Extracting PCI ID database from ${PCI_IDS_GZ_PATH}...")
execute_process(COMMAND gzip -k -d ${PCI_IDS_GZ_PATH})
file(MAKE_DIRECTORY ${CMAKE_INSTALL_DATAROOTDIR})
file(RENAME ${PCI_IDS_PATH} ${PCI_IDS_INSTALL_PATH})
endif()