Meta: Make it possible to (somewhat) build the system inside Serenity

This removes some hard references to the toolchain, some unnecessary
uses of an external install command, and disables a -Werror flag (for
the time being) - only if run inside serenity.

With this, we can build and link the kernel :^)
This commit is contained in:
AnotherTest 2021-02-15 01:19:25 +03:30 committed by Andreas Kling
parent 80d6f46d4e
commit 5729e76c7d
Notes: sideshowbarker 2024-07-18 22:14:31 +09:00
3 changed files with 27 additions and 20 deletions

View file

@ -69,7 +69,14 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES SerenityOS)
# 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(-Wno-unknown-warning-option -Wall -Wextra -Wmissing-declarations -Wformat=2 -fdiagnostics-color=always -ftls-model=initial-exec)
else()
add_compile_options(-Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -Wformat=2 -fdiagnostics-color=always -ftls-model=initial-exec)
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fconcepts)
@ -106,6 +113,9 @@ 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)
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES SerenityOS)
message("Good job on building cmake!")
else()
set(TOOLCHAIN_PATH ${CMAKE_SOURCE_DIR}/Toolchain/Local/${SERENITY_ARCH}/bin)
set(TOOLCHAIN_PREFIX ${TOOLCHAIN_PATH}/${SERENITY_ARCH}-pc-serenity-)
@ -116,6 +126,7 @@ set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib)
set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}strip)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
endif()
foreach(lang ASM C CXX OBJC OBJCXX)
unset(CMAKE_${lang}_OSX_COMPATIBILITY_VERSION_FLAG)

View file

@ -306,7 +306,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pie -fPIE -fno-rtti -ffreestanding -fbu
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-80387 -mno-mmx -mno-sse -mno-sse2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-asynchronous-unwind-tables")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong")
if (NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES SerenityOS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -nostdinc -nostdinc++")
endif()
# Kernel Address Sanitize (KASAN) implementation is still a work in progress, this option
# is not currently meant to be used, besides when developing Kernel ASAN support.
@ -329,7 +331,6 @@ file(GENERATE OUTPUT linker.ld INPUT linker.ld)
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES SerenityOS)
include_directories(/usr/local/include/c++/10.2.0/)
include_directories(/usr/local/include/c++/10.2.0/${SERENITY_ARCH}-pc-serenity/)
else()
include_directories(../Toolchain/Local/${SERENITY_ARCH}/${SERENITY_ARCH}-pc-serenity/include/c++/10.2.0/)
include_directories(../Toolchain/Local/${SERENITY_ARCH}/${SERENITY_ARCH}-pc-serenity/include/c++/10.2.0/${SERENITY_ARCH}-pc-serenity/)

View file

@ -56,20 +56,15 @@ set(ELF_SOURCES ${ELF_SOURCES} ../LibELF/Arch/i386/plt_trampoline.S)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -DSERENITY_LIBC_BUILD")
find_program(INSTALL_COMMAND ginstall)
if(NOT INSTALL_COMMAND)
set(INSTALL_COMMAND install)
endif()
add_library(crt0 STATIC crt0.cpp)
add_custom_command(
TARGET crt0
COMMAND ${INSTALL_COMMAND} -D $<TARGET_OBJECTS:crt0> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0.o
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:crt0> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0.o
)
add_library(crt0_shared STATIC crt0_shared.cpp)
add_custom_command(
TARGET crt0_shared
COMMAND ${INSTALL_COMMAND} -D $<TARGET_OBJECTS:crt0_shared> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0_shared.o
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:crt0_shared> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0_shared.o
)
set_source_files_properties (ssp.cpp PROPERTIES COMPILE_FLAGS
@ -77,7 +72,7 @@ set_source_files_properties (ssp.cpp PROPERTIES COMPILE_FLAGS
add_library(ssp STATIC ssp.cpp)
add_custom_command(
TARGET ssp
COMMAND ${INSTALL_COMMAND} -D $<TARGET_OBJECTS:ssp> ${CMAKE_INSTALL_PREFIX}/usr/lib/ssp.o
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:ssp> ${CMAKE_INSTALL_PREFIX}/usr/lib/ssp.o
)
set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ELF_SOURCES})