cmake: "fix" compiler stuff
I have no idea if i've made things better or worse with these changes, but tbh i don't really care. It didn't compile (with the upcoming changes to kprintf(), that is) before, it does compile now. End of story.
This commit is contained in:
parent
9e89be2eab
commit
c31149c6cc
2 changed files with 26 additions and 6 deletions
|
@ -1,5 +1,13 @@
|
|||
# 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)
|
||||
|
@ -20,7 +28,7 @@ configure_file(
|
|||
|
||||
include("arch/${ARCH}/config/toolchain.cmake")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffreestanding")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffreestanding -fno-stack-protector")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -D_ASM_SOURCE")
|
||||
if(DEBUG)
|
||||
# -Og on gcc optimizes for the best debugging experience, but apparently this
|
||||
|
@ -38,8 +46,8 @@ endif()
|
|||
|
||||
# --whole-archive ensures no (seemingly) unused symbols
|
||||
# like the multiboot table are omitted from the archive
|
||||
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -nodefaultlibs -static --whole-archive")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nostdlib -nodefaultlibs -static")
|
||||
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"
|
||||
|
@ -67,6 +75,10 @@ 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)
|
||||
|
|
|
@ -10,14 +10,22 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
|||
set(CMAKE_AR ${TOOLCHAIN_PATH}/${CMAKE_EXECUTABLE_PREFIX}ar${CMAKE_EXECUTABLE_SUFFIX})
|
||||
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PATH}/${CMAKE_EXECUTABLE_PREFIX}clang${CMAKE_EXECUTABLE_SUFFIX})
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/${CMAKE_EXECUTABLE_PREFIX}clang${CMAKE_EXECUTABLE_SUFFIX})
|
||||
set(CMAKE_LINKER ${TOOLCHAIN_PATH}/${CMAKE_EXECUTABLE_PREFIX}ld${CMAKE_EXECUTABLE_SUFFIX})
|
||||
set(CMAKE_LINKER ${TOOLCHAIN_PATH}/${CMAKE_EXECUTABLE_PREFIX}ld.lld${CMAKE_EXECUTABLE_SUFFIX})
|
||||
set(CMAKE_OBJCOPY ${TOOLCHAIN_PATH}/${CMAKE_EXECUTABLE_PREFIX}objcopy${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "")
|
||||
set(CMAKE_RANLIB ${TOOLCHAIN_PATH}/${CMAKE_EXECUTABLE_PREFIX}ranlib${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "")
|
||||
set(CMAKE_SZE ${TOOLCHAIN_PATH}/${CMAKE_EXECUTABLE_PREFIX}szr${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "")
|
||||
set(CMAKE_STRIP ${TOOLCHAIN_PATH}/${CMAKE_EXECUTABLE_PREFIX}strip${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target i686-none -m32")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -target i686-none -m32")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32 -march=i686")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32 -march=i686")
|
||||
|
||||
set(triple i686-pc-none-elf)
|
||||
set(CMAKE_C_COMPILER_TARGET ${triple})
|
||||
set(CMAKE_ASM_COMPILER_TARGET ${triple})
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=lld")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld")
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_LIST_DIR}/kernel_config.ld.in"
|
||||
|
|
Loading…
Reference in a new issue