Clean up cmake files (Part 1)
I've been cleaning up the way compilation flags are passed to the targets and there are still some changes that must be made, in the next commit. I've also done some renaming, all_programs into programs and the same for tests. The gdb initialization file now is just one, populated using the find command and using realpath to get the absolute path to the files. I've tested if the generated gdb.run file works and it does.
This commit is contained in:
+18
-18
@@ -88,7 +88,7 @@ add_custom_target(filesystem
|
||||
COMMAND echo '============================================================================='
|
||||
COMMAND echo 'Done!'
|
||||
COMMAND echo '============================================================================='
|
||||
DEPENDS all_programs all_tests
|
||||
DEPENDS programs tests
|
||||
)
|
||||
|
||||
# =============================================================================
|
||||
@@ -135,8 +135,8 @@ set(EMULATOR_FLAGS ${EMULATOR_FLAGS} -drive file=${CMAKE_BINARY_DIR}/rootfs.img,
|
||||
add_custom_target(
|
||||
qemu
|
||||
COMMAND test -e ${CMAKE_BINARY_DIR}/rootfs.img || ${CMAKE_COMMAND} -E cmake_echo_color --red "No filesystem file detected, you need to run: make filesystem"
|
||||
COMMAND ${EMULATOR} ${EMULATOR_FLAGS} -kernel ${CMAKE_BINARY_DIR}/mentos/kernel-bootloader.bin
|
||||
DEPENDS kernel-bootloader.bin
|
||||
COMMAND ${EMULATOR} ${EMULATOR_FLAGS} -kernel ${CMAKE_BINARY_DIR}/mentos/bootloader.bin
|
||||
DEPENDS bootloader.bin
|
||||
)
|
||||
|
||||
# =============================================================================
|
||||
@@ -147,19 +147,19 @@ add_custom_target(
|
||||
# executables.
|
||||
add_custom_target(
|
||||
gdbinit
|
||||
BYPRODUCTS ${CMAKE_BINARY_DIR}/.gdbinit ${CMAKE_BINARY_DIR}/gdb.run
|
||||
BYPRODUCTS ${CMAKE_BINARY_DIR}/gdb.run
|
||||
# Create the generic gdb configuration.
|
||||
COMMAND echo "add-symbol-file ${CMAKE_BINARY_DIR}/mentos/kernel.bin" > ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND echo "add-symbol-file ${CMAKE_BINARY_DIR}/mentos/kernel-bootloader.bin" >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND ls -1 ${CMAKE_BINARY_DIR}/programs/tests/test_* | sed 's/^/add-symbol-file /' >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND ls -1 ${CMAKE_BINARY_DIR}/programs/prog_* | sed 's/^/add-symbol-file /' >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND echo "break boot.c: boot_main" >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND echo "break kernel.c: kmain" >> ${CMAKE_BINARY_DIR}/.gdbinit
|
||||
COMMAND echo "add-symbol-file ${CMAKE_BINARY_DIR}/mentos/kernel.bin" > ${CMAKE_BINARY_DIR}/gdb.run
|
||||
COMMAND echo "add-symbol-file ${CMAKE_BINARY_DIR}/mentos/bootloader.bin" >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
COMMAND find ${CMAKE_SOURCE_DIR}/files/bin -type f | xargs realpath | sed 's/^/add-symbol-file /' >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
COMMAND echo "break boot.c: boot_main" >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
COMMAND echo "break kernel.c: kmain" >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
# Create the GDB connection file.
|
||||
COMMAND echo "target remote localhost:1234" > ${CMAKE_BINARY_DIR}/gdb.run
|
||||
DEPENDS kernel-bootloader.bin
|
||||
DEPENDS all_programs
|
||||
DEPENDS all_tests
|
||||
COMMAND echo "target remote localhost:1234" >> ${CMAKE_BINARY_DIR}/gdb.run
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/mentos/bootloader.bin
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/mentos/kernel.bin
|
||||
DEPENDS programs
|
||||
DEPENDS tests
|
||||
DEPENDS libc
|
||||
)
|
||||
|
||||
@@ -177,8 +177,8 @@ add_custom_target(
|
||||
COMMAND echo "or if you want to use cgdb, type:"
|
||||
COMMAND echo " cgdb --quiet --command=gdb.run"
|
||||
COMMAND echo ""
|
||||
COMMAND ${EMULATOR} ${EMULATOR_FLAGS} -s -S -kernel ${CMAKE_BINARY_DIR}/mentos/kernel-bootloader.bin
|
||||
DEPENDS kernel-bootloader.bin
|
||||
COMMAND ${EMULATOR} ${EMULATOR_FLAGS} -s -S -kernel ${CMAKE_BINARY_DIR}/mentos/bootloader.bin
|
||||
DEPENDS bootloader.bin
|
||||
DEPENDS gdbinit
|
||||
)
|
||||
|
||||
@@ -190,9 +190,9 @@ add_custom_target(
|
||||
add_custom_target(
|
||||
cdrom.iso
|
||||
COMMAND cp -rf ${CMAKE_SOURCE_DIR}/iso .
|
||||
COMMAND cp ${CMAKE_BINARY_DIR}/mentos/kernel-bootloader.bin ${CMAKE_BINARY_DIR}/iso/boot
|
||||
COMMAND cp ${CMAKE_BINARY_DIR}/mentos/bootloader.bin ${CMAKE_BINARY_DIR}/iso/boot
|
||||
COMMAND grub-mkrescue -o ${CMAKE_BINARY_DIR}/cdrom.iso ${CMAKE_BINARY_DIR}/iso
|
||||
DEPENDS kernel-bootloader.bin
|
||||
DEPENDS bootloader.bin
|
||||
)
|
||||
|
||||
# This third target runs the emualtor, but this time, the kernel binary file is
|
||||
|
||||
@@ -11,7 +11,7 @@ project(kernel C ASM)
|
||||
# =============================================================================
|
||||
# Set the main file names.
|
||||
set(KERNEL_NAME kernel)
|
||||
set(BOOTLOADER_NAME kernel_bootloader)
|
||||
set(BOOTLOADER_NAME bootloader)
|
||||
set(BUDDY_SYSTEM_NAME kernel_memory)
|
||||
set(BUDDY_SYSTEM_FILE ${PROJECT_SOURCE_DIR}/src/mem/libbuddysystem.a)
|
||||
|
||||
@@ -298,12 +298,10 @@ target_compile_definitions(
|
||||
# =============================================================================
|
||||
# Build the kernel.
|
||||
add_custom_target(
|
||||
kernel-bootloader.bin ALL
|
||||
COMMAND ${CMAKE_LINKER} -melf_i386 -static --oformat elf32-i386 --output kernel.bin --script ${CMAKE_CURRENT_SOURCE_DIR}/kernel.lds -Map kernel.map -u kmain
|
||||
$<TARGET_FILE_NAME:${KERNEL_NAME}> ${BUDDY_SYSTEM_FILE}
|
||||
${BOOTLOADER_NAME}.bin ALL
|
||||
COMMAND ${CMAKE_LINKER} -melf_i386 -static --oformat elf32-i386 --output kernel.bin --script ${CMAKE_CURRENT_SOURCE_DIR}/kernel.lds -Map kernel.map -u kmain $<TARGET_FILE_NAME:${KERNEL_NAME}> ${BUDDY_SYSTEM_FILE}
|
||||
COMMAND objcopy -I binary -O elf32-i386 -B i386 kernel.bin kernel.bin.o
|
||||
COMMAND ${CMAKE_LINKER} -melf_i386 -static --oformat elf32-i386 --output kernel-bootloader.bin --script ${CMAKE_CURRENT_SOURCE_DIR}/boot.lds -Map kernel-bootloader.map
|
||||
kernel.bin.o $<TARGET_FILE_NAME:${BOOTLOADER_NAME}>
|
||||
COMMAND ${CMAKE_LINKER} -melf_i386 -static --oformat elf32-i386 --output ${BOOTLOADER_NAME}.bin --script ${CMAKE_CURRENT_SOURCE_DIR}/boot.lds -Map bootloader.map kernel.bin.o $<TARGET_FILE_NAME:${BOOTLOADER_NAME}>
|
||||
DEPENDS ${KERNEL_NAME}
|
||||
DEPENDS ${BOOTLOADER_NAME}
|
||||
)
|
||||
|
||||
@@ -56,7 +56,7 @@ endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
# BUILD
|
||||
# =============================================================================
|
||||
# Add the executables (manually).
|
||||
set(PROGRAMS
|
||||
set(PROGRAM_LIST
|
||||
nice.c
|
||||
ls.c
|
||||
mkdir.c
|
||||
@@ -89,7 +89,7 @@ set(PROGRAMS
|
||||
# Set the directory where the compiled binaries will be placed.
|
||||
set(MENTOS_BIN_DIR ${CMAKE_SOURCE_DIR}/files/bin)
|
||||
|
||||
foreach(FILE_NAME ${PROGRAMS})
|
||||
foreach(FILE_NAME ${PROGRAM_LIST})
|
||||
# Prepare the program name.
|
||||
string(REPLACE ".c" "" EXECUTABLE_NAME ${FILE_NAME})
|
||||
|
||||
@@ -133,4 +133,4 @@ foreach(FILE_NAME ${PROGRAMS})
|
||||
endforeach()
|
||||
|
||||
# Add the overall target that builds all the programs.
|
||||
add_custom_target(all_programs ALL DEPENDS ${ALL_EXECUTABLES})
|
||||
add_custom_target(programs ALL DEPENDS ${ALL_EXECUTABLES})
|
||||
|
||||
@@ -56,7 +56,7 @@ endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
# BUILD
|
||||
# =============================================================================
|
||||
# Add your file in this list.
|
||||
set(TESTS
|
||||
set(TEST_LIST
|
||||
t_gid.c
|
||||
t_alarm.c
|
||||
t_periodic3.c
|
||||
@@ -91,7 +91,7 @@ set(TESTS
|
||||
# Set the directory where the compiled binaries will be placed.
|
||||
set(MENTOS_TESTS_DIR ${CMAKE_SOURCE_DIR}/files/bin/tests)
|
||||
|
||||
foreach(FILE_NAME ${TESTS})
|
||||
foreach(FILE_NAME ${TEST_LIST})
|
||||
# Prepare the program name.
|
||||
string(REPLACE ".c" "" EXECUTABLE_NAME ${FILE_NAME})
|
||||
|
||||
@@ -131,8 +131,8 @@ foreach(FILE_NAME ${TESTS})
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${EXECUTABLE_NAME}")
|
||||
|
||||
# Append the program name to the list of all the executables.
|
||||
list(APPEND ALL_TESTS ${TARGET_NAME})
|
||||
list(APPEND ALL_EXECUTABLES ${TARGET_NAME})
|
||||
endforeach()
|
||||
|
||||
# Add the overall target that builds all the programs.
|
||||
add_custom_target(all_tests ALL DEPENDS ${ALL_TESTS})
|
||||
add_custom_target(tests ALL DEPENDS ${ALL_EXECUTABLES})
|
||||
|
||||
Reference in New Issue
Block a user