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.
This commit is contained in:
Matt Penny 2024-10-19 16:30:58 -04:00
parent 4e9e9d32d6
commit 42a9189c95
7 changed files with 16 additions and 12 deletions

View File

@ -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)

View File

@ -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

View File

@ -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}
)

View File

@ -1,6 +1,5 @@
#include "../src/defs.h"
.include "macros.inc"
#include "macros.inc"
.section .text, "ax"

View File

@ -1,4 +1,4 @@
.include "macros.inc"
#include "macros.inc"
.section .data

View File

@ -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

View File

@ -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")