Are my CMakeLists.txt files correct for my C++ Kernel?
Posted: Tue Dec 27, 2022 8:19 am
For those who built their Kernel using C++ and CMake, can someone ensure that my CMakeLists.txt's file are correct? I'm unsure if I'm invoking the linker script correctly and
I'm unsure if I have my toolchain properly configured
I plan on this being a fully-fledged OS so I set up my `CMakeLists.txt` in the top level directory like:
Then in my `Project/Kernel/CMakeLists.txt`. This is where I add the bootstrapped assembly as a source file and where I invoke the linker script.
In my original project, I had a bash script that looks something like
But I replaced it with the following Toolchain file (and I think this is okay?)
I then invoke `CMake` with
Is there anything wrong with these files?
I'm unsure if I have my toolchain properly configured
I plan on this being a fully-fledged OS so I set up my `CMakeLists.txt` in the top level directory like:
Code: Select all
cmake_minimum_required(VERSION 3.20)
project(NakOS)
add_subdirectory(Kernel)
Code: Select all
set(KERNEL_SOURCES
${CMAKE_SOURCE_DIR/Boot/boot.s} # Bootstrapped Assembly
${CMAKE_SOURCE_DIR/Kernel/src/kernel_main.cpp}
)
add_executable(nak ${KERNEL_SOURCES})
target_include_directories(nak PUBLIC ${CMAKE_SOURCE_DIR} )
target_compile_options(nak PRIVATE
$<$<CONFIG:Debug>:
-fsanitize=address,leak,undefined -pedantic -Wall -Wextra -Wundef -Werror -Wno-unused-parameter -ffreestanding -fno-exceptions -fno-rtti
>
)
target_link_options(nak PRIVATE
$<$<CONFIG:Debug>:
-fsanitize=address,leak,undefined -ffreestanding -nostdlib -T loader.ld -T ${CMAKE_CURRENT_SOURCE_DIR}/Boot/loader.ld # specifies linker script
>
)
target_compile_features(nak
PRIVATE
cxx_std_20
)
Code: Select all
#/bin/bash
export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"
# Use the cross compiler
export CXX="$HOME/opt/cross/bin/$TARGET-gcc"
Code: Select all
set(CMAKE_SYSTEM_PROCESSOR i686)
set(CMAKE_C_COMPILER ${CMAKE_SOURCE_DIR}/Toolchain/opt/cross/bin/i686-elf-gcc)
set(CMAKE_CXX_COMPILER ${CMAKE_SOURCE_DIR}/Toolchain/opt/cross/bin/i686-elf-g++)
Code: Select all
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 . -GNinja -DCMAKE_TOOLCHAIN_FILE=Toolchain/os-dev-toolchain.cmake