Skip to content

Commit

Permalink
Use CMake as build system
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjian85 committed Mar 31, 2024
1 parent a7fc44a commit 795b6a9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 51 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt-get install gcc-riscv64-unknown-elf libnewlib-dev
- name: Make
run: make CROSS_PREFIX=riscv64-unknown-elf-
run: sudo apt-get install gcc-riscv64-unknown-elf
- name: Configure CMake
run: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/riscv64.cmake -B ${{github.workspace}}/build
- name: Build
run: cmake --build ${{github.workspace}}/build
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: kernel.elf
path: build/kernel.elf
path: ${{github.workspace}}/build/kernel.elf
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
# Build products
*.o
*.d
*.elf

# LSP files
compile_commands.json
.cache/
build/
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.29)

project(karg ASM C)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/kernel.ld)
set(CMAKE_C_FLAGS "-ffreestanding -mcmodel=medany")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nostdlib -T ${LINKER_SCRIPT}")

add_executable(karg.elf src/entry.S src/kmain.c src/kprintf.c src/syscall.c src/trap.S src/uart.c)
set_target_properties(karg.elf PROPERTIES LINK_DEPENDS ${LINKER_SCRIPT})
target_include_directories(karg.elf PRIVATE include/)
39 changes: 0 additions & 39 deletions Makefile

This file was deleted.

4 changes: 4 additions & 0 deletions cmake/riscv64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(TOOLCHAIN_PREFIX "riscv64-unknown-elf-")
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)

0 comments on commit 795b6a9

Please sign in to comment.