diff options
author | Marvin Borner | 2020-01-03 17:39:23 +0100 |
---|---|---|
committer | Marvin Borner | 2020-01-03 17:39:23 +0100 |
commit | a67919783e4c69644b24a0ced0d5373bb8adf794 (patch) | |
tree | 01916a057d07018c3d7dbeef796c0022432aa845 | |
parent | 233f26019e5e2edc00a04dc8ce6feba7d85ec972 (diff) |
CMake...
CMake isn't as easy as expected, especially because the user binary is somehow messed up.. Maybe I'll use a SH script or Makefile after all :/
-rw-r--r-- | CMakeLists.txt | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2942c02..937f06d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,28 +1,39 @@ cmake_minimum_required(VERSION 3.0) project(Melvix) enable_language(ASM) +set(CMAKE_VERBOSE_MAKEFILE on) +# Melvix variables +set(NETWORK "rtl8139") + +# Compiler and linker set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS " ") set(CMAKE_C_COMPILER "${CMAKE_CURRENT_SOURCE_DIR}/cross/opt/bin/i686-elf-gcc") set(CMAKE_ASM_COMPILER "nasm") set(CMAKE_LINKER "${CMAKE_CURRENT_SOURCE_DIR}/cross/opt/bin/i686-elf-gcc") +set(CMAKE_ASM_LINKER_PREFERENCE ${CMAKE_LINKER}) +set(CMAKE_C_LINKER_PREFERENCE ${CMAKE_LINKER}) -set(CMAKE_C_FLAGS "-c -I./src -std=gnu99 -ffreestanding -O2 -Wall -Wextra") -set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <SOURCE> -o <OBJECT> -f elf32") -set(CMAKE_EXE_LINKER_FLAGS "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/linker.ld -o ${CMAKE_CURRENT_SOURCE_DIR}/iso/boot/kernel.bin -ffreestanding -O2 -nostdlib") +# Compiler and linker flags +set(CMAKE_C_FLAGS "-c -std=gnu99 -ffreestanding -O2 -Wall -Wextra") +set(CMAKE_EXE_LINKER_FLAGS "-std=gnu99 -ffreestanding -O3 -nostdlib") +set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <SOURCE> -o <OBJECT> -f elf") set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") +set(CMAKE_ASM_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") -file(GLOB_RECURSE kernel_sources src/kernel/*.c src/kernel/*.h src/kernel/*.asm) +# Recursive sources +file(GLOB_RECURSE kernel_sources src/kernel/*.c src/kernel/*.asm) file(GLOB_RECURSE resources_sources src/resources/*.c) -file(GLOB_RECURSE user_sources src/userspace/*.c src/userspace/*.h src/userspace/*.asm) +file(GLOB_RECURSE user_sources src/userspace/*.c src/userspace/*.asm) # KERNEL -include_directories(kernel "./src") add_executable(kernel ${kernel_sources}) +target_include_directories(kernel PRIVATE "src") set_target_properties(kernel PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/iso/boot/kernel.bin") +target_compile_options(kernel PRIVATE "-D ${NETWORK}") +target_link_libraries(kernel PRIVATE "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/linker.ld") # RESOURCES -include_directories(resources "./src") add_executable(resources ${resources_sources}) set_target_properties(resources PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/iso/font.o") add_custom_command( @@ -33,8 +44,8 @@ add_custom_command( ) # USERSPACE -include_directories(user "./src/userspace") add_executable(user ${user_sources}) +target_include_directories(user PRIVATE "src/userspace") set_target_properties(user PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/iso/user.o") add_custom_command( TARGET user POST_BUILD @@ -58,10 +69,13 @@ if (DEFINED ENV{DISPLAY}) add_custom_command( TARGET kernel POST_BUILD COMMAND head -c 10485760 /dev/zero > iso/hdd10M.img - COMMAND qemu-system-i386 -no-reboot -vga std -smp $$(nproc) -serial stdio -rtc base=localtime -m 256M -net nic,model=rtl8139,macaddr=42:42:42:42:42:42 -net user -cdrom iso/melvix.iso -drive file=iso/hdd10M.img,format=raw + COMMAND qemu-system-i386 -s -no-reboot -vga std -smp $$(nproc) -serial stdio -rtc base=localtime -m 256M -net nic,model=rtl8139,macaddr=42:42:42:42:42:42 -net user -cdrom iso/melvix.iso -drive file=iso/hdd10M.img,format=raw WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif () +# CLEAN add_custom_target(clean_iso COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/iso && mkdir -p ${CMAKE_CURRENT_SOURCE_DIR}/iso/boot) + +# Dependencies add_dependencies(kernel clean_iso resources user)
\ No newline at end of file |