CeDOS - Commit d4349677

cmake: Add function for adding CeDOS executable Signed-off-by: Celina Sophie Kalus <hello@celinakalus.de>
Celina Sophie Kalus
Fri, 01 Aug 2025 22:40:34 +0200
1 files changed, 49 insertions(+), 28 deletions(-)

jump to
M CMakeLists.txtCMakeLists.txt

@@ -33,6 +33,47 @@ COMMAND ${CMAKE_OBJCOPY} -O binary ${target_elf} ${target_bin}

) endfunction() +function(cedos_add_image image_name kernel_target bootloader_target) + # image root directory + add_custom_target( + ${image_name}_root ALL + COMMAND mkdir -p ${CMAKE_BINARY_DIR}/root ${CMAKE_BINARY_DIR}/input + ) + + # image + add_custom_target( + cedos.img ALL + DEPENDS ${kernel_target} ${bootloader_target} ${image_name}_root + COMMAND cp ${kernel_target} ${CMAKE_BINARY_DIR}/root + COMMAND cp ${bootloader_target} ${CMAKE_BINARY_DIR}/input + COMMAND genimage --config ${CMAKE_SOURCE_DIR}/image.conf + ) +endfunction() + +function(cedos_add_executable image_target executable_target) + add_executable(${executable_target}) + + add_custom_command( + TARGET ${executable_target} POST_BUILD + COMMAND cp ${executable_target} ${CMAKE_BINARY_DIR}/root + DEPENDS root_dir + ) + + add_dependencies(${executable_target} ${image_target}_root) + add_dependencies(${image_target} ${executable_target}) + + target_link_libraries(${executable_target} cedos) + target_include_directories(${executable_target} PRIVATE + libcedos/ + common/ + ) + cedos_linker_script(${executable_target} ${CMAKE_SOURCE_DIR}/shell/link.txt) + + target_link_options(${executable_target} PRIVATE + LINKER:-Map=${CMAKE_BINARY_DIR}/${executable_target}.map + ) +endfunction() + execute_process( COMMAND git describe --abbrev=4 --dirty --always --tags OUTPUT_VARIABLE GIT_VERSION

@@ -173,6 +214,8 @@ cedos_strip_binary(kernel.elf)

cedos_mapfile(kernel.elf) cedos_print_usage(kernel.elf) +cedos_add_image(cedos.img kernel.bin boot.bin) + # libcedos add_library(cedos STATIC ${COMMON_SRC}

@@ -185,9 +228,10 @@ common/

) # shell -list(APPEND IMAGE_APPS ${SHELL_APPS}) foreach(SHELL_APP IN LISTS SHELL_APPS) - add_executable(${SHELL_APP} + cedos_add_executable(cedos.img ${SHELL_APP}) + target_sources(${SHELL_APP} + PRIVATE shell/${SHELL_APP}.c ) endforeach()

@@ -195,39 +239,16 @@

if (DEFINED CEDOS_TEST) list(APPEND IMAGE_APPS ${TEST_APPS}) foreach(TEST_APP IN LISTS TEST_APPS) - add_executable(${TEST_APP} + cedos_add_executable(cedos.img ${TEST_APP}) + target_sources(${TEST_APP} + PRIVATE tests/${TEST_APP}.c ) target_include_directories(${TEST_APP} PRIVATE tests/ ) endforeach() - list(APPEND IMAGE_FILES ${CMAKE_SOURCE_DIR}/tests/testfile.txt) endif() -foreach(SHELL_APP IN LISTS IMAGE_APPS) - target_link_libraries(${SHELL_APP} cedos) - target_include_directories(${SHELL_APP} PRIVATE - libcedos/ - common/ - ) - cedos_linker_script(${SHELL_APP} ${CMAKE_SOURCE_DIR}/shell/link.txt) - - target_link_options(${SHELL_APP} PRIVATE - LINKER:-Map=${CMAKE_BINARY_DIR}/${SHELL_APP}.map - ) - - list(APPEND IMAGE_FILES ${SHELL_APP}) -endforeach() - target_compile_options(ce3d PRIVATE -mhard-float) -# image -add_custom_target( - cedos.img ALL - DEPENDS kernel.bin boot.bin ${IMAGE_APPS} - COMMAND mkdir -p ${CMAKE_BINARY_DIR}/root ${CMAKE_BINARY_DIR}/input - COMMAND cp kernel.bin ${IMAGE_FILES} ${CMAKE_BINARY_DIR}/root - COMMAND cp boot.bin ${CMAKE_BINARY_DIR}/input - COMMAND genimage --config ${CMAKE_SOURCE_DIR}/image.conf -)