You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
4.0 KiB
CMake
112 lines
4.0 KiB
CMake
# See the end of this file for copyright and license terms.
|
|
|
|
# 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_image DEPENDS gaybsd_image.elf)
|
|
add_custom_command(
|
|
TARGET gaybsd_image
|
|
COMMAND "${CMAKE_OBJCOPY}"
|
|
ARGS
|
|
-O binary
|
|
"$<TARGET_FILE:gaybsd_image.elf>"
|
|
"${CMAKE_BINARY_DIR}/gaybsd_image"
|
|
)
|
|
|
|
add_custom_target(gaybsd ALL DEPENDS
|
|
gaybsd_image
|
|
)
|
|
|
|
# This file is part of GayBSD.
|
|
# Copyright (c) 2021 fef <owo@fef.moe>.
|
|
#
|
|
# GayBSD is nonviolent software: you may only use, redistribute, and/or
|
|
# modify it under the terms of the Cooperative Nonviolent Public License
|
|
# (CNPL) as found in the LICENSE file in the source code root directory
|
|
# or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
|
# of the license, or (at your option) any later version.
|
|
#
|
|
# GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
|
# permitted by applicable law. See the CNPL for details.
|