aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/cmake/flags.cmake
blob: 5d9c751ef657e2f04f943e1c709bff4941e3d47b (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
# libpsn00b interface targets
# (C) 2021 spicyjpeg - MPL licensed

# This script creates several "virtual" targets (psn00bsdk_*) that set include
# directories and compiler flags when a target is linked against them. The
# following targets are currently defined:
# - psn00bsdk_common
# - psn00bsdk_static_exe
# - psn00bsdk_dynamic_exe
# - psn00bsdk_static_lib
# - psn00bsdk_object_lib (same as psn00bsdk_static_lib)
# - psn00bsdk_shared_lib
# - psn00bsdk_module_lib (same as psn00bsdk_shared_lib)
#
# NOTE: building a static library and linking it as part of a DLL is currently
# *not* supported.

if(NOT TARGET psn00bsdk_common) # Include guard

add_library(psn00bsdk_common INTERFACE)

foreach(
	_target IN ITEMS
	static_exe dynamic_exe static_lib object_lib shared_lib module_lib
)
	add_library          (psn00bsdk_${_target} INTERFACE)
	target_link_libraries(psn00bsdk_${_target} INTERFACE psn00bsdk_common)
endforeach()

# Options common to all target types:
# - Define PLAYSTATION=1
# - Optimize for MIPS R3000
# - Inject zero checks into division operations (will throw breaks)
# - All standard libraries (including libgcc) disabled
# - Put all symbols into separate sections when building
# - C++ features that require runtime support disabled
# - Unused section stripping enabled
target_compile_options(
	psn00bsdk_common INTERFACE
		# CPU options
		-msoft-float
		-march=r3000
		-mtune=r3000
		-mabi=32
		-mno-mt
		-mno-llsc
		-mdivide-breaks
		-O2
		# Standard library options
		-ffreestanding
		-fno-builtin
		-nostdlib
		# Other options
		-g
		-fdata-sections
		-ffunction-sections
		-fsigned-char
		-fno-strict-overflow
		-fdiagnostics-color=always
	$<$<COMPILE_LANGUAGE:CXX>:
		# C++ options
		-fno-exceptions
		-fno-rtti
		-fno-unwind-tables
		-fno-threadsafe-statics
		-fno-use-cxa-atexit
	>
)
target_link_options(
	psn00bsdk_common INTERFACE
		-nostdlib
		-Wl,-gc-sections
)
target_compile_definitions(
	psn00bsdk_common INTERFACE
		PLAYSTATION=1
		$<$<CONFIG:DEBUG>:DEBUG=1>
)

# Options for executables without support for dynamic linking:
# - Position-independent code disabled
# - GP-relative addressing enabled only for local symbols
# - ABI-compatible calls disabled (incompatible with GP-relative addr)
target_compile_options(
	psn00bsdk_static_exe INTERFACE
		-G8
		-fno-pic
		-mno-abicalls
		-mgpopt
		-mno-extern-sdata
)
target_link_options(
	psn00bsdk_static_exe INTERFACE
		-G8
		-static
)

# Options for executables with support for dynamic linking:
# - Position-independent code disabled
# - GP-relative addressing disabled
# - ABI-compatible calls disabled (must be performed manually)
target_compile_options(
	psn00bsdk_dynamic_exe INTERFACE
		-G0
		-fno-pic
		-mno-abicalls
		-mno-gpopt
)
target_link_options(
	psn00bsdk_dynamic_exe INTERFACE
		-G0
		-static
)

# Options for static libraries:
# - Position-independent code disabled
# - GP-relative addressing disabled
# - ABI-compatible calls disabled
# - Local stripping enabled
target_compile_options(
	psn00bsdk_static_lib INTERFACE
		-G0
		-fno-pic
		-mno-abicalls
		-mno-gpopt
		-Wa,--strip-local-absolute
)

target_link_libraries(psn00bsdk_object_lib INTERFACE psn00bsdk_static_lib)

# Options for dynamically-loaded libraries:
# - Position-independent code enabled
# - GP-relative addressing disabled (incompatible with ABI calls)
# - ABI-compatible calls enabled
target_compile_options(
	psn00bsdk_shared_lib INTERFACE
		-G0
		-fPIC
		-mabicalls
		-mno-gpopt
		-mshared
)
target_link_options(
	psn00bsdk_shared_lib INTERFACE
		-G0
		-shared
)

target_link_libraries(psn00bsdk_module_lib INTERFACE psn00bsdk_shared_lib)

endif()