From: falcovorbis <fal...@us...> - 2024-04-23 07:01:39
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 1ff6f043444446a09d55e464fd9a73be5307c740 (commit) from 5ae615b8c20b78cab7485856a6d8f541c331c089 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 1ff6f043444446a09d55e464fd9a73be5307c740 Author: Paul Cercueil <pa...@cr...> Date: Tue Apr 23 06:25:57 2024 +0200 cmake: Simplify toolchain script (#501) * cmake: Simplify toolchain script Instead of duplicating all the CFLAGS and LDFLAGS that should be set by the user in the environ*.sh scripts, use the KOS wrappers as the compilers, which makes sure that the user flags are used by default. Signed-off-by: Paul Cercueil <pa...@cr...> * dreamcast.cmake work to support new toolchain * Added subarch-specific defines to build env - __DREAMCAST__ - __NAOMI__ * Update dreamcast.cmake Fixing typo! * Added config variables to dreamcast.cmake 1) Changed all references to $ENV{KOS_XXX} to just KOS_XXX 2) Either inherits KOS_XXX variables from KOS toolchain file, looks for them in the environment, or errors out --------- Signed-off-by: Paul Cercueil <pa...@cr...> Co-authored-by: Falco Girgis <gyr...@gm...> ----------------------------------------------------------------------- Summary of changes: environ_dreamcast.sh | 2 + utils/cmake/dreamcast.cmake | 70 ++++++++++++------------ utils/cmake/dreamcast.toolchain.cmake | 100 +++++++--------------------------- 3 files changed, 56 insertions(+), 116 deletions(-) diff --git a/environ_dreamcast.sh b/environ_dreamcast.sh index 7108f2cd..50551209 100644 --- a/environ_dreamcast.sh +++ b/environ_dreamcast.sh @@ -10,9 +10,11 @@ export KOS_CFLAGS="${KOS_CFLAGS} ${KOS_SH4_PRECISION} -ml -ffunction-sections -f export KOS_AFLAGS="${KOS_AFLAGS} -little" if [ x${KOS_SUBARCH} = xnaomi ]; then + export KOS_CFLAGS="${KOS_CFLAGS} -D__NAOMI__" export KOS_LDFLAGS="${KOS_LDFLAGS} ${KOS_SH4_PRECISION} -ml -Wl,-Ttext=0x8c020000 -Wl,--gc-sections" export KOS_LD_SCRIPT="-T${KOS_BASE}/utils/ldscripts/shlelf-naomi.xc" else + export KOS_CFLAGS="${KOS_CFLAGS} -D__DREAMCAST__" export KOS_LDFLAGS="${KOS_LDFLAGS} ${KOS_SH4_PRECISION} -ml -Wl,-Ttext=0x8c010000 -Wl,--gc-sections" export KOS_LD_SCRIPT="-T${KOS_BASE}/utils/ldscripts/shlelf.xc" fi diff --git a/utils/cmake/dreamcast.cmake b/utils/cmake/dreamcast.cmake index 4fff3a9c..0a30e304 100644 --- a/utils/cmake/dreamcast.cmake +++ b/utils/cmake/dreamcast.cmake @@ -1,6 +1,35 @@ +# Auxiliary CMake Utility Functions +# Copyright (C) 2023 Colton Pawielski +# Copyright (C) 2024 Falco Girgis +# +# This file implements utilities for the following additional functionality +# which exists in the KOS Make build system: +# 1) linking to existing binaries +# 2) adding a romdisk +# +# NOTE: When using the KOS CMake toolchain file, you do not need to include +# this file directly! + ### This minimum is based on the minimum requirement in dreamcast.toolchain.cmake cmake_minimum_required(VERSION 3.13) +#### Set Configuration Variables From Environment (if Necessary) #### +if(NOT DEFINED KOS_BASE) + if(NOT DEFINED ENV{KOS_BASE}) + message(FATAL_ERROR "KOS_BASE environment variable not found!") + else() + set(KOS_BASE $ENV{KOS_BASE}) + endif() +endif() + +if(NOT DEFINED KOS_CC_BASE) + if(NOT DEFINED ENV{KOS_CC_BASE}) + message(FATAL_ERROR "KOS_CC_BASE environment variable not found!") + else() + set(KOS_CC_BASE $ENV{KOS_CC_BASE}) + endif() +endif() + ### Helper Function for Bin2Object ### function(kos_bin2o inFile symbol) # outFile is optional and defaults to the symbol name in the build directory @@ -14,13 +43,14 @@ function(kos_bin2o inFile symbol) add_custom_command( OUTPUT ${outFile} DEPENDS ${inFile} - COMMAND $ENV{KOS_BASE}/utils/bin2o/bin2o ${inFile} ${symbol} ${outFile} + COMMAND ${KOS_BASE}/utils/bin2o/bin2o ${inFile} ${symbol} ${outFile} ) endfunction() function(kos_add_binary target inFile symbol) + file(REAL_PATH "${inFile}" inFile) set(outFile ${CMAKE_CURRENT_BINARY_DIR}/${symbol}.o) - kos_bin2o(${CMAKE_CURRENT_SOURCE_DIR}/${inFile} ${symbol} ${outFile}) + kos_bin2o(${inFile} ${symbol} ${outFile}) target_sources(${target} PRIVATE ${outFile}) endfunction() @@ -33,7 +63,7 @@ function(kos_add_romdisk target romdiskPath) set(romdiskName ${ARGN}) endif() - set(romdiskPath ${CMAKE_CURRENT_SOURCE_DIR}/${romdiskPath}) + file(REAL_PATH "${romdiskPath}" romdiskPath) set(obj ${CMAKE_CURRENT_BINARY_DIR}/${romdiskName}.o) set(obj_tmp ${CMAKE_CURRENT_BINARY_DIR}/${romdiskName}_tmp.o) @@ -52,7 +82,7 @@ function(kos_add_romdisk target romdiskPath) add_custom_command( OUTPUT ${img} DEPENDS ${romdiskFiles} - COMMAND $ENV{KOS_BASE}/utils/genromfs/genromfs -f ${img} -d ${romdiskPath} -v + COMMAND ${KOS_BASE}/utils/genromfs/genromfs -f ${img} -d ${romdiskPath} -v ) kos_bin2o(${img} ${romdiskName} ${obj_tmp}) @@ -61,40 +91,10 @@ function(kos_add_romdisk target romdiskPath) add_custom_command( OUTPUT ${obj} DEPENDS ${obj_tmp} - COMMAND ${CMAKE_C_COMPILER} -o ${obj} -r ${obj_tmp} -L$ENV{KOS_BASE}/lib/dreamcast -Wl,--whole-archive -lromdiskbase + COMMAND ${KOS_CC_BASE}/bin/sh-elf-gcc -o ${obj} -r ${obj_tmp} -L${KOS_BASE}/lib/dreamcast -Wl,--whole-archive -lromdiskbase COMMAND rm ${obj_tmp} ) # Append romdisk object to target target_sources(${target} PRIVATE ${obj}) endfunction() - -### Function to Enable SH4 Math Optimizations ### -function(kos_enable_sh4_math) - if(NOT ${PLATFORM_DREAMCAST}) - message(WARN " PLATFORM_DREAMCAST not set, skipping SH4 Math flags") - return() - endif() - - message(INFO " Enabling SH4 Math Optimizations") - add_compile_options(-ffast-math) - - # Check if -mfsrra and -mfsca are supported by the compiler - # They were added for GCC 4.8, so the Legacy GCC4.7 toolchain - # will complain if they are added. - include(CheckCCompilerFlag) - check_c_compiler_flag("-mfsrra" COMPILER_HAS_FSRRA) - check_c_compiler_flag("-mfsca" COMPILER_HAS_FSCA) - if(COMPILER_HAS_FSRRA) - add_compile_options(-mfsrra) - else() - message(WARN " Must have GCC4.8 or later for -mfsrra to be enabled") - endif() - - if(COMPILER_HAS_FSCA) - add_compile_options(-mfsca) - else() - message(WARN " Must have GCC4.8 or later for -mfsca to be enabled") - endif() - -endfunction() diff --git a/utils/cmake/dreamcast.toolchain.cmake b/utils/cmake/dreamcast.toolchain.cmake index 23071c9e..281c0e91 100644 --- a/utils/cmake/dreamcast.toolchain.cmake +++ b/utils/cmake/dreamcast.toolchain.cmake @@ -1,5 +1,8 @@ # CMake Toolchain file for targeting the Dreamcast or NAOMI with CMake. -# (c)2023 Falco Girgis, Luke Benstead +# Copyright (C) 2023 Luke Benstead +# Copyright (C) 2023, 2024 Falco Girgis +# Copyright (C) 2024 Donald Haase +# Copyright (C) 2024 Paul Cercueil # # This file is to be passed to CMake when compiling a regular CMake project # to cross-compile for the Dreamcast, using the KOS environment and settings. @@ -10,6 +13,10 @@ # # cmake /path/to/src -DCMAKE_TOOLCHAIN_FILE=${KOS_CMAKE_TOOLCHAIN} # +# or even: +# +# kos-cmake /path/to/src +# # Frame pointers are enabled in debug builds as these are required for # stack traces and GDB. They are disabled in release. # @@ -20,36 +27,16 @@ cmake_minimum_required(VERSION 3.13) #### Set Configuration Variables From Environment #### -if(NOT DEFINED KOS_BASE) - if(NOT DEFINED ENV{KOS_BASE}) - message(FATAL_ERROR "Variable KOS_BASE not set and was not found in the environment") - endif() +if(NOT DEFINED ENV{KOS_BASE} + OR NOT DEFINED ENV{KOS_CC_BASE} + OR NOT DEFINED ENV{KOS_SUBARCH} + OR NOT DEFINED ENV{KOS_PORTS}) + message(FATAL_ERROR "KallistiOS environment variables not found") +else() set(KOS_BASE $ENV{KOS_BASE}) - message(VERBOSE "KOS_BASE: ${KOS_BASE}") -endif() - -if(NOT DEFINED KOS_CC_BASE) - if(NOT DEFINED ENV{KOS_CC_BASE}) - message(FATAL_ERROR "Variable KOS_CC_BASE not set and was not found in the environment") - endif() set(KOS_CC_BASE $ENV{KOS_CC_BASE}) - message(VERBOSE "KOS_CC_BASE: ${KOS_CC_BASE}") -endif() - -if(NOT DEFINED KOS_SUBARCH) - if(NOT DEFINED ENV{KOS_SUBARCH}) - message(FATAL_ERROR "Variable KOS_SUBARCH not set and was not found in the environment") - endif() set(KOS_SUBARCH $ENV{KOS_SUBARCH}) - message(VERBOSE "KOS_SUBARCH: ${KOS_SUBARCH}") -endif() - -if(NOT DEFINED KOS_PORTS) - if(NOT DEFINED ENV{KOS_PORTS}) - message(FATAL_ERROR "Variable KOS_PORTS not set and was not found in the environment") - endif() set(KOS_PORTS $ENV{KOS_PORTS}) - message(VERBOSE "KOS_PORTS: ${KOS_PORTS}") endif() list(APPEND CMAKE_MODULE_PATH $ENV{KOS_BASE}/utils/cmake) @@ -63,11 +50,11 @@ set(PLATFORM_DREAMCAST TRUE) ##### Configure Cross-Compiler ##### set(CMAKE_CROSSCOMPILING TRUE) -set(CMAKE_ASM_COMPILER ${KOS_CC_BASE}/bin/sh-elf-as) -set(CMAKE_C_COMPILER ${KOS_CC_BASE}/bin/sh-elf-gcc) -set(CMAKE_CXX_COMPILER ${KOS_CC_BASE}/bin/sh-elf-g++) -set(CMAKE_OBJC_COMPILER ${KOS_CC_BASE}/bin/sh-elf-gcc) -set(CMAKE_OBJCXX_COMPILER ${KOS_CC_BASE}/bin/sh-elf-g++) +set(CMAKE_ASM_COMPILER ${KOS_BASE}/utils/gnu_wrappers/kos-as) +set(CMAKE_C_COMPILER ${KOS_BASE}/utils/gnu_wrappers/kos-cc) +set(CMAKE_CXX_COMPILER ${KOS_BASE}/utils/gnu_wrappers/kos-c++) +set(CMAKE_OBJC_COMPILER ${KOS_BASE}/utils/gnu_wrappers/kos-cc) +set(CMAKE_OBJCXX_COMPILER ${KOS_BASE}/utils/gnu_wrappers/kos-c++) set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") @@ -78,18 +65,6 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_SYSROOT ${KOS_PORTS}) set(ENV{PKG_CONFIG_SYSROOT_DIR} ${KOS_PORTS}) -##### Add Platform-Specific #defines ##### -add_compile_definitions(__DREAMCAST__ _arch_dreamcast) - -if(${KOS_SUBARCH} MATCHES naomi) - add_compile_definitions(__NAOMI__ _arch_sub_naomi) -else() - add_compile_definitions(_arch_sub_pristine) -endif() - -##### Configure Build Flags ##### -add_compile_options(-ml -m4-single-only -ffunction-sections -fdata-sections -matomic-model=soft-imask -ftls-model=local-exec) - set(ENABLE_DEBUG_FLAGS $<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>) set(ENABLE_RELEASE_FLAGS $<OR:$<CONFIG:Release>,$<CONFIG:MinSizeRel>>) @@ -101,41 +76,4 @@ add_compile_options( set(CMAKE_ASM_FLAGS "") set(CMAKE_ASM_FLAGS_RELEASE "") -##### Configure Include Directories ##### -set(CMAKE_SYSTEM_INCLUDE_PATH "${CMAKE_SYSTEM_INCLUDE_PATH} ${KOS_BASE}/include ${KOS_BASE}/kernel/arch/dreamcast/include ${KOS_BASE}/addons/include ${KOS_PORTS}/include") - -include_directories( - $ENV{KOS_BASE}/include - $ENV{KOS_BASE}/kernel/arch/dreamcast/include - $ENV{KOS_BASE}/addons/include - $ENV{KOS_PORTS}/include -) - -##### Configure Linker ##### -set(CMAKE_SYSTEM_LIBRARY_PATH "${CMAKE_SYSTEM_LIBRARY_PATH} ${KOS_BASE}/lib/dreamcast ${KOS_BASE}/addons/lib/dreamcast ${KOS_PORTS}/lib") - -if(${KOS_SUBARCH} MATCHES naomi) - add_link_options(-Wl,-Ttext=0x8c020000 -T${KOS_BASE}/utils/ldscripts/shlelf-naomi.xc) -else() - add_link_options(-Wl,-Ttext=0x8c010000 -T${KOS_BASE}/utils/ldscripts/shlelf.xc) -endif() - -add_link_options(-ml -m4-single-only -Wl,--gc-sections -nodefaultlibs) - -link_directories( - ${KOS_BASE}/lib/dreamcast - ${KOS_BASE}/addons/lib/dreamcast - ${KOS_PORTS}/lib -) - -add_link_options(-L${KOS_BASE}/lib/dreamcast -L${KOS_BASE}/addons/lib/dreamcast -L${KOS_PORTS}/lib) - -##### Custom Build Rules ##### -set(CMAKE_C_LINK_EXECUTABLE - "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> \ - -lm -Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group") -set(CMAKE_CXX_LINK_EXECUTABLE - "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> \ - -lm -Wl,--start-group -lstdc++ -lkallisti -lc -lgcc -Wl,--end-group") - include("${KOS_BASE}/utils/cmake/dreamcast.cmake") hooks/post-receive -- A pseudo Operating System for the Dreamcast. |