OSDev.org

The Place to Start for Operating System Developers
It is currently Thu May 09, 2024 3:13 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Are my CMakeLists.txt files correct for my C++ Kernel?
PostPosted: Tue Dec 27, 2022 8:19 am 
Offline

Joined: Tue Dec 27, 2022 7:59 am
Posts: 1
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:

Code:
cmake_minimum_required(VERSION 3.20)
project(NakOS)

add_subdirectory(Kernel)


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.

Code:
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
)


In my original project, I had a bash script that looks something like

Code:
#/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"


But I replaced it with the following Toolchain file (and I think this is okay?)

Code:
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++)


I then invoke `CMake` with
Code:
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 . -GNinja -DCMAKE_TOOLCHAIN_FILE=Toolchain/os-dev-toolchain.cmake


Is there anything wrong with these files?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], SemrushBot [Bot] and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group