From 0942321b4f09db58927dcd56940785567e19db92 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 7 Oct 2023 11:31:42 +0200 Subject: build: perform cleaner split for platform settings --- source/CMakeLists.txt | 2 +- source/boot/CMakeLists.txt | 15 +++++++++++++++ source/boot/arch/x86_64/CMakeLists.txt | 4 +--- source/kernel/CMakeLists.txt | 33 +++++++++++++------------------- source/kernel/arch/x86_64/CMakeLists.txt | 30 +++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 24 deletions(-) create mode 100644 source/boot/CMakeLists.txt create mode 100644 source/kernel/arch/x86_64/CMakeLists.txt (limited to 'source') diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 80b566e..0ae9e40 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -7,5 +7,5 @@ project("kernel" LANGUAGES ASM C CXX ) -add_subdirectory("boot/arch/${CMAKE_SYSTEM_PROCESSOR}") +add_subdirectory("boot") add_subdirectory("kernel") diff --git a/source/boot/CMakeLists.txt b/source/boot/CMakeLists.txt new file mode 100644 index 0000000..5591d70 --- /dev/null +++ b/source/boot/CMakeLists.txt @@ -0,0 +1,15 @@ +#[============================================================================[ +# Configure the generic settings for the bootstrapping library. +# +# All the settings (e.g. include paths, linker flags, etc.) applied in this +# directly, are expected to be platform independent. +#]============================================================================] + +add_library("_boot" STATIC) +add_library("teachos::boot" ALIAS "_boot") + +#[============================================================================[ +# Apply the platform dependent settings to the bootstrapping library. +#]============================================================================] + +add_subdirectory("arch/${CMAKE_SYSTEM_PROCESSOR}") \ No newline at end of file diff --git a/source/boot/arch/x86_64/CMakeLists.txt b/source/boot/arch/x86_64/CMakeLists.txt index 454f347..0fd6539 100644 --- a/source/boot/arch/x86_64/CMakeLists.txt +++ b/source/boot/arch/x86_64/CMakeLists.txt @@ -1,8 +1,6 @@ -add_library("boot" STATIC +target_sources("_boot" PRIVATE "src/boot.s" "src/crti.s" "src/crtn.s" "src/multiboot.s" ) - -add_library("teachos::boot" ALIAS "boot") \ No newline at end of file diff --git a/source/kernel/CMakeLists.txt b/source/kernel/CMakeLists.txt index 48c9e4a..64b5bcf 100644 --- a/source/kernel/CMakeLists.txt +++ b/source/kernel/CMakeLists.txt @@ -1,9 +1,11 @@ -set(TEACHOS_KERNEL_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/arch/${CMAKE_SYSTEM_PROCESSOR}/kern.ld") -mark_as_advanced(TEACHOS_KERNEL_LINKER_SCRIPT) +#[============================================================================[ +# Configure the generic settings for the kernel image. +# +# All the settings (e.g. include paths, linker flags, etc.) applied in this +# directly, are expected to be platform independent. +#]============================================================================] -add_executable("kernel" - "arch/${CMAKE_SYSTEM_PROCESSOR}/src/entry.cpp" -) +add_executable("kernel") target_compile_features("kernel" PRIVATE "cxx_std_20" @@ -16,22 +18,13 @@ target_compile_options("kernel" PRIVATE "$<$:-pedantic-errors>" ) -target_include_directories("kernel" PRIVATE - "arch/${CMAKE_SYSTEM_PROCESSOR}/include" -) - -target_link_options("kernel" PRIVATE - "-T${TEACHOS_KERNEL_LINKER_SCRIPT}" -) - -target_link_libraries("kernel" PRIVATE - "-Wl,--whole-archive" - "teachos::boot" - "-Wl,--no-whole-archive" -) - set_target_properties("kernel" PROPERTIES CXX_EXTENSIONS OFF CXX_STANDARD_REQUIRED YES - LINK_DEPENDS "${TEACHOS_KERNEL_LINKER_SCRIPT}" ) + +#[============================================================================[ +# Apply the platform dependent settings to the kernel image. +#]============================================================================] + +add_subdirectory("arch/${CMAKE_SYSTEM_PROCESSOR}") \ No newline at end of file diff --git a/source/kernel/arch/x86_64/CMakeLists.txt b/source/kernel/arch/x86_64/CMakeLists.txt new file mode 100644 index 0000000..04701c6 --- /dev/null +++ b/source/kernel/arch/x86_64/CMakeLists.txt @@ -0,0 +1,30 @@ +#[============================================================================[ +# x86_64 specific configuration for the kernel image. +#]============================================================================] + +set(TEACHOS_KERNEL_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/kern.ld") +mark_as_advanced(TEACHOS_KERNEL_LINKER_SCRIPT) + +target_sources("kernel" PRIVATE + "src/entry.cpp" +) + +target_include_directories("kernel" PRIVATE + "include" +) + +target_link_options("kernel" PRIVATE + "-T${TEACHOS_KERNEL_LINKER_SCRIPT}" +) + +target_link_libraries("kernel" PRIVATE + "-Wl,--whole-archive" + "teachos::boot" + "-Wl,--no-whole-archive" +) + +set_target_properties("kernel" PROPERTIES + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED YES + LINK_DEPENDS "${TEACHOS_KERNEL_LINKER_SCRIPT}" +) -- cgit v1.2.3