From: ljsebald <ljs...@us...> - 2023-03-31 19:45:42
|
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 8017df8cd9e88c7ed80e5bd095cd874b9ac6a21a (commit) via 99dd5dbf44fd8237a8edbf262572ba26e5011f6f (commit) via d500f410b742bd359fa59894074cd765df5ac68b (commit) via 0fd372b473a767041f13af7f5276b453debd10fb (commit) via 58f0b86eeb7364669aaf8ba883cafa97ec7d319e (commit) via 94d79b8c0b1c9401647d4e93701e9790fda3a3b4 (commit) via 941774c45f6f28a8bf87b4135efcfbcb176b60d7 (commit) via 0a8727d99d37f55f9b18f196e0d5d75b55f9b071 (commit) via 5a407b67225d2427dcbc95e556daf6592551eebd (commit) via c83711685a5c0dcca7a366e4401d25ba8047faba (commit) from 4c7ef784f214b83ef5503fe2a56145e68f93bb75 (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 8017df8cd9e88c7ed80e5bd095cd874b9ac6a21a Merge: 4c7ef78 99dd5db Author: Lawrence Sebald <ljs...@us...> Date: Fri Mar 31 15:44:40 2023 -0400 Merge pull request #91 from gyrovorbis/cmake Added CMake Toolchain file + environment variable commit 99dd5dbf44fd8237a8edbf262572ba26e5011f6f Author: Colton Pawielski <cep...@mt...> Date: Tue Mar 14 21:19:15 2023 -0500 Fix errors in CMake ENV Var Checks commit d500f410b742bd359fa59894074cd765df5ac68b Author: Colton Pawielski <cep...@mt...> Date: Tue Mar 14 21:17:01 2023 -0500 Make spacing uniform across CMake files commit 0fd372b473a767041f13af7f5276b453debd10fb Author: Colton Pawielski <cep...@mt...> Date: Thu Mar 9 17:39:38 2023 -0600 Add CMake helper functions generate_romdisk() will create a romdisk from the folder passed and add it to the target enable_sh4_math() will add flags for math optimization (when available) commit 58f0b86eeb7364669aaf8ba883cafa97ec7d319e Author: falco <gyr...@gm...> Date: Thu Mar 9 18:10:23 2023 -0500 Addressed most of the code review commentary 1) fast math flags have been removed - there's no way to detect compiler-version within the toolchain's execution context, and the fast math flags aren't in "legacy" 4.7 2) KOS environment flags are now configurable flags which default to being populated via environment variables - allows for the user to override programmatically - allows for other logic to access these variables 3) Debug/Release flags now use generator expressions and are deduplicated across configurations 4) Duplicate linker libraries have been removed commit 94d79b8c0b1c9401647d4e93701e9790fda3a3b4 Author: falco <gyr...@gm...> Date: Wed Feb 1 23:13:44 2023 -0500 Removed redundant arch def, added default configs - removed redundante define for __arch_dreamcast - removed -g0 for disabling debug information from release (CMake handles this for targets, including RelWithDebInfo) - added SH4 instruction flags to all configurations because none of them are enabled without -ffast-math, and all should be available - added default configurations for RelWithDebInfo and RelMinSize commit 941774c45f6f28a8bf87b4135efcfbcb176b60d7 Author: falco <gyr...@gm...> Date: Wed Feb 1 16:18:45 2023 -0500 Reordered Naomi platform definitions to match DC's commit 0a8727d99d37f55f9b18f196e0d5d75b55f9b071 Author: falco <gyr...@gm...> Date: Wed Feb 1 16:10:40 2023 -0500 Made SH4 math instructions optional - Removed -ffast-math from both C and CXX configurations so that it must be provided by the user's CMakeLists.txt for the target in order to activate -mfsrra and -mfsca. - Added description of how to do this. commit 5a407b67225d2427dcbc95e556daf6592551eebd Author: falco <gyr...@gm...> Date: Wed Feb 1 06:17:14 2023 -0500 Added define for Naomi to Cmake Toolchain commit c83711685a5c0dcca7a366e4401d25ba8047faba Author: falco <gyr...@gm...> Date: Wed Feb 1 06:03:04 2023 -0500 Added CMake Toolchain file + environment variable - Added utils/cmake/dreamcast.toolchain.cmake, a toolchain file configured for setting up KOS and cross-compiling for DC with CMake - added environment variable to doc/environ.sh.sample for being able to conveniently reference the toolchain when passing it to CMake from the command-line ----------------------------------------------------------------------- Summary of changes: doc/environ.sh.sample | 3 + utils/cmake/dreamcast.cmake | 63 +++++++++++++++++ utils/cmake/dreamcast.toolchain.cmake | 127 ++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 utils/cmake/dreamcast.cmake create mode 100644 utils/cmake/dreamcast.toolchain.cmake diff --git a/doc/environ.sh.sample b/doc/environ.sh.sample index f5516fb..28e93a5 100644 --- a/doc/environ.sh.sample +++ b/doc/environ.sh.sample @@ -31,6 +31,9 @@ export KOS_PORTS="${KOS_BASE}/../kos-ports" export KOS_MAKE="make" #export KOS_MAKE="gmake" +# CMake toolchain +export KOS_CMAKE_TOOLCHAIN="${KOS_BASE}/utils/cmake/dreamcast.toolchain.cmake" + # Load utility export KOS_LOADER="dc-tool -x" # dcload, preconfigured # export KOS_LOADER="dc-tool-ser -t /dev/ttyS0 -x" # dcload-serial diff --git a/utils/cmake/dreamcast.cmake b/utils/cmake/dreamcast.cmake new file mode 100644 index 0000000..a6254e5 --- /dev/null +++ b/utils/cmake/dreamcast.cmake @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.23) + +### Helper Function for Generating Romdisk ### +function(generate_romdisk target romdiskName romdiskPath) + set(obj ${CMAKE_CURRENT_BINARY_DIR}/${romdiskName}.o) + set(img ${CMAKE_CURRENT_BINARY_DIR}/${romdiskName}.img) + + # Variable holding all files in the romdiskPath folder + # CONFIGURE_DEPENDS causes the folder to always be rechecked + # at build time not only when CMake is re-run + file(GLOB romdiskFiles CONFIGURE_DEPENDS + "${romdiskPath}/*" + ) + + # Custom Command to generate romdisk image from folder + # Only run when folder contents have changed by depending on + # the romdiskFiles variable + add_custom_command( + OUTPUT ${img} + COMMAND $ENV{KOS_GENROMFS} -f ${img} -d ${romdiskPath} -v + DEPENDS ${romdiskFiles} +) + + # Custom Command to generate romdisk object file from image +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${romdiskName}.o + COMMAND $ENV{KOS_BASE}/utils/bin2o/bin2o ${img} ${romdiskName} ${obj} + DEPENDS ${img} + ) + + # Append romdisk object to target + target_sources(${target} PRIVATE ${obj}) +endfunction() + +### Function to Enable SH4 Math Optimizations ### +function(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() \ No newline at end of file diff --git a/utils/cmake/dreamcast.toolchain.cmake b/utils/cmake/dreamcast.toolchain.cmake new file mode 100644 index 0000000..8377404 --- /dev/null +++ b/utils/cmake/dreamcast.toolchain.cmake @@ -0,0 +1,127 @@ +# CMake Toolchain file for targeting the Dreamcast or NAOMI with CMake. +# (c)2023 Falco Girgis, Luke Benstead +# +# 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. +# +# cmake /path/to/src -DCMAKE_TOOLCHAIN_FILE=${KOS_BASE}/kos/utils/cmake/dreamcast.toolchain.cmake +# +# or alternatively: +# +# cmake /path/to/src -DCMAKE_TOOLCHAIN_FILE=${KOS_CMAKE_TOOLCHAIN} +# +# Frame pointers are enabled in debug builds as these are required for +# stack traces and GDB. They are disabled in release. +# +# The original toolchain file was created by Kazade for the Simulant +# engine who has graciously allowed the rest of the scene to warez it. + +cmake_minimum_required(VERSION 3.23) + +#### 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() + set(KOS_BASE $ENV{KOS_BASE}) + message("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("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("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("KOS_PORTS: ${KOS_PORTS}") +endif() + +##### Configure CMake System ##### +set(CMAKE_SYSTEM_NAME Generic-ELF) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR SH4) +set(PLATFORM_DREAMCAST TRUE) + +##### Configure Cross-Compiler ##### +set(CMAKE_CROSSCOMPILING TRUE) +set(CMAKE_C_COMPILER ${KOS_CC_BASE}/bin/sh-elf-gcc) +set(CMAKE_CXX_COMPILER ${KOS_CC_BASE}/bin/sh-elf-g++) + +set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + +# Never use the CMAKE_FIND_ROOT_PATH to find programs with find_program() +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +##### Add Platform-Specific #defines ##### +ADD_DEFINITIONS( + -D__DREAMCAST__ + -D_arch_dreamcast +) + +if(${KOS_SUBARCH} MATCHES naomi) + ADD_DEFINITONS( + -D__NAOMI__ + -D_arch_sub_naomi + ) +else() + ADD_DEFINITIONS(-D_arch_sub_pristine) +endif() + +##### Configure Build Flags ##### +add_compile_options(-ml -m4-single-only -ffunction-sections -fdata-sections) + +set(ENABLE_DEBUG_FLAGS $<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>) +set(ENABLE_RELEASE_FLAGS $<OR:$<CONFIG:Release>,$<CONFIG:MinSizeRel>>) + +add_compile_options( + "$<${ENABLE_DEBUG_FLAGS}:-DFRAME_POINTERS;-fno-omit-frame-pointer>" + "$<${ENABLE_RELEASE_FLAGS}:-fomit-frame-pointer>" + ) + +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 Libraries ##### +set(CMAKE_SYSTEM_LIBRARY_PATH "${CMAKE_SYSTEM_LIBRARY_PATH} ${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) +LINK_LIBRARIES(-Wl,--start-group -lstdc++ -lkallisti -lc -lgcc -Wl,--end-group m) \ No newline at end of file hooks/post-receive -- A pseudo Operating System for the Dreamcast. |