From 42a9189c9503ca3c0c8961d1765f9b587d1de6b1 Mon Sep 17 00:00:00 2001 From: Matt Penny Date: Sat, 19 Oct 2024 16:30:58 -0400 Subject: [PATCH] CMake: get assembly working * Assemble through `gcc` instead of `as` directly, so source files are preprocessed (i.e., `#include`) * `gcc` does not pass `-I` include directories to `as`. This can supposedly be fixed by recompiling `gcc` with `--with-gnu-as`. Popular N64 toolchain binary distributions don't do this, and to lower the barrier to entry I don't want to force users to have to compile their own. Work around it by passing `-Wa,-I`. * CMake only finds assembly dependencies when preprocessing, not when assembling. Use `#include` instead of `.include` to work around this. The `.incbin`s used by `sound_data.s` are covered by the sound_data_tables target dependency. --- CMakeLists.txt | 1 + Makefile | 4 ++-- asm/CMakeLists.txt | 8 +++----- asm/entry.s | 3 +-- asm/sound_data.s | 2 +- assets/sound/CMakeLists.txt | 6 ++++++ cmake/Toolchain-N64.cmake | 4 ++-- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8bfb65..09f5f91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ add_compile_definitions(CMAKE) set(USING_LIBULTRA TRUE) +# Programs used in build find_package(Blender 3.6 EXACT REQUIRED) find_program(FFmpeg_EXECUTABLE ffmpeg REQUIRED) find_program(Git_EXECUTABLE git REQUIRED) diff --git a/Makefile b/Makefile index 8d37ef5..55cd6cf 100644 --- a/Makefile +++ b/Makefile @@ -153,7 +153,7 @@ endif include $(COMMONRULES) .s.o: - $(AS) -Wa,-Iasm -o $@ $< + $(AS) -o $@ $< build/%.o: %.c @mkdir -p $(@D) @@ -162,7 +162,7 @@ build/%.o: %.c build/%.o: %.s @mkdir -p $(@D) - $(AS) -Wa,-Iasm -o $@ $< + $(AS) -o $@ $< #################### ## Assets diff --git a/asm/CMakeLists.txt b/asm/CMakeLists.txt index 08a9b11..5cb74da 100644 --- a/asm/CMakeLists.txt +++ b/asm/CMakeLists.txt @@ -2,18 +2,16 @@ ## Assembly files ## #################### -# TODO: proper dependencies (defs.h, macros.inc, sounds) - set(ASM_FILES entry.s rom_header.s sound_data.s ) -add_library(asm_sources OBJECT) +add_library(asm_sources INTERFACE) add_dependencies(asm_sources - sound_tables + sound_data_tables ) -target_sources(asm_sources PRIVATE +target_sources(asm_sources INTERFACE ${ASM_FILES} ) diff --git a/asm/entry.s b/asm/entry.s index e93076d..04afd7d 100644 --- a/asm/entry.s +++ b/asm/entry.s @@ -1,6 +1,5 @@ #include "../src/defs.h" - -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/asm/sound_data.s b/asm/sound_data.s index 4bc0026..e3122b2 100644 --- a/asm/sound_data.s +++ b/asm/sound_data.s @@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" .section .data diff --git a/assets/sound/CMakeLists.txt b/assets/sound/CMakeLists.txt index 69ac131..cffdcf5 100644 --- a/assets/sound/CMakeLists.txt +++ b/assets/sound/CMakeLists.txt @@ -468,6 +468,12 @@ add_custom_target(sound_tables ${SOUND_LOOKUP_TABLE_FILES} ) +add_library(sound_data_tables INTERFACE) +add_dependencies(sound_data_tables sound_tables) +target_sources(sound_data_tables INTERFACE + ${SOUND_DATA_TABLE_FILES} +) + add_library(sound_lookup_tables INTERFACE) add_dependencies(sound_lookup_tables sound_tables) target_sources(sound_lookup_tables INTERFACE diff --git a/cmake/Toolchain-N64.cmake b/cmake/Toolchain-N64.cmake index f95b33a..bab9e55 100644 --- a/cmake/Toolchain-N64.cmake +++ b/cmake/Toolchain-N64.cmake @@ -21,7 +21,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Don't try to dynamically link during compiler tests set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) -find_program(CMAKE_ASM_COMPILER ${N64_TOOLCHAIN_PREFIX}as REQUIRED) +find_program(CMAKE_ASM_COMPILER ${N64_TOOLCHAIN_PREFIX}gcc REQUIRED) find_program(CMAKE_C_COMPILER ${N64_TOOLCHAIN_PREFIX}gcc REQUIRED) find_program(CMAKE_CXX_COMPILER ${N64_TOOLCHAIN_PREFIX}g++ REQUIRED) find_program(CMAKE_LINKER ${N64_TOOLCHAIN_PREFIX}ld REQUIRED) @@ -33,7 +33,7 @@ set(COMPILE_FLAGS_DEBUGOPTIMIZED "-g -Os") set(COMPILE_FLAGS_RELEASE "-DNDEBUG -Os") # Program-specific flags -set(CMAKE_ASM_FLAGS_INIT "${COMPILE_FLAGS} -x assembler-with-cpp") +set(CMAKE_ASM_FLAGS_INIT "${COMPILE_FLAGS} -x assembler-with-cpp -Wa,-I${PROJECT_SOURCE_DIR}") set(CMAKE_C_FLAGS_INIT "${COMPILE_FLAGS} -ffreestanding") set(CMAKE_CXX_FLAGS_INIT "${COMPILE_FLAGS} -fno-nonansi-builtins") set(CMAKE_EXE_LINKER_FLAGS_INIT "--no-check-sections")