-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
216 lines (181 loc) · 4.82 KB
/
CMakeLists.txt
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
cmake_minimum_required(VERSION 3.25)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain.cmake")
project(
psbw
LANGUAGES C CXX ASM
VERSION 1.0.0
)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
set(GAME_NAME game)
file(GLOB audio_files "${PROJECT_SOURCE_DIR}/assets/music/*.mp3")
set(audio_tracks "")
foreach(audio_file IN LISTS audio_files)
get_filename_component(audio_filename ${audio_file} NAME)
set(audio_tracks "${audio_tracks}\n<track type=\"audio\" source=\"${audio_file}\" />")
endforeach()
configure_file(
"${PROJECT_SOURCE_DIR}/iso.xml"
"${PROJECT_BINARY_DIR}/iso.xml"
)
configure_file(
"${PROJECT_SOURCE_DIR}/system.cnf"
"${PROJECT_BINARY_DIR}/system.cnf"
)
# Create common library which contains things like CPP support and libc
add_library(
common OBJECT
lib/libc/crt0.c
lib/libc/cxxsupport.cpp
lib/libc/malloc.c
lib/libc/memset.s
lib/libc/misc.c
lib/libc/misc.s
lib/libc/string.c
lib/ps1/system.c
lib/ps1/system.s
lib/ps1/unhandledexc.c
lib/vendor/printf.c
)
target_include_directories(
common PUBLIC
lib
inc
lib/libc
)
# Create the Game library which contains the actual game code
add_library(
${GAME_NAME} OBJECT
game/main.cpp
game/scenes/MainMenu.cpp
game/scenes/Psxris.cpp
game/scenes/Test3D.cpp
)
target_include_directories(
${GAME_NAME} PUBLIC
lib
inc
lib/libc
)
# Create the final executable of the engine and link common and game into it
add_executable(${PROJECT_NAME}
#Internal
src/main.cpp
src/interrupts.c
src/draw.cpp
src/vsync.c
src/cdrom.c
src/cdread.c
src/cdmisc.c
src/filesystem.c
src/gte.c
src/trig.c
src/sio0.cpp
#API
src/psbw/Sio.cpp
src/psbw/Scene.cpp
src/psbw/GameObject.cpp
src/psbw/Sprite.cpp
src/psbw/Mesh.cpp
src/psbw/Text.cpp
src/psbw/Manager.cpp
src/psbw/Controller.cpp
src/psbw/Sound.cpp
src/psbw/Fudgebundle.cpp
src/psbw/Font.cpp
)
target_link_libraries(${PROJECT_NAME} PRIVATE ${GAME_NAME} common)
target_include_directories(${PROJECT_NAME} PUBLIC inc)
# The final executable requires conversion to be ran on the PSX
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
BYPRODUCTS ${GAME_NAME}.psexe
COMMAND
"${Python3_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/tools/convertExecutable.py"
"$<TARGET_FILE:${PROJECT_NAME}>" ${GAME_NAME}.psexe
VERBATIM
)
function(addBinaryFile target name path)
set(_file "${PROJECT_BINARY_DIR}/${target}_${name}.s")
cmake_path(ABSOLUTE_PATH path OUTPUT_VARIABLE _path)
file(
CONFIGURE
OUTPUT "${_file}"
CONTENT [[
.section .data.${name}, "aw"
.balign 8
.global ${name}
.type ${name}, @object
.size ${name}, (${name}_end - ${name})
${name}:
.incbin "${_path}"
${name}_end:
]]
ESCAPE_QUOTES
NEWLINE_STYLE LF
)
target_sources(${target} PRIVATE "${_file}")
set_source_files_properties("${_file}" PROPERTIES OBJECT_DEPENDS "${_path}")
endfunction()
function(convertImage input bpp)
add_custom_command(
OUTPUT ${ARGN}
DEPENDS "${PROJECT_SOURCE_DIR}/${input}"
COMMAND
"${Python3_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/tools/convertImage.py"
-b ${bpp} "${PROJECT_SOURCE_DIR}/${input}" ${ARGN}
VERBATIM
)
endfunction()
function(psn00bsdk_add_cd_image name image_name config_file)
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(MKPSXISO mkpsxiso.exe)
ELSE()
set(MKPSXISO ${PROJECT_BINARY_DIR}/tree/bin/mkpsxiso)
ENDIF()
cmake_path(HASH config_file _hash)
add_custom_command(
OUTPUT ${image_name}.bin ${image_name}.cue
COMMAND
${MKPSXISO} -y
-o ${image_name}.bin -c ${image_name}.cue ${PROJECT_BINARY_DIR}/iso.xml
COMMENT "Building CD image ${image_name}"
VERBATIM
${ARGN}
)
add_custom_target(
${name} ALL
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${image_name}.bin
${CMAKE_CURRENT_BINARY_DIR}/${image_name}.cue
)
endfunction()
if (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
include(ExternalProject)
ExternalProject_Add(
mkpsxiso
PREFIX subprojects
SOURCE_DIR ${PROJECT_SOURCE_DIR}/tools/mkpsxiso
INSTALL_DIR tree
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${PROJECT_BINARY_DIR}/tree
)
ENDIF()
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
psn00bsdk_add_cd_image(
iso # Target name
${GAME_NAME} # Output file name (= template.bin + template.cue)
iso.xml # Path to config file
DEPENDS psbw system.cnf
)
ELSE()
psn00bsdk_add_cd_image(
iso # Target name
${GAME_NAME} # Output file name (= template.bin + template.cue)
iso.xml # Path to config file
DEPENDS psbw system.cnf mkpsxiso
)
ENDIF()
include(${PROJECT_SOURCE_DIR}/cmake/defines.cmake)
read_yaml_and_set_defines(GameSettings.yaml)
convertImage(font.png 4 font.dat fontPalette.dat)
addBinaryFile(${PROJECT_NAME} debugFont "${PROJECT_BINARY_DIR}/font.dat")
addBinaryFile(${PROJECT_NAME} debugFontPalette "${PROJECT_BINARY_DIR}/font.dat")