blob: 7d6bfdd71f169e2efe3ee8b59c1af8a21cc68a48 (
plain) (
blame)
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
|
# PSn00bSDK internal setup script for CMake
# (C) 2021 spicyjpeg - MPL licensed
# This script is included automatically when using the toolchain file and
# defines helper functions.
cmake_minimum_required(VERSION 3.20)
include(GNUInstallDirs)
# Fetch SDK version information from build.json.
if(NOT DEFINED PSN00BSDK_VERSION)
file(READ ${CMAKE_CURRENT_LIST_DIR}/../build.json _json)
string(JSON PSN00BSDK_VERSION GET ${_json} version)
string(JSON PSN00BSDK_BUILD_DATE GET ${_json} build_date)
string(JSON PSN00BSDK_GIT_TAG GET ${_json} git_tag)
string(JSON PSN00BSDK_GIT_COMMIT GET ${_json} git_commit)
endif()
## Settings (can be overridden by projects)
set(PSN00BSDK_EXECUTABLE_SUFFIX ".exe")
set(PSN00BSDK_SHARED_LIBRARY_SUFFIX ".dll")
set(PSN00BSDK_SYMBOL_MAP_SUFFIX ".map")
## SDK libraries
# DON'T CHANGE THE ORDER or you'll break the libraries' internal dependencies.
set(PSN00BSDK_LIBRARIES psxgpu psxgte psxspu psxcd psxsio psxetc psxapi lzp c)
include(${CMAKE_CURRENT_LIST_DIR}/libpsn00b.cmake OPTIONAL)
include(${CMAKE_CURRENT_LIST_DIR}/flags.cmake)
# Use the toolchain path to find libgcc (used to build libpsn00b). Of course
# different installers, packages and distros have different opinions when it
# comes to deciding where to install toolchains, so we have to bruteforce
# multiple combinations of paths.
if(CMAKE_C_COMPILER_VERSION)
string(REGEX MATCH "^([0-9]+)\." _dummy ${CMAKE_C_COMPILER_VERSION})
find_library(
PSN00BSDK_LIBGCC gcc
HINTS
${PSN00BSDK_TC}/lib/gcc-cross/${PSN00BSDK_TARGET}/${CMAKE_C_COMPILER_VERSION}
${PSN00BSDK_TC}/lib/gcc-cross/${PSN00BSDK_TARGET}/${CMAKE_MATCH_1}
${PSN00BSDK_TC}/lib/gcc/${PSN00BSDK_TARGET}/${CMAKE_C_COMPILER_VERSION}
${PSN00BSDK_TC}/lib/gcc/${PSN00BSDK_TARGET}/${CMAKE_MATCH_1}
${PSN00BSDK_TC}/../lib/gcc-cross/${PSN00BSDK_TARGET}/${CMAKE_C_COMPILER_VERSION}
${PSN00BSDK_TC}/../lib/gcc-cross/${PSN00BSDK_TARGET}/${CMAKE_MATCH_1}
${PSN00BSDK_TC}/../lib/gcc/${PSN00BSDK_TARGET}/${CMAKE_C_COMPILER_VERSION}
${PSN00BSDK_TC}/../lib/gcc/${PSN00BSDK_TARGET}/${CMAKE_MATCH_1}
NO_DEFAULT_PATH
DOC "Path to libgcc (bundled with the GCC toolchain)"
)
endif()
## Tools
set(
PSN00BSDK_TOOLS
${CMAKE_CURRENT_LIST_DIR}/../../../${CMAKE_INSTALL_BINDIR}
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
)
find_program(ELF2X elf2x HINTS ${PSN00BSDK_TOOLS})
find_program(ELF2CPE elf2cpe HINTS ${PSN00BSDK_TOOLS})
find_program(SMXLINK smxlink HINTS ${PSN00BSDK_TOOLS})
find_program(LZPACK lzpack HINTS ${PSN00BSDK_TOOLS})
find_program(MKPSXISO mkpsxiso HINTS ${PSN00BSDK_TOOLS})
## Helper functions for executables
set(PSN00BSDK_LDSCRIPTS ${CMAKE_CURRENT_LIST_DIR}/../ldscripts)
if(IS_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../include)
set(PSN00BSDK_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/../include)
else()
set(PSN00BSDK_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/../../../include/libpsn00b)
endif()
# psn00bsdk_add_executable(
# <target name> <STATIC|DYNAMIC>
# [EXCLUDE_FROM_ALL]
# <sources> ...
# )
function(psn00bsdk_add_executable name type)
string(TOLOWER ${type} _type)
if(NOT ${_type} MATCHES "^(static|dynamic)$")
message(FATAL_ERROR "Invalid executable type: ${type} (must be STATIC or DYNAMIC)")
endif()
# Throw an error if elf2x was not found (which should never happen if the
# SDK is installed properly).
if(ELF2X STREQUAL "ELF2X-NOTFOUND")
message(FATAL_ERROR "Failed to locate elf2x. Check your PATH environment variable.")
endif()
add_executable (${name} ${ARGN})
target_link_libraries(${name} psn00bsdk_${_type}_exe ${PSN00BSDK_LIBRARIES})
set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX ".elf")
target_link_options (${name} PRIVATE -T${PSN00BSDK_LDSCRIPTS}/exe.ld)
target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE})
# Add post-build steps to generate the .exe and symbol map once the
# executable is built.
add_custom_command(
TARGET ${name} POST_BUILD
COMMAND ${ELF2X} -q ${name}.elf ${name}${PSN00BSDK_EXECUTABLE_SUFFIX}
COMMAND ${TOOLCHAIN_NM} -f posix -l -n ${name}.elf $<ANGLE-R>${name}${PSN00BSDK_SYMBOL_MAP_SUFFIX}
BYPRODUCTS ${name}${PSN00BSDK_EXECUTABLE_SUFFIX} ${name}${PSN00BSDK_SYMBOL_MAP_SUFFIX}
)
endfunction()
# psn00bsdk_add_library(
# <target name> <STATIC|SHARED|MODULE>
# [EXCLUDE_FROM_ALL]
# <sources> ...
# )
# Note that SHARED and MODULE have the same meaning (both will create a DLL).
# SDK libraries are NOT statically linked in by default; if you need to link
# something, use target_link_libraries() manually.
function(psn00bsdk_add_library name type)
string(TOUPPER ${type} _type_upper)
string(TOLOWER ${type} _type)
if(NOT ${_type} MATCHES "^(static|object|shared|module)$")
message(FATAL_ERROR "Invalid library type: ${type} (must be STATIC, OBJECT, SHARED or MODULE)")
endif()
add_library (${name} ${_type_upper} ${ARGN})
target_link_libraries(${name} psn00bsdk_${_type}_lib)
target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE})
if(${_type} MATCHES "^(shared|module)$")
set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX ".so")
target_link_options (${name} PRIVATE -T${PSN00BSDK_LDSCRIPTS}/dll.ld)
# Add a post-build step to dump the DLL's raw contents into a new file
# separate from the built ELF.
add_custom_command(
TARGET ${name} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary ${name}.so ${name}${PSN00BSDK_SHARED_LIBRARY_SUFFIX}
BYPRODUCTS ${name}${PSN00BSDK_SHARED_LIBRARY_SUFFIX}
)
else()
set_target_properties(${name} PROPERTIES PREFIX "lib" SUFFIX ".a")
# Remove virtual target dependencies to make sure linking against the
# library does not also propagate static library flags.
set_target_properties(${name} PROPERTIES INTERFACE_LINK_LIBRARIES "")
endif()
endfunction()
# psn00bsdk_add_cd_image(
# <target name>
# <image file name>
# <mkpsxiso config template>
# [DEPENDS <dependencies> ...]
# [additional options passed to add_custom_target()]
# )
function(psn00bsdk_add_cd_image name image_name config_file)
# Throw an error if mkpsxiso was not found. Performing this check manually
# (instead of just marking mkpsxiso as required) allows simple projects to
# be built even if mkpsxiso is not installed.
if(MKPSXISO STREQUAL "MKPSXISO-NOTFOUND")
message(FATAL_ERROR "Failed to locate mkpsxiso. If mkpsxiso wasn't installed alongside the SDK, check your PATH environment variable.")
endif()
set(CD_IMAGE_NAME ${image_name})
configure_file(${config_file} _gen_${config_file})
add_custom_target(
${name} ALL
COMMAND ${MKPSXISO} -y -q _gen_${config_file}
BYPRODUCTS ${image_name}.bin ${image_name}.cue
COMMENT "Building CD image ${image_name}"
${ARGN}
)
endfunction()
## Helper functions for assets
# TODO: add them
|