-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathframework64.libultra.cmake
More file actions
170 lines (129 loc) · 7.58 KB
/
Copy pathframework64.libultra.cmake
File metadata and controls
170 lines (129 loc) · 7.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Note: Helpful resource: https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
set(FW64_PLATFORM_NAME "n64_libultra")
set(CMAKE_C_COMPILER mips-n64-gcc)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR mips64)
set(CMAKE_C_FLAGS "-mabi=32 -ffreestanding -mfix4300 -G 0")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DNU_DEBUG)
else()
add_definitions(-D_FINALROM)
endif()
add_definitions(-DF3DEX_GBI_2 -DFW64_PLATFORM_N64_LIBULTRA)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # note: roms will be copied into this directory as post build step
set(FW64_N64_ASM_SRC_DIR ${FW64_ROOT_DIR}/src/framework64/n64_libultra/asm)
function (enable_all_warnings_as_errors)
set(options)
set(oneValueArgs TARGET)
set(multiValueArgs)
cmake_parse_arguments(ENABLE_ALL_WARNINGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
set(target_name ${ENABLE_ALL_WARNINGS_TARGET})
# Turn this on when CI is enabled
set_property(TARGET ${target_name} PROPERTY COMPILE_WARNING_AS_ERROR ON)
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Wpedantic)
endfunction()
# performs platform specific configuration of the framework 64 library
function (configure_core_library)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_options(framework64 PUBLIC -O0)
endif()
# target_compile_options(${target_name} PUBLIC -G 0 -mabi=32 -ffreestanding -mfix4300)
target_include_directories(framework64
PUBLIC /usr/include/n64 /usr/include/n64/PR /usr/include/n64/nusys /usr/include/n64/nustd)
enable_all_warnings_as_errors(TARGET framework64)
target_compile_definitions(framework64 PUBLIC "$<$<CONFIG:Debug>:FW64_COLLISION_GEOMETRY_DEBUG_INFO>")
target_compile_definitions(framework64 PUBLIC "$<$<CONFIG:Debug>:FW64_RENDERER_DEBUG_INFO>")
endfunction()
# performs platform specific configuration of a framework64 game
function(create_game)
set(options ALL_WARNINGS_AS_ERRORS)
set(oneValueArgs TARGET SAVE_FILE_TYPE GAME_HEADER_PATH HTML_TEMPLATE_PATH)
set(multiValueArgs SOURCES EXTRA_LIBS STATIC_MODULES)
cmake_parse_arguments(N64_ROM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
# set the correct EEPROM type for the rom
# default setting is no EEPROM
set(FW64_N64_ROM_ID ".ascii \" \"")
set(FW64_N64_SETTINGS_BYTE ".ascii \" \"")
if (DEFINED N64_ROM_SAVE_FILE_TYPE)
set(FW64_N64_ROM_ID ".ascii \"ED\"")
if ("${N64_ROM_SAVE_FILE_TYPE}" STREQUAL "N64_EEPROM_4K")
set(FW64_N64_SETTINGS_BYTE ".byte 0x12")
elseif("${N64_ROM_SAVE_FILE_TYPE}" STREQUAL "N64_EEPROM_16K")
set(FW64_N64_SETTINGS_BYTE ".byte 0x22")
else()
message(FATAL_ERROR "Unsupported Save File type specified for ${N64_ROM_TARGET}: ${N64_ROM_SAVE_FILE_TYPE}")
endif()
endif()
set(target_name ${N64_ROM_TARGET})
set(game_sources ${N64_ROM_SOURCES})
set(game_asset_dir ${CMAKE_SOURCE_DIR}/build_n64_libultra/bin/${target_name}/assets)
# copy the assembly files into the build dir and add them to the target
set(asm_dest_dir ${CMAKE_CURRENT_BINARY_DIR}/asm)
file(MAKE_DIRECTORY ${asm_dest_dir})
configure_file(${FW64_N64_ASM_SRC_DIR}/macros.inc ${asm_dest_dir}/macros.inc COPYONLY)
configure_file(${FW64_N64_ASM_SRC_DIR}/entry.s ${asm_dest_dir}/entry.s COPYONLY)
configure_file(${FW64_N64_ASM_SRC_DIR}/rom_header.s ${asm_dest_dir}/rom_header.s)
configure_file(${FW64_N64_ASM_SRC_DIR}/asset_data.s ${asm_dest_dir}/asset_data.s)
set(asm_files
${asm_dest_dir}/entry.s
${asm_dest_dir}/rom_header.s
${asm_dest_dir}/asset_data.s
)
if (DEFINED N64_ROM_GAME_HEADER_PATH)
set(game_include_path ${N64_ROM_GAME_HEADER_PATH})
else()
set(game_include_path "game.h")
endif()
set(main_file_src ${FW64_ROOT_DIR}/src/framework64/n64_libultra/main_n64.c)
set(main_file_dest ${CMAKE_CURRENT_BINARY_DIR}/main_n64_${target_name}.c)
configure_file(${main_file_src} ${main_file_dest})
add_executable(${target_name} ${game_sources} ${main_file_dest} ${asm_files})
# Include the game specific asset directory
target_include_directories(${target_name} PUBLIC ${game_asset_dir}/include)
# Add any extra libraries that need to be linked in
if (DEFINED N64_ROM_EXTRA_LIBS)
target_link_libraries(${target_name} PUBLIC ${N64_ROM_EXTRA_LIBS})
endif()
target_link_libraries(${target_name} PUBLIC framework64)
set(elf_output_name ${target_name}.elf)
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${elf_output_name})
add_game_modules(TARGET ${target_name} MODULES ${N64_ROM_STATIC_MODULES})
# configure assembly compile options
set(asm_compile_options "-x;assembler-with-cpp;-MMD;-Wa,-I${asm_dest_dir}")
set_source_files_properties(${asm_dest_dir}/entry.s PROPERTIES LANGUAGE C COMPILE_OPTIONS "${asm_compile_options}")
set_source_files_properties(${asm_dest_dir}/rom_header.s PROPERTIES LANGUAGE C COMPILE_OPTIONS "${asm_compile_options}")
set_source_files_properties(${asm_dest_dir}/asset_data.s PROPERTIES LANGUAGE C COMPILE_OPTIONS "${asm_compile_options}")
# prepare bootcode object
set(bootcode_src /usr/lib/n64/PR/bootcode/boot.6102)
set(bootcode_dest ${CMAKE_CURRENT_BINARY_DIR}/boot.6102.o)
execute_process(COMMAND mips-n64-objcopy -I binary -B mips -O elf32-bigmips ${bootcode_src} ${bootcode_dest})
# set assembly file paths to configure linkerscript
# Note: cmake is passing the paths to these files relative to the current binary directory. The paths we configure should match the path on the linker command line
set(obj_folder_root CMakeFiles/${target_name}.dir)
set(entry_path ${obj_folder_root}/asm/entry.s.obj)
set(rom_header_path ${obj_folder_root}/asm/rom_header.s.obj)
set(asset_data_path ${obj_folder_root}/asm/asset_data.s.obj)
set(bootcode_path boot.6102.o)
# create the linkerscript file containing the paths to the built obects
set(main_obj_dir ${obj_folder_root})
set(configured_linkerfile_path ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.ld.in)
configure_file(${FW64_ROOT_DIR}/src/framework64/n64_libultra/linkerscript.ld.in ${configured_linkerfile_path})
# Run the linker file though the preprocessor
set(linkerscript_dest ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.ld)
execute_process(COMMAND cpp -P -Wno-trigraphs -I/usr/include/n64 -I/usr/include/n64/PR -I/usr/include/n64/nusys -D_FINALROM=1 -DNDEBUG=1 -DF3DEX_GBI_2=1 -MMD -MP -o ${linkerscript_dest} ${configured_linkerfile_path})
# configure target specific build options
target_include_directories(${target_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_directories(${target_name} PUBLIC /usr/lib/n64/nusys /usr/lib/n64)
target_link_libraries(${target_name} PUBLIC -lnualsgi_n -ln_audio -lnusys -lultra_rom -lnustd $ENV{N64_LIBGCCDIR}/libgcc.a)
target_link_options(${target_name} PUBLIC -T ${linkerscript_dest} -Wl,--no-check-sections ${bootcode_path} /usr/lib/n64/nusys/nusys_rom.o)
# build the rom
set(rom_elf_src ${CMAKE_CURRENT_BINARY_DIR}/${elf_output_name})
set(final_rom_path ${CMAKE_BINARY_DIR}/bin/${target_name}.z64)
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND mips-n64-objcopy --pad-to=0x100000 --gap-fill=0xFF ${rom_elf_src} ${final_rom_path} -O binary
)
# mask the rom
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND makemask ${final_rom_path}
)
endfunction()