From ae9ce33e3c3e738b99da7fabeb91afbbe0bda496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 00:03:03 +0200 Subject: [PATCH 01/28] refactor: Move compile options to target.properties interface library --- alkos/CMakeLists.txt | 2 ++ alkos/libc/CMakeLists.txt | 12 +------- alkos/libc/arch/x86_64/CMakeLists.txt | 4 +++ .../{x86_64-flags.cmake => x86_64-conf.cmake} | 28 +++++++++++++++++++ scripts/config/configure.bash | 2 +- 5 files changed, 36 insertions(+), 12 deletions(-) rename alkos/toolchains/{x86_64-flags.cmake => x86_64-conf.cmake} (64%) diff --git a/alkos/CMakeLists.txt b/alkos/CMakeLists.txt index 867c6a979..d589aef29 100644 --- a/alkos/CMakeLists.txt +++ b/alkos/CMakeLists.txt @@ -20,6 +20,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(ValidationHelpers) include(SourceHelpers) +add_library(target.properties INTERFACE) # Populated by the toolchain file + ################################################################################ # Conf file # ################################################################################ diff --git a/alkos/libc/CMakeLists.txt b/alkos/libc/CMakeLists.txt index 1e8efedb2..97b4ff544 100644 --- a/alkos/libc/CMakeLists.txt +++ b/alkos/libc/CMakeLists.txt @@ -30,17 +30,7 @@ set_target_properties(lib${LIB_NAME} PROPERTIES OUTPUT_NAME "${LIB_NAME}") ############################# Setting Custom Properties ######################### -target_compile_options(lib${LIB_NAME} PRIVATE - "$<$:-mcmodel=kernel>" - "$<$:-mno-red-zone>" - "$<$:-mcmodel=kernel>" - "$<$:-mno-red-zone>" -) -target_compile_options(lib${LIB_NAME}.32 PRIVATE - "$<$:-mno-red-zone>" - "$<$:-mno-red-zone>" -) - +target_link_libraries(lib${LIB_NAME} PUBLIC target.properties) ############################### Adding includes ############################### diff --git a/alkos/libc/arch/x86_64/CMakeLists.txt b/alkos/libc/arch/x86_64/CMakeLists.txt index 8286556ad..f188313b4 100644 --- a/alkos/libc/arch/x86_64/CMakeLists.txt +++ b/alkos/libc/arch/x86_64/CMakeLists.txt @@ -15,6 +15,10 @@ target_include_directories(lib${LIB_NAME}.32 PRIVATE ../../internal ) +############################# Setting Custom Properties ######################### + +target_link_libraries(lib${LIB_NAME}.32 INTERFACE target.properties.32) + ################################# Dependencies ################################ add_dependencies(lib${LIB_NAME}.32 lib${LIB_NAME}) diff --git a/alkos/toolchains/x86_64-flags.cmake b/alkos/toolchains/x86_64-conf.cmake similarity index 64% rename from alkos/toolchains/x86_64-flags.cmake rename to alkos/toolchains/x86_64-conf.cmake index 225afdae2..766b8cf84 100644 --- a/alkos/toolchains/x86_64-flags.cmake +++ b/alkos/toolchains/x86_64-conf.cmake @@ -35,3 +35,31 @@ elseif (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RELEAS else () message(FATAL_ERROR "UNKNOWN BUILD TYPE: ${CMAKE_BUILD_TYPE}") endif () + +################################################################################ +# Property Interface Libraries # +################################################################################ + +if (NOT TARGET target.properties) + message(FATAL_ERROR "target.properties INTERFACE library is not defined. This should be defined by main CMakeLists.txt") +endif () + +#################################### 64 bit #################################### + +target_compile_options(target.properties INTERFACE + "$<$:-mcmodel=kernel>" + "$<$:-mno-red-zone>" + "$<$:-mcmodel=kernel>" + "$<$:-mno-red-zone>" + "$<$:-f elf64>" +) + +#################################### 32 bit #################################### + +add_library(target.properties.32 INTERFACE) +target_compile_options(target.properties.32 INTERFACE + "$<$:-m32>" + "$<$:-m32>" + "$<$:-f elf32>" +) + diff --git a/scripts/config/configure.bash b/scripts/config/configure.bash index 5dae46f0b..196a4e455 100755 --- a/scripts/config/configure.bash +++ b/scripts/config/configure.bash @@ -14,7 +14,7 @@ declare -A CONFIGURE_TOOLCHAINS=( ) declare -A CONFIGURE_FLAGS=( - ["x86_64"]="${CONFIGURE_TOOLCHAIN_DIR}/x86_64-flags.cmake" + ["x86_64"]="${CONFIGURE_TOOLCHAIN_DIR}/x86_64-conf.cmake" ) declare -A CONFIGURE_BUILD_TYPES_DESC=( From 18aca3fad64eb3d05cc8984dbb56c86e9d5612de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 00:08:17 +0200 Subject: [PATCH 02/28] refactor: Remove post-arch action and consolidate target properties linking --- alkos/kernel/CMakeLists.txt | 13 ------------- alkos/kernel/arch/x86_64/kernel/CMakeLists.txt | 7 ++----- alkos/libc/arch/x86_64/CMakeLists.txt | 2 +- alkos/toolchains/x86_64-conf.cmake | 9 ++++++--- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index e00976f5a..80f380162 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -107,19 +107,6 @@ add_subdirectory(thirdparty) target_link_libraries(alkos.kernel PRIVATE libk gcc ${THIRD_PARTY_LIBRARIES} AutoGenLib) -############################## Post Arch Action ############################## - -# Note: architecture file has a possibility to define custom command to run -# before linking -if (DEFINED POST_ARCH_ACTION) - message(STATUS "POST ACTION: ${POST_ARCH_ACTION}") - - add_custom_command(TARGET alkos.kernel PRE_LINK - COMMAND ${POST_ARCH_ACTION} - COMMENT "Running post build arch action" - ) -endif () - ############## Linker Configuration for CXX Global Constructors ############## # Set the linker to link objects in the correct order # NOTE: ARCH cmake is expected to provide variables for global constructors diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index 85ab462a8..60c994543 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -33,11 +33,8 @@ target_link_options(alkos.kernel PRIVATE ######################### Setting Custom Properties ########################## -target_compile_options(alkos.kernel PRIVATE - "$<$:-mcmodel=kernel>" - "$<$:-mno-red-zone>" - "$<$:-mcmodel=kernel>" - "$<$:-mno-red-zone>" +target_link_libraries(alkos.kernel PRIVATE + target.properties ) ########################## CXX Global Constructors ########################### diff --git a/alkos/libc/arch/x86_64/CMakeLists.txt b/alkos/libc/arch/x86_64/CMakeLists.txt index f188313b4..05b8784c2 100644 --- a/alkos/libc/arch/x86_64/CMakeLists.txt +++ b/alkos/libc/arch/x86_64/CMakeLists.txt @@ -17,7 +17,7 @@ target_include_directories(lib${LIB_NAME}.32 PRIVATE ############################# Setting Custom Properties ######################### -target_link_libraries(lib${LIB_NAME}.32 INTERFACE target.properties.32) +target_link_libraries(lib${LIB_NAME}.32 PUBLIC target.properties.32) ################################# Dependencies ################################ diff --git a/alkos/toolchains/x86_64-conf.cmake b/alkos/toolchains/x86_64-conf.cmake index 766b8cf84..e4e9e363c 100644 --- a/alkos/toolchains/x86_64-conf.cmake +++ b/alkos/toolchains/x86_64-conf.cmake @@ -44,7 +44,9 @@ if (NOT TARGET target.properties) message(FATAL_ERROR "target.properties INTERFACE library is not defined. This should be defined by main CMakeLists.txt") endif () -#################################### 64 bit #################################### +#------------------------------------------------------------------------------# +# 64 bit # +#------------------------------------------------------------------------------# target_compile_options(target.properties INTERFACE "$<$:-mcmodel=kernel>" @@ -53,8 +55,9 @@ target_compile_options(target.properties INTERFACE "$<$:-mno-red-zone>" "$<$:-f elf64>" ) - -#################################### 32 bit #################################### +#------------------------------------------------------------------------------# +# 32 bit # +#------------------------------------------------------------------------------# add_library(target.properties.32 INTERFACE) target_compile_options(target.properties.32 INTERFACE From a0c686207bf9201cd550aee13b14072b7c485cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 00:10:59 +0200 Subject: [PATCH 03/28] refactor: Update 32-bit loader CMake configuration to use target properties instead of source file flags --- alkos/kernel/arch/x86_64/loader32/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt index 2e6641f5a..4fbebb769 100644 --- a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt @@ -33,9 +33,7 @@ target_include_directories(alkos.loader32 PRIVATE .) ################################ Exec Flags ################################## -set_source_files_properties(${ARCH_SOURCES_32} PROPERTIES COMPILE_FLAGS "-m32") - -set_source_files_properties(${ARCH_ASM_32} PROPERTIES COMPILE_FLAGS "-f elf32 ") +target_link_libraries(alkos.loader32 PRIVATE target.properties.32) set(CMAKE_ASM_NASM_COMPILE_OBJECT " -o ") From 196a7ad3e14c4d34e61733debf7322be5e172b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 00:14:47 +0200 Subject: [PATCH 04/28] refactor: Simplify source file handling in CMakeLists.txt for x86_64 architecture --- .../x86_64/common-loader-all/CMakeLists.txt | 54 +++---------------- .../arch/x86_64/loader32/CMakeLists.txt | 24 +++------ 2 files changed, 14 insertions(+), 64 deletions(-) diff --git a/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt b/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt index 28bd8dda0..a00729961 100644 --- a/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt @@ -1,65 +1,27 @@ message(STATUS "Configuring x86_64 common-loader-all") -############################## Finding Sources ############################### - -# TODO: Update this when there is a separate solution to applying custom properties based on file extensions -# for .c, .cpp and .asm files, prefferably from an arch defined preset - -file(GLOB_RECURSE COMMON_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/*.c" -) - -file(GLOB_RECURSE COMMON_ASM - "${CMAKE_CURRENT_SOURCE_DIR}/*.s" - "${CMAKE_CURRENT_SOURCE_DIR}/*.S" - "${CMAKE_CURRENT_SOURCE_DIR}/*.asm" - "${CMAKE_CURRENT_SOURCE_DIR}/*.nasm" -) - -file(GLOB_RECURSE COMMON_ASM_32 - "${CMAKE_CURRENT_SOURCE_DIR}/*.s" - "${CMAKE_CURRENT_SOURCE_DIR}/*.S" - "${CMAKE_CURRENT_SOURCE_DIR}/*.asm" - "${CMAKE_CURRENT_SOURCE_DIR}/*.nasm" -) - ############################## Preparing targets ############################### -add_library(arch.common.all.64 OBJECT - ${COMMON_SOURCES} - ${COMMON_ASM} -) +add_library(arch.common.all.64 OBJECT) +add_library(arch.common.all.32 OBJECT) -add_library(arch.common.all.32 OBJECT - ${COMMON_SOURCES} - ${COMMON_ASM_32} -) +############################## Finding Sources ############################### + +alkos_target_sources(arch.common.all.64) +alkos_target_sources(arch.common.all.32) ############################# Linking libraries ############################## target_link_libraries(arch.common.all.64 PRIVATE libk + target.properties ) target_link_libraries(arch.common.all.32 PRIVATE libk.32 + target.properties.32 ) -######################### Setting Custom Properties ########################## - -target_compile_options(arch.common.all.64 PRIVATE - "$<$:-mcmodel=kernel>" - "$<$:-mno-red-zone>" - "$<$:-mcmodel=kernel>" - "$<$:-mno-red-zone>" -) -target_compile_options(arch.common.all.32 PRIVATE - "$<$:-mno-red-zone>" - "$<$:-mno-red-zone>" -) - - ############################### Applying Flags ############################### target_compile_options(arch.common.all.32 PRIVATE "-m32") diff --git a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt index 4fbebb769..6da19e8e1 100644 --- a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt @@ -1,29 +1,17 @@ message(STATUS "Configuring x86_64 32-bit loader") -############################## Finding Sources ############################### - -# TODO: Use alkos_find_sources() to find Sources -# But this requires adding another function that will -# handle adding compiler flags appropriately for 32-bit .c, .cpp and .asm files -file(GLOB_RECURSE ARCH_SOURCES_32 - "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/*.c" -) - -file(GLOB_RECURSE ARCH_ASM_32 - "${CMAKE_CURRENT_SOURCE_DIR}/*.s" - "${CMAKE_CURRENT_SOURCE_DIR}/*.S" - "${CMAKE_CURRENT_SOURCE_DIR}/*.asm" - "${CMAKE_CURRENT_SOURCE_DIR}/*.nasm" -) #################################### Exec #################################### add_executable(alkos.loader32 - ${ARCH_SOURCES_32} - ${ARCH_ASM_32} ) +############################## Finding Sources ############################### + +alkos_target_sources(alkos.loader32) + +############################## Finding CXX Compiler ############################ + message(STATUS "32 bit compiler: ${CMAKE_CXX_COMPILER_32}") set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_COMPILER_32} -o ") From 8d6ada843297a486dce79cfa2a5f5eca7f2a411d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 00:19:42 +0200 Subject: [PATCH 05/28] refactor: Simplify CMakeLists.txt by removing redundant source file handling and consolidating target properties --- .../common-loader-64-kernel/CMakeLists.txt | 31 +++---------------- .../x86_64/common-loader-all/CMakeLists.txt | 5 --- alkos/kernel/thirdparty/uacpi/CMakeLists.txt | 5 ++- 3 files changed, 7 insertions(+), 34 deletions(-) diff --git a/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt index 1dc3bfb6a..bb5b03041 100644 --- a/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt @@ -1,36 +1,19 @@ message(STATUS "Configuring common-loader-64-kernel") -############################## Finding Sources ############################### - -file(GLOB_RECURSE COMMON_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/*.c" -) - -file(GLOB_RECURSE COMMON_ASM - "${CMAKE_CURRENT_SOURCE_DIR}/*.s" - "${CMAKE_CURRENT_SOURCE_DIR}/*.S" - "${CMAKE_CURRENT_SOURCE_DIR}/*.asm" - "${CMAKE_CURRENT_SOURCE_DIR}/*.nasm" -) - ############################## Preparing targets ############################### add_library(arch.common.kernel-loader.64 OBJECT - ${COMMON_SOURCES} - ${COMMON_ASM} ) +############################## Finding Sources ############################### + +alkos_target_sources(arch.common.kernel-loader.64) ######################### Setting Custom Properties ########################## -target_compile_options(arch.common.kernel-loader.64 PRIVATE - "$<$:-mcmodel=kernel>" - "$<$:-mno-red-zone>" - "$<$:-mcmodel=kernel>" - "$<$:-mno-red-zone>" +target_link_libraries(arch.common.kernel-loader.64 PRIVATE + target.properties ) - ############################# Linking libraries ############################## target_link_libraries(arch.common.kernel-loader.64 PRIVATE @@ -38,10 +21,6 @@ target_link_libraries(arch.common.kernel-loader.64 PRIVATE arch.common.all.64 ) -############################### Applying Flags ############################### - -set_source_files_properties(${COMMON_ASM} PROPERTIES COMPILE_FLAGS "-f elf64") - ############################### Adding Headers ############################### target_include_directories(alkos.kernel.headers INTERFACE diff --git a/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt b/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt index a00729961..117aebe10 100644 --- a/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt @@ -24,13 +24,8 @@ target_link_libraries(arch.common.all.32 PRIVATE ############################### Applying Flags ############################### -target_compile_options(arch.common.all.32 PRIVATE "-m32") - set(CMAKE_ASM_NASM_COMPILE_OBJECT " -o ") -set_source_files_properties(${COMMON_ASM_32} PROPERTIES COMPILE_FLAGS "-f elf32") -set_source_files_properties(${COMMON_ASM} PROPERTIES COMPILE_FLAGS "-f elf64") - ############################### Adding Headers ############################### target_include_directories(alkos.kernel.headers INTERFACE diff --git a/alkos/kernel/thirdparty/uacpi/CMakeLists.txt b/alkos/kernel/thirdparty/uacpi/CMakeLists.txt index 28521fe55..11f047951 100644 --- a/alkos/kernel/thirdparty/uacpi/CMakeLists.txt +++ b/alkos/kernel/thirdparty/uacpi/CMakeLists.txt @@ -36,9 +36,8 @@ target_link_libraries(uacpi PRIVATE libk) ######################### Setting Custom Properties ########################## -target_compile_options(uacpi PRIVATE - "$<$:-mcmodel=kernel>" - "$<$:-mcmodel=kernel>" +target_link_libraries(uacpi PRIVATE + target.properties ) # Propagate the uACPI library to the parent scope From 0a3783328885dbdf57f757f638891df57de4851e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 01:22:47 +0200 Subject: [PATCH 06/28] refactor: Simplify third-party library linking in kernel build system --- alkos/kernel/CMakeLists.txt | 6 +++++- alkos/kernel/thirdparty/CMakeLists.txt | 7 ++----- alkos/kernel/thirdparty/uacpi/CMakeLists.txt | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 80f380162..1899fffe8 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -103,9 +103,13 @@ endif() message(STATUS "Adding third-party libraries...") add_subdirectory(thirdparty) +target_link_libraries(alkos.kernel.headers INTERFACE + alkos.kernel.thirdparty +) + ################################## Linking ################################### -target_link_libraries(alkos.kernel PRIVATE libk gcc ${THIRD_PARTY_LIBRARIES} AutoGenLib) +target_link_libraries(alkos.kernel PRIVATE libk gcc AutoGenLib) ############## Linker Configuration for CXX Global Constructors ############## # Set the linker to link objects in the correct order diff --git a/alkos/kernel/thirdparty/CMakeLists.txt b/alkos/kernel/thirdparty/CMakeLists.txt index 530ad2952..1ce318828 100644 --- a/alkos/kernel/thirdparty/CMakeLists.txt +++ b/alkos/kernel/thirdparty/CMakeLists.txt @@ -1,14 +1,11 @@ include(FetchContent) -set(THIRD_PARTY_LIBRARIES "") +add_library(alkos.kernel.thirdparty INTERFACE) -# Iterate over all dependencies and add them to the project +# Iterate over all dependencies and add them to the thirdparty library file(GLOB directories RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) foreach(dir ${directories}) if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir}) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir}) endif() endforeach() - -# Propagate the third-party libraries to the parent scope -set(THIRD_PARTY_LIBRARIES ${THIRD_PARTY_LIBRARIES} PARENT_SCOPE) diff --git a/alkos/kernel/thirdparty/uacpi/CMakeLists.txt b/alkos/kernel/thirdparty/uacpi/CMakeLists.txt index 11f047951..b3f8e5312 100644 --- a/alkos/kernel/thirdparty/uacpi/CMakeLists.txt +++ b/alkos/kernel/thirdparty/uacpi/CMakeLists.txt @@ -40,5 +40,6 @@ target_link_libraries(uacpi PRIVATE target.properties ) -# Propagate the uACPI library to the parent scope -set(THIRD_PARTY_LIBRARIES ${THIRD_PARTY_LIBRARIES} uacpi PARENT_SCOPE) +################################ Export itself ################################# + +target_link_libraries(alkos.kernel.thirdparty INTERFACE uacpi) From 3858125384c653a7f759d96de41c531215574943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 01:25:59 +0200 Subject: [PATCH 07/28] chore: Move third-party library status messages to appropriate CMakeLists.txt files --- alkos/kernel/CMakeLists.txt | 1 - alkos/kernel/thirdparty/CMakeLists.txt | 1 + alkos/kernel/thirdparty/uacpi/CMakeLists.txt | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 1899fffe8..cb7ad0f52 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -100,7 +100,6 @@ endif() ################################# ThirdParty ################################# -message(STATUS "Adding third-party libraries...") add_subdirectory(thirdparty) target_link_libraries(alkos.kernel.headers INTERFACE diff --git a/alkos/kernel/thirdparty/CMakeLists.txt b/alkos/kernel/thirdparty/CMakeLists.txt index 1ce318828..9c2237786 100644 --- a/alkos/kernel/thirdparty/CMakeLists.txt +++ b/alkos/kernel/thirdparty/CMakeLists.txt @@ -1,3 +1,4 @@ +message(STATUS "Adding third-party libraries...") include(FetchContent) add_library(alkos.kernel.thirdparty INTERFACE) diff --git a/alkos/kernel/thirdparty/uacpi/CMakeLists.txt b/alkos/kernel/thirdparty/uacpi/CMakeLists.txt index b3f8e5312..2548db338 100644 --- a/alkos/kernel/thirdparty/uacpi/CMakeLists.txt +++ b/alkos/kernel/thirdparty/uacpi/CMakeLists.txt @@ -1,3 +1,5 @@ +message(STATUS "-> uACPI...") + ####################################################################### # uACPI # ####################################################################### From faf0d381d657d16cc930940ba97653219487ef59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 02:00:58 +0200 Subject: [PATCH 08/28] refactor: Use target properties for kernel configuration and CRT objects --- alkos/CMakeLists.txt | 16 ++- alkos/cmake/ValidationHelpers.cmake | 67 ++++++++++- alkos/kernel/CMakeLists.txt | 107 ++++++++---------- alkos/kernel/arch/x86_64/CMakeLists.txt | 19 ++-- .../kernel/arch/x86_64/kernel/CMakeLists.txt | 4 +- 5 files changed, 134 insertions(+), 79 deletions(-) diff --git a/alkos/CMakeLists.txt b/alkos/CMakeLists.txt index d589aef29..cf77fd20a 100644 --- a/alkos/CMakeLists.txt +++ b/alkos/CMakeLists.txt @@ -88,9 +88,21 @@ add_subdirectory(libc) add_subdirectory(generated) add_subdirectory(kernel) +get_property(BOOTABLE_KERNEL_EXECUTABLE TARGET alkos.kernel.config PROPERTY BOOTABLE_KERNEL_EXECUTABLE) +get_property(KERNEL_MODULES TARGET alkos.kernel.config PROPERTY KERNEL_MODULES) +get_property(KERNEL_COMMANDS TARGET alkos.kernel.config PROPERTY KERNEL_COMMANDS) +get_property(ARCH_QEMU_COMMAND TARGET alkos.kernel.config PROPERTY ARCH_QEMU_COMMAND) +get_property(ARCH_QEMU_NORMAL_FLAGS TARGET alkos.kernel.config PROPERTY ARCH_QEMU_NORMAL_FLAGS) +get_property(ARCH_QEMU_TEST_FLAGS TARGET alkos.kernel.config PROPERTY ARCH_QEMU_TEST_FLAGS) + alkos_ensure_defined( - VARS BOOTABLE_KERNEL_EXECUTABLE - MESSAGE "No primary kernel executable defined by the end of the configuration." + VARS + BOOTABLE_KERNEL_EXECUTABLE + KERNEL_MODULES + KERNEL_COMMANDS + ARCH_QEMU_COMMAND + ARCH_QEMU_NORMAL_FLAGS + ARCH_QEMU_TEST_FLAGS ) ################################################################################ diff --git a/alkos/cmake/ValidationHelpers.cmake b/alkos/cmake/ValidationHelpers.cmake index c8dd7d590..6c33b4317 100644 --- a/alkos/cmake/ValidationHelpers.cmake +++ b/alkos/cmake/ValidationHelpers.cmake @@ -7,8 +7,8 @@ # alkos_ensure_defined #=============================================================================== # -# Checks if one or more variables are defined and halts with a fatal error, -# listing all undefined variables at once. +# Checks if one or more variables are defined (and nonempty) and halts with a +# fatal error, listing all undefined variables at once. # # Parameters: # VARS ... A list of variable names to check. @@ -45,6 +45,9 @@ function(alkos_ensure_defined) if(NOT DEFINED ${var_name}) list(APPEND undefined_vars "${var_name}") endif() + if(${var_name} STREQUAL "") + list(APPEND undefined_vars "${var_name}") + endif() endforeach() if(undefined_vars) @@ -59,3 +62,63 @@ function(alkos_ensure_defined) message(FATAL_ERROR "${error_message}") endif() endfunction() + +#=============================================================================== +# alkos_ensure_property_defined +#=============================================================================== +# +# Checks if a property is defined for a target and halts with a fatal error_message, +# listing all undefined properties at once. +# +# Parameters: +# TARGET The target to check the properties for. +# PROPS ... A list of property names to check. +# MESSAGE (Optional) A supplementary message to append to the +# standard error output. This is useful for providing +# additional context or instructions to the user. +# +# Example: +# # Assume alkos.kernel.config is a target and BOOTABLE_KERNEL_EXECUTABLE +# # is not defined. +# alkos_ensure_property_defined( +# TARGET alkos.kernel.config +# PROPS BOOTABLE_KERNEL_EXECUTABLE KERNEL_MODULES +# MESSAGE "The BOOTABLE_KERNEL_EXECUTABLE property must be set for the KERNEL_MODULES target." +# ) +# +function(alkos_ensure_property_defined) + set(options) + set(oneValueArgs MESSAGE) + set(multiValueArgs TARGET PROPS) + + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT ARG_TARGET) + message(FATAL_ERROR "alkos_ensure_property_defined() called without a TARGET to check.") + endif() + + if(NOT ARG_PROPS) + message(FATAL_ERROR "alkos_ensure_property_defined() called without any PROPS to check.") + endif() + + set(undefined_props "") + foreach(prop_name ${ARG_PROPS}) + get_property(is_defined TARGET ${ARG_TARGET} PROPERTY ${prop_name} DEFINED) + if(NOT is_defined) + list(APPEND undefined_props "${prop_name}") + endif() + endforeach() + + if(undefined_props) + string(JOIN ", " undefined_props_str "${undefined_props}") + + set(error_message "The following required properties are not defined for target '${ARG_TARGET}': ${undefined_props_str}") + + if(ARG_MESSAGE) + string(APPEND error_message "\n${ARG_MESSAGE}") + endif() + + message(FATAL_ERROR "${error_message}") + endif() +endfunction() + diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index cb7ad0f52..9342665e4 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -1,5 +1,9 @@ message(STATUS "Configuring kernel...") +# This target acts as a central hub for configuration data (e.g., kernel modules) +# that needs to be communicated to the top-level CMakeLists.txt. +add_library(alkos.kernel.config INTERFACE) + ############################### Error Checking ############################### alkos_ensure_defined( @@ -11,19 +15,6 @@ alkos_ensure_defined( add_compile_definitions(__ALKOS_KERNEL__=1) add_compile_definitions(__ALKOS_LIBK__=1) # For LIBK headers -############################# Arch Dependent Vars ############################ - -# ---------------------------------------------------------------------------- -# Arch can optionally create other executables (for chainloading, etc) -# They need to place themselves in sysroot/boot -# This is the list of executables that will be loaded by the bootloader as -# modules -set(KERNEL_MODULES "") -# ---------------------------------------------------------------------------- -# This is the executable that the bootloader will give control to -set(BOOTABLE_KERNEL_EXECUTABLE alkos.kernel) -# ---------------------------------------------------------------------------- - ########################### Setting Sysroot Boot ############################# file(MAKE_DIRECTORY ${SYSROOT}/boot) @@ -72,31 +63,9 @@ target_link_libraries(alkos.kernel PRIVATE add_subdirectory(arch/${ARCH}) -############################### Error Checking ############################### - -alkos_ensure_defined( - VARS - BOOTABLE_KERNEL_EXECUTABLE - KERNEL_MODULES - KERNEL_COMMANDS - ARCH_QEMU_COMMAND - ARCH_QEMU_NORMAL_FLAGS - ARCH_QEMU_TEST_FLAGS - CRTI_OBJ - CRTN_OBJ -) - -message(STATUS "Bootable kernel executable: ${BOOTABLE_KERNEL_EXECUTABLE}") -message(STATUS "Kernel modules: ${KERNEL_MODULES}") -message(STATUS "Kernel commands: ${KERNEL_COMMANDS}") - -list(LENGTH KERNEL_MODULES KERNEL_MODULES_LENGTH) -list(LENGTH KERNEL_COMMANDS KERNEL_COMMANDS_LENGTH) - -# Check if the two lists are the same size -if(NOT KERNEL_MODULES_LENGTH EQUAL KERNEL_COMMANDS_LENGTH) - message(FATAL_ERROR "KERNEL_MODULES and KERNEL_COMMANDS have different sizes: ${KERNEL_MODULES_LENGTH} vs ${KERNEL_COMMANDS_LENGTH}") -endif() +# TODO: Immediately here, error checking should happen +# But the error checking itself fails!!! and for some reason +# alkos_ensure_property_defined() says the property is not defined ################################# ThirdParty ################################# @@ -108,35 +77,51 @@ target_link_libraries(alkos.kernel.headers INTERFACE ################################## Linking ################################### -target_link_libraries(alkos.kernel PRIVATE libk gcc AutoGenLib) +target_link_libraries(alkos.kernel PRIVATE libk AutoGenLib) ############## Linker Configuration for CXX Global Constructors ############## -# Set the linker to link objects in the correct order -# NOTE: ARCH cmake is expected to provide variables for global constructors -# according to the compiler needs # NOTE: This linking must be done at this level as global constructors # should be supported on each architecture -if (NOT DEFINED CRTI_OBJ OR NOT DEFINED CRTN_OBJ) - message(FATAL_ERROR "One of: crti.o, crtn.o is not defined. Those should be defined in the ARCH CMakeLists.txt file") -endif () -set(CMAKE_CXX_LINKER_LAUNCHER "/bin/bash -c") -set(CMAKE_CXX_LINK_EXECUTABLE -"/bin/bash -c \"${CMAKE_CXX_COMPILER} \ -${CRTI_OBJ} \ -\$\(${CMAKE_C_COMPILER} -print-file-name=crtbegin.o\) \ - \ -\$\(${CMAKE_C_COMPILER} -print-file-name=crtend.o\) \ -${CRTN_OBJ} \ --o \"" +# Retrieve our custom CRT object paths from the arch-specific configuration. +get_property(CRTI_OBJ_PATH TARGET alkos.kernel.config PROPERTY CRTI_OBJ) +get_property(CRTN_OBJ_PATH TARGET alkos.kernel.config PROPERTY CRTN_OBJ) +alkos_ensure_defined( + VARS CRTI_OBJ_PATH CRTN_OBJ_PATH + MESSAGE "CRTI_OBJ/CRTN_OBJ properties were not set by the architecture-specific CMake file." +) + +# Find the compiler's CRT object files at configure-time. +execute_process( + COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtbegin.o + OUTPUT_VARIABLE CRTBEGIN_OBJ_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtend.o + OUTPUT_VARIABLE CRTEND_OBJ_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +alkos_ensure_defined( + VARS CRTBEGIN_OBJ_PATH CRTEND_OBJ_PATH + MESSAGE "Could not find compiler's crtbegin.o/crtend.o files." ) -########################## Back-Propagate Variables ########################## +message(STATUS "Found CRT Objects:") +message(STATUS " crti: ${CRTI_OBJ_PATH}") +message(STATUS " crtbegin: ${CRTBEGIN_OBJ_PATH}") +message(STATUS " crtend: ${CRTEND_OBJ_PATH}") +message(STATUS " crtn: ${CRTN_OBJ_PATH}") -set(BOOTABLE_KERNEL_EXECUTABLE ${BOOTABLE_KERNEL_EXECUTABLE} PARENT_SCOPE) -set(KERNEL_MODULES ${KERNEL_MODULES} PARENT_SCOPE) -set(KERNEL_COMMANDS ${KERNEL_COMMANDS} PARENT_SCOPE) +# Add all objects and libraries to the kernel target in the correct link order. +# The linker requires: crti, crtbegin,
, , crtend, crtn +# target_link_libraries preserves this order. +target_link_libraries(alkos.kernel PRIVATE + ${CRTI_OBJ_PATH} + ${CRTBEGIN_OBJ_PATH} -set(ARCH_QEMU_COMMAND ${ARCH_QEMU_COMMAND} PARENT_SCOPE) -set(ARCH_QEMU_NORMAL_FLAGS ${ARCH_QEMU_NORMAL_FLAGS} PARENT_SCOPE) -set(ARCH_QEMU_TEST_FLAGS ${ARCH_QEMU_TEST_FLAGS} PARENT_SCOPE) + ${CRTEND_OBJ_PATH} + ${CRTN_OBJ_PATH} + + gcc +) diff --git a/alkos/kernel/arch/x86_64/CMakeLists.txt b/alkos/kernel/arch/x86_64/CMakeLists.txt index 573be933b..98d44762a 100644 --- a/alkos/kernel/arch/x86_64/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/CMakeLists.txt @@ -42,17 +42,12 @@ alkos_ensure_defined( message(STATUS "Bootable kernel executable: ${BOOTABLE_KERNEL_EXECUTABLE}") message(STATUS "Kernel modules: ${KERNEL_MODULES}") -message(STATUS "CRTI_OBJ: ${CRTI_OBJ}, CRTN_OBJ: ${CRTN_OBJ}") +########################## Set Kernel Properties ########################## -########################## Back-Propagate Variables ########################## +set_property(TARGET alkos.kernel.config PROPERTY BOOTABLE_KERNEL_EXECUTABLE ${BOOTABLE_KERNEL_EXECUTABLE}) +set_property(TARGET alkos.kernel.config PROPERTY KERNEL_MODULES ${KERNEL_MODULES}) +set_property(TARGET alkos.kernel.config PROPERTY KERNEL_COMMANDS ${KERNEL_COMMANDS}) -set(CRTI_OBJ "${CRTI_OBJ}" PARENT_SCOPE) -set(CRTN_OBJ "${CRTN_OBJ}" PARENT_SCOPE) - -set(BOOTABLE_KERNEL_EXECUTABLE ${BOOTABLE_KERNEL_EXECUTABLE} PARENT_SCOPE) -set(KERNEL_MODULES ${KERNEL_MODULES} PARENT_SCOPE) -set(KERNEL_COMMANDS ${KERNEL_COMMANDS} PARENT_SCOPE) - -set(ARCH_QEMU_COMMAND ${ARCH_QEMU_COMMAND} PARENT_SCOPE) -set(ARCH_QEMU_NORMAL_FLAGS ${ARCH_QEMU_NORMAL_FLAGS} PARENT_SCOPE) -set(ARCH_QEMU_TEST_FLAGS ${ARCH_QEMU_TEST_FLAGS} PARENT_SCOPE) +set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_COMMAND ${ARCH_QEMU_COMMAND}) +set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_NORMAL_FLAGS ${ARCH_QEMU_NORMAL_FLAGS}) +set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_TEST_FLAGS ${ARCH_QEMU_TEST_FLAGS}) diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index 60c994543..15b66715c 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -48,8 +48,8 @@ add_library(alkos.kernel.crts OBJECT ) # Set the CRT object paths -set(CRTI_OBJ "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crts.dir/cxx/crti.nasm.o" PARENT_SCOPE) -set(CRTN_OBJ "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crts.dir/cxx/crtn.nasm.o" PARENT_SCOPE) +set_property(TARGET alkos.kernel.config PROPERTY CRTI_OBJ "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crts.dir/cxx/crti.nasm.o") +set_property(TARGET alkos.kernel.config PROPERTY CRTN_OBJ "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crts.dir/cxx/crtn.nasm.o") add_dependencies(alkos.kernel alkos.kernel.crts) From 30442002bbf7265757cca0bfec498bf79b98229e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 02:06:33 +0200 Subject: [PATCH 09/28] refactor: Split CXX global constructors into separate object libraries and update dependencies --- .../kernel/arch/x86_64/kernel/CMakeLists.txt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index 15b66715c..d84250e14 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -39,19 +39,16 @@ target_link_libraries(alkos.kernel PRIVATE ########################## CXX Global Constructors ########################### -set(SRTI_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cxx/crti.nasm") -set(SRTN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cxx/crtn.nasm") - -add_library(alkos.kernel.crts OBJECT - ${SRTI_FILE} - ${SRTN_FILE} +add_library(alkos.kernel.crti OBJECT + cxx/crti.nasm +) +add_library(alkos.kernel.crtn OBJECT + cxx/crtn.nasm ) -# Set the CRT object paths -set_property(TARGET alkos.kernel.config PROPERTY CRTI_OBJ "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crts.dir/cxx/crti.nasm.o") -set_property(TARGET alkos.kernel.config PROPERTY CRTN_OBJ "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crts.dir/cxx/crtn.nasm.o") - -add_dependencies(alkos.kernel alkos.kernel.crts) +set_property(TARGET alkos.kernel.config PROPERTY CRTI_OBJ "$") +set_property(TARGET alkos.kernel.config PROPERTY CRTN_OBJ "$") +add_dependencies(alkos.kernel PRIVATE alkos.kernel.crti alkos.kernel.crtn) ############################### Link Libraries ############################### From d61fd2c34494193e4150140baa80b7a5a66a72d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 02:12:09 +0200 Subject: [PATCH 10/28] refactor: Use target properties for kernel configuration and simplify validation logic --- alkos/cmake/ValidationHelpers.cmake | 5 +-- alkos/kernel/arch/x86_64/CMakeLists.txt | 43 +++++++------------------ 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/alkos/cmake/ValidationHelpers.cmake b/alkos/cmake/ValidationHelpers.cmake index 6c33b4317..051fab073 100644 --- a/alkos/cmake/ValidationHelpers.cmake +++ b/alkos/cmake/ValidationHelpers.cmake @@ -42,10 +42,7 @@ function(alkos_ensure_defined) set(undefined_vars "") foreach(var_name ${ARG_VARS}) - if(NOT DEFINED ${var_name}) - list(APPEND undefined_vars "${var_name}") - endif() - if(${var_name} STREQUAL "") + if(NOT ${var_name}) list(APPEND undefined_vars "${var_name}") endif() endforeach() diff --git a/alkos/kernel/arch/x86_64/CMakeLists.txt b/alkos/kernel/arch/x86_64/CMakeLists.txt index 98d44762a..dda69e7b5 100644 --- a/alkos/kernel/arch/x86_64/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/CMakeLists.txt @@ -2,52 +2,31 @@ message(STATUS "Configuring for x86_64") ############################# Arch Dependent Vars ############################ -set(KERNEL_MODULES "") -set(KERNEL_COMMANDS "") # Kernel commands for the bootloader, has to be same size as KERNEL_MODULES -set(BOOTABLE_KERNEL_EXECUTABLE "") -set(ARCH_QEMU_COMMAND "qemu-system-x86_64") -set(ARCH_QEMU_NORMAL_FLAGS "-serial stdio -enable-kvm -cpu host -display default,show-cursor=on -m 4G -smp sockets=1,cores=4,threads=1") -set(ARCH_QEMU_TEST_FLAGS "-serial stdio -enable-kvm -cpu host -display none -m 4G -smp sockets=1,cores=4,threads=1") +set_property(TARGET alkos.kernel.config PROPERTY KERNEL_MODULES "") +set_property(TARGET alkos.kernel.config PROPERTY KERNEL_COMMANDS "") +set_property(TARGET alkos.kernel.config PROPERTY BOOTABLE_KERNEL_EXECUTABLE "") +set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_COMMAND "qemu-system-x86_64") +set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_NORMAL_FLAGS "-serial stdio -enable-kvm -cpu host -display default,show-cursor=on -m 4G -smp sockets=1,cores=4,threads=1") +set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_TEST_FLAGS "-serial stdio -enable-kvm -cpu host -display none -m 4G -smp sockets=1,cores=4,threads=1") ################################### Boot32 ################################### add_subdirectory(loader32) -# Retrieve the bootable kernel executable -set(BOOTABLE_KERNEL_EXECUTABLE alkos.loader32) +set_property(TARGET alkos.kernel.config PROPERTY BOOTABLE_KERNEL_EXECUTABLE alkos.loader32) ################################### Boot64 ################################### add_subdirectory(loader64) -set(KERNEL_MODULES ${KERNEL_MODULES} alkos.loader64) -set(KERNEL_COMMANDS ${KERNEL_COMMANDS} "loader64") +set_property(TARGET alkos.kernel.config APPEND PROPERTY KERNEL_MODULES alkos.loader64) +set_property(TARGET alkos.kernel.config APPEND PROPERTY KERNEL_COMMANDS "loader64") ################################### Kernel ################################### add_subdirectory(kernel) -set(KERNEL_MODULES ${KERNEL_MODULES} alkos.kernel) -set(KERNEL_COMMANDS ${KERNEL_COMMANDS} "kernel") +set_property(TARGET alkos.kernel.config APPEND PROPERTY KERNEL_MODULES alkos.kernel) +set_property(TARGET alkos.kernel.config APPEND PROPERTY KERNEL_COMMANDS "kernel") ################################### Common ################################### add_subdirectory(common-loader-all) add_subdirectory(common-loader-64-kernel) - -############################### Error Checking ############################### - -alkos_ensure_defined( - VARS BOOTABLE_KERNEL_EXECUTABLE - MESSAGE "No primary kernel executable defined for x86_64 architecture." -) - -message(STATUS "Bootable kernel executable: ${BOOTABLE_KERNEL_EXECUTABLE}") -message(STATUS "Kernel modules: ${KERNEL_MODULES}") - -########################## Set Kernel Properties ########################## - -set_property(TARGET alkos.kernel.config PROPERTY BOOTABLE_KERNEL_EXECUTABLE ${BOOTABLE_KERNEL_EXECUTABLE}) -set_property(TARGET alkos.kernel.config PROPERTY KERNEL_MODULES ${KERNEL_MODULES}) -set_property(TARGET alkos.kernel.config PROPERTY KERNEL_COMMANDS ${KERNEL_COMMANDS}) - -set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_COMMAND ${ARCH_QEMU_COMMAND}) -set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_NORMAL_FLAGS ${ARCH_QEMU_NORMAL_FLAGS}) -set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_TEST_FLAGS ${ARCH_QEMU_TEST_FLAGS}) From fc698e8f7d03ba3fb19311ae5301718d376b54bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 02:34:16 +0200 Subject: [PATCH 11/28] fix: Remove PRIVATE keyword from add_dependencies call --- alkos/kernel/arch/x86_64/kernel/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index d84250e14..474356d83 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -48,7 +48,7 @@ add_library(alkos.kernel.crtn OBJECT set_property(TARGET alkos.kernel.config PROPERTY CRTI_OBJ "$") set_property(TARGET alkos.kernel.config PROPERTY CRTN_OBJ "$") -add_dependencies(alkos.kernel PRIVATE alkos.kernel.crti alkos.kernel.crtn) +add_dependencies(alkos.kernel alkos.kernel.crti alkos.kernel.crtn) ############################### Link Libraries ############################### From 7e87790968da57128539e87cf0e4f81f3e730c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= <60490378+kryczkal@users.noreply.github.com> Date: Wed, 6 Aug 2025 12:09:47 +0200 Subject: [PATCH 12/28] Fix message Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- alkos/cmake/ValidationHelpers.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alkos/cmake/ValidationHelpers.cmake b/alkos/cmake/ValidationHelpers.cmake index 051fab073..091ba0d08 100644 --- a/alkos/cmake/ValidationHelpers.cmake +++ b/alkos/cmake/ValidationHelpers.cmake @@ -64,7 +64,7 @@ endfunction() # alkos_ensure_property_defined #=============================================================================== # -# Checks if a property is defined for a target and halts with a fatal error_message, +# Checks if a property is defined for a target and halts with a fatal error, # listing all undefined properties at once. # # Parameters: From 771f77a0758ca5cdf3b0b459ad975934efc63dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= <60490378+kryczkal@users.noreply.github.com> Date: Wed, 6 Aug 2025 12:10:05 +0200 Subject: [PATCH 13/28] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- alkos/cmake/ValidationHelpers.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alkos/cmake/ValidationHelpers.cmake b/alkos/cmake/ValidationHelpers.cmake index 091ba0d08..594851a65 100644 --- a/alkos/cmake/ValidationHelpers.cmake +++ b/alkos/cmake/ValidationHelpers.cmake @@ -85,8 +85,8 @@ endfunction() # function(alkos_ensure_property_defined) set(options) - set(oneValueArgs MESSAGE) - set(multiValueArgs TARGET PROPS) + set(oneValueArgs TARGET MESSAGE) + set(multiValueArgs PROPS) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) From 5c9ab8028220fb6ae4594ed44ed417ce67868e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 12:45:11 +0200 Subject: [PATCH 14/28] chore: Update toolchain versions to binutils 2.44 and gcc 15.1.0 --- scripts/env/toolchain_versions.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/env/toolchain_versions.txt b/scripts/env/toolchain_versions.txt index 8d882acdc..910c4eeda 100644 --- a/scripts/env/toolchain_versions.txt +++ b/scripts/env/toolchain_versions.txt @@ -1,3 +1,3 @@ -binutils=2.43.1 +binutils=2.44 gdb=16.3 -gcc=14.2.0 +gcc=15.1.0 From e64ce059814c83c3933a9c683b5342f4057af550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 12:56:53 +0200 Subject: [PATCH 15/28] chore: Add error handling and debug output for crtbegin/crtend object file detection, and update .gitignore with common patterns --- alkos/kernel/CMakeLists.txt | 13 ++++ scripts/.gitignore | 143 ++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 scripts/.gitignore diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 9342665e4..c35066c53 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -95,13 +95,26 @@ alkos_ensure_defined( execute_process( COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtbegin.o OUTPUT_VARIABLE CRTBEGIN_OBJ_PATH + ERROR_VARIABLE CRTBEGIN_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtend.o OUTPUT_VARIABLE CRTEND_OBJ_PATH + ERROR_VARIABLE CRTEND_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ) + +# !!! Debug start !!! +message(STATUS "!!! DEBUG START !!!") +message(STATUS "DEBUG: CMAKE_C_COMPILER is ${CMAKE_C_COMPILER}") +message(STATUS "DEBUG: Output of crtbegin search: '${CRTBEGIN_OBJ_PATH}'") +message(STATUS "DEBUG: Error of crtbegin search: '${CRTBEGIN_ERROR}'") +message(STATUS "DEBUG: Output of crtend search: '${CRTEND_OBJ_PATH}'") +message(STATUS "DEBUG: Error of crtend search: '${CRTEND_ERROR}'") +message(STATUS "!!! DEBUG END !!!") +# !!! Debug end !!! + alkos_ensure_defined( VARS CRTBEGIN_OBJ_PATH CRTEND_OBJ_PATH MESSAGE "Could not find compiler's crtbegin.o/crtend.o files." diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 000000000..b000197c6 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,143 @@ +*.DS_Store +.AppleDouble +.LSOverride +._* + +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db +Desktop.ini +$RECYCLE.BIN/ + +.directory +.dropbox +.dropbox.attr + +*.log +*.log.* +*.sql +*.sqlite +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar +*.exe +*.dll +*.so +*.dylib +*.bak +*.swp +*~ +*.tmp + +__pycache__/ +*.py[cod] +*$py.class +.Python +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +.pytest_cache/ +.coverage +.coverage.* +coverage.xml +*.cover + +bin/ +pkg/ +*.test +*.prof + +## Rust +target/ +*.rs.bk + +build/ +*.o +*.obj +*.out +*.a +*.lib +*.pdb + +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +dependency-reduced-pom.xml +release.properties +tomcat*/ +*.class + +bin/ +obj/ +*.user +*.suo +*.csproj.bak +*.cache +*.ilk +*.meta +*.ncx +*.nupkg + +_build/ +deps/ +*.ez + +.Rhistory +.RData +.Rproj.user/ +*.Rout + +node_modules/ +dist/ +build/ +*.min.* +npm-debug.log* +yarn-debug.log* +yarn-error.log* +*.tsbuildinfo + +DerivedData/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +*.xccheckout +*.moved-aside +*.xcuserstate +*.xcworkspace +Pods/ + +.gradle/ +build/ +*.apk +*.ap_ +*.aab +local.properties +*.idea/ +*.iml + +.idea/ +*.iml +.vscode/ +*.swp +*.swo +nbproject/ +*.code-workspace + +.env +.env.local +.env.*.local +*.cache +*.lock +*.pid From 1bf5395203cb10791d286387dbd5bf6fe0210c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 13:21:39 +0200 Subject: [PATCH 16/28] refactor: Reorder and enhance toolchain setup in prepare_env action --- .github/actions/prepare_env/action.yaml | 37 +++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/actions/prepare_env/action.yaml b/.github/actions/prepare_env/action.yaml index aee24f9ff..8bc5ac202 100644 --- a/.github/actions/prepare_env/action.yaml +++ b/.github/actions/prepare_env/action.yaml @@ -13,20 +13,15 @@ runs: shell: bash run: sudo "$GITHUB_WORKSPACE/scripts/env/install_deps_ubuntu.bash" --install -v - - name: Configure environment - env: - ARCH: ${{ inputs.arch }} - shell: bash - run: sudo "$GITHUB_WORKSPACE/scripts/config/configure.bash" "$ARCH" debug -v -p test_mode - - name: Cache toolchain uses: actions/cache@v4 id: cache-build-tools with: - key: tools-${{ inputs.arch }}-${{ hashFiles('scripts/env/toolchain_versions.txt') }} + key: tools-${{ inputs.arch }}-${{ hashFiles('scripts/env/toolchain_versions.txt', 'scripts/env/build_cross_compile.bash') }} path: tools - - name: Build toolchain + - name: Build toolchain and Setup PATH + id: build_toolchain env: TOOLCHAIN_PATH: ${{ github.workspace }}/tools BUILD_PATH: ${{ github.workspace }}/build @@ -35,16 +30,24 @@ runs: shell: bash run: | if [[ $BUILD_TOOLS_CACHE_HIT == 'true' ]]; then - echo "Toolchain is cached, skipping build" - if [[ $ARCH == 'x86_64' ]]; then - echo "Adding x86 toolchain paths to the PATH" - echo "$TOOLCHAIN_PATH/i386-elf/bin" >> $GITHUB_PATH - echo "$TOOLCHAIN_PATH/x86_64-elf/bin" >> $GITHUB_PATH - else - echo "Unsupported arch" - exit 1 - fi + echo "Toolchain is cached, skipping build" else echo "Building toolchain" sudo "$GITHUB_WORKSPACE/scripts/env/install_toolchain.bash" "$TOOLCHAIN_PATH" "$BUILD_PATH" "$ARCH" -v fi + + echo "Adding toolchain to PATH for subsequent steps" + if [[ $ARCH == 'x86_64' ]]; then + echo "$TOOLCHAIN_PATH/i386-elf/bin" >> $GITHUB_PATH + echo "$TOOLCHAIN_PATH/x86_64-elf/bin" >> $GITHUB_PATH + else + echo "Unsupported arch" + exit 1 + fi + + - name: Configure environment + needs: build_toolchain + env: + ARCH: ${{ inputs.arch }} + shell: bash + run: sudo "$GITHUB_WORKSPACE/scripts/config/configure.bash" "$ARCH" debug -v -p test_mode From e120be27b37b0827a5084fcf0b3684a62d5f3cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 13:23:08 +0200 Subject: [PATCH 17/28] refactor: Remove unnecessary step dependencies in prepare_env action --- .github/actions/prepare_env/action.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/actions/prepare_env/action.yaml b/.github/actions/prepare_env/action.yaml index 8bc5ac202..99965563c 100644 --- a/.github/actions/prepare_env/action.yaml +++ b/.github/actions/prepare_env/action.yaml @@ -21,7 +21,6 @@ runs: path: tools - name: Build toolchain and Setup PATH - id: build_toolchain env: TOOLCHAIN_PATH: ${{ github.workspace }}/tools BUILD_PATH: ${{ github.workspace }}/build @@ -46,7 +45,6 @@ runs: fi - name: Configure environment - needs: build_toolchain env: ARCH: ${{ inputs.arch }} shell: bash From 32e57f7da4d4c5f92f2328a3fe0d819396b444a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 14:06:51 +0200 Subject: [PATCH 18/28] refactor: Reorganize kernel CMakeLists.txt to improve dependency management and linking order --- alkos/kernel/CMakeLists.txt | 25 +++++++++++-------- .../kernel/arch/x86_64/kernel/CMakeLists.txt | 9 +++++-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index c35066c53..6629ff18b 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -2,7 +2,10 @@ message(STATUS "Configuring kernel...") # This target acts as a central hub for configuration data (e.g., kernel modules) # that needs to be communicated to the top-level CMakeLists.txt. -add_library(alkos.kernel.config INTERFACE) +add_library(alkos.kernel.config INTERFACE) +add_library(alkos.kernel.headers INTERFACE) # Kernel headers for exporting +add_library(alkos.kernel.deps INTERFACE) # Target to link all dependencies to, to ensure + # proper linking order ############################### Error Checking ############################### @@ -48,17 +51,12 @@ add_executable(alkos.kernel ############################### Adding Headers ############################### -add_library(alkos.kernel.headers INTERFACE) target_include_directories(alkos.kernel.headers INTERFACE include test abi ) -target_link_libraries(alkos.kernel PRIVATE - alkos.kernel.headers -) - ########################## Configure for given Arch ########################## add_subdirectory(arch/${ARCH}) @@ -71,14 +69,12 @@ add_subdirectory(arch/${ARCH}) add_subdirectory(thirdparty) -target_link_libraries(alkos.kernel.headers INTERFACE +target_link_libraries(alkos.kernel.deps INTERFACE alkos.kernel.thirdparty + libk + AutoGenLib ) -################################## Linking ################################### - -target_link_libraries(alkos.kernel PRIVATE libk AutoGenLib) - ############## Linker Configuration for CXX Global Constructors ############## # NOTE: This linking must be done at this level as global constructors # should be supported on each architecture @@ -130,9 +126,16 @@ message(STATUS " crtn: ${CRTN_OBJ_PATH}") # The linker requires: crti, crtbegin,
, , crtend, crtn # target_link_libraries preserves this order. target_link_libraries(alkos.kernel PRIVATE + target.properties + ${CRTI_OBJ_PATH} ${CRTBEGIN_OBJ_PATH} + # Order is important here! + # Do not link ANYTHING before crtbegin.o + alkos.kernel.headers + alkos.kernel.deps + ${CRTEND_OBJ_PATH} ${CRTN_OBJ_PATH} diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index 474356d83..b95e7d5fb 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -52,8 +52,13 @@ add_dependencies(alkos.kernel alkos.kernel.crti alkos.kernel.crtn) ############################### Link Libraries ############################### -target_link_libraries(alkos.kernel PRIVATE +target_link_libraries(alkos.kernel.deps INTERFACE arch.common.all.64 arch.common.kernel-loader.64 - AutoGenLib +) + +# This makes the interface also properly link to object files +target_sources(alkos.kernel.deps INTERFACE + $ + $ ) From 069a6933ae7552b9d8d2374fe911d6af5198eaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 14:37:06 +0200 Subject: [PATCH 19/28] docs: Add note about linking objects to interface libraries in CMakeLists.txt --- alkos/kernel/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 6629ff18b..df951952a 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -6,6 +6,9 @@ add_library(alkos.kernel.config INTERFACE) add_library(alkos.kernel.headers INTERFACE) # Kernel headers for exporting add_library(alkos.kernel.deps INTERFACE) # Target to link all dependencies to, to ensure # proper linking order +# Note: Caveat - linking objects to this target also requires +# using target_sources $ syntax because +# interface libraries are only carriers for headers and properties ############################### Error Checking ############################### From 7113a04cb7ff2864c46d5a029cf5cacd144208f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 15:00:30 +0200 Subject: [PATCH 20/28] refactor: Improve kernel build configuration and linking order --- alkos/CMakeLists.txt | 2 ++ alkos/kernel/CMakeLists.txt | 25 +++++++++++-------- .../kernel/arch/x86_64/kernel/CMakeLists.txt | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/alkos/CMakeLists.txt b/alkos/CMakeLists.txt index cf77fd20a..9ae51d2bb 100644 --- a/alkos/CMakeLists.txt +++ b/alkos/CMakeLists.txt @@ -12,6 +12,8 @@ set(PROJECT_NAME AlkOS) set(PROJECT_VERSION "0.0") set(PROJECT_AUTHOR "ALK Organisation") +set(CMAKE_VERBOSE_MAKEFILE ON) + ################################################################################ # Helpers # ################################################################################ diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index df951952a..a9908ab06 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -2,10 +2,9 @@ message(STATUS "Configuring kernel...") # This target acts as a central hub for configuration data (e.g., kernel modules) # that needs to be communicated to the top-level CMakeLists.txt. -add_library(alkos.kernel.config INTERFACE) -add_library(alkos.kernel.headers INTERFACE) # Kernel headers for exporting -add_library(alkos.kernel.deps INTERFACE) # Target to link all dependencies to, to ensure - # proper linking order +add_library(alkos.kernel.config INTERFACE) +add_library(alkos.kernel.headers INTERFACE) # Kernel headers for exporting +add_library(alkos.kernel.deps INTERFACE) # Target to link all dependencies to # Note: Caveat - linking objects to this target also requires # using target_sources $ syntax because # interface libraries are only carriers for headers and properties @@ -46,11 +45,12 @@ if (CMAKE_FEATURE_FLAG_RUN_TEST_MODE) list(APPEND KERNEL_SOURCES ${KERNEL_TEST_SOURCES}) endif () +add_library(alkos.kernel.objects OBJECT ${KERNEL_SOURCES}) + #################################### Exec #################################### -add_executable(alkos.kernel - ${KERNEL_SOURCES} -) +add_executable(alkos.kernel "") +target_link_libraries(alkos.kernel.objects PRIVATE target.properties) ############################### Adding Headers ############################### @@ -65,7 +65,7 @@ target_include_directories(alkos.kernel.headers INTERFACE add_subdirectory(arch/${ARCH}) # TODO: Immediately here, error checking should happen -# But the error checking itself fails!!! and for some reason +# But the error checking itself fails!!! and for some reason # alkos_ensure_property_defined() says the property is not defined ################################# ThirdParty ################################# @@ -125,6 +125,12 @@ message(STATUS " crtbegin: ${CRTBEGIN_OBJ_PATH}") message(STATUS " crtend: ${CRTEND_OBJ_PATH}") message(STATUS " crtn: ${CRTN_OBJ_PATH}") +target_link_libraries(alkos.kernel.objects PUBLIC + target.properties + alkos.kernel.headers + alkos.kernel.deps +) + # Add all objects and libraries to the kernel target in the correct link order. # The linker requires: crti, crtbegin,
, , crtend, crtn # target_link_libraries preserves this order. @@ -136,8 +142,7 @@ target_link_libraries(alkos.kernel PRIVATE # Order is important here! # Do not link ANYTHING before crtbegin.o - alkos.kernel.headers - alkos.kernel.deps + alkos.kernel.objects ${CRTEND_OBJ_PATH} ${CRTN_OBJ_PATH} diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index b95e7d5fb..6776b0519 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -10,7 +10,7 @@ if (NOT CMAKE_FEATURE_FLAG_RUN_TEST_MODE) list(APPEND exclude_patterns ".*/tests/.*") endif () -alkos_target_sources(alkos.kernel +alkos_target_sources(alkos.kernel.objects EXCLUDE ${exclude_patterns} ) From 0feb2da0174dbe4d69e21cf8031d3b1d74cb39d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 15:25:07 +0200 Subject: [PATCH 21/28] refactor: Simplify kernel build configuration and remove debug messages --- alkos/CMakeLists.txt | 2 -- alkos/kernel/CMakeLists.txt | 34 +++---------------- .../kernel/arch/x86_64/kernel/CMakeLists.txt | 2 +- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/alkos/CMakeLists.txt b/alkos/CMakeLists.txt index 9ae51d2bb..cf77fd20a 100644 --- a/alkos/CMakeLists.txt +++ b/alkos/CMakeLists.txt @@ -12,8 +12,6 @@ set(PROJECT_NAME AlkOS) set(PROJECT_VERSION "0.0") set(PROJECT_AUTHOR "ALK Organisation") -set(CMAKE_VERBOSE_MAKEFILE ON) - ################################################################################ # Helpers # ################################################################################ diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index a9908ab06..5db5609e4 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -45,12 +45,10 @@ if (CMAKE_FEATURE_FLAG_RUN_TEST_MODE) list(APPEND KERNEL_SOURCES ${KERNEL_TEST_SOURCES}) endif () -add_library(alkos.kernel.objects OBJECT ${KERNEL_SOURCES}) #################################### Exec #################################### -add_executable(alkos.kernel "") -target_link_libraries(alkos.kernel.objects PRIVATE target.properties) +add_executable(alkos.kernel ${KERNEL_SOURCES}) ############################### Adding Headers ############################### @@ -104,16 +102,6 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) -# !!! Debug start !!! -message(STATUS "!!! DEBUG START !!!") -message(STATUS "DEBUG: CMAKE_C_COMPILER is ${CMAKE_C_COMPILER}") -message(STATUS "DEBUG: Output of crtbegin search: '${CRTBEGIN_OBJ_PATH}'") -message(STATUS "DEBUG: Error of crtbegin search: '${CRTBEGIN_ERROR}'") -message(STATUS "DEBUG: Output of crtend search: '${CRTEND_OBJ_PATH}'") -message(STATUS "DEBUG: Error of crtend search: '${CRTEND_ERROR}'") -message(STATUS "!!! DEBUG END !!!") -# !!! Debug end !!! - alkos_ensure_defined( VARS CRTBEGIN_OBJ_PATH CRTEND_OBJ_PATH MESSAGE "Could not find compiler's crtbegin.o/crtend.o files." @@ -125,27 +113,15 @@ message(STATUS " crtbegin: ${CRTBEGIN_OBJ_PATH}") message(STATUS " crtend: ${CRTEND_OBJ_PATH}") message(STATUS " crtn: ${CRTN_OBJ_PATH}") -target_link_libraries(alkos.kernel.objects PUBLIC +target_link_libraries(alkos.kernel PUBLIC target.properties + alkos.kernel.config alkos.kernel.headers alkos.kernel.deps ) # Add all objects and libraries to the kernel target in the correct link order. # The linker requires: crti, crtbegin,
, , crtend, crtn -# target_link_libraries preserves this order. -target_link_libraries(alkos.kernel PRIVATE - target.properties - - ${CRTI_OBJ_PATH} - ${CRTBEGIN_OBJ_PATH} - - # Order is important here! - # Do not link ANYTHING before crtbegin.o - alkos.kernel.objects - - ${CRTEND_OBJ_PATH} - ${CRTN_OBJ_PATH} - - gcc +set(CMAKE_CXX_LINK_EXECUTABLE + "${CMAKE_CXX_COMPILER} ${CRTI_OBJ_PATH} ${CRTBEGIN_OBJ_PATH} ${CRTEND_OBJ_PATH} ${CRTN_OBJ_PATH} -o " ) diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index 6776b0519..b95e7d5fb 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -10,7 +10,7 @@ if (NOT CMAKE_FEATURE_FLAG_RUN_TEST_MODE) list(APPEND exclude_patterns ".*/tests/.*") endif () -alkos_target_sources(alkos.kernel.objects +alkos_target_sources(alkos.kernel EXCLUDE ${exclude_patterns} ) From ce589c27c79145f97f68d0b0bf55ea9b58ed9ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 15:28:25 +0200 Subject: [PATCH 22/28] refactor: Simplify CRT object linking in kernel build configuration --- alkos/kernel/CMakeLists.txt | 29 +++++++++---------- .../kernel/arch/x86_64/kernel/CMakeLists.txt | 4 --- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 5db5609e4..7ded40e12 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -80,14 +80,6 @@ target_link_libraries(alkos.kernel.deps INTERFACE # NOTE: This linking must be done at this level as global constructors # should be supported on each architecture -# Retrieve our custom CRT object paths from the arch-specific configuration. -get_property(CRTI_OBJ_PATH TARGET alkos.kernel.config PROPERTY CRTI_OBJ) -get_property(CRTN_OBJ_PATH TARGET alkos.kernel.config PROPERTY CRTN_OBJ) -alkos_ensure_defined( - VARS CRTI_OBJ_PATH CRTN_OBJ_PATH - MESSAGE "CRTI_OBJ/CRTN_OBJ properties were not set by the architecture-specific CMake file." -) - # Find the compiler's CRT object files at configure-time. execute_process( COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtbegin.o @@ -108,20 +100,27 @@ alkos_ensure_defined( ) message(STATUS "Found CRT Objects:") -message(STATUS " crti: ${CRTI_OBJ_PATH}") message(STATUS " crtbegin: ${CRTBEGIN_OBJ_PATH}") message(STATUS " crtend: ${CRTEND_OBJ_PATH}") -message(STATUS " crtn: ${CRTN_OBJ_PATH}") target_link_libraries(alkos.kernel PUBLIC + # Custom properties (flags) target.properties alkos.kernel.config + + # Linker requires: crti, crtbegin,
, , crtend, crtn + + # We link directly to the OBJECT library. CMake will expand this to the .o file. + alkos.kernel.crti + + # Then the compiler's CRT begin object. + ${CRTBEGIN_OBJ_PATH} + + # Then all other dependencies (your kernel's .cpp.o files, libk, uacpi, etc.). alkos.kernel.headers alkos.kernel.deps -) -# Add all objects and libraries to the kernel target in the correct link order. -# The linker requires: crti, crtbegin,
, , crtend, crtn -set(CMAKE_CXX_LINK_EXECUTABLE - "${CMAKE_CXX_COMPILER} ${CRTI_OBJ_PATH} ${CRTBEGIN_OBJ_PATH} ${CRTEND_OBJ_PATH} ${CRTN_OBJ_PATH} -o " + # Finally, the compiler's CRT end object and our custom CRT end object. + ${CRTEND_OBJ_PATH} + alkos.kernel.crtn ) diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index b95e7d5fb..88f283757 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -46,10 +46,6 @@ add_library(alkos.kernel.crtn OBJECT cxx/crtn.nasm ) -set_property(TARGET alkos.kernel.config PROPERTY CRTI_OBJ "$") -set_property(TARGET alkos.kernel.config PROPERTY CRTN_OBJ "$") -add_dependencies(alkos.kernel alkos.kernel.crti alkos.kernel.crtn) - ############################### Link Libraries ############################### target_link_libraries(alkos.kernel.deps INTERFACE From b86a7499ff65d25a27471fd448c246e987191b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 15:43:19 +0200 Subject: [PATCH 23/28] refactor: Improve kernel linking order and CRT object handling --- alkos/kernel/CMakeLists.txt | 53 ++++++++++++------- .../kernel/arch/x86_64/kernel/CMakeLists.txt | 14 +++++ 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 7ded40e12..94fbdcf92 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -5,9 +5,20 @@ message(STATUS "Configuring kernel...") add_library(alkos.kernel.config INTERFACE) add_library(alkos.kernel.headers INTERFACE) # Kernel headers for exporting add_library(alkos.kernel.deps INTERFACE) # Target to link all dependencies to +#------------------------------------------------------------------------------# +# Notes: alkos.kernel.deps # +#------------------------------------------------------------------------------# # Note: Caveat - linking objects to this target also requires # using target_sources $ syntax because # interface libraries are only carriers for headers and properties +# +#------------------------------------------------------------------------------# +# Note: This target is used to ensure proper linking order +# Idea was that this is the linking "api" of the kernel +# So that arch etc, doesn't have to care about the linking order +# This is current unused in the intended way, but may be useful in the future +# +#------------------------------------------------------------------------------# ############################### Error Checking ############################### @@ -66,6 +77,15 @@ add_subdirectory(arch/${ARCH}) # But the error checking itself fails!!! and for some reason # alkos_ensure_property_defined() says the property is not defined +################################ Linking Kernel ################################ + +target_link_libraries(alkos.kernel PUBLIC + target.properties + alkos.kernel.config + alkos.kernel.headers + alkos.kernel.deps +) + ################################# ThirdParty ################################# add_subdirectory(thirdparty) @@ -80,6 +100,14 @@ target_link_libraries(alkos.kernel.deps INTERFACE # NOTE: This linking must be done at this level as global constructors # should be supported on each architecture +# Retrieve our custom CRT object paths from the arch-specific configuration. +get_property(CRTI_OBJ_PATH TARGET alkos.kernel.config PROPERTY CRTI_OBJ) +get_property(CRTN_OBJ_PATH TARGET alkos.kernel.config PROPERTY CRTN_OBJ) +alkos_ensure_defined( + VARS CRTI_OBJ_PATH CRTN_OBJ_PATH + MESSAGE "CRTI_OBJ/CRTN_OBJ properties were not set by the architecture-specific CMake file." +) + # Find the compiler's CRT object files at configure-time. execute_process( COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtbegin.o @@ -100,27 +128,14 @@ alkos_ensure_defined( ) message(STATUS "Found CRT Objects:") +message(STATUS " crti: ${CRTI_OBJ_PATH}") message(STATUS " crtbegin: ${CRTBEGIN_OBJ_PATH}") message(STATUS " crtend: ${CRTEND_OBJ_PATH}") +message(STATUS " crtn: ${CRTN_OBJ_PATH}") -target_link_libraries(alkos.kernel PUBLIC - # Custom properties (flags) - target.properties - alkos.kernel.config - - # Linker requires: crti, crtbegin,
, , crtend, crtn - - # We link directly to the OBJECT library. CMake will expand this to the .o file. - alkos.kernel.crti - - # Then the compiler's CRT begin object. - ${CRTBEGIN_OBJ_PATH} - - # Then all other dependencies (your kernel's .cpp.o files, libk, uacpi, etc.). - alkos.kernel.headers - alkos.kernel.deps - # Finally, the compiler's CRT end object and our custom CRT end object. - ${CRTEND_OBJ_PATH} - alkos.kernel.crtn +# Add all objects and libraries to the kernel target in the correct link order. +# The linker requires: crti, crtbegin,
, , crtend, crtn +set(CMAKE_CXX_LINK_EXECUTABLE + "${CMAKE_CXX_COMPILER} ${CRTI_OBJ_PATH} ${CRTBEGIN_OBJ_PATH} ${CRTEND_OBJ_PATH} ${CRTN_OBJ_PATH} -o " ) diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index 88f283757..5da63f039 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -46,6 +46,20 @@ add_library(alkos.kernel.crtn OBJECT cxx/crtn.nasm ) +# TODO: Maybe later we can get this code to work +# set_property(TARGET alkos.kernel.config PROPERTY CRTI_OBJ "$") +# set_property(TARGET alkos.kernel.config PROPERTY CRTN_OBJ "$") +# I used combination of the above code, and target_link_libraries to link in specific order +# Worked but introduced a bug where no tests were detected +# So I reverted to the old way of linking the object files + +set(CRTI_OBJ_FILE_PATH "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crti.dir/cxx/crti.nasm.o") +set(CRTN_OBJ_FILE_PATH "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crtn.dir/cxx/crtn.nasm.o") +set_property(TARGET alkos.kernel.config PROPERTY CRTI_OBJ "${CRTI_OBJ_FILE_PATH}") +set_property(TARGET alkos.kernel.config PROPERTY CRTN_OBJ "${CRTN_OBJ_FILE_PATH}") + +add_dependencies(alkos.kernel alkos.kernel.crti alkos.kernel.crtn) + ############################### Link Libraries ############################### target_link_libraries(alkos.kernel.deps INTERFACE From 70b331b8a0fbc2a91bf5022025d47706a87e9003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 15:58:39 +0200 Subject: [PATCH 24/28] refactor: Reorganize CMakeLists.txt linking and remove redundant target_link_libraries calls --- alkos/kernel/CMakeLists.txt | 21 ++- .../common-loader-64-kernel/CMakeLists.txt | 9 +- .../x86_64/common-loader-all/CMakeLists.txt | 18 +-- .../kernel/arch/x86_64/kernel/CMakeLists.txt | 7 +- .../arch/x86_64/loader32/CMakeLists.txt | 6 +- .../arch/x86_64/loader64/CMakeLists.txt | 3 +- scripts/.gitignore | 143 ------------------ 7 files changed, 29 insertions(+), 178 deletions(-) delete mode 100644 scripts/.gitignore diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 94fbdcf92..467782fce 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -77,13 +77,6 @@ add_subdirectory(arch/${ARCH}) # But the error checking itself fails!!! and for some reason # alkos_ensure_property_defined() says the property is not defined -################################ Linking Kernel ################################ - -target_link_libraries(alkos.kernel PUBLIC - target.properties - alkos.kernel.config - alkos.kernel.headers - alkos.kernel.deps ) ################################# ThirdParty ################################# @@ -96,6 +89,14 @@ target_link_libraries(alkos.kernel.deps INTERFACE AutoGenLib ) +################################ Linking Kernel ################################ + +target_link_libraries(alkos.kernel PUBLIC + target.properties + alkos.kernel.config + alkos.kernel.headers + alkos.kernel.deps + ############## Linker Configuration for CXX Global Constructors ############## # NOTE: This linking must be done at this level as global constructors # should be supported on each architecture @@ -133,9 +134,15 @@ message(STATUS " crtbegin: ${CRTBEGIN_OBJ_PATH}") message(STATUS " crtend: ${CRTEND_OBJ_PATH}") message(STATUS " crtn: ${CRTN_OBJ_PATH}") +# TODO: +# The below code could technically be replaced with target_link_libraries() +# it also should enforce the correct linking order. +# I have done so with success, but it introduced a bug where no tests were +# detected in the kernel and I was unable to reslove it so gave up for now. # Add all objects and libraries to the kernel target in the correct link order. # The linker requires: crti, crtbegin,
, , crtend, crtn set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_COMPILER} ${CRTI_OBJ_PATH} ${CRTBEGIN_OBJ_PATH} ${CRTEND_OBJ_PATH} ${CRTN_OBJ_PATH} -o " ) + diff --git a/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt index bb5b03041..114047242 100644 --- a/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt @@ -17,8 +17,10 @@ target_link_libraries(arch.common.kernel-loader.64 PRIVATE ############################# Linking libraries ############################## target_link_libraries(arch.common.kernel-loader.64 PRIVATE - libk arch.common.all.64 + alkos.kernel.headers + libk + AutoGenLib ) ############################### Adding Headers ############################### @@ -26,8 +28,3 @@ target_link_libraries(arch.common.kernel-loader.64 PRIVATE target_include_directories(alkos.kernel.headers INTERFACE . ) - -target_link_libraries(arch.common.kernel-loader.64 PRIVATE - alkos.kernel.headers - AutoGenLib -) diff --git a/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt b/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt index 117aebe10..62cad3d61 100644 --- a/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt @@ -13,13 +13,17 @@ alkos_target_sources(arch.common.all.32) ############################# Linking libraries ############################## target_link_libraries(arch.common.all.64 PRIVATE - libk target.properties + libk + alkos.kernel.headers + AutoGenLib ) target_link_libraries(arch.common.all.32 PRIVATE - libk.32 target.properties.32 + libk.32 + alkos.kernel.headers + AutoGenLib ) ############################### Applying Flags ############################### @@ -31,13 +35,3 @@ set(CMAKE_ASM_NASM_COMPILE_OBJECT " target_include_directories(alkos.kernel.headers INTERFACE . ) - -target_link_libraries(arch.common.all.64 PRIVATE - alkos.kernel.headers - AutoGenLib -) - -target_link_libraries(arch.common.all.32 PRIVATE - alkos.kernel.headers - AutoGenLib -) diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index 5da63f039..d9624a760 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -31,12 +31,6 @@ target_link_options(alkos.kernel PRIVATE -lgcc # Link against GCC ) -######################### Setting Custom Properties ########################## - -target_link_libraries(alkos.kernel PRIVATE - target.properties -) - ########################## CXX Global Constructors ########################### add_library(alkos.kernel.crti OBJECT @@ -63,6 +57,7 @@ add_dependencies(alkos.kernel alkos.kernel.crti alkos.kernel.crtn) ############################### Link Libraries ############################### target_link_libraries(alkos.kernel.deps INTERFACE + target.properties arch.common.all.64 arch.common.kernel-loader.64 ) diff --git a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt index 6da19e8e1..3d78c454e 100644 --- a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt @@ -21,8 +21,6 @@ target_include_directories(alkos.loader32 PRIVATE .) ################################ Exec Flags ################################## -target_link_libraries(alkos.loader32 PRIVATE target.properties.32) - set(CMAKE_ASM_NASM_COMPILE_OBJECT " -o ") ################################ Linker Flags ################################ @@ -42,8 +40,10 @@ target_compile_definitions(alkos.loader32 PUBLIC __i386__=1 ) +################################### Linking #################################### + target_link_libraries(alkos.loader32 PRIVATE - gcc + target.properties.32 arch.common.all.32 libk.32 alkos.kernel.headers diff --git a/alkos/kernel/arch/x86_64/loader64/CMakeLists.txt b/alkos/kernel/arch/x86_64/loader64/CMakeLists.txt index 820a36c26..2a12ad1a9 100644 --- a/alkos/kernel/arch/x86_64/loader64/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/loader64/CMakeLists.txt @@ -28,10 +28,11 @@ target_link_options(alkos.loader64 PRIVATE ############################### Link Libraries ############################### target_link_libraries(alkos.loader64 PRIVATE - gcc + target.properties libk arch.common.all.64 arch.common.kernel-loader.64 alkos.kernel.headers AutoGenLib + gcc ) diff --git a/scripts/.gitignore b/scripts/.gitignore deleted file mode 100644 index b000197c6..000000000 --- a/scripts/.gitignore +++ /dev/null @@ -1,143 +0,0 @@ -*.DS_Store -.AppleDouble -.LSOverride -._* - -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db -Desktop.ini -$RECYCLE.BIN/ - -.directory -.dropbox -.dropbox.attr - -*.log -*.log.* -*.sql -*.sqlite -*.jar -*.war -*.ear -*.zip -*.tar.gz -*.rar -*.exe -*.dll -*.so -*.dylib -*.bak -*.swp -*~ -*.tmp - -__pycache__/ -*.py[cod] -*$py.class -.Python -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -.pytest_cache/ -.coverage -.coverage.* -coverage.xml -*.cover - -bin/ -pkg/ -*.test -*.prof - -## Rust -target/ -*.rs.bk - -build/ -*.o -*.obj -*.out -*.a -*.lib -*.pdb - -target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -dependency-reduced-pom.xml -release.properties -tomcat*/ -*.class - -bin/ -obj/ -*.user -*.suo -*.csproj.bak -*.cache -*.ilk -*.meta -*.ncx -*.nupkg - -_build/ -deps/ -*.ez - -.Rhistory -.RData -.Rproj.user/ -*.Rout - -node_modules/ -dist/ -build/ -*.min.* -npm-debug.log* -yarn-debug.log* -yarn-error.log* -*.tsbuildinfo - -DerivedData/ -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 -*.xccheckout -*.moved-aside -*.xcuserstate -*.xcworkspace -Pods/ - -.gradle/ -build/ -*.apk -*.ap_ -*.aab -local.properties -*.idea/ -*.iml - -.idea/ -*.iml -.vscode/ -*.swp -*.swo -nbproject/ -*.code-workspace - -.env -.env.local -.env.*.local -*.cache -*.lock -*.pid From 616435c00e6b5dc5740e6ffdbfa8dd0fb41ce4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= <60490378+kryczkal@users.noreply.github.com> Date: Wed, 6 Aug 2025 16:12:52 +0200 Subject: [PATCH 25/28] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- alkos/kernel/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 467782fce..9f00716ee 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -91,7 +91,7 @@ target_link_libraries(alkos.kernel.deps INTERFACE ################################ Linking Kernel ################################ -target_link_libraries(alkos.kernel PUBLIC +target_link_libraries(alkos.kernel PRIVATE target.properties alkos.kernel.config alkos.kernel.headers From 1b101943b498c3bb4c74308bde043e9cb8596d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 16:43:45 +0200 Subject: [PATCH 26/28] chore: Fix CMakeLists.txt syntax errors and add compile definitions for x86_64 and i386 architectures --- alkos/kernel/CMakeLists.txt | 3 +-- alkos/kernel/arch/x86_64/loader32/CMakeLists.txt | 1 - alkos/toolchains/x86_64-conf.cmake | 8 +++++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 9f00716ee..d87b80f55 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -77,8 +77,6 @@ add_subdirectory(arch/${ARCH}) # But the error checking itself fails!!! and for some reason # alkos_ensure_property_defined() says the property is not defined -) - ################################# ThirdParty ################################# add_subdirectory(thirdparty) @@ -96,6 +94,7 @@ target_link_libraries(alkos.kernel PRIVATE alkos.kernel.config alkos.kernel.headers alkos.kernel.deps +) ############## Linker Configuration for CXX Global Constructors ############## # NOTE: This linking must be done at this level as global constructors diff --git a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt index 3d78c454e..697cdfd6b 100644 --- a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt @@ -12,7 +12,6 @@ alkos_target_sources(alkos.loader32) ############################## Finding CXX Compiler ############################ -message(STATUS "32 bit compiler: ${CMAKE_CXX_COMPILER_32}") set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_COMPILER_32} -o ") ############################## Finding Headers ############################### diff --git a/alkos/toolchains/x86_64-conf.cmake b/alkos/toolchains/x86_64-conf.cmake index e4e9e363c..e49edd21c 100644 --- a/alkos/toolchains/x86_64-conf.cmake +++ b/alkos/toolchains/x86_64-conf.cmake @@ -55,6 +55,10 @@ target_compile_options(target.properties INTERFACE "$<$:-mno-red-zone>" "$<$:-f elf64>" ) +target_compile_definitions(target.properties INTERFACE + "__x86_64__=1" +) + #------------------------------------------------------------------------------# # 32 bit # #------------------------------------------------------------------------------# @@ -65,4 +69,6 @@ target_compile_options(target.properties.32 INTERFACE "$<$:-m32>" "$<$:-f elf32>" ) - +target_compile_definitions(target.properties.32 INTERFACE + "__i386__=1" +) From 2843e70717065c5cf225c1b9c9dfc772f32aebfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Wed, 6 Aug 2025 16:46:27 +0200 Subject: [PATCH 27/28] refactor: Reorganize CMakeLists.txt to improve dependency linking and remove redundant properties --- alkos/libc/CMakeLists.txt | 12 ++++++------ alkos/libc/arch/x86_64/CMakeLists.txt | 15 ++++++--------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/alkos/libc/CMakeLists.txt b/alkos/libc/CMakeLists.txt index 97b4ff544..975b8d80e 100644 --- a/alkos/libc/CMakeLists.txt +++ b/alkos/libc/CMakeLists.txt @@ -28,10 +28,6 @@ add_subdirectory(arch/${ARCH}) add_library(lib${LIB_NAME} STATIC ${LIB_SOURCES}) set_target_properties(lib${LIB_NAME} PROPERTIES OUTPUT_NAME "${LIB_NAME}") -############################# Setting Custom Properties ######################### - -target_link_libraries(lib${LIB_NAME} PUBLIC target.properties) - ############################### Adding includes ############################### target_include_directories(lib${LIB_NAME} PUBLIC @@ -42,9 +38,13 @@ target_include_directories(lib${LIB_NAME} PRIVATE internal ) -target_link_libraries(lib${LIB_NAME} PRIVATE gcc) +############################### Adding dependencies ############################### -target_link_libraries(lib${LIB_NAME} PRIVATE AutoGenLib) +target_link_libraries(lib${LIB_NAME} PRIVATE + target.properties + gcc + AutoGenLib +) if (SYSTEM_LIB_TYPE STREQUAL "k" OR SYSTEM_LIB_TYPE STREQUAL "K") target_link_libraries(lib${LIB_NAME} PRIVATE alkos.kernel.headers) diff --git a/alkos/libc/arch/x86_64/CMakeLists.txt b/alkos/libc/arch/x86_64/CMakeLists.txt index 05b8784c2..5e4164484 100644 --- a/alkos/libc/arch/x86_64/CMakeLists.txt +++ b/alkos/libc/arch/x86_64/CMakeLists.txt @@ -3,8 +3,6 @@ add_library(lib${LIB_NAME}.32 STATIC ${LIB_SOURCES}) set_target_properties(lib${LIB_NAME}.32 PROPERTIES OUTPUT_NAME "${LIB_NAME}.32") -target_compile_options(lib${LIB_NAME}.32 PRIVATE -m32) - ############################### Adding includes ############################### target_include_directories(lib${LIB_NAME}.32 PUBLIC @@ -15,24 +13,23 @@ target_include_directories(lib${LIB_NAME}.32 PRIVATE ../../internal ) -############################# Setting Custom Properties ######################### - -target_link_libraries(lib${LIB_NAME}.32 PUBLIC target.properties.32) - ################################# Dependencies ################################ add_dependencies(lib${LIB_NAME}.32 lib${LIB_NAME}) +target_link_libraries(lib${LIB_NAME}.32 PUBLIC + target.properties.32 + AutoGenLib + gcc +) + if (SYSTEM_LIB_TYPE STREQUAL "k" OR SYSTEM_LIB_TYPE STREQUAL "K") target_link_libraries(lib${LIB_NAME}.32 PRIVATE alkos.kernel.headers) endif () -target_link_libraries(lib${LIB_NAME}.32 PRIVATE AutoGenLib) - ############################### Processing output ############################### set_target_properties(lib${LIB_NAME}.32 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${SYSROOT}/usr/lib LIBRARY_OUTPUT_DIRECTORY ${SYSROOT}/usr/lib ) -target_link_libraries(lib${LIB_NAME}.32 PRIVATE gcc) From 721656a5cd89aad74a55dd51ea65830c2a47ba7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kryczka?= Date: Sat, 9 Aug 2025 14:52:56 +0200 Subject: [PATCH 28/28] Quickfix --- scripts/env/clean_build_dir.bash | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/env/clean_build_dir.bash b/scripts/env/clean_build_dir.bash index 7412d2ee1..2e178f9be 100755 --- a/scripts/env/clean_build_dir.bash +++ b/scripts/env/clean_build_dir.bash @@ -6,9 +6,6 @@ CONF_BUILD_DIR="${CLEAN_BUILD_SCRIPT_DIR}/../../build" source "${CLEAN_BUILD_SCRIPT_DIR}/../utils/conf_handlers.bash" -source_conf_file -verify_conf_var_exists CONF_BUILD_DIR - source "${CLEAN_BUILD_SCRIPT_DIR}/../utils/pretty_print.bash" source "${CLEAN_BUILD_SCRIPT_DIR}/../utils/helpers.bash" source "${CLEAN_BUILD_SCRIPT_DIR}/../utils/argparse.bash"