Files
magenta/CMakeLists.txt
T
wash 4d30949a4d meta: add debugging library
the debug library can be used by both server (the kernel) and client
(the debugger) applications. the library implements the protocol
that is used for communication between the kernel and debugger, as
well as handling for any requests supported by the protocol.
2026-06-06 17:25:00 +01:00

88 lines
2.6 KiB
CMake

cmake_minimum_required(VERSION 3.31)
project(magenta C ASM)
if (NOT BUILD_TOOLS_DIR)
message(FATAL_ERROR "No build tools directory specified. Please run build.sh")
endif ()
set(CMAKE_C_STANDARD 17)
set(kernel_arch x86_64)
set(kernel_name "Magenta")
set(kernel_exe_name "magenta_kernel")
set(generic_src_dirs ds init kernel libc sched util vm syscall)
set(kernel_sources "")
set(kernel_headers "")
set(version_args --arch ${CMAKE_SYSTEM_PROCESSOR})
if (CMAKE_BUILD_TYPE)
if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(version_args ${version_args} "--release")
endif ()
endif()
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/magenta.buildid
${version_args}
OUTPUT_VARIABLE kernel_version
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Magenta kernel version: ${kernel_version}")
foreach (dir ${generic_src_dirs})
file(GLOB_RECURSE dir_sources ${dir}/*.c)
file(GLOB_RECURSE dir_headers ${dir}/*.h)
set(kernel_sources ${kernel_sources} ${dir_sources})
set(kernel_headers ${kernel_headers} ${dir_headers})
endforeach (dir)
file(GLOB_RECURSE arch_sources_c arch/${kernel_arch}/*.c)
file(GLOB_RECURSE arch_sources_asm arch/${kernel_arch}/*.S)
file(GLOB_RECURSE arch_headers arch/${kernel_arch}/*.h)
add_executable(${kernel_exe_name}
${kernel_sources}
${kernel_headers}
${arch_sources_c}
${arch_sources_asm}
${arch_headers})
target_include_directories(${kernel_exe_name} PRIVATE
include
libc/include
libmagenta/include
arch/${kernel_arch}/include)
target_compile_options(${kernel_exe_name} PRIVATE
-nostdlib -ffreestanding
-Wall -Werror -pedantic -Wno-language-extension-token -Wno-unused-function -Wno-gnu-statement-expression
-g -fPIC -Iinclude -Iarch/${kernel_arch}/include -Ilibc/include)
add_custom_command(
TARGET ${kernel_exe_name}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${kernel_exe_name}> $<TARGET_FILE:${kernel_exe_name}>.debug
COMMAND ${CMAKE_STRIP} -g $<TARGET_FILE:${kernel_exe_name}>)
target_link_libraries(${kernel_exe_name} -nostdlib -ffreestanding -lgcc)
target_compile_definitions(${kernel_exe_name} PRIVATE
KERNEL_NAME="${kernel_name}"
KERNEL_VERSION="${kernel_version}"
KERNEL_ARCH="${kernel_arch}")
include(arch/${kernel_arch}/config.cmake)
include(arch/${kernel_arch}/targets.cmake)
add_subdirectory(debug)
target_link_libraries(${kernel_exe_name} magenta_debug)
target_compile_definitions(magenta_debug PRIVATE KERNEL_VERSION="${kernel_version}")
target_include_directories(magenta_debug PRIVATE
include
libc/include
libmagenta/include
arch/${kernel_arch}/include)