aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-11-28 17:40:48 +0100
committerspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-11-28 17:40:48 +0100
commit6d9ceda63aefe8910e798b6b38a7783d00b855f1 (patch)
treeccff94aa3cbfda72a45f14219cdad97d99d6e9bf
parent603b42797c4b0e7a3e2a3cac320daecf1ee34feb (diff)
downloadpsn00bsdk-6d9ceda63aefe8910e798b6b38a7783d00b855f1.tar.gz
Refactor libpsn00b CMake scripts, move include directory
-rw-r--r--cpack/setup.cmake14
-rw-r--r--libpsn00b/CMakeLists.txt21
-rw-r--r--libpsn00b/build.json.template5
-rw-r--r--libpsn00b/cmake/flags.cmake148
-rw-r--r--libpsn00b/cmake/internal_setup.cmake22
-rw-r--r--libpsn00b/cmake/virtual_targets.cmake109
-rw-r--r--libpsn00b/ldscripts/dll.ld4
-rw-r--r--libpsn00b/ldscripts/exe.ld2
8 files changed, 200 insertions, 125 deletions
diff --git a/cpack/setup.cmake b/cpack/setup.cmake
index 33f127e..57568bb 100644
--- a/cpack/setup.cmake
+++ b/cpack/setup.cmake
@@ -14,10 +14,10 @@ set(
BUNDLE_TOOLCHAIN OFF
CACHE BOOL "Include the GCC toolchain in installer packages"
)
-set(
- BUNDLE_CMAKE OFF
- CACHE BOOL "Include CMake in installer packages (Windows only)"
-)
+#set(
+ #BUNDLE_CMAKE OFF
+ #CACHE BOOL "Include CMake in installer packages (Windows only)"
+#)
## Bundled components
@@ -134,6 +134,7 @@ set(
CPACK_NSIS_MENU_LINKS
"${PROJECT_HOMEPAGE_URL}" "About PSn00bSDK"
"https://github.com/Lameguy64/PSn00bSDK" "GitHub repo"
+ "Uninstall.exe" "Uninstall PSn00bSDK"
)
# Paths in CPACK_NSIS_* variables are not converted to native paths by CMake
@@ -166,6 +167,11 @@ cpack_add_component(
DISPLAY_NAME "SDK documentation"
DESCRIPTION "Select to install additional documentation files and a project template (recommended)."
)
+cpack_add_component(
+ examples
+ DISPLAY_NAME "SDK examples"
+ DESCRIPTION "Select to copy the examples' source code to the documentation folder (recommended)."
+)
if(BUNDLE_TOOLCHAIN)
cpack_add_component(
diff --git a/libpsn00b/CMakeLists.txt b/libpsn00b/CMakeLists.txt
index 7b5f7a5..2b2e76d 100644
--- a/libpsn00b/CMakeLists.txt
+++ b/libpsn00b/CMakeLists.txt
@@ -58,12 +58,29 @@ add_custom_command(
## Installation
install(
- TARGETS ${PSN00BSDK_LIBRARIES} ${PSN00BSDK_VIRTUAL_TARGETS}
+ TARGETS ${PSN00BSDK_LIBRARIES}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b
EXPORT libpsn00b
)
install(
- DIRECTORY cmake include ldscripts
+ 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.
+string(TIMESTAMP PSN00BSDK_BUILD_DATE UTC)
+configure_file(
+ build.json.template build.json
+ ESCAPE_QUOTES
+ NEWLINE_STYLE LF
+)
+install(
+ FILES ${PROJECT_BINARY_DIR}/build.json
DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b
)
diff --git a/libpsn00b/build.json.template b/libpsn00b/build.json.template
new file mode 100644
index 0000000..666bb43
--- /dev/null
+++ b/libpsn00b/build.json.template
@@ -0,0 +1,5 @@
+{
+ "version": "${PSN00BSDK_VERSION}",
+ "build_date": "${PSN00BSDK_BUILD_DATE}",
+ "build_info": "${PSN00BSDK_BUILD_INFO}"
+}
diff --git a/libpsn00b/cmake/flags.cmake b/libpsn00b/cmake/flags.cmake
new file mode 100644
index 0000000..e163e52
--- /dev/null
+++ b/libpsn00b/cmake/flags.cmake
@@ -0,0 +1,148 @@
+# 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_object_lib (same as psn00bsdk_common)
+# - psn00bsdk_static_exe
+# - psn00bsdk_dynamic_exe
+# - 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.
+
+add_library(psn00bsdk_common INTERFACE)
+
+foreach(
+ _target IN ITEMS
+ object_lib
+ static_exe
+ dynamic_exe
+ static_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
+ -mdivide-breaks
+ -O2
+ # Standard library options
+ -ffreestanding
+ -fno-builtin
+ -nostdlib
+ # Other options
+ -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
+)
+
+# 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)
diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake
index b0c4591..1d63e92 100644
--- a/libpsn00b/cmake/internal_setup.cmake
+++ b/libpsn00b/cmake/internal_setup.cmake
@@ -7,8 +7,14 @@
cmake_minimum_required(VERSION 3.20)
include(GNUInstallDirs)
-# IMPORTANT TODO: set a version number
-set(PSN00BSDK_VERSION 0.1.0)
+# Fetch the SDK version number 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_BUILD_INFO GET ${_json} build_info)
+endif()
## Settings (can be overridden by projects)
@@ -22,9 +28,7 @@ set(PSN00BSDK_SYMBOL_MAP_SUFFIX ".map")
set(PSN00BSDK_LIBRARIES psxgpu psxgte psxspu psxcd psxsio psxetc psxapi lzp c)
include(${CMAKE_CURRENT_LIST_DIR}/libpsn00b.cmake OPTIONAL)
-if(NOT TARGET psn00bsdk_common)
- include(${CMAKE_CURRENT_LIST_DIR}/virtual_targets.cmake)
-endif()
+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
@@ -59,14 +63,18 @@ set(
find_program(ELF2X elf2x HINTS ${PSN00BSDK_TOOLS})
find_program(ELF2CPE elf2cpe HINTS ${PSN00BSDK_TOOLS})
-find_program(SMXLINK elf2x 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_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/../include)
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>
diff --git a/libpsn00b/cmake/virtual_targets.cmake b/libpsn00b/cmake/virtual_targets.cmake
deleted file mode 100644
index 9afcebd..0000000
--- a/libpsn00b/cmake/virtual_targets.cmake
+++ /dev/null
@@ -1,109 +0,0 @@
-# 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. These
-# all end up in the autogenerated libpsn00b setup script after installation,
-# so this file is only included when building libpsn00b.
-
-# The following targets are currently defined:
-# - psn00bsdk_common
-# - psn00bsdk_object_lib (same as psn00bsdk_common)
-# - psn00bsdk_static_exe
-# - psn00bsdk_dynamic_exe
-# - psn00bsdk_static_lib
-# - psn00bsdk_shared_lib
-# - psn00bsdk_module_lib (same as psn00bsdk_shared_lib)
-
-include(GNUInstallDirs)
-
-set(PSN00BSDK_VIRTUAL_TARGETS "")
-
-macro(_add_interface_target name)
- add_library(${name} INTERFACE)
- list(APPEND PSN00BSDK_VIRTUAL_TARGETS ${name})
-
- target_compile_options(
- ${name} INTERFACE
- ${_aflags}
- $<$<COMPILE_LANGUAGE:C,CXX>:${_cflags}>
- $<$<COMPILE_LANGUAGE:CXX>:${_cxxflags}>
- )
- target_link_options (${name} INTERFACE ${_ldflags})
- target_link_libraries(${name} INTERFACE ${ARGN})
-endmacro()
-
-macro(_add_alias_target name)
- #add_library(${name} ALIAS ${ARGN})
- add_library(${name} INTERFACE)
- list(APPEND PSN00BSDK_VIRTUAL_TARGETS ${name})
-
- target_link_libraries(${name} INTERFACE ${ARGN})
-endmacro()
-
-# Options common to all target types:
-# - Define PLAYSTATION=1 and set include directories
-# - 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
-set(_aflags -msoft-float -march=r3000 -mtune=r3000 -mabi=32)
-set(_cflags -mdivide-breaks -O2 -ffreestanding -fno-builtin -nostdlib -fdata-sections -ffunction-sections -fsigned-char -fno-strict-overflow -fdiagnostics-color=always)
-set(_cxxflags -fno-exceptions -fno-rtti -fno-unwind-tables -fno-threadsafe-statics -fno-use-cxa-atexit)
-set(_ldflags -nostdlib -Wl,-gc-sections)
-
-_add_interface_target(psn00bsdk_common)
-_add_alias_target (psn00bsdk_object_lib psn00bsdk_common)
-
-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)
-set(_aflags -G8)
-set(_cflags -mno-abicalls -mgpopt -mno-extern-sdata)
-set(_cxxflags)
-set(_ldflags -G8 -static)
-
-_add_interface_target(psn00bsdk_static_exe psn00bsdk_common)
-
-# Options for executables with support for dynamic linking:
-# - Position-independent code disabled
-# - GP-relative addressing disabled
-# - ABI-compatible calls disabled (must be performed manually)
-set(_aflags -G0)
-set(_cflags -mno-abicalls -mno-gpopt)
-set(_cxxflags)
-set(_ldflags -G0 -static)
-
-_add_interface_target(psn00bsdk_dynamic_exe psn00bsdk_common)
-
-# Options for static libraries:
-# - GP-relative addressing disabled
-# - ABI-compatible calls disabled
-# - Local stripping enabled
-set(_aflags -G0 -Wa,--strip-local-absolute)
-set(_cflags -mno-abicalls -mno-gpopt)
-set(_cxxflags)
-set(_ldflags)
-
-_add_interface_target(psn00bsdk_static_lib psn00bsdk_common)
-
-# Options for dynamically-loaded libraries:
-# - Position-independent code enabled
-# - GP-relative addressing disabled (incompatible with ABI calls)
-# - ABI-compatible calls enabled
-set(_aflags -G0)
-set(_cflags -mabicalls -mshared -mno-gpopt -fPIC)
-set(_cxxflags)
-set(_ldflags -G0 -shared)
-
-_add_interface_target(psn00bsdk_shared_lib psn00bsdk_common)
-_add_alias_target (psn00bsdk_module_lib psn00bsdk_shared_lib)
diff --git a/libpsn00b/ldscripts/dll.ld b/libpsn00b/ldscripts/dll.ld
index 59cbb53..a03a504 100644
--- a/libpsn00b/ldscripts/dll.ld
+++ b/libpsn00b/ldscripts/dll.ld
@@ -7,8 +7,8 @@
* replaced by the global offset table (GOT) and .bss being merged with .data.
*/
-OUTPUT_FORMAT(elf32-littlemips)
-/*ENTRY(_start)
+/*OUTPUT_FORMAT(elf32-littlemips)
+ENTRY(_start)
STARTUP(start.o)*/
MEMORY {
diff --git a/libpsn00b/ldscripts/exe.ld b/libpsn00b/ldscripts/exe.ld
index 3033636..c6b9f29 100644
--- a/libpsn00b/ldscripts/exe.ld
+++ b/libpsn00b/ldscripts/exe.ld
@@ -8,7 +8,7 @@
* compatible with dynamic linking, as DLLs require GP to be unused.
*/
-OUTPUT_FORMAT(elf32-littlemips)
+/*OUTPUT_FORMAT(elf32-littlemips)*/
ENTRY(_start)
/*STARTUP(start.o)*/