From 6ffe96d1e3f0289c2070e050cf8e1a30288e6d91 Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Fri, 27 Mar 2026 14:03:55 +0700 Subject: 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 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 --- CMakeLists.txt | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 CMakeLists.txt (limited to 'CMakeLists.txt') 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 -o ") +# 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_link_libraries(Objective PRIVATE + CRTI + Architecture + Kernel + Drivers + CRTN +) + +target_link_libraries(Objective PRIVATE CXX_LINKER_REQUIREMENTS) -- cgit v1.2.3