aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/CMakeLists.txt
blob: a6b6df392a245926513877c72895e1ed4b487edf (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
# libpsn00b build script
# (C) 2021-2022 spicyjpeg - MPL licensed

cmake_minimum_required(VERSION 3.21)

# ${PROJECT_SOURCE_DIR} is not available until project() is called.
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/cmake/sdk.cmake)

project(
	libpsn00b
	LANGUAGES    C CXX ASM
	DESCRIPTION  "PSn00bSDK libraries"
	HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
)

include(${PROJECT_SOURCE_DIR}/cmake/flags.cmake)

## Libraries

set(_types    EXECUTABLE_GPREL EXECUTABLE_NOGPREL SHARED_LIBRARY)
set(_suffixes _exe_gprel _exe_nogprel _dll)

foreach(_library IN LISTS PSN00BSDK_LIBRARIES)
	# libc needs special handling due to the different directory name.
	if(${_library} STREQUAL "c")
		set(_path ${PROJECT_SOURCE_DIR}/libc)
	else()
		set(_path ${PROJECT_SOURCE_DIR}/${_library})
	endif()

	file(
		GLOB_RECURSE _sources
		${_path}/*.s ${_path}/*.c ${_path}/*.cpp
	)

	# Build a separate version of the library for each supported target type
	# and create a virtual target that links the appropriate version of the
	# library.
	add_library(${_library} INTERFACE)

	foreach(_type _suffix IN ZIP_LISTS _types _suffixes)
		set(_name ${_library}${_suffix})
		list(APPEND _libraries ${_name})

		psn00bsdk_add_library(${_name} STATIC ${_sources})
		set_target_properties(${_name} PROPERTIES PSN00BSDK_TARGET_TYPE ${_type})
		target_link_libraries(
			${_library} INTERFACE
			$<$<STREQUAL:$<UPPER_CASE:$<TARGET_PROPERTY:PSN00BSDK_TARGET_TYPE>>,${_type}>:${_name}>
		)

		target_compile_definitions(${_name} PRIVATE SDK_LIBRARY_NAME="${_library}")
	endforeach()
endforeach()

# Add binary assets to each version of the libraries.
foreach(_suffix IN LISTS _suffixes)
	psn00bsdk_target_incbin(
		psxgpu${_suffix} PRIVATE _gpu_debug_font
		psxgpu/dbugfont.tim
	)
endforeach()

## Installation

install(
	TARGETS     psn00bsdk ${PSN00BSDK_LIBRARIES} ${_libraries}
	DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b/$<LOWER_CASE:$<CONFIG>>
	EXPORT      libpsn00b
)
install(
	DIRECTORY   cmake ldscripts
	DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b
)
install(
	DIRECTORY   include/
	DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libpsn00b
)

# Generate build.json. This file is used to determine the SDK version after
# installation and may contain additional metadata about the build.
file(
	CONFIGURE
	OUTPUT  build.json
	CONTENT [[{
	"version":       "${PSN00BSDK_VERSION}",
	"build_date":    "${PSN00BSDK_BUILD_DATE}",
	"git_tag":       "${PSN00BSDK_GIT_TAG}",
	"git_commit":    "${PSN00BSDK_GIT_COMMIT}",
	"cmake_version": "${CMAKE_VERSION}",
	"host_system":   "${CMAKE_HOST_SYSTEM_NAME}"
}]]
	ESCAPE_QUOTES
	NEWLINE_STYLE LF
)
install(
	FILES       ${PROJECT_BINARY_DIR}/build.json
	DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b
)

# Generate an import script, which will be used by the setup script to find the
# libraries. Note that CMake actually generates two separate import scripts
# (one setting configuration-specific options), so this won't create conflicts
# once the debug and release builds are merged into the same installation tree.
install(
	EXPORT      libpsn00b
	DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b/cmake
	#EXPORT_LINK_INTERFACE_LIBRARIES
)