ladybird/CMakeLists.txt

315 lines
12 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.16)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Meta/CMake")
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()
if(NOT CMAKE_SYSTEM_NAME STREQUAL "SerenityOS")
message(FATAL_ERROR "System name is not SerenityOS, this is unsupported.\n"
"Please re-read the BuildInstructions documentation, and use the superbuild configuration\n")
endif()
# Check for toolchain mismatch, user might need to rebuild toolchain
set(GCC_VERSION "11.2.0")
set(LLVM_VERSION "13.0.0")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(EXPECTED_COMPILER_VERSION "${GCC_VERSION}")
else()
set(EXPECTED_COMPILER_VERSION "${LLVM_VERSION}")
endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "${EXPECTED_COMPILER_VERSION}")
message(FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} version (${CMAKE_CXX_COMPILER_VERSION}) does not match "
"expected compiler version (${EXPECTED_COMPILER_VERSION}).\n"
"Please rebuild the ${CMAKE_CXX_COMPILER_ID} Toolchain\n")
endif()
set(CMAKE_INSTALL_MESSAGE NEVER)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT COMMAND serenity_option)
macro(serenity_option)
set(${ARGV})
endmacro()
endif()
include(serenity_options)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE FILEPATH "Path to a compiler launcher program, e.g. ccache")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE FILEPATH "Path to a compiler launcher program, e.g. ccache")
endif()
if (NOT HACKSTUDIO_BUILD)
# FIXME: With cmake 3.18, we can change unzip/untar steps to use
# file( ARCHIVE_EXTRACT) instead
find_program(UNZIP unzip REQUIRED)
find_program(TAR tar REQUIRED)
# Host tools, required to generate files for the build
find_package(Lagom CONFIG REQUIRED)
endif()
# Meta target to run all code-gen steps in the build.
add_custom_target(all_generated)
add_custom_target(run
COMMAND "${CMAKE_COMMAND}" -E env "SERENITY_ARCH=${SERENITY_ARCH}" "${SerenityOS_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=${SerenityOS_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" "SERENITY_TOOLCHAIN=${CMAKE_CXX_COMPILER_ID}" "LLVM_VERSION=${CMAKE_CXX_COMPILER_VERSION}" "${SerenityOS_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=${SerenityOS_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" "SERENITY_TOOLCHAIN=${CMAKE_CXX_COMPILER_ID}" "LLVM_VERSION=${CMAKE_CXX_COMPILER_VERSION}" "${SerenityOS_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=${SerenityOS_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" "SERENITY_TOOLCHAIN=${CMAKE_CXX_COMPILER_ID}" "LLVM_VERSION=${CMAKE_CXX_COMPILER_VERSION}" "${SerenityOS_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 "${SerenityOS_SOURCE_DIR}/Meta/lint-shell-scripts.sh"
USES_TERMINAL
)
add_custom_target(check-style
COMMAND "${SerenityOS_SOURCE_DIR}/Meta/check-style.sh"
USES_TERMINAL
)
add_custom_target(install-ports
COMMAND "${CMAKE_COMMAND}" -E env "SERENITY_SOURCE_DIR=${SerenityOS_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" "SERENITY_TOOLCHAIN=${CMAKE_CXX_COMPILER_ID}" "${SerenityOS_SOURCE_DIR}/Meta/install-ports-tree.sh"
USES_TERMINAL
)
if (NOT HACKSTUDIO_BUILD)
add_custom_target(configure-components
COMMAND "$<TARGET_FILE:Lagom::ConfigureComponents>"
USES_TERMINAL
)
add_dependencies(configure-components Lagom::ConfigureComponents)
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (ENABLE_ALL_DEBUG_FACILITIES)
set(ENABLE_ALL_THE_DEBUG_MACROS ON)
set(ENABLE_EXTRA_KERNEL_DEBUG_SYMBOLS ON)
# Immediately finds violations during boot, shouldn't be discoverable
# by people who aren't working on fixing issues. Use this check to make
# sure this code continues to build instead of all_debug_macros to avoid
# people filing bugs.
set(KMALLOC_VERIFY_NO_SPINLOCK_HELD ON)
# Enables KCOV API and injects kernel coverage instrumentation via
# -fsanitize-coverage=trace-pc. Mostly here to ensure that the CI catches
# commits breaking this flag.
set(ENABLE_KERNEL_COVERAGE_COLLECTION ON)
endif()
if (ENABLE_ALL_THE_DEBUG_MACROS)
include(all_the_debug_macros)
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)
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)
# 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(-Wall)
add_compile_options(-Wextra)
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()
# 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-qual)
add_compile_options(-Wdeprecated-copy)
add_compile_options(-Wduplicated-cond)
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(-Wnon-virtual-dtor)
add_compile_options(-Wsuggest-override)
add_compile_options(-Wno-unknown-warning-option)
add_compile_options(-Wundef)
add_compile_options(-Wunused)
add_compile_options(-Wno-unused-command-line-argument)
add_compile_options(-Wwrite-strings)
add_compile_options(-fdiagnostics-color=always)
add_compile_options(-fno-delete-null-pointer-checks)
add_compile_options(-ffile-prefix-map=${SerenityOS_SOURCE_DIR}=.)
add_compile_options(-fno-exceptions)
add_compile_options(-fno-semantic-interposition)
add_compile_options(-fsized-deallocation)
add_compile_options(-fstack-clash-protection)
add_compile_options(-fstack-protector-strong)
add_compile_options(-g1)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wno-literal-suffix)
add_compile_options(-Wno-maybe-uninitialized)
# Only ignore expansion-to-defined for g++, clang's implementation doesn't complain about function-like macros
add_compile_options(-Wno-expansion-to-defined)
add_compile_options(-Wcast-align)
add_compile_options(-Wdouble-promotion)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
add_compile_options(-Wno-user-defined-literals)
add_compile_options(-Wno-atomic-alignment)
add_compile_options(-Wno-implicit-const-int-float-conversion)
add_compile_options(-Wno-unused-const-variable)
add_compile_options(-Wno-unused-private-field)
add_compile_options(-fconstexpr-steps=16777216)
# Clang doesn't add compiler_rt to the search path when compiling with -nostdlib.
link_directories(${TOOLCHAIN_ROOT}/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/${SERENITY_ARCH}-pc-serenity/)
endif()
add_link_options(LINKER:-z,text)
add_link_options(LINKER:--no-allow-shlib-undefined)
add_compile_definitions(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(-Wno-unused-command-line-argument)
include_directories(.)
include_directories(Userland/Libraries)
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
if (ENABLE_UNDEFINED_SANITIZER)
add_compile_options(-fsanitize=undefined -fno-sanitize=vptr)
add_link_options(-fsanitize=undefined -fno-sanitize=vptr)
endif()
add_custom_target(components ALL)
option(BUILD_EVERYTHING "Build all optional components" ON)
include(utils)
include(wasm_spec_tests)
serenity_component(
Tests
RECOMMENDED
)
if (HACKSTUDIO_BUILD)
include(${HACKSTUDIO_BUILD_CMAKE_FILE})
return()
endif()
add_subdirectory(AK)
add_subdirectory(Kernel)
if(NOT "${SERENITY_ARCH}" STREQUAL "aarch64")
if (ENABLE_MOLD_LINKER)
add_link_options(-fuse-ld=mold)
endif()
add_subdirectory(Userland)
add_subdirectory(Tests)
endif()
if (ENABLE_COMPILETIME_HEADER_CHECK)
add_subdirectory(Meta/HeaderCheck)
endif()
export_components("${CMAKE_BINARY_DIR}/components.ini")
set(PCI_IDS_FILE pci.ids)
set(PCI_IDS_GZ_URL https://pci-ids.ucw.cz/v2.2/${PCI_IDS_FILE}.gz)
set(PCI_IDS_GZ_PATH ${CMAKE_BINARY_DIR}/${PCI_IDS_FILE}.gz)
set(PCI_IDS_PATH ${CMAKE_BINARY_DIR}/${PCI_IDS_FILE})
set(PCI_IDS_INSTALL_PATH ${CMAKE_INSTALL_DATAROOTDIR}/${PCI_IDS_FILE})
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}...")
file(MAKE_DIRECTORY ${CMAKE_INSTALL_DATAROOTDIR})
execute_process(COMMAND gzip -d -c "${PCI_IDS_GZ_PATH}" OUTPUT_FILE "${PCI_IDS_INSTALL_PATH}")
endif()
set(USB_IDS_FILE usb.ids)
set(USB_IDS_GZ_URL http://www.linux-usb.org/${USB_IDS_FILE}.gz)
set(USB_IDS_GZ_PATH ${CMAKE_BINARY_DIR}/${USB_IDS_FILE}.gz)
set(USB_IDS_PATH ${CMAKE_BINARY_DIR}/${USB_IDS_FILE})
set(USB_IDS_INSTALL_PATH ${CMAKE_INSTALL_DATAROOTDIR}/${USB_IDS_FILE})
if(ENABLE_USB_IDS_DOWNLOAD AND NOT EXISTS ${USB_IDS_GZ_PATH})
message(STATUS "Downloading USB ID database from ${USB_IDS_GZ_URL}...")
file(DOWNLOAD ${USB_IDS_GZ_URL} ${USB_IDS_GZ_PATH} INACTIVITY_TIMEOUT 10)
endif()
if(EXISTS ${USB_IDS_GZ_PATH} AND NOT EXISTS ${USB_IDS_INSTALL_PATH})
message(STATUS "Extracting USB ID database from ${USB_IDS_GZ_PATH}...")
file(MAKE_DIRECTORY ${CMAKE_INSTALL_DATAROOTDIR})
execute_process(COMMAND gzip -d -c "${USB_IDS_GZ_PATH}" OUTPUT_FILE "${USB_IDS_INSTALL_PATH}")
endif()