From e9e234a42cc79ad8aef3c9313cba6e4d2dfab187 Mon Sep 17 00:00:00 2001 From: Craig Hackney Date: Thu, 29 Feb 2024 13:12:14 -0800 Subject: [PATCH 1/2] Added CMakeLists.txt to create SGDK libs and host based utilities. To build the libraries, follow the instructions below... Ensure the PREFIX and GDK env vars are set for the GCC tools in use. export GDK=~/SGDK export PREFIX=m68k-elf- cmake -S $GDK -B $GDK/build -DCMAKE_BUILD_TYPE=Release cmake --build $GDK/build cmake -S $GDK -B $GDK/build -DCMAKE_BUILD_TYPE=Debug cmake --build $GDK/build This build file also includes building of the following native utilities. bintos xgmtool sjasm --- CMakeLists.txt | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..334bda61 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,114 @@ +cmake_minimum_required(VERSION 3.22) + +project(md C ASM) + +# Set the compiler prefix +if(DEFINED ENV{PREFIX}) + set(PREFIX "$ENV{PREFIX}") +endif() + +# Check for sjasm submodule +if(NOT IS_DIRECTORY "${PROJECT_SOURCE_DIR}/tools/sjasm") + find_package(Git) + if(Git_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init + --recursive ${PROJECT_SOURCE_DIR}) + else() + message(CHECK_FAIL "Could not find git executable") + endif() +endif() + +include(ExternalProject) +ExternalProject_Add( + BINTOS + SOURCE_DIR ${PROJECT_SOURCE_DIR}/tools/bintos/src + BINARY_DIR ${PROJECT_SOURCE_DIR}/tools/bintos/src/build + INSTALL_COMMAND install bintos ${PROJECT_SOURCE_DIR}/bin + BUILD_ALWAYS TRUE) +ExternalProject_Add( + XGMTOOL + SOURCE_DIR ${PROJECT_SOURCE_DIR}/tools/xgmtool/src + BINARY_DIR ${PROJECT_SOURCE_DIR}/tools/xgmtool/src/build + INSTALL_COMMAND install xgmtool ${PROJECT_SOURCE_DIR}/bin + BUILD_ALWAYS TRUE) +ExternalProject_Add( + SJASM + CONFIGURE_COMMAND "" + DOWNLOAD_COMMAND "" + BUILD_COMMAND make -C ${PROJECT_SOURCE_DIR}/tools/sjasm/Sjasm + INSTALL_COMMAND install ${PROJECT_SOURCE_DIR}/tools/sjasm/Sjasm/sjasm + ${PROJECT_SOURCE_DIR}/bin + BUILD_ALWAYS TRUE) + +# Set the compiler/assembler name +set(CMAKE_C_COMPILER ${PREFIX}gcc) +set(CMAKE_ASM_COMPILER ${PREFIX}gcc) +set(CMAKE_AR ${PREFIX}ar) + +include_directories(${PROJECT_SOURCE_DIR}/inc) +include_directories(${PROJECT_SOURCE_DIR}/res) +include_directories(${PROJECT_SOURCE_DIR}/src) + +set(RESCOMP java -jar ${PROJECT_SOURCE_DIR}/bin/rescomp.jar) +set(ASMZ80 ${PROJECT_SOURCE_DIR}/bin/sjasm -q) +set(BINTOS_EXE ${PROJECT_SOURCE_DIR}/bin/bintos) + +add_compile_options( + -DSGDK_GCC + -m68000 + -Wall + -Wextra + -Wno-main + -Wno-shift-negative-value + -Wno-unused-parameter + -fno-builtin + -nostdlib + -nodefaultlibs) + +add_compile_options( + "$<$:-fuse-linker-plugin;-fno-web;-fno-gcse;-fno-unit-at-a-time;-fomit-frame-pointer;-ffat-lto-objects;-flto>" + "$<$:-O0;-DDEBUG=1>" + "$<$:-xassembler-with-cpp;-Wa,-I${PROJECT_SOURCE_DIR};-Wa,--register-prefix-optional,--bitwise-or>" +) + +# If CMAKE_BUILD_TYPE is not set +add_compile_options("$<$:-O3>") + +# Gather sources +file(GLOB_RECURSE SRC_LIB_C src/*.c) +string(REPLACE "src/boot/rom_head.c" "" SRC_LIB_C "${SRC_LIB_C}") +file(GLOB_RECURSE SRC_LIB_S src/*.s) +string(REPLACE "src/boot/sega.s" "" SRC_LIB_S "${SRC_LIB_S}") +file(GLOB_RECURSE SRC_LIB_S80 src/*.s80) +string(REGEX REPLACE "[.]s80" ".s;" Z80SRC ${SRC_LIB_S80}) +file(GLOB_RECURSE RES_LIB_RES res/*.res) +string(REGEX REPLACE "[.]res" ".s;" RESSRC ${RES_LIB_RES}) + +# Rules to build Z80 source code +foreach(z80_source ${Z80SRC}) + get_filename_component(file ${z80_source} NAME_WE) + get_filename_component(dir ${z80_source} DIRECTORY) + set(file ${dir}/${file}) + add_custom_command( + OUTPUT ${z80_source} + COMMAND ${ASMZ80} -i${PROJECT_SOURCE_DIR}/inc/snd ${file}.s80 ${file}.out && + ${BINTOS_EXE} ${file}.out ${file}.s + DEPENDS ${file}.s80 BINTOS SJASM + BYPRODUCTS ${file}.out ${file}.h) +endforeach() + +# Rules to build resources +foreach(res_source ${RESSRC}) + string(REGEX REPLACE "[.]s" ".h" res_header ${res_source}) + add_custom_command( + OUTPUT ${res_source} ${res_header} + COMMAND ${RESCOMP} ${PROJECT_SOURCE_DIR}/res/libres.res + DEPENDS ${PROJECT_SOURCE_DIR}/res/libres.res XGMTOOL) +endforeach() + +add_library(md STATIC ${SRC_LIB_C} ${SRC_LIB_S} ${Z80SRC} ${RESSRC}) +set_target_properties( + md + PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib + OUTPUT_NAME "md" + DEBUG_OUTPUT_NAME "md_debug") From f5f251f4b39583ef6d5af4e4195baadb879b0ca7 Mon Sep 17 00:00:00 2001 From: Craig Hackney Date: Tue, 5 Mar 2024 08:19:49 -0800 Subject: [PATCH 2/2] Corrected resource building rule. --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 334bda61..1b4767ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,10 +100,11 @@ endforeach() # Rules to build resources foreach(res_source ${RESSRC}) string(REGEX REPLACE "[.]s" ".h" res_header ${res_source}) + string(REGEX REPLACE "[.]s" ".res" res ${res_source}) add_custom_command( OUTPUT ${res_source} ${res_header} - COMMAND ${RESCOMP} ${PROJECT_SOURCE_DIR}/res/libres.res - DEPENDS ${PROJECT_SOURCE_DIR}/res/libres.res XGMTOOL) + COMMAND ${RESCOMP} ${res} + DEPENDS ${res} XGMTOOL) endforeach() add_library(md STATIC ${SRC_LIB_C} ${SRC_LIB_S} ${Z80SRC} ${RESSRC})