summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Gavrilov <alexey.gavrilov@mail.com>2026-03-27 14:03:55 +0700
committerAlexey Gavrilov <alexey.gavrilov@mail.com>2026-03-27 14:03:55 +0700
commit6ffe96d1e3f0289c2070e050cf8e1a30288e6d91 (patch)
tree746485cfc0f55dad82d1d0daad9677bf63475cba
parenta4dea4148157a94a9143dbbd92fdd88b4358676c (diff)
Cmake build generator support: build stage
Multi-target architecture implementation: each root source code directory presents the one *INTERFACE* target to it's subdirectory subtargets that link only as *STATIC* library. For instance, *arch* directory presents *Architecture* target then *Architecture* target has *CPUID*, *IO*, *PORT* and etc. dependencies Exact order of linking targets is: boot.o CRTIBUNDLE <TARGETS> CRTNBUNDLE. Sequence destruction cause to UB. Please to pay attention to this. TODO - Debug information - Build type - Toolchain file - Image creation - Build by WinGW compiler on Windows platform (optional) Signed-off-by: Alexey Gavrilov <alexey.gavrilov@mail.com>
-rw-r--r--CMakeLists.txt99
-rw-r--r--arch/CMakeLists.txt17
-rw-r--r--arch/SecondaryInit.h2
-rw-r--r--arch/x86/CMakeLists.txt34
-rw-r--r--arch/x86/boot.nasm (renamed from kernel/boot.s)0
-rw-r--r--arch/x86/cpuid/CMakeLists.txt25
-rw-r--r--arch/x86/cpuid/Cpuid.h2
-rw-r--r--arch/x86/cpuid/CpuidCheck.nasm (renamed from arch/x86/cpuid/CpuidCheck.s)0
-rw-r--r--arch/x86/gdt/CMakeLists.txt23
-rwxr-xr-xarch/x86/gdt/Gdt.h2
-rw-r--r--arch/x86/gdt/SwitchToGdt.nasm (renamed from arch/x86/gdt/SwitchToGdt.s)0
-rw-r--r--arch/x86/ic/CMakeLists.txt16
-rw-r--r--arch/x86/ic/IPic.h2
-rw-r--r--arch/x86/idt/CMakeLists.txt15
-rw-r--r--arch/x86/io/CMakeLists.txt16
-rw-r--r--arch/x86/io/VGADisplayInfo.h2
-rw-r--r--arch/x86/msr/CMakeLists.txt15
-rw-r--r--arch/x86/port/CMakeLists.txt16
-rw-r--r--arch/x86/port/PortOps.h2
-rw-r--r--cmake/module/metadata.cmake8
-rw-r--r--drivers/CMakeLists.txt3
-rw-r--r--drivers/acpi/Acpi.h2
-rw-r--r--drivers/acpi/CMakeLists.txt17
-rw-r--r--drivers/acpi/Ics.h2
-rw-r--r--include/CMakeLists.txt27
-rw-r--r--include/MemoryOperations.h2
-rw-r--r--include/StringOperations.h2
-rw-r--r--include/Templates.h2
-rw-r--r--include/TypeConverter.h2
-rw-r--r--include/Types.h (renamed from include/types.h)0
-rw-r--r--include/containers/CMakeLists.txt10
-rw-r--r--kernel/CMakeLists.txt14
-rw-r--r--kernel/details/CMakeLists.txt8
-rw-r--r--kernel/kernel.cpp (renamed from kernel/kernel.c)0
-rw-r--r--libgcc/CMakeLists.txt25
-rw-r--r--libgcc/x86/CMakeLists.txt15
-rw-r--r--libgcc/x86/crti.nasm (renamed from libgcc/x86/crti.s)0
-rw-r--r--libgcc/x86/crtn.nasm (renamed from libgcc/x86/crtn.s)0
-rw-r--r--makefile72
39 files changed, 415 insertions, 84 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..33ac2dc
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,99 @@
+# Regard that file as root of whole project
+# which include farther subprojects source codes
+
+# Expected input variables:
+# ARCH: type of architecture
+
+set(CXX_FLAGS
+ -Wall
+ -ffreestanding
+ -nostdinc
+ -nostdlib
+ -fno-rtti
+ -mgeneral-regs-only
+)
+
+#---DEV PROPERTIES--- (delete in production)
+# message(STATUS ${CMAKE_ASM_NASM_COMPILER})
+set(CMAKE_SYSTEM_NAME Generic)
+set(CMAKE_ASM_NASM_OBJECT_FORMAT elf32)
+set(CMAKE_CXX_COMPILER i686-elf-g++)
+set(CMAKE_CXX_COMPILER_WORKS 1)
+# set(CMAKE_CUSTOM_LINKER i686-elf-ld)
+# set(CMAKE_CXX_LINK_EXECUTABLE
+# "ld <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+# set(CMAKE_CXX_FLAGS "-I${CMAKE_CURRENT_LIST_DIR}/include")
+# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -Wall -ffreestanding -nostdinc -nostdlib -fno-rtti -mgeneral-regs-only")
+# message(STATUS ${CMAKE_ASM_NASM_FLAGS})
+# message(STATUS ${CMAKE_ASM_NASM_OBJECT_FORMAT})
+# message(STATUS ${CMAKE_CXX_LINK_EXECUTABLE})
+# message(STATUS ${CMAKE_CXX_LINK_FLAGS})
+#--------------------------------------------
+
+cmake_minimum_required(VERSION 3.25)
+
+project(ObjectiveProject LANGUAGES CXX ASM_NASM)
+
+list(APPEND CMAKE_MODULE_PATH
+ "${ObjectiveProject_SOURCE_DIR}/cmake/module"
+)
+
+include(metadata)
+
+set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+add_executable(Objective)
+
+# Set architecture by default if not present
+if(NOT ARCH IN_LIST OBJECTIVE_SUPPORTED_PROCESSORS)
+ list(GET OBJECTIVE_SUPPORTED_PROCESSORS 0 ARCH)
+endif()
+
+# Create target with compiler requirements (include directories, flags and etc)
+add_library(CXX_COMPILER_REQUIREMENTS INTERFACE)
+
+# Target with linker requirements
+add_library(CXX_LINKER_REQUIREMENTS INTERFACE)
+target_link_options(CXX_LINKER_REQUIREMENTS INTERFACE
+ ${CXX_FLAGS}
+)
+target_link_libraries(CXX_LINKER_REQUIREMENTS INTERFACE
+ gcc
+)
+
+# Set compiler flags
+if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
+ target_compile_options(CXX_COMPILER_REQUIREMENTS INTERFACE
+ ${CXX_FLAGS}
+ )
+endif()
+
+target_include_directories(CXX_COMPILER_REQUIREMENTS
+ INTERFACE
+ ${ObjectiveProject_SOURCE_DIR}/include
+)
+
+# Subscribe compiler requirements to Object executable
+target_link_libraries(Objective PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+add_subdirectory(arch)
+add_subdirectory(kernel)
+add_subdirectory(drivers)
+add_subdirectory(include)
+add_subdirectory(libgcc)
+
+target_sources(Objective PRIVATE
+ $<TARGET_OBJECTS:Boot>
+)
+
+target_link_libraries(Objective PRIVATE
+ CRTI
+ Architecture
+ Kernel
+ Drivers
+ CRTN
+)
+
+target_link_libraries(Objective PRIVATE CXX_LINKER_REQUIREMENTS)
diff --git a/arch/CMakeLists.txt b/arch/CMakeLists.txt
new file mode 100644
index 0000000..c8719ce
--- /dev/null
+++ b/arch/CMakeLists.txt
@@ -0,0 +1,17 @@
+add_library(Architecture INTERFACE)
+
+add_library(Initialization STATIC)
+target_link_libraries(Initialization PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+target_sources(Initialization PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/SecondaryInit.cpp
+)
+
+target_sources(Initialization
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/SecondaryInit.h
+)
+
+add_subdirectory(${ARCH})
diff --git a/arch/SecondaryInit.h b/arch/SecondaryInit.h
index 53ff191..104f44c 100644
--- a/arch/SecondaryInit.h
+++ b/arch/SecondaryInit.h
@@ -1,6 +1,6 @@
-#include <types.h>
#include "../kernel/mem/Segments.h"
#include "../kernel/mem/Kheap.h"
+#include <Types.h>
#if defined(__IAPC)
#include "x86/PrimaryInit.h"
diff --git a/arch/x86/CMakeLists.txt b/arch/x86/CMakeLists.txt
new file mode 100644
index 0000000..5601efa
--- /dev/null
+++ b/arch/x86/CMakeLists.txt
@@ -0,0 +1,34 @@
+target_link_options(CXX_LINKER_REQUIREMENTS INTERFACE
+ LINKER:-L${CMAKE_CURRENT_LIST_DIR}
+)
+
+target_sources(Initialization PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/PrimaryInit.cpp
+)
+
+target_sources(Initialization
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/PrimaryInit.h
+)
+
+target_link_libraries(Architecture INTERFACE Initialization)
+
+# Create library for assembler build
+add_library(ArchitectureAssemblerSources STATIC)
+
+add_library(Boot OBJECT)
+target_sources(Boot PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/boot.nasm
+)
+
+add_subdirectory(cpuid)
+add_subdirectory(idt)
+add_subdirectory(gdt)
+add_subdirectory(ic)
+add_subdirectory(io)
+add_subdirectory(msr)
+add_subdirectory(port)
+
+target_link_libraries(Architecture INTERFACE ArchitectureAssemblerSources)
diff --git a/kernel/boot.s b/arch/x86/boot.nasm
index 11175af..11175af 100644
--- a/kernel/boot.s
+++ b/arch/x86/boot.nasm
diff --git a/arch/x86/cpuid/CMakeLists.txt b/arch/x86/cpuid/CMakeLists.txt
new file mode 100644
index 0000000..e8528e8
--- /dev/null
+++ b/arch/x86/cpuid/CMakeLists.txt
@@ -0,0 +1,25 @@
+add_library(CPUID STATIC)
+target_link_libraries(CPUID PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+target_sources(CPUID PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/Cpuid.cpp
+)
+
+target_sources(CPUID
+ PUBLIC
+ FILE_SET HEADERS
+ BASE_DIRS
+ ${CMAKE_CURRENT_LIST_DIR}
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/Cpuid.h
+)
+
+target_link_libraries(Architecture INTERFACE CPUID)
+
+add_library(CPUIDASM OBJECT)
+
+target_sources(CPUIDASM PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/CpuidCheck.nasm
+)
+
+target_sources(ArchitectureAssemblerSources PRIVATE $<TARGET_OBJECTS:CPUIDASM>)
diff --git a/arch/x86/cpuid/Cpuid.h b/arch/x86/cpuid/Cpuid.h
index a65cdc8..c8ad4aa 100644
--- a/arch/x86/cpuid/Cpuid.h
+++ b/arch/x86/cpuid/Cpuid.h
@@ -1,6 +1,6 @@
#ifndef CPUID_H
#define CPUID_H
-#include <types.h>
+#include <Types.h>
#include <MemoryOperations.h>
// To declare cpuid::Executor::Executor()
diff --git a/arch/x86/cpuid/CpuidCheck.s b/arch/x86/cpuid/CpuidCheck.nasm
index 67bc9eb..67bc9eb 100644
--- a/arch/x86/cpuid/CpuidCheck.s
+++ b/arch/x86/cpuid/CpuidCheck.nasm
diff --git a/arch/x86/gdt/CMakeLists.txt b/arch/x86/gdt/CMakeLists.txt
new file mode 100644
index 0000000..57e3c26
--- /dev/null
+++ b/arch/x86/gdt/CMakeLists.txt
@@ -0,0 +1,23 @@
+add_library(GDT STATIC)
+target_link_libraries(GDT PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+target_sources(GDT PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/Gdt.cpp
+)
+
+target_sources(GDT
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/Gdt.h
+)
+
+target_link_libraries(Architecture INTERFACE GDT)
+
+add_library(GDTASM OBJECT)
+
+target_sources(GDTASM PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/SwitchToGdt.nasm
+)
+
+target_sources(ArchitectureAssemblerSources PRIVATE $<TARGET_OBJECTS:GDTASM>)
diff --git a/arch/x86/gdt/Gdt.h b/arch/x86/gdt/Gdt.h
index 321d67c..8f1d967 100755
--- a/arch/x86/gdt/Gdt.h
+++ b/arch/x86/gdt/Gdt.h
@@ -1,7 +1,7 @@
#ifndef GDT_H
#define GDT_H
-#include <types.h>
+#include <Types.h>
#include <MemoryOperations.h>
diff --git a/arch/x86/gdt/SwitchToGdt.s b/arch/x86/gdt/SwitchToGdt.nasm
index 52ebbc7..52ebbc7 100644
--- a/arch/x86/gdt/SwitchToGdt.s
+++ b/arch/x86/gdt/SwitchToGdt.nasm
diff --git a/arch/x86/ic/CMakeLists.txt b/arch/x86/ic/CMakeLists.txt
new file mode 100644
index 0000000..e6130d7
--- /dev/null
+++ b/arch/x86/ic/CMakeLists.txt
@@ -0,0 +1,16 @@
+add_library(IC STATIC)
+target_link_libraries(IC PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+target_sources(IC PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/Pic.cpp
+)
+
+target_sources(IC
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/Pic.h
+ ${CMAKE_CURRENT_LIST_DIR}/IPic.h
+)
+
+target_link_libraries(Architecture INTERFACE IC)
diff --git a/arch/x86/ic/IPic.h b/arch/x86/ic/IPic.h
index 9bb1b4f..5e0449b 100644
--- a/arch/x86/ic/IPic.h
+++ b/arch/x86/ic/IPic.h
@@ -1,7 +1,7 @@
#ifndef IPIC_H
#define IPIC_H
-#include <types.h>
+#include <Types.h>
// Defines
diff --git a/arch/x86/idt/CMakeLists.txt b/arch/x86/idt/CMakeLists.txt
new file mode 100644
index 0000000..da7bdae
--- /dev/null
+++ b/arch/x86/idt/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_library(IDT STATIC)
+target_link_libraries(IDT PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+target_sources(IDT PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/Idt.cpp
+)
+
+target_sources(IDT
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/Idt.h
+)
+
+target_link_libraries(Architecture INTERFACE IDT)
diff --git a/arch/x86/io/CMakeLists.txt b/arch/x86/io/CMakeLists.txt
new file mode 100644
index 0000000..9c2dd33
--- /dev/null
+++ b/arch/x86/io/CMakeLists.txt
@@ -0,0 +1,16 @@
+add_library(IO STATIC)
+target_link_libraries(IO PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+target_sources(IO PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/VGADisplay.cpp
+)
+
+target_sources(IO
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/VGADisplay.h
+ ${CMAKE_CURRENT_LIST_DIR}/VGADisplayInfo.h
+)
+
+target_link_libraries(Architecture INTERFACE IO)
diff --git a/arch/x86/io/VGADisplayInfo.h b/arch/x86/io/VGADisplayInfo.h
index 875e7e5..55303dd 100644
--- a/arch/x86/io/VGADisplayInfo.h
+++ b/arch/x86/io/VGADisplayInfo.h
@@ -1,7 +1,7 @@
#ifndef VGAINFOCLASS_H
#define VGAINFOCLASS_H
-#include <types.h>
+#include <Types.h>
#define TOBG(attr) attr << 4
diff --git a/arch/x86/msr/CMakeLists.txt b/arch/x86/msr/CMakeLists.txt
new file mode 100644
index 0000000..86d3330
--- /dev/null
+++ b/arch/x86/msr/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_library(MSR STATIC)
+target_link_libraries(MSR PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+target_sources(MSR PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/Msr.cpp
+)
+
+target_sources(MSR
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/Msr.h
+)
+
+target_link_libraries(Architecture INTERFACE MSR)
diff --git a/arch/x86/port/CMakeLists.txt b/arch/x86/port/CMakeLists.txt
new file mode 100644
index 0000000..6ad61ef
--- /dev/null
+++ b/arch/x86/port/CMakeLists.txt
@@ -0,0 +1,16 @@
+add_library(Port STATIC)
+target_link_libraries(Port PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+target_sources(Port PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/PortOps.cpp
+)
+
+target_sources(Port
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/PortOps.h
+ ${CMAKE_CURRENT_LIST_DIR}/Operations
+)
+
+target_link_libraries(Architecture INTERFACE Port)
diff --git a/arch/x86/port/PortOps.h b/arch/x86/port/PortOps.h
index 7db3a5f..f8dac63 100644
--- a/arch/x86/port/PortOps.h
+++ b/arch/x86/port/PortOps.h
@@ -1,7 +1,7 @@
#ifndef PORT_H
#define PORT_H
-#include <types.h>
+#include <Types.h>
using regb = uint8;
diff --git a/cmake/module/metadata.cmake b/cmake/module/metadata.cmake
new file mode 100644
index 0000000..fec5bf8
--- /dev/null
+++ b/cmake/module/metadata.cmake
@@ -0,0 +1,8 @@
+# FIX: get elements from ObjectiveProject_ROOT/arch directory
+set(OBJECTIVE_SUPPORTED_PROCESSORS x86;arm/sunxi CACHE STRING "Supported
+processors by Objective kernel")
+
+# FIX: get apps from docs
+set(OBJECTIVE_SUPPORTED_ISO_CREATION_APPS grub-mkrescue CACHE STRING "Supported
+apps to create ISO image")
+
diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt
new file mode 100644
index 0000000..c11b75f
--- /dev/null
+++ b/drivers/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library(Drivers INTERFACE)
+
+add_subdirectory(acpi)
diff --git a/drivers/acpi/Acpi.h b/drivers/acpi/Acpi.h
index 506ab99..d9dc378 100644
--- a/drivers/acpi/Acpi.h
+++ b/drivers/acpi/Acpi.h
@@ -1,4 +1,4 @@
-#include <types.h>
+#include <Types.h>
#include <StringOperations.h>
#include "Ics.h"
diff --git a/drivers/acpi/CMakeLists.txt b/drivers/acpi/CMakeLists.txt
new file mode 100644
index 0000000..32f2fac
--- /dev/null
+++ b/drivers/acpi/CMakeLists.txt
@@ -0,0 +1,17 @@
+add_library(ACPI STATIC)
+target_link_libraries(ACPI PUBLIC CXX_COMPILER_REQUIREMENTS)
+
+target_sources(ACPI PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/Acpi.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/Ics.cpp
+)
+
+target_sources(ACPI
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/Acpi.h
+ ${CMAKE_CURRENT_LIST_DIR}/Ics.h
+)
+
+target_link_libraries(Drivers INTERFACE ACPI)
diff --git a/drivers/acpi/Ics.h b/drivers/acpi/Ics.h
index 8289c90..b4e38d4 100644
--- a/drivers/acpi/Ics.h
+++ b/drivers/acpi/Ics.h
@@ -1,4 +1,4 @@
-#include <types.h>
+#include <Types.h>
class Ics
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
new file mode 100644
index 0000000..1b06451
--- /dev/null
+++ b/include/CMakeLists.txt
@@ -0,0 +1,27 @@
+add_library(Include STATIC)
+
+target_sources(Include
+ PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/MemoryOperations.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/StringOperations.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/TypeConverter.cpp
+)
+
+target_sources(Include
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/ISingleton.h
+ ${CMAKE_CURRENT_LIST_DIR}/MemoryOperations.h
+ ${CMAKE_CURRENT_LIST_DIR}/StringOperations.h
+ ${CMAKE_CURRENT_LIST_DIR}/Templates.h
+ ${CMAKE_CURRENT_LIST_DIR}/TypeConverter.h
+ ${CMAKE_CURRENT_LIST_DIR}/Types.h
+)
+
+add_subdirectory(containers)
+
+# Link include library to all consumers
+target_link_libraries(Architecture INTERFACE Include)
+target_link_libraries(Kernel INTERFACE Include)
+target_link_libraries(Drivers INTERFACE Include)
diff --git a/include/MemoryOperations.h b/include/MemoryOperations.h
index 046ca1d..ef116dd 100644
--- a/include/MemoryOperations.h
+++ b/include/MemoryOperations.h
@@ -1,7 +1,7 @@
#ifndef MEMORYOPERATIONS_H
#define MEMORYOPERATIONS_H
-#include <types.h>
+#include <Types.h>
class MemoryOperations
diff --git a/include/StringOperations.h b/include/StringOperations.h
index 5d2826c..53519fe 100644
--- a/include/StringOperations.h
+++ b/include/StringOperations.h
@@ -1,7 +1,7 @@
#ifndef STRINGOPERATIONS_H
#define STRINGOPERATIONS_H
-#include <types.h>
+#include <Types.h>
class MemArea
diff --git a/include/Templates.h b/include/Templates.h
index 8a1bd95..00b97d3 100644
--- a/include/Templates.h
+++ b/include/Templates.h
@@ -2,7 +2,7 @@
#define TEMPLATES_H
-#include <types.h>
+#include <Types.h>
template<typename T, T val>
struct constant
diff --git a/include/TypeConverter.h b/include/TypeConverter.h
index f9db95c..8b426b9 100644
--- a/include/TypeConverter.h
+++ b/include/TypeConverter.h
@@ -1,7 +1,7 @@
#ifndef TYPECONVERTER_H
#define TYPECONVERTER_H
-#include <types.h>
+#include <Types.h>
class IntConverter
{
diff --git a/include/types.h b/include/Types.h
index 9f59063..9f59063 100644
--- a/include/types.h
+++ b/include/Types.h
diff --git a/include/containers/CMakeLists.txt b/include/containers/CMakeLists.txt
new file mode 100644
index 0000000..aab0387
--- /dev/null
+++ b/include/containers/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_library(ContainersHeaders INTERFACE)
+
+target_sources(ContainersHeaders
+ PUBLIC
+ FILE_SET HEADERS
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/Tuple.h
+)
+
+target_link_libraries(Include PUBLIC ContainersHeaders)
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
new file mode 100644
index 0000000..cd249d0
--- /dev/null
+++ b/kernel/CMakeLists.txt
@@ -0,0 +1,14 @@
+target_link_options(CXX_LINKER_REQUIREMENTS INTERFACE
+ LINKER:-T${CMAKE_CURRENT_LIST_DIR}/linker.ld
+)
+
+add_library(Kernel INTERFACE)
+
+add_library(Main STATIC)
+target_sources(Main PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/kernel.cpp
+)
+target_link_libraries(Main PUBLIC CXX_COMPILER_REQUIREMENTS Architecture Include)
+target_link_libraries(Kernel INTERFACE Main)
+
+add_subdirectory(details)
diff --git a/kernel/details/CMakeLists.txt b/kernel/details/CMakeLists.txt
new file mode 100644
index 0000000..881d360
--- /dev/null
+++ b/kernel/details/CMakeLists.txt
@@ -0,0 +1,8 @@
+target_sources(CPUID
+ PUBLIC
+ FILE_SET HEADERS
+ BASE_DIRS
+ ${CMAKE_CURRENT_LIST_DIR}
+ FILES
+ ${CMAKE_CURRENT_LIST_DIR}/Platform.h
+)
diff --git a/kernel/kernel.c b/kernel/kernel.cpp
index c280755..c280755 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.cpp
diff --git a/libgcc/CMakeLists.txt b/libgcc/CMakeLists.txt
new file mode 100644
index 0000000..b5b2abc
--- /dev/null
+++ b/libgcc/CMakeLists.txt
@@ -0,0 +1,25 @@
+macro(setup_crt_object_file object_file target_name)
+ execute_process(
+ COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=${object_file}
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE PATH
+ ERROR_VARIABLE ERROR_MESSAGE
+ RESULT_VARIABLE RESULT
+ )
+
+ if(RESULT)
+ message(FATAL_ERROR ${ERROR_MESSAGE})
+ endif()
+
+ add_library(${target_name} OBJECT IMPORTED GLOBAL)
+ set_target_properties(${target_name} PROPERTIES
+ IMPORTED_OBJECTS ${PATH}
+ )
+
+endmacro()
+
+# TODO: set platform specific CRT objects
+setup_crt_object_file(crtbegin.o CRTBEGIN)
+setup_crt_object_file(crtend.o CRTEND)
+
+add_subdirectory(${ARCH})
diff --git a/libgcc/x86/CMakeLists.txt b/libgcc/x86/CMakeLists.txt
new file mode 100644
index 0000000..2a1bec9
--- /dev/null
+++ b/libgcc/x86/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_library(CRTI INTERFACE)
+add_library(CRTIBUNDLE STATIC)
+target_sources(CRTIBUNDLE PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/crti.nasm
+ $<TARGET_OBJECTS:CRTBEGIN>
+)
+target_link_libraries(CRTI INTERFACE CRTIBUNDLE)
+
+add_library(CRTN INTERFACE)
+add_library(CRTNBUNDLE STATIC)
+target_sources(CRTNBUNDLE PRIVATE
+ ${CMAKE_CURRENT_LIST_DIR}/crtn.nasm
+ $<TARGET_OBJECTS:CRTEND>
+)
+target_link_libraries(CRTN INTERFACE CRTNBUNDLE)
diff --git a/libgcc/x86/crti.s b/libgcc/x86/crti.nasm
index 57cb8c1..57cb8c1 100644
--- a/libgcc/x86/crti.s
+++ b/libgcc/x86/crti.nasm
diff --git a/libgcc/x86/crtn.s b/libgcc/x86/crtn.nasm
index 537fa65..537fa65 100644
--- a/libgcc/x86/crtn.s
+++ b/libgcc/x86/crtn.nasm
diff --git a/makefile b/makefile
deleted file mode 100644
index 79152f8..0000000
--- a/makefile
+++ /dev/null
@@ -1,72 +0,0 @@
-CC = i686-elf-g++
-LD = ld
-ASM = nasm
-# test -O2 flag
-CFLAGS = -std=c++20 -c -m32 -Wall -ffreestanding -nostdinc -nostdlib -fno-rtti -mgeneral-regs-only
-AFLAGS = -f elf32
-LDFLAGS = -m elf_i386 $(patsubst %,-L%,$(subst :, ,$(LIBS_PATH))) -lgcc
-QEMUFLAGS =
-
-CFILES = $(shell find ./ -type f \( -name \*.cpp -o -name \*.c \))
-AFILES = $(shell find ./ -type f \( -iname \*.s -o -name \*.asm \))
-LDFILE = ./kernel/linker.ld
-SOURCE_FILES = $(CFILES) $(AFILES)
-OBJ_FILES = $(addprefix $(BDIR)/, $(addsuffix .o, $(basename $(SOURCE_FILES))))
-INCLUDE = ./include
-# Bad practice!
-ARCHDIR = arch/x86
-
-ifdef DEBUG
- CFLAGS := -g3 $(CFLAGS)
- AFLAGS := -g $(AFLAGS)
- QEMUFLAGS := -s -S $(QEMUFLAGS)
-endif
-
-OS_BINARY = $(BDIR)/kernel.bin
-BDIR = ./build
-
-BOOTOBJ = $(filter %boot.o, $(OBJ_FILES))
-CRTIOBJ = $(filter %crti.o, $(OBJ_FILES))
-CRTNOBJ = $(filter %crtn.o, $(OBJ_FILES))
-OBJ_REORDERING = $(filter-out $(BOOTOBJ), $(filter-out $(CRTIOBJ), $(filter-out $(CRTNOBJ), $(OBJ_FILES))))
-
-
-.PHONY: install $(SOURCE_FILES)
-
-build: startbuild $(SOURCE_FILES)
- @echo "Bootfile: " $(BOOTOBJ) $(CRTIOBJ) $(CRTNOBJ)
- @echo $(OBJ_FILES)
- echo $(AFLAGS)
- echo $(CFLAGS)
- @echo "Link object files..."
- $(LD) -o $(OS_BINARY) -L$(ARCHDIR) -T$(LDFILE) $(BOOTOBJ) $(CRTIOBJ) $(LIBS_PATH)crtbegin.o $(OBJ_REORDERING) $(LIBS_PATH)crtend.o $(CRTNOBJ) $(LDFLAGS)
- @echo "Project was built"
-
-$(CFILES):
- mkdir -p $(BDIR)/$(@D)
- $(CC) $(CFLAGS) -I $(INCLUDE) -o $(BDIR)/$(addsuffix .o, $(basename $@)) $@
-
-$(AFILES):
- mkdir -p $(BDIR)/$(@D)
- $(ASM) $(AFLAGS) -o $(BDIR)/$(addsuffix .o, $(basename $@)) $@
-
-startbuild:
- @echo $(OBJ_FILES)
- rm -rf $(BDIR)
- mkdir $(BDIR)
- @echo "Compile source files..."
-
-install:
- @echo "Creating an iso image of OS"
- mkdir -p ./iso/os/
- cp ./$(BDIR)/kernel.bin ./iso/os/
- grub-mkrescue -o ./$(BDIR)/kernel.iso ./iso
-
-clean:
- rm -rf $(BDIR)
- rm -rf ./iso/os/kernel.bin
-
-run:
- qemu-system-i386 $(QEMUFLAGS) -cdrom ./$(BDIR)/kernel.iso
-
-all: clean build install run