As of now, everything except the code imported from FreeBSD is proprietary. Of course, it won't be like this for long, only until we have decided which license we like to use. The rationale is that releasing everything under a copyleft license later is always easier than doing so immediately and then changing it afterwards. Naturally, any changes made before this commit are still subject to the terms of the CNPL.
89 lines
3.2 KiB
CMake
89 lines
3.2 KiB
CMake
# Copyright (C) 2021 fef <owo@fef.moe>. All rights reserved.
|
|
|
|
# Look, i have absolutely zero patience when it comes to fucking around with
|
|
# build tools. This is most probably not the correct way to do it (especially
|
|
# with the cross compiler setup in arch/<arch>/config/toolchain.cmake), but i
|
|
# literally do not care. After hours of Duck Duck Googling random shit, i
|
|
# finally got this to work (kind of). If you know your way around CMake, you
|
|
# are more than welcome to submit a PR that fixes this mess, i would appreciate
|
|
# it very much. But i certainly don't have the energy for it.
|
|
|
|
cmake_minimum_required(VERSION 3.14.0)
|
|
|
|
project(gaybsd VERSION 0.1.0 LANGUAGES C ASM)
|
|
set(CMAKE_C_STANDARD 11)
|
|
set(CMAKE_C_EXTENSIONS ON)
|
|
|
|
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
endif()
|
|
|
|
include(cmake/git.cmake)
|
|
|
|
include(cmake/config.cmake)
|
|
configure_file(
|
|
"${CMAKE_SOURCE_DIR}/include/gay/config.h.in"
|
|
"${CMAKE_BINARY_DIR}/include/gay/config.h"
|
|
)
|
|
|
|
include("arch/${ARCH}/config/toolchain.cmake")
|
|
|
|
# Used by the KASSERT macro for printing the filename relative to the source root
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -nostdinc -ffreestanding -fno-stack-protector")
|
|
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -pipe -D_ASM_SOURCE")
|
|
if(DEBUG)
|
|
# -Og on gcc optimizes for the best debugging experience, but apparently this
|
|
# is treated the same as -O1 on clang for some reason. The LLVM manual says
|
|
# you're supposed to use -O0 in order to get the most submissive and debuggable
|
|
# code instead:
|
|
# <https://clang.llvm.org/docs/CommandGuide/clang.html#code-generation-options>
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")
|
|
# i don't think -O0 does anything for assembly code, but it can't hurt to
|
|
# have it in there just in case (somebody check on this at some point plz)
|
|
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O0 -ggdb")
|
|
else()
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -ggdb")
|
|
endif()
|
|
|
|
# --whole-archive ensures no (seemingly) unused symbols
|
|
# like the multiboot table are omitted from the archive
|
|
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -ffreestanding -static --whole-archive")
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ffreestanding -nostdlib -static")
|
|
|
|
set(GAY_INCLUDE_DIRS
|
|
"${CMAKE_SOURCE_DIR}/include"
|
|
"${CMAKE_SOURCE_DIR}/arch/${ARCH}/include"
|
|
"${CMAKE_BINARY_DIR}/include"
|
|
)
|
|
|
|
set(GAY_DEFINITIONS
|
|
"_GAY_SOURCE=202109L"
|
|
)
|
|
set(GAY_KERNEL_DEFINITIONS
|
|
"_KERNEL" # FreeBSD uses the same macro name
|
|
${GAY_DEFINITIONS}
|
|
)
|
|
|
|
include("lib/lib.cmake")
|
|
|
|
add_subdirectory("arch/${ARCH}")
|
|
add_subdirectory("kernel")
|
|
|
|
add_executable(gaybsd_image.elf)
|
|
# TODO: find a way around this hack
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/_empty.c" "")
|
|
target_sources(gaybsd_image.elf PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/_empty.c")
|
|
target_link_libraries(gaybsd_image.elf PRIVATE
|
|
gay_arch
|
|
gay_kernel
|
|
# libgcc is needed for some internal stuff like 64-bit division which
|
|
# isn't natively supported by the CPU instruction set (on i686).
|
|
# Apparently, clang uses that too.
|
|
gcc
|
|
)
|
|
|
|
add_custom_target(gaybsd ALL DEPENDS
|
|
gaybsd_image.elf
|
|
)
|