2020-05-15 10:52:37 +03:00
|
|
|
cmake_minimum_required(VERSION 3.16)
|
|
|
|
project(SerenityOS C CXX ASM)
|
2020-05-06 18:40:06 +03:00
|
|
|
|
2020-06-06 04:23:31 +03:00
|
|
|
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
|
|
|
|
message(FATAL
|
|
|
|
": 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()
|
|
|
|
|
2020-06-19 17:52:39 +03:00
|
|
|
set(CMAKE_INSTALL_MESSAGE NEVER)
|
|
|
|
|
2020-05-06 18:40:06 +03:00
|
|
|
enable_testing()
|
|
|
|
|
2020-11-12 01:59:06 +03:00
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
2020-12-29 06:38:52 +03:00
|
|
|
set(SERENITY_ARCH "i686" CACHE STRING "Target architecture for SerenityOS.")
|
|
|
|
|
2021-01-01 13:26:52 +03:00
|
|
|
# Central location for all custom options used in the Serenity build.
|
2021-01-01 13:19:48 +03:00
|
|
|
option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer testing in gcc/clang" FALSE)
|
|
|
|
option(ENABLE_MEMORY_SANITIZER "Enable memory sanitizer testing in gcc/clang" FALSE)
|
|
|
|
option(ENABLE_UNDEFINED_SANITIZER "Enable undefined behavior sanitizer testing in gcc/clang" FALSE)
|
|
|
|
option(ENABLE_FUZZER_SANITIZER "Enable fuzzer sanitizer testing in clang" FALSE)
|
2021-01-01 13:26:52 +03:00
|
|
|
option(ENABLE_ALL_THE_DEBUG_MACROS "Enable all debug macros to validate they still compile" FALSE)
|
2021-01-01 13:44:04 +03:00
|
|
|
option(BUILD_LAGOM "Build parts of the system targeting the host OS for fuzzing/testing" FALSE)
|
2021-01-01 13:19:48 +03:00
|
|
|
|
2020-05-06 18:40:06 +03:00
|
|
|
add_custom_target(run
|
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/Meta/run.sh
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
|
|
|
|
2020-06-20 04:04:42 +03:00
|
|
|
add_custom_target(image
|
|
|
|
DEPENDS qemu-image
|
|
|
|
)
|
|
|
|
add_custom_target(qemu-image
|
2020-12-29 06:38:52 +03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E env "SERENITY_ROOT=${CMAKE_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" ${CMAKE_SOURCE_DIR}/Meta/build-image-qemu.sh
|
2020-06-20 04:04:42 +03:00
|
|
|
BYPRODUCTS ${CMAKE_BINARY_DIR}/_disk_image
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
2020-05-27 00:51:18 +03:00
|
|
|
add_custom_target(grub-image
|
2020-12-29 06:38:52 +03:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E env "SERENITY_ROOT=${CMAKE_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" ${CMAKE_SOURCE_DIR}/Meta/build-image-grub.sh
|
2020-05-28 11:08:38 +03:00
|
|
|
BYPRODUCTS ${CMAKE_BINARY_DIR}/grub_disk_image
|
2020-05-27 00:51:18 +03:00
|
|
|
USES_TERMINAL
|
|
|
|
)
|
|
|
|
|
2020-05-28 22:06:44 +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
|
|
|
|
)
|
|
|
|
|
2020-12-22 03:47:47 +03:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2020-12-26 10:42:36 +03:00
|
|
|
add_compile_options(-Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -Wformat=2 -fdiagnostics-color=always -ftls-model=initial-exec)
|
2020-12-22 04:04:46 +03:00
|
|
|
|
2020-08-04 18:08:03 +03:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
2020-12-22 04:04:46 +03:00
|
|
|
add_compile_options(-fconcepts)
|
2020-08-04 18:08:03 +03:00
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
2020-12-22 04:04:46 +03:00
|
|
|
add_compile_options(-Wno-overloaded-virtual)
|
2020-08-04 18:08:03 +03:00
|
|
|
endif()
|
2020-05-06 18:40:06 +03:00
|
|
|
|
2021-01-01 13:26:52 +03:00
|
|
|
if (ENABLE_ALL_THE_DEBUG_MACROS)
|
2020-12-23 20:07:22 +03:00
|
|
|
include(${CMAKE_SOURCE_DIR}/Meta/CMake/all_the_debug_macros.cmake)
|
2021-01-01 13:26:52 +03:00
|
|
|
endif(ENABLE_ALL_THE_DEBUG_MACROS)
|
2020-08-27 01:59:36 +03:00
|
|
|
|
2021-01-24 01:29:11 +03:00
|
|
|
configure_file(AK/Debug.h.in AK/Debug.h @ONLY)
|
2021-01-25 18:07:10 +03:00
|
|
|
configure_file(Kernel/Debug.h.in Kernel/Debug.h @ONLY)
|
2021-01-24 01:29:11 +03:00
|
|
|
|
2021-01-12 14:17:30 +03:00
|
|
|
include_directories(Userland/Libraries)
|
2020-05-06 18:40:06 +03:00
|
|
|
include_directories(.)
|
2021-01-24 01:29:11 +03:00
|
|
|
include_directories(${CMAKE_BINARY_DIR})
|
2020-05-06 18:40:06 +03:00
|
|
|
|
|
|
|
add_subdirectory(Meta/Lagom)
|
2021-01-12 14:18:55 +03:00
|
|
|
add_subdirectory(Userland/DevTools/IPCCompiler)
|
2021-01-12 14:17:30 +03:00
|
|
|
add_subdirectory(Userland/Libraries/LibWeb/CodeGenerators)
|
2020-05-06 18:40:06 +03:00
|
|
|
add_subdirectory(AK/Tests)
|
2021-01-12 14:17:30 +03:00
|
|
|
add_subdirectory(Userland/Libraries/LibRegex/Tests)
|
2020-05-06 18:40:06 +03:00
|
|
|
|
2020-08-02 16:54:06 +03:00
|
|
|
set(write_if_different ${CMAKE_SOURCE_DIR}/Meta/write-only-on-difference.sh)
|
|
|
|
|
2020-05-06 18:40:06 +03:00
|
|
|
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)
|
|
|
|
|
2020-12-29 06:38:52 +03:00
|
|
|
set(TOOLCHAIN_PATH ${CMAKE_SOURCE_DIR}/Toolchain/Local/${SERENITY_ARCH}/bin)
|
|
|
|
set(TOOLCHAIN_PREFIX ${TOOLCHAIN_PATH}/${SERENITY_ARCH}-pc-serenity-)
|
2020-05-06 18:40:06 +03:00
|
|
|
|
|
|
|
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}ranlib)
|
|
|
|
set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}strip)
|
|
|
|
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
|
|
|
|
|
2020-07-09 00:57:51 +03:00
|
|
|
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)
|
2021-01-07 13:39:24 +03:00
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES Darwin)
|
|
|
|
## MacOS Workaround. Don't generate install_name flag when cross compiling
|
|
|
|
set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
|
|
|
|
"<CMAKE_${lang}_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
|
|
|
endif()
|
2020-07-09 00:57:51 +03:00
|
|
|
endforeach()
|
|
|
|
|
2020-12-28 02:04:29 +03:00
|
|
|
set(CMAKE_INSTALL_NAME_TOOL "")
|
2020-07-09 00:57:51 +03:00
|
|
|
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
2021-01-05 18:42:45 +03:00
|
|
|
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-shared -Wl,--hash-style=gnu")
|
|
|
|
set(CMAKE_CXX_LINK_FLAGS "-Wl,--hash-style=gnu")
|
2020-07-09 00:57:51 +03:00
|
|
|
|
2021-01-07 02:55:01 +03:00
|
|
|
# We disable it completely because it makes cmake very spammy.
|
2020-12-28 02:04:29 +03:00
|
|
|
# This will need to be revisited when the Loader supports RPATH/RUN_PATH.
|
2021-01-07 02:55:01 +03:00
|
|
|
set(CMAKE_SKIP_RPATH TRUE)
|
2020-12-28 02:04:29 +03:00
|
|
|
|
2021-01-02 02:27:42 +03:00
|
|
|
add_compile_options(-Os -g1 -fno-exceptions -fstack-protector-strong -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-nonnull-compare -Wno-deprecated-copy -Wno-expansion-to-defined)
|
2020-12-22 04:04:46 +03:00
|
|
|
add_compile_options(-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.)
|
2020-05-06 18:40:06 +03:00
|
|
|
|
2020-12-22 04:04:46 +03:00
|
|
|
add_compile_definitions(DEBUG SANITIZE_PTRS)
|
2020-12-11 16:44:08 +03:00
|
|
|
set(CMAKE_CXX_FLAGS_STATIC "${CMAKE_CXX_FLAGS} -static")
|
2020-12-20 23:32:10 +03:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pie -fpic")
|
2021-01-01 13:20:55 +03:00
|
|
|
|
2021-02-08 20:26:28 +03:00
|
|
|
if (DBGLN_NO_COMPILETIME_FORMAT_CHECK)
|
|
|
|
add_compile_definitions(DBGLN_NO_COMPILETIME_FORMAT_CHECK)
|
|
|
|
endif()
|
|
|
|
|
2020-05-06 18:40:06 +03:00
|
|
|
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/LibM)
|
2021-02-05 14:16:30 +03:00
|
|
|
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)
|
2020-09-14 13:51:12 +03:00
|
|
|
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)
|
2020-05-06 18:40:06 +03:00
|
|
|
|
2020-05-26 21:20:24 +03:00
|
|
|
add_subdirectory(AK)
|
2020-05-06 18:40:06 +03:00
|
|
|
add_subdirectory(Kernel)
|
|
|
|
add_subdirectory(Userland)
|
2021-02-07 02:52:40 +03:00
|
|
|
|
|
|
|
set(PCI_IDS_URL https://pci-ids.ucw.cz/v2.2/pci.ids)
|
|
|
|
set(PCI_IDS_PATH ${CMAKE_INSTALL_DATAROOTDIR}/pci.ids)
|
|
|
|
if(NOT EXISTS ${PCI_IDS_PATH})
|
|
|
|
message(STATUS "Downloading PCI ID database from ${PCI_IDS_URL}...")
|
|
|
|
file(DOWNLOAD ${PCI_IDS_URL} ${PCI_IDS_PATH} INACTIVITY_TIMEOUT 10)
|
|
|
|
endif()
|