-
Notifications
You must be signed in to change notification settings - Fork 1
Kryczkal/cmake modularization 03 #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
ae9ce33
refactor: Move compile options to target.properties interface library
kryczkal 18aca3f
refactor: Remove post-arch action and consolidate target properties l…
kryczkal a0c6862
refactor: Update 32-bit loader CMake configuration to use target prop…
kryczkal 196a7ad
refactor: Simplify source file handling in CMakeLists.txt for x86_64 …
kryczkal 8d6ada8
refactor: Simplify CMakeLists.txt by removing redundant source file h…
kryczkal 0a37833
refactor: Simplify third-party library linking in kernel build system
kryczkal 3858125
chore: Move third-party library status messages to appropriate CMakeL…
kryczkal faf0d38
refactor: Use target properties for kernel configuration and CRT objects
kryczkal 3044200
refactor: Split CXX global constructors into separate object librarie…
kryczkal d61fd2c
refactor: Use target properties for kernel configuration and simplify…
kryczkal fc698e8
fix: Remove PRIVATE keyword from add_dependencies call
kryczkal 7e87790
Fix message
kryczkal 771f77a
Apply suggestion from @Copilot
kryczkal 5c9ab80
chore: Update toolchain versions to binutils 2.44 and gcc 15.1.0
kryczkal e64ce05
chore: Add error handling and debug output for crtbegin/crtend object…
kryczkal 1bf5395
refactor: Reorder and enhance toolchain setup in prepare_env action
kryczkal e120be2
refactor: Remove unnecessary step dependencies in prepare_env action
kryczkal 32e57f7
refactor: Reorganize kernel CMakeLists.txt to improve dependency mana…
kryczkal 069a693
docs: Add note about linking objects to interface libraries in CMakeL…
kryczkal 7113a04
refactor: Improve kernel build configuration and linking order
kryczkal 0feb2da
refactor: Simplify kernel build configuration and remove debug messages
kryczkal ce589c2
refactor: Simplify CRT object linking in kernel build configuration
kryczkal b86a749
refactor: Improve kernel linking order and CRT object handling
kryczkal 70b331b
refactor: Reorganize CMakeLists.txt linking and remove redundant targ…
kryczkal 616435c
Apply suggestion from @Copilot
kryczkal 1b10194
chore: Fix CMakeLists.txt syntax errors and add compile definitions f…
kryczkal 2843e70
refactor: Reorganize CMakeLists.txt to improve dependency linking and…
kryczkal 0ec692b
Merge branch 'dev' into kryczkal/cmake-modularization-03
kryczkal 721656a
Quickfix
kryczkal f442572
Merge branch 'dev' into kryczkal/cmake-modularization-03
kryczkal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,25 @@ | ||
| 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 | ||
| #------------------------------------------------------------------------------# | ||
| # Notes: alkos.kernel.deps # | ||
| #------------------------------------------------------------------------------# | ||
| # Note: Caveat - linking objects to this target also requires | ||
| # using target_sources $<TARGET_OBJECTS:{some lib name}> 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 ############################### | ||
|
|
||
| alkos_ensure_defined( | ||
|
|
@@ -11,19 +31,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) | ||
|
|
@@ -49,91 +56,92 @@ if (CMAKE_FEATURE_FLAG_RUN_TEST_MODE) | |
| list(APPEND KERNEL_SOURCES ${KERNEL_TEST_SOURCES}) | ||
| endif () | ||
|
|
||
|
|
||
| #################################### Exec #################################### | ||
|
|
||
| add_executable(alkos.kernel | ||
| ${KERNEL_SOURCES} | ||
| ) | ||
| add_executable(alkos.kernel ${KERNEL_SOURCES}) | ||
|
|
||
| ############################### 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}) | ||
|
|
||
| ############################### 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 | ||
|
Comment on lines
+76
to
+78
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create issue?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems important |
||
|
|
||
| ################################# ThirdParty ################################# | ||
|
|
||
| message(STATUS "Adding third-party libraries...") | ||
| add_subdirectory(thirdparty) | ||
|
|
||
| ################################## Linking ################################### | ||
| target_link_libraries(alkos.kernel.deps INTERFACE | ||
| alkos.kernel.thirdparty | ||
| libk | ||
| AutoGenLib | ||
| ) | ||
|
|
||
| target_link_libraries(alkos.kernel PRIVATE libk gcc ${THIRD_PARTY_LIBRARIES} AutoGenLib) | ||
| ################################ Linking Kernel ################################ | ||
|
|
||
| target_link_libraries(alkos.kernel PRIVATE | ||
| target.properties | ||
| alkos.kernel.config | ||
| alkos.kernel.headers | ||
| alkos.kernel.deps | ||
| ) | ||
|
|
||
| ############## 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} <CMAKE_CXX_LINK_FLAGS> <FLAGS> <LINK_FLAGS> \ | ||
| ${CRTI_OBJ} \ | ||
| \$\(${CMAKE_C_COMPILER} -print-file-name=crtbegin.o\) \ | ||
| <OBJECTS> \ | ||
| \$\(${CMAKE_C_COMPILER} -print-file-name=crtend.o\) \ | ||
| ${CRTN_OBJ} \ | ||
| -o <TARGET> <LINK_LIBRARIES>\"" | ||
| # 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 | ||
| 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 | ||
| ) | ||
|
|
||
| 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}") | ||
|
|
||
| # 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. | ||
|
|
||
| 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, <main objects>, <libraries>, crtend, crtn | ||
| set(CMAKE_CXX_LINK_EXECUTABLE | ||
| "${CMAKE_CXX_COMPILER} <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> ${CRTI_OBJ_PATH} ${CRTBEGIN_OBJ_PATH} <OBJECTS> ${CRTEND_OBJ_PATH} ${CRTN_OBJ_PATH} -o <TARGET> <LINK_LIBRARIES>" | ||
| ) | ||
|
|
||
| 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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.