Code: Select all
MyOS
│ .clang-format
│ CMakeLists.txt
│ foo.txt
│
├───kernel
│ │ CMakeLists.txt
│ │
│ ├───include
│ │ └───vga
│ │ text.h
│ │
│ └───src
│ │ boot.asm
│ │ CMakeLists.txt
│ │ crti.asm
│ │ crti.o
│ │ crtn.asm
│ │ crtn.o
│ │ linker.ld
│ │ main.c
│ │
│ └───vga
│ └───text
│ text.c
│
└───libc
│ CMakeLists.txt
│
├───include
│ │ stdio.h
│ │ string.h
│ │
│ └───sys
│ cdefs.h
│
└───src
│ CMakeLists.txt
│
├───stdio
│ fputs.c
│ putchar.c
│ puts.c
│
└───string
memmove.c
These are the relevent CMake files:
Code: Select all
# MyOS/CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(
MyOS
VERSION 0.1
DESCRIPTION "A Hobby OS written in C"
LANGUAGES C ASM_NASM)
set(CMAKE_C_COMPILER i686-elf-gcc)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
if(MSVC)
set(${PROJECT_NAME}_C_WARNINGS "/W4 /WX")
else()
set(${PROJECT_NAME}_C_WARNINGS "-Wall -Wextra -pedantic-errors")
endif()
set(${PROJECT_NAME}_NASM_WARNINGS "-w+all")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_subdirectory(kernel)
add_subdirectory(libc)
Code: Select all
# MyOS/kernel/CMakeLists.txt
add_subdirectory(src)
Code: Select all
# MyOS/kernel/src/CMakeLists.txt
file(GLOB_RECURSE HEADER_LIST ../include/*.h ../../libc/include)
add_library(kernel OBJECT
vga/text/text.c
${HEADER_LIST})
target_include_directories(src
PRIVATE
${CMAKE_SOURCE_DIR}/libc/include
PUBLIC
../include)
target_link_libraries(src ${PROJECT_NAME}-libc)
target_compile_options(src PRIVATE ${${PROJECT_NAME}_C_WARNINGS})
Code: Select all
# MyOS/libc/CMakeLists.txt
configure_file(include/stdio.h "${CMAKE_SOURCE_DIR}/sysroot/usr/include/stdio.h" COPYONLY)
configure_file(include/stdio.h "${CMAKE_SOURCE_DIR}/sysroot/usr/include/string.h" COPYONLY)
configure_file(include/sys/cdefs.h "${CMAKE_SOURCE_DIR}/sysroot/usr/include/sys/cdefs.h" COPYONLY)
add_subdirectory(src)
Code: Select all
# MyOS/libc/src/CMakeLists.txt
file(GLOB_RECURSE HEADER_LIST "../include/*.h" "${CMAKE_SOURCE_DIR}/kernel/include/*.h")
add_library(${PROJECT_NAME}-libc STATIC
stdio/fputs.c
stdio/putchar.c
stdio/puts.c
string/memmove.c
${HEADER_LIST})
target_include_directories(${PROJECT_NAME}-libc
PUBLIC
../include
${CMAKE_SOURCE_DIR})
target_compile_options(${PROJECT_NAME}-libc PRIVATE ${${PROJECT_NAME}_C_WARNINGS})
What I would like to know is, are the CMakeLists.txt files I've written thus far okay, and what else do I need to add to complete the build? I'd be happy to share any other files or details if needed. As far as I've checked, I cannot find a similar question on this forum. I found one where someone claimed to have ported the build process to CMake, but didn't share any files. Thank you in advance.