From 1b1e9b85a51444751dddc0e94a09d19bd4f0885e Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sun, 9 Oct 2022 20:26:25 +0200 Subject: Refactor CMake scripts, add separate debug/release builds --- libpsn00b/cmake/internal_setup.cmake | 230 ++++++++++++++++++----------------- 1 file changed, 118 insertions(+), 112 deletions(-) (limited to 'libpsn00b/cmake/internal_setup.cmake') diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index d293127..e9f0db5 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -1,5 +1,5 @@ # PSn00bSDK internal setup script for CMake -# (C) 2021 spicyjpeg - MPL licensed +# (C) 2021-2022 spicyjpeg - MPL licensed # This script is included automatically when using the toolchain file and # defines helper functions. @@ -7,6 +7,10 @@ cmake_minimum_required(VERSION 3.20) include(GNUInstallDirs) +# Re-enable support for dynamic linking as CMake's "Generic" system type +# disables it. +set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS ON) + # Fetch SDK version information from build.json. if(NOT DEFINED PSN00BSDK_VERSION) file(READ ${CMAKE_CURRENT_LIST_DIR}/../build.json _json) @@ -17,13 +21,9 @@ if(NOT DEFINED PSN00BSDK_VERSION) 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") +include(${CMAKE_CURRENT_LIST_DIR}/../libpsn00b.cmake OPTIONAL) -## SDK libraries +## Settings (can be overridden by projects) # DON'T CHANGE THE ORDER or you'll break the libraries' internal dependencies. set( @@ -40,33 +40,23 @@ set( c ) -include(${CMAKE_CURRENT_LIST_DIR}/libpsn00b.cmake OPTIONAL) -include(${CMAKE_CURRENT_LIST_DIR}/flags.cmake) +set(PSN00BSDK_EXECUTABLE_LINK_LIBRARIES ${PSN00BSDK_LIBRARIES}) +set(PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES "") -# 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}) +set(PSN00BSDK_EXECUTABLE_SUFFIX ".exe") +set(PSN00BSDK_SHARED_LIBRARY_SUFFIX ".dll") +set(PSN00BSDK_SYMBOL_MAP_SUFFIX ".map") - 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)" - ) +## Include paths + +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() -## Tools +## Tool paths set( PSN00BSDK_TOOLS @@ -80,26 +70,41 @@ 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 +## libgcc -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() +# Use the toolchain path to find libgcc. 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}) -# psn00bsdk_add_executable( -# -# [EXCLUDE_FROM_ALL] -# ... -# ) -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)") + find_library( + PSN00BSDK_LIBGCC gcc #REQUIRED + 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)" + ) + if(PSN00BSDK_LIBGCC STREQUAL "PSN00BSDK_LIBGCC-NOTFOUND") + message(FATAL_ERROR "Failed to find libgcc in the GCC toolchain's files. Check your toolchain settings, or set the path to libgcc using -DPSN00BSDK_LIBGCC.") endif() + add_library(gcc STATIC IMPORTED) + set_property(TARGET gcc PROPERTY IMPORTED_LOCATION ${PSN00BSDK_LIBGCC}) + link_libraries(gcc) +endif() + +## Target helpers + +function(psn00bsdk_add_executable name type) # Throw an error if elf2x was not found (which should never happen if the # SDK is installed properly). if(ELF2X STREQUAL "ELF2X-NOTFOUND") @@ -107,10 +112,10 @@ function(psn00bsdk_add_executable name type) 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) + psn00bsdk_target_link_sdk (${name} PRIVATE EXECUTABLE ${type} ${PSN00BSDK_EXECUTABLE_LINK_LIBRARIES}) target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE}) # Add post-build steps to generate the .exe and symbol map once the @@ -123,30 +128,26 @@ function(psn00bsdk_add_executable name type) ) endfunction() -# psn00bsdk_add_library( -# -# [EXCLUDE_FROM_ALL] -# ... -# ) -# 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() + string(TOUPPER ${type} _type) - add_library (${name} ${_type_upper} ${ARGN}) - target_link_libraries(${name} psn00bsdk_${_type}_lib) - - target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE}) + if(_type MATCHES "^(STATIC|OBJECT)$") + # Remove virtual target dependencies to make sure linking against the + # library does not also propagate static library flags. + add_library (${name} ${_type} ${ARGN}) + set_target_properties(${name} PROPERTIES PREFIX "lib" SUFFIX ".a") + set_target_properties(${name} PROPERTIES INTERFACE_LINK_LIBRARIES "") + target_link_libraries(${name} PRIVATE psn00bsdk_common) - if(${_type} MATCHES "^(shared|module)$") + target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE}) + elseif(_type MATCHES "^(SHARED|MODULE)$") + add_library (${name} ${_type} ${ARGN}) set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX ".so") target_link_options (${name} PRIVATE -T${PSN00BSDK_LDSCRIPTS}/dll.ld) + psn00bsdk_target_link_sdk (${name} PRIVATE SHARED_LIBRARY ${PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES}) + target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE}) + # Add a post-build step to dump the DLL's raw contents into a new file # separate from the built ELF. add_custom_command( @@ -155,63 +156,48 @@ function(psn00bsdk_add_library name type) 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 "") + message(FATAL_ERROR "Invalid library type: ${type} (must be STATIC, OBJECT, SHARED or MODULE)") endif() endfunction() -# psn00bsdk_add_cd_image( -# -# -# -# [DEPENDS ...] -# [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.") +## Linking helpers + +function(psn00bsdk_target_link_sdk name type target_type) + set(_libraries ${ARGN}) + string(TOUPPER ${target_type} _target_type) + + if(_target_type STREQUAL "EXECUTABLE") + list(POP_FRONT _libraries) + string(TOUPPER ${ARGV3} _exe_type) + + if(_exe_type MATCHES "^(STATIC|GPREL)$") + set(_suffix _exe_gprel) + elseif(_exe_type MATCHES "^(DYNAMIC|NOGPREL)$") + set(_suffix _exe_nogprel) + else() + message(FATAL_ERROR "Invalid executable type: ${ARGV3} (must be STATIC, GPREL, DYNAMIC or NOGPREL)") + endif() + elseif(_target_type STREQUAL "SHARED_LIBRARY") + set(_suffix _dll) + else() + message(FATAL_ERROR "Invalid target type: ${target_type} (must be EXECUTABLE or SHARED_LIBRARY)") endif() - cmake_path(HASH config_file _hash) - - set(CD_IMAGE_NAME ${image_name}) - set(CD_CONFIG_FILE cd_image_${_hash}.xml) - configure_file(${config_file} ${CD_CONFIG_FILE}) - - add_custom_target( - ${name} ALL - COMMAND ${MKPSXISO} -y ${CD_CONFIG_FILE} - BYPRODUCTS ${image_name}.bin ${image_name}.cue - COMMENT "Building CD image ${image_name}" - ${ARGN} - ) + list(TRANSFORM _libraries APPEND ${_suffix}) + target_link_libraries(${name} ${type} psn00bsdk${_suffix} ${_libraries}) endfunction() -## Helper functions for assets - -# psn00bsdk_target_incbin_a( -# -# -# -# -# -# -# ) function(psn00bsdk_target_incbin_a name type symbol_name size_name path section align) string(MAKE_C_IDENTIFIER ${symbol_name} _id) string(MAKE_C_IDENTIFIER ${size_name} _size) cmake_path(ABSOLUTE_PATH path OUTPUT_VARIABLE _path) + string(SHA1 _hash "${name} ${_id}") + set(_asm_file ${CMAKE_CURRENT_BINARY_DIR}/incbin_${_hash}.s) + # Generate an assembly source file that includes the binary file and add it # to the target's sources. The file is also added as a depedency to ensure # CMake builds it before the target (if it's not a static file). - set(_asm_file ${PROJECT_BINARY_DIR}/incbin_${name}_${_id}.s) file( CONFIGURE OUTPUT ${_asm_file} @@ -246,11 +232,6 @@ ${_size}: set_source_files_properties(${_asm_file} PROPERTIES OBJECT_DEPENDS ${_path}) endfunction() -# psn00bsdk_target_incbin( -# -# -# -# ) function(psn00bsdk_target_incbin name type symbol_name path) string(MAKE_C_IDENTIFIER ${symbol_name} _id) @@ -264,3 +245,28 @@ function(psn00bsdk_target_incbin name type symbol_name path) 4 ) endfunction() + +## CD image and asset helpers + +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() + + cmake_path(HASH config_file _hash) + + set(CD_IMAGE_NAME ${image_name}) + set(CD_CONFIG_FILE cd_image_${_hash}.xml) + configure_file(${config_file} ${CD_CONFIG_FILE}) + + add_custom_target( + ${name} ALL + COMMAND ${MKPSXISO} -y ${CD_CONFIG_FILE} + BYPRODUCTS ${image_name}.bin ${image_name}.cue + COMMENT "Building CD image ${image_name}" + ${ARGN} + ) +endfunction() -- cgit v1.2.3 From 1a468c901a7b473a556c6a572c03c68186f03f89 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Tue, 11 Oct 2022 11:17:28 +0200 Subject: Update CMake scripts to use generator expressions --- examples/lowlevel/cartrom/CMakeLists.txt | 10 ++- libpsn00b/CMakeLists.txt | 29 ++++--- libpsn00b/cmake/flags.cmake | 127 ++++++++++------------------ libpsn00b/cmake/internal_setup.cmake | 137 ++++++++++++++++++------------- libpsn00b/cmake/sdk.cmake | 14 ++-- 5 files changed, 156 insertions(+), 161 deletions(-) (limited to 'libpsn00b/cmake/internal_setup.cmake') diff --git a/examples/lowlevel/cartrom/CMakeLists.txt b/examples/lowlevel/cartrom/CMakeLists.txt index 2efe6cf..6a94d9f 100644 --- a/examples/lowlevel/cartrom/CMakeLists.txt +++ b/examples/lowlevel/cartrom/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.21) project( cartrom @@ -17,9 +17,13 @@ file(GLOB _sources *.c *.s) # executable has to be created manually and converted into raw binary format # (for testing on emulators or flashing to a cheat cartridge). add_executable (cartrom ${_sources}) -target_link_libraries(cartrom psn00bsdk_exe_nogprel) -set_target_properties(cartrom PROPERTIES PREFIX "" SUFFIX ".elf") target_link_options (cartrom PRIVATE -T${PROJECT_SOURCE_DIR}/rom.ld) +set_target_properties( + cartrom PROPERTIES + PREFIX "" + SUFFIX ".elf" + PSN00BSDK_TARGET_TYPE EXECUTABLE_NOGPREL +) target_include_directories(cartrom PRIVATE ${PROJECT_SOURCE_DIR}) diff --git a/libpsn00b/CMakeLists.txt b/libpsn00b/CMakeLists.txt index 71cc659..602b3c8 100644 --- a/libpsn00b/CMakeLists.txt +++ b/libpsn00b/CMakeLists.txt @@ -1,7 +1,7 @@ # libpsn00b build script -# (C) 2021 spicyjpeg - MPL licensed +# (C) 2021-2022 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.20) +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) @@ -17,6 +17,9 @@ 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") @@ -30,17 +33,26 @@ foreach(_library IN LISTS PSN00BSDK_LIBRARIES) ${_path}/*.s ${_path}/*.c ${_path}/*.cpp ) - foreach(_suffix IN ITEMS _exe_nogprel _exe_gprel _dll) + # 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}) - target_link_libraries(${_name} PUBLIC psn00bsdk${_suffix}) + set_target_properties(${_name} PROPERTIES PSN00BSDK_TARGET_TYPE ${_type}) + target_link_libraries( + ${_library} INTERFACE + $<$>,${_type}>:${_name}> + ) endforeach() endforeach() # Add binary assets to each version of the libraries. -foreach(_suffix IN ITEMS _exe_nogprel _exe_gprel _dll) +foreach(_suffix IN LISTS _suffixes) psn00bsdk_target_incbin( psxgpu${_suffix} PRIVATE _gpu_debug_font psxgpu/dbugfont.tim @@ -50,12 +62,7 @@ endforeach() ## Installation install( - TARGETS - psn00bsdk_common - psn00bsdk_exe_gprel - psn00bsdk_exe_nogprel - psn00bsdk_dll - ${_libraries} + TARGETS psn00bsdk ${PSN00BSDK_LIBRARIES} ${_libraries} DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b/$> EXPORT libpsn00b ) diff --git a/libpsn00b/cmake/flags.cmake b/libpsn00b/cmake/flags.cmake index fea26cd..e56d3fc 100644 --- a/libpsn00b/cmake/flags.cmake +++ b/libpsn00b/cmake/flags.cmake @@ -6,122 +6,85 @@ # only used when building libpsn00b, as CMake automatically saves these targets # into the export script once libpsn00b is installed. -## Options common to all target types +add_library (psn00bsdk INTERFACE) +link_libraries(psn00bsdk) -# - Define PSN00BSDK=1 -# - Always generate debug symbols (stripped by elf2x) -# - 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 - -add_library(psn00bsdk_common INTERFACE) target_compile_options( - psn00bsdk_common INTERFACE - # CPU options - -msoft-float - -march=r3000 - -mtune=r3000 - -mabi=32 - -mno-mt - -mno-llsc - -mdivide-breaks + psn00bsdk INTERFACE + # Options common to all target types + -g + -Wa,--strip-local-absolute -O2 - # Standard library options -ffreestanding -fno-builtin -nostdlib - # Other options - -g - -Wa,--strip-local-absolute -fdata-sections -ffunction-sections -fsigned-char -fno-strict-overflow -fdiagnostics-color=always + -msoft-float + -march=r3000 + -mtune=r3000 + -mabi=32 + -mno-mt + -mno-llsc + -mdivide-breaks $<$: - # C++ options + # Options common to all target types (C++) -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 - PSN00BSDK=1 - $<$: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 addressing) - -add_library(psn00bsdk_exe_gprel INTERFACE) -target_link_libraries(psn00bsdk_exe_gprel INTERFACE psn00bsdk_common) -target_compile_options( - psn00bsdk_exe_gprel INTERFACE + $<$>,EXECUTABLE_GPREL>: + # Options for executables with $gp-relative addressing -G8 -fno-pic -mno-abicalls -mgpopt -mno-extern-sdata -) -target_link_options( - psn00bsdk_exe_gprel 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) - -add_library(psn00bsdk_exe_nogprel INTERFACE) -target_link_libraries(psn00bsdk_exe_nogprel INTERFACE psn00bsdk_common) -target_compile_options( - psn00bsdk_exe_nogprel INTERFACE + > + $<$>,EXECUTABLE_NOGPREL>: + # Options for executables without $gp-relative addressing -G0 -fno-pic -mno-abicalls -mno-gpopt -) -target_link_options( - psn00bsdk_exe_nogprel INTERFACE - -G0 - -static -) - -## Options for dynamically-linked libraries - -# - Position-independent code enabled -# - $gp-relative addressing disabled (incompatible with ABI calls) -# - ABI-compatible calls enabled - -add_library(psn00bsdk_dll INTERFACE) -target_link_libraries(psn00bsdk_dll INTERFACE psn00bsdk_common) -target_compile_options( - psn00bsdk_dll INTERFACE + > + $<$>,SHARED_LIBRARY>: + # Options for DLLs -G0 -fPIC -mabicalls -mno-gpopt -mshared + > ) target_link_options( - psn00bsdk_dll INTERFACE + psn00bsdk INTERFACE + # Options common to all target types + -nostdlib + -Wl,-gc-sections + $<$>,EXECUTABLE_GPREL>: + # Options for executables with $gp-relative addressing + -G8 + -static + > + $<$>,EXECUTABLE_NOGPREL>: + # Options for executables without $gp-relative addressing + -G0 + -static + > + $<$>,SHARED_LIBRARY>: + # Options for DLLs -G0 -shared + > +) +target_compile_definitions( + psn00bsdk INTERFACE + PSN00BSDK=1 + $<$:DEBUG=1> ) diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index e9f0db5..6fecb9f 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -4,13 +4,26 @@ # This script is included automatically when using the toolchain file and # defines helper functions. -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.21) include(GNUInstallDirs) -# Re-enable support for dynamic linking as CMake's "Generic" system type -# disables it. +## CMake configuration + +# Setting these variables and properties would technically be the toolchain +# script's responsibility, however they are overridden by project() so their +# setting is deferred to this script. +set(CMAKE_EXECUTABLE_SUFFIX ".elf") +set(CMAKE_STATIC_LIBRARY_PREFIX "lib") +set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") +set(CMAKE_SHARED_LIBRARY_PREFIX "") +set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") +set(CMAKE_SHARED_MODULE_PREFIX "") +set(CMAKE_SHARED_MODULE_SUFFIX ".so") + set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS ON) +## PSn00bSDK initialization + # Fetch SDK version information from build.json. if(NOT DEFINED PSN00BSDK_VERSION) file(READ ${CMAKE_CURRENT_LIST_DIR}/../build.json _json) @@ -22,8 +35,9 @@ if(NOT DEFINED PSN00BSDK_VERSION) endif() include(${CMAKE_CURRENT_LIST_DIR}/../libpsn00b.cmake OPTIONAL) - -## Settings (can be overridden by projects) +if(TARGET psn00bsdk) + link_libraries(psn00bsdk) +endif() # DON'T CHANGE THE ORDER or you'll break the libraries' internal dependencies. set( @@ -40,6 +54,8 @@ set( c ) +## Settings (can be overridden by projects) + set(PSN00BSDK_EXECUTABLE_LINK_LIBRARIES ${PSN00BSDK_LIBRARIES}) set(PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES "") @@ -47,6 +63,12 @@ set(PSN00BSDK_EXECUTABLE_SUFFIX ".exe") set(PSN00BSDK_SHARED_LIBRARY_SUFFIX ".dll") set(PSN00BSDK_SYMBOL_MAP_SUFFIX ".map") +define_property( + TARGET PROPERTY PSN00BSDK_TARGET_TYPE + BRIEF_DOCS "Type of this target (EXECUTABLE_GPREL, EXECUTABLE_NOGPREL or SHARED_LIBRARY)" + FULL_DOCS "Type of this target (if executable or DLL) or of the executable/DLL this target is going to be linked to (if static library)" +) + ## Include paths set(PSN00BSDK_LDSCRIPTS ${CMAKE_CURRENT_LIST_DIR}/../ldscripts) @@ -56,6 +78,8 @@ else() set(PSN00BSDK_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/../../../include/libpsn00b) endif() +include_directories(AFTER ${PSN00BSDK_INCLUDE}) + ## Tool paths set( @@ -97,14 +121,24 @@ if(CMAKE_C_COMPILER_VERSION) message(FATAL_ERROR "Failed to find libgcc in the GCC toolchain's files. Check your toolchain settings, or set the path to libgcc using -DPSN00BSDK_LIBGCC.") endif() - add_library(gcc STATIC IMPORTED) - set_property(TARGET gcc PROPERTY IMPORTED_LOCATION ${PSN00BSDK_LIBGCC}) - link_libraries(gcc) + add_library (gcc STATIC IMPORTED) + set_target_properties(gcc PROPERTIES IMPORTED_LOCATION ${PSN00BSDK_LIBGCC}) + link_libraries (gcc) endif() ## Target helpers function(psn00bsdk_add_executable name type) + string(TOUPPER ${type} _type) + + if(_type MATCHES "^(STATIC|GPREL)$") + set(_type EXECUTABLE_GPREL) + elseif(_type MATCHES "^(DYNAMIC|NOGPREL)$") + set(_type EXECUTABLE_NOGPREL) + else() + message(FATAL_ERROR "Invalid executable type: ${type} (must be STATIC, GPREL, DYNAMIC or NOGPREL)") + endif() + # Throw an error if elf2x was not found (which should never happen if the # SDK is installed properly). if(ELF2X STREQUAL "ELF2X-NOTFOUND") @@ -112,19 +146,34 @@ function(psn00bsdk_add_executable name type) endif() add_executable (${name} ${ARGN}) - set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX ".elf") - target_link_options (${name} PRIVATE -T${PSN00BSDK_LDSCRIPTS}/exe.ld) - - psn00bsdk_target_link_sdk (${name} PRIVATE EXECUTABLE ${type} ${PSN00BSDK_EXECUTABLE_LINK_LIBRARIES}) - target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE}) + set_target_properties(${name} PROPERTIES PSN00BSDK_TARGET_TYPE ${_type}) + target_link_libraries(${name} PRIVATE ${PSN00BSDK_EXECUTABLE_LINK_LIBRARIES}) + target_link_options (${name} PRIVATE -T$) # Add post-build steps to generate the .exe and symbol map once the # executable is built. + # FIXME: CMake does not (yet) allow target-dependent generator expressions + # to specify the byproducts, so we have to make sure the generated files + # have no prefix/suffix and are in the current build directory. + #set(_repl PATH:REPLACE_EXTENSION,LAST_ONLY,$) 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 $${name}${PSN00BSDK_SYMBOL_MAP_SUFFIX} - BYPRODUCTS ${name}${PSN00BSDK_EXECUTABLE_SUFFIX} ${name}${PSN00BSDK_SYMBOL_MAP_SUFFIX} + TARGET ${name} POST_BUILD + COMMAND + ${ELF2X} -q + $> + #$> + $ + COMMAND + ${TOOLCHAIN_NM} -f posix -l -n + $> + #$$> + $$ + BYPRODUCTS + #$<${_repl},${PSN00BSDK_EXECUTABLE_SUFFIX}> + #$<${_repl},${PSN00BSDK_SYMBOL_MAP_SUFFIX}> + ${CMAKE_CURRENT_BINARY_DIR}/${name}${PSN00BSDK_EXECUTABLE_SUFFIX} + ${CMAKE_CURRENT_BINARY_DIR}/${name}${PSN00BSDK_SYMBOL_MAP_SUFFIX} + VERBATIM ) endfunction() @@ -132,28 +181,27 @@ function(psn00bsdk_add_library name type) string(TOUPPER ${type} _type) if(_type MATCHES "^(STATIC|OBJECT)$") - # Remove virtual target dependencies to make sure linking against the - # library does not also propagate static library flags. add_library (${name} ${_type} ${ARGN}) - set_target_properties(${name} PROPERTIES PREFIX "lib" SUFFIX ".a") - set_target_properties(${name} PROPERTIES INTERFACE_LINK_LIBRARIES "") - target_link_libraries(${name} PRIVATE psn00bsdk_common) - - target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE}) + #target_link_libraries(${name} PRIVATE psn00bsdk) elseif(_type MATCHES "^(SHARED|MODULE)$") add_library (${name} ${_type} ${ARGN}) - set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX ".so") - target_link_options (${name} PRIVATE -T${PSN00BSDK_LDSCRIPTS}/dll.ld) - - psn00bsdk_target_link_sdk (${name} PRIVATE SHARED_LIBRARY ${PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES}) - target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE}) + set_target_properties(${name} PROPERTIES PSN00BSDK_TARGET_TYPE SHARED_LIBRARY) + target_link_libraries(${name} PRIVATE ${PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES}) + target_link_options (${name} PRIVATE -T$) # Add a post-build step to dump the DLL's raw contents into a new file # separate from the built ELF. + #set(_repl PATH:REPLACE_EXTENSION,LAST_ONLY,$) 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} + TARGET ${name} POST_BUILD + COMMAND + ${CMAKE_OBJCOPY} -O binary + $> + #$> + $ + #BYPRODUCTS $<${_repl},${PSN00BSDK_SHARED_LIBRARY_SUFFIX}> + BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${name}${PSN00BSDK_SHARED_LIBRARY_SUFFIX} + VERBATIM ) else() message(FATAL_ERROR "Invalid library type: ${type} (must be STATIC, OBJECT, SHARED or MODULE)") @@ -162,31 +210,6 @@ endfunction() ## Linking helpers -function(psn00bsdk_target_link_sdk name type target_type) - set(_libraries ${ARGN}) - string(TOUPPER ${target_type} _target_type) - - if(_target_type STREQUAL "EXECUTABLE") - list(POP_FRONT _libraries) - string(TOUPPER ${ARGV3} _exe_type) - - if(_exe_type MATCHES "^(STATIC|GPREL)$") - set(_suffix _exe_gprel) - elseif(_exe_type MATCHES "^(DYNAMIC|NOGPREL)$") - set(_suffix _exe_nogprel) - else() - message(FATAL_ERROR "Invalid executable type: ${ARGV3} (must be STATIC, GPREL, DYNAMIC or NOGPREL)") - endif() - elseif(_target_type STREQUAL "SHARED_LIBRARY") - set(_suffix _dll) - else() - message(FATAL_ERROR "Invalid target type: ${target_type} (must be EXECUTABLE or SHARED_LIBRARY)") - endif() - - list(TRANSFORM _libraries APPEND ${_suffix}) - target_link_libraries(${name} ${type} psn00bsdk${_suffix} ${_libraries}) -endfunction() - function(psn00bsdk_target_incbin_a name type symbol_name size_name path section align) string(MAKE_C_IDENTIFIER ${symbol_name} _id) string(MAKE_C_IDENTIFIER ${size_name} _size) diff --git a/libpsn00b/cmake/sdk.cmake b/libpsn00b/cmake/sdk.cmake index 37b9fd0..facee26 100644 --- a/libpsn00b/cmake/sdk.cmake +++ b/libpsn00b/cmake/sdk.cmake @@ -1,7 +1,7 @@ # PSn00bSDK toolchain setup file for CMake # (C) 2021-2022 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.21) set( PSN00BSDK_TC "" @@ -70,10 +70,9 @@ endif() ## Toolchain executables -# ${CMAKE_EXECUTABLE_SUFFIX} seems not to work in toolchain scripts, so we -# can't rely on it to determine the host OS extension for executables. The best -# workaround I found is to extract the extension from the path returned by -# find_program() using a regex. +# As we have overridden ${CMAKE_EXECUTABLE_SUFFIX} we can't rely on it to +# determine the host OS extension for executables. A workaround is to extract +# the extension from the path returned by find_program() using a regex. set(_prefix ${_bin}/${PSN00BSDK_TARGET}) string(REGEX MATCH ".+-gcc(.*)$" _dummy ${_gcc}) @@ -90,7 +89,6 @@ set(TOOLCHAIN_NM ${_prefix}-nm${CMAKE_MATCH_1}) ## SDK setup -# We can't set up the SDK here as the find_*() functions may fail if they are -# called before project(). We can however set a script to be executed right -# after project() is invoked. +# Continue initialization by running internal_setup.cmake after project() is +# invoked. set(CMAKE_PROJECT_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/internal_setup.cmake) -- cgit v1.2.3 From 8e92156bc6a977651771d2cf91ac5800a0e9a913 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Tue, 11 Oct 2022 15:39:36 +0200 Subject: Update preset files, README, docs and changelog --- CHANGELOG.md | 32 +++ CMakePresets.json | 4 +- README.md | 66 +++-- cpack/setup.cmake | 4 +- doc/cmake_reference.md | 465 ++++++++++++++++++++++------------- doc/installation.md | 6 +- doc/known_bugs.md | 26 +- examples/README.md | 4 +- libpsn00b/cmake/internal_setup.cmake | 2 - template/CMakePresets.json | 25 +- 10 files changed, 399 insertions(+), 235 deletions(-) (limited to 'libpsn00b/cmake/internal_setup.cmake') diff --git a/CHANGELOG.md b/CHANGELOG.md index f7f4f93..3f04108 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,38 @@ to ensure the changelog can be parsed correctly. ------------------------------------------------------------------------------- +## 2022-10-11: 0.21 + +spicyjpeg: + +- libpsn00b: Completely rewritten CMake scripts. Six copies of each library are + now built and installed, one for each combination of configuration (debug and + release) and target type (executable with/without $gp-relative addressing and + DLL). Library debug logging is now completely disabled when a project is + built in release mode (using `-DCMAKE_BUILD_TYPE=Release`). + +- libc: Replaced `memset()` with a much faster optimized implementation that + makes use of Duff's device. Added `GetHeapUsage()` and `TrackHeapUsage()`. + Removed `_mem_init()`. + +- psxetc: Fixed a critical bug in `DMACallback()` that would lead to the DMA + interrupt handler being disabled entirely in some edge cases. + +- psxgpu: Replaced the debug font with an improved one. No changes have been + made to the API. + +- psxcd: Added `CdGetSector2()` (asynchronous variant of `CdGetSector()`). + `CdControl()` can now take a `CdlLOC` as second argument when issuing a seek + command (previously the argument was ignored if the command was not `ReadN` + or `ReadS`). + +- Replaced the `DEBUG` macro with the standard C `NDEBUG` macro, which is only + defined if the project is being built in release mode. + +- Added `PSN00BSDK_*_LINK_LIBRARIES` CMake variables to control which SDK + libraries are linked to newly created executables and DLLs. Updated + `cmake_reference.md` to reflect the changes. + ## 2022-09-22 spicyjpeg: diff --git a/CMakePresets.json b/CMakePresets.json index 89002a3..eca1478 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,8 +1,8 @@ { - "version": 2, + "version": 3, "cmakeMinimumRequired": { "major": 3, - "minor": 20, + "minor": 21, "patch": 0 }, "configurePresets": [ diff --git a/README.md b/README.md index e4a2d15..07ad738 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ and performance reasons. ## Notable features -As of March 28, 2022 +As of October 11, 2022: * Extensive GPU support with lines, flat shaded or textured polygon and sprite primitives, high-speed DMA for VRAM transfers and ordering tables. All video @@ -54,26 +54,24 @@ As of March 28, 2022 HLE BIOS implementations and loader/menu type homebrew programs. * BIOS controller functions for polling controller input work as intended - thanks to proper handling of hardware interrupts. No crude direct I/O polling - of controllers in the main loop. - -* Complete Serial I/O support with SIOCONS driver for tty stdin/stdout - console access. Hardware flow control supported. - -* Full CD-ROM support using libpsxcd featuring data read, CD audio and XA audio - playback, built-in ISO9660 file system parser with no file count limit - (classic ISO9660 only, no Rock Ridge or Joliet extensions) and multi-session. - -* Preliminary MDEC support implemented with libpsxpress (no VLC decoding yet). - Sample encoder included. - -* Can target Konami System 573 arcade hardware with limited support - (see examples/io/system573/main.c for details) - -* Experimental support for compiling separate sections of an executable into - shared library files (DLLs) and linking them dynamically at runtime, plus - support for function and variable introspection by loading a map file - generated at build time. + thanks to proper handling of hardware interrupts. Optional limited support + for manual polling. + +* Complete Serial I/O support and console driver to redirect standard input and + output to the serial port. Hardware flow control supported. + +* Full CD-ROM support using `libpsxcd` featuring data reading, CD-DA and XA + audio playback, a built-in ISO9660 file system parser with no file count + limit and support for multi-session discs. + +* MDEC support, lossy image decompression and video playback using + `libpsxpress` (currently only bitstream versions 1 and 2 are supported). + +* Preliminary limited support for Konami System 573 arcade hardware. + +* Experimental support for dynamic linking at runtime, with support for + function and variable introspection by loading a map file generated at build + time. * Uses Sony SDK library syntax for familiarity to experienced programmers and makes porting existing homebrew projects to PSn00bSDK easier. @@ -113,21 +111,21 @@ apply to PSn00bSDK. ## To-do List -* psxspu: Plenty of work to be done. Hardware timer driven sound/music - system may need to be implemented (an equivalent to the Ss* series of - functions in libspu basically). Functions that make use of the SPU RAM - interrupt feature to play or capture streamed audio should also be added. +* `libpsxspu`: Plenty of work to be done. Some kind of MIDI sequencer (similar + to the one present in the official SDK) should be added at some point, along + with a proper API for audio streaming. -* psxcd: Implement a command queue mechanism for the CD-ROM? +* `libpsxcd`: Implement a command queue mechanism for the CD-ROM. -* libc: Improve the memory allocation framework with multiple allocators, GC - and maybe helpers to manage swapping between main RAM and VRAM/SPU RAM. +* `libpsxpress`: Add support for version 3 and IKI frame bitstreams. -* Further support for MDEC, and tooling to transcode videos to .STR files - (either reimplementing the container and compression format used by the Sony - SDK, or a custom format with better compression). +* `libc`: Improve the memory allocation framework with multiple allocators, + replace the string functions with optimized implementations and maybe add + helpers to manage swapping between main RAM and VRAM/SPU RAM. -* Pad and memory card libraries that don't use the BIOS routines. +* Add a full controller and memory card API that does not depend on the BIOS + controller driver, and possibly a library for interfacing to IDE/ATAPI drives + to make development for arcade systems easier. ## Credits @@ -138,8 +136,8 @@ Main developer/author/whatever: Contributors: -* **spicyjpeg**: dynamic linker, CMake scripts, some docs and examples - (`system/dynlink`, `sound/spustream`, `io/pads`, `io/system573`). +* **spicyjpeg**: dynamic linker, `libpsxpress`, CMake scripts, some docs and + examples. * **Silent**, **G4Vi**, **Chromaryu**: `mkpsxiso` and `dumpsxiso` (maintained as a [separate repo](https://github.com/Lameguy64/mkpsxiso)). diff --git a/cpack/setup.cmake b/cpack/setup.cmake index eaf16f2..d585641 100644 --- a/cpack/setup.cmake +++ b/cpack/setup.cmake @@ -128,11 +128,11 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY PSn00bSDK) ## DEB/RPM variables -set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.28), cmake (>= 3.20)") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.28), cmake (>= 3.21)") set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "ninja-build (>= 1.10)") set(CPACK_DEBIAN_PACKAGE_SUGGESTS "git (>= 2.25)") set(CPACK_DEBIAN_PACKAGE_SECTION devel) -set(CPACK_RPM_PACKAGE_REQUIRES "cmake >= 3.20") +set(CPACK_RPM_PACKAGE_REQUIRES "cmake >= 3.21") set(CPACK_RPM_PACKAGE_SUGGESTS "ninja-build >= 1.10, git >= 2.25") #set(CPACK_RPM_PACKAGE_RELOCATABLE ON) diff --git a/doc/cmake_reference.md b/doc/cmake_reference.md index 25a89ec..bceaac9 100644 --- a/doc/cmake_reference.md +++ b/doc/cmake_reference.md @@ -1,6 +1,15 @@ # PSn00bSDK CMake reference +- [Setup](#setup) +- [Targets](#targets) +- [Commands](#commands) +- [Target properties](#target-properties) +- [Preprocessor definitions](#preprocessor-definitions) +- [Cached settings](#cached-settings) +- [Internal settings](#internal-settings) +- [Read-only variables](#read-only-variables) + ## Setup The only requirement to use the SDK in CMake is to set the @@ -10,32 +19,35 @@ This can be done on the command line (`-DCMAKE_TOOLCHAIN_FILE=...`), in `CMakeLists.txt` (`set(CMAKE_TOOLCHAIN_FILE ...)` before `project()`) or using [presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html). -It's suggested to have a default preset that sets `CMAKE_TOOLCHAIN_FILE` to +It's suggested to have a default preset that sets the toolchain file to `$env{PSN00BSDK_LIBS}/cmake/sdk.cmake`, taking advantage of the `PSN00BSDK_LIBS` environment variable (used by former PSn00bSDK versions) to -automatically find the SDK. Such a preset can be created by placing a +automatically find the SDK if set. Such a preset can be created by placing a `CMakePresets.json` file in the project's root with the following contents: ```json { - "version": 2, + "version": 3, "cmakeMinimumRequired": { "major": 3, - "minor": 20, + "minor": 21, "patch": 0 }, "configurePresets": [ { - "name": "default", - "displayName": "Default configuration", - "description": "Use this preset to build the project using PSn00bSDK.", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build", + "name": "default", + "displayName": "Default configuration", + "description": "Use this preset to build the project using PSn00bSDK.", + "generator": "Ninja", + "toolchainFile": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake", + "binaryDir": "${sourceDir}/build", "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_TOOLCHAIN_FILE": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake", - "PSN00BSDK_TC": "", - "PSN00BSDK_TARGET": "mipsel-none-elf" + "CMAKE_BUILD_TYPE": "Debug", + "PSN00BSDK_TC": "", + "PSN00BSDK_TARGET": "mipsel-none-elf" + }, + "warnings": { + "dev": false } } ] @@ -43,230 +55,345 @@ automatically find the SDK. Such a preset can be created by placing a ``` To avoid having to pass variables to CMake each time the project is built, a -second presets file named `CMakeUserPresets.json` can be created and populated -with hardcoded values in the `cacheVariables` section. This file can be kept -private (e.g. by adding it to `.gitignore`); CMake will automatically load -presets from it instead of `CMakePresets.json` if it exists. +second file named `CMakeUserPresets.json` can be created and populated with +hardcoded values in the `cacheVariables` section. This file can be kept private +(e.g. by adding it to `.gitignore`), and CMake will automatically load presets +from it instead of `CMakePresets.json` if it exists. See the [template](../template/CMakeLists.txt) for an example CMake script showing how to build a simple project. ## Targets -These targets are defined when using PSn00bSDK. There is no need to explicitly -link against any of these, as the helper commands (see below) handle linking -behind the scenes. To avoid conflicts, however, no target should be given any -of these names. - -- `c`, `psxgpu`, `psxgte`, `psxspu`, `psxcd`, `psxsio`, `psxetc`, `psxapi`, `lzp` -- `psn00bsdk_common`, `psn00bsdk_object_lib` -- `psn00bsdk_static_exe` -- `psn00bsdk_dynamic_exe` -- `psn00bsdk_static_lib` -- `psn00bsdk_shared_lib`, `psn00bsdk_module_lib` +The toolchain script creates a target for each PSn00bSDK library. Currently +the following targets are defined: + +- `psxgpu` +- `psxgte` +- `psxspu` +- `psxcd` +- `psxpress` +- `psxsio` +- `psxetc` +- `psxapi` +- `lzp` +- `c` + +Note that these are not actual libraries but virtual targets that link to the +appropriate version of the respective library, depending on the value of the +`PSN00BSDK_TARGET_TYPE` property; refer to the target properties section for +more information. Linking manually using the `target_link_libraries()` command +is usually not necessary for executables as they are linked to all libraries +by default (see `PSN00BSDK_EXECUTABLE_LINK_LIBRARIES`). + +Additionally, two "hidden" libraries named `gcc` and `psn00bsdk` are linked by +default to all targets. The former is the GCC toolchain's `libgcc` (see +`PSN00BSDK_LIBGCC`) while the latter is a virtual target used to set compiler +flags and paths. ## Commands -- `psn00bsdk_add_executable( [EXCLUDE_FROM_ALL] [sources...])` +### `psn00bsdk_add_executable` - A wrapper around `add_executable()` to create PS1 executables. Three files - will be generated for each call to this function: +```cmake +psn00bsdk_add_executable( + + [EXCLUDE_FROM_ALL] + [sources...] +) +``` - - `.elf` (regular ELF executable) - - `.exe` (executable converted to the format expected by the PS1) - - `.map` (symbol map file for dynamic linking/introspection) +A wrapper around `add_executable()` to create PS1 executables. Three files will +be generated for each call to this function: - The `.exe` and `.map` extensions can be customized by overriding - `PSN00BSDK_EXECUTABLE_SUFFIX` and `PSN00BSDK_SYMBOL_MAP_SUFFIX` prior to - creating the executable. +- `.elf` (regular ELF executable) +- `.exe` (executable converted to the format expected by the PS1) +- `.map` (symbol map file for dynamic linking/introspection) - The second argument (mandatory) specifies whether the executable is going to - load DLLs at runtime. If set to `STATIC`, $gp-relative addressing (i.e. - reusing the $gp register normally used for DLL addressing) will be enabled, - slightly reducing executable size and RAM usage but breaking compatibility - with the dynamic linker. +The `.exe` and `.map` extensions can be customized by overriding +`PSN00BSDK_EXECUTABLE_SUFFIX` and `PSN00BSDK_SYMBOL_MAP_SUFFIX` prior to +creating the executable. -- `psn00bsdk_add_library( [EXCLUDE_FROM_ALL] [sources...])` +The second argument (mandatory) specifies whether the executable is going to +load DLLs at runtime. If set to `GPREL` or `STATIC`, $gp-relative addressing +(i.e. reusing the $gp register normally used for DLL addressing to reference +global variables) will be enabled, slightly reducing executable size and RAM +usage but breaking compatibility with the dynamic linker. - Wraps `add_library()` to create static libraries or dynamically-linked - libraries (DLLs). +All executables are automatically linked to the libraries listed in +`PSN00BSDK_EXECUTABLE_LINK_LIBRARIES` (all SDK libraries by default). This +variable can be modified prior to creating the executable to select which +libraries to link. - The second argument (mandatory, unlike `add_library()`) specifies the type of - library to create. `STATIC` will create a static library named `lib.a`. - `SHARED` and `MODULE` will compile a DLL, producing the following files (note - that there is no `lib` prefix for DLLs): +### `psn00bsdk_add_library` - - `.so` (regular ELF shared library) - - `.dll` (raw binary with some ELF headers prepended) +```cmake +psn00bsdk_add_library( + + [EXCLUDE_FROM_ALL] + [sources...] +) +``` - As with executables, the `.dll` extension can be customized by setting - `PSN00BSDK_SHARED_LIBRARY_SUFFIX`. +Wraps `add_library()` to create static libraries or dynamically-linked +libraries (DLLs). -- `psn00bsdk_add_cd_image( [DEPENDS ...] [...])` +The second argument (mandatory, unlike CMake's regular `add_library()`) +specifies the type of library to create. `STATIC` will create a static library +named `lib.a`. `SHARED` and `MODULE` will compile a DLL, producing +the following files (there is no `lib` prefix for DLLs): - Creates a new target that will build a CD image using `mkpsxiso`. +- `.so` (regular ELF shared library) +- `.dll` (raw binary with some ELF headers prepended) - The first argument is the name of the target to create; next up is the name - of the generated image file (`.bin` + `.cue`). The - third argument is the path to the XML file (relative to the source directory) - passed to `mkpsxiso`. +The `.dll` extension can be customized by setting +`PSN00BSDK_SHARED_LIBRARY_SUFFIX` prior to creating the DLL. - The XML file is "configured" by CMake, i.e. any `${var}` or `@var@` - expressions are replaced with the values of the respective variables. In - particular `${CD_IMAGE_NAME}` is replaced with the second argument passed to - `psn00bsdk_add_cd_image()`; the file must properly set the output file names - like this: +All DLLs are automatically linked to the libraries listed in +`PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES` (none by default). This variable can +be modified prior to creating the DLL to select which libraries to link. - ```xml - - - ``` +**IMPORTANT**: when adding a static library using this command (or CMake's +`add_library()`), the `PSN00BSDK_TARGET_TYPE` property **must** be set on it +afterwards in order to let CMake know whether the static library is going to be +linked to an executable or a DLL. See `PSN00BSDK_TARGET_TYPE` for more +information. - Any additional argument is passed through to the underlying call to - `add_custom_target()`, so most of the options supported by - `add_custom_target()` (including `DEPENDS`) are also supported here. +### `psn00bsdk_add_cd_image` -- `psn00bsdk_target_incbin( )` +```cmake +psn00bsdk_add_cd_image( + + + + [DEPENDS ] + [other options...] +) +``` - Embeds the contents of a binary file into an executable or a library. +Creates a new virtual target that will build a CD image using `mkpsxiso`. The +CD image will always be considered out-of-date and built, even if none of its +dependencies or any other files have been modified. + +The first argument is the name of the target to create; next up is the name of +the generated image file (`.bin` + `.cue`). The third +argument is the path to the XML file (relative to the source directory) passed +to `mkpsxiso`. + +The XML file is "configured" by CMake, i.e. any `${var}` or `@var@` expressions +are replaced with the values of the respective variables. In particular +`${CD_IMAGE_NAME}` is replaced with the second argument passed to +`psn00bsdk_add_cd_image()`; the file must properly set the output file names +like this: + +```xml + + + + +``` - A new symbol/object will be created with the given name, escaped by replacing - non-alphanumeric characters with underscores. The contents of the file will - be aligned to 4 bytes and placed in the `.data` section. An unsigned 32-bit - integer named `_size` will also be defined and set to the length - of the file in bytes (without taking alignment/padding into account). +Any additional argument is passed through to the underlying call to +`add_custom_target()`, so most of the options supported by +`add_custom_target()` (including `DEPENDS`) are also supported here. - Once added the file and its size can be accessed by C/C++ code by declaring - the respective symbols as an extern array and as an integer, like this: +### `psn00bsdk_target_incbin` - ```c - extern const uint8_t my_file[]; - extern const size_t my_file_size; - ``` +```cmake +psn00bsdk_target_incbin( + + + +) +``` - The fourth argument specifies the path to the binary file relative to the - source directory. This path can be prepended with `${PROJECT_BINARY_DIR}/` to - reference a file generated by the build script (such as an LZP archive): in - that case a file-level dependency will also be created, ensuring CMake does - not attempt to compile the executable or library before the file is built. +Embeds the contents of a binary file into an executable or a library. - **IMPORTANT**: in order for this command to work, assembly language support - must be enabled by specifying `LANGUAGES C ASM` (or `LANGUAGES C CXX ASM` if - C++ is also used) when invoking `project()`. +A new symbol/object will be created with the given name, escaped by replacing +non-alphanumeric characters with underscores. The contents of the file will be +aligned to 4 bytes and placed in the `.data` section. An unsigned 32-bit +integer named `_size` will also be defined and set to the length +of the file in bytes (without taking alignment/padding into account). -- `psn00bsdk_target_incbin_a( )` +Once added the file and its size can be accessed by C/C++ code by declaring the +respective symbols as an extern array and as an integer, like this: - Advanced variant of `psn00bsdk_target_incbin()` that allows specifying a - custom name for the size symbol and changing the default alignment setting. - Note that the size integer is always aligned to a multiple of 4 bytes as the - MIPS architecture doesn't support unaligned reads. +```c +extern const uint8_t my_file[]; +extern const size_t my_file_size; +``` -## Definitions +The fourth argument specifies the path to the binary file relative to the +source directory. This path can be prepended with `${PROJECT_BINARY_DIR}/` to +reference a file generated by the build script (such as an LZP archive): in +that case a file-level dependency will also be created, ensuring CMake does not +attempt to compile the executable or library before the file is built. + +**IMPORTANT**: in order for this command to work, assembly language support +must be enabled by specifying `LANGUAGES C ASM` (or `LANGUAGES C CXX ASM` to +enable C++ support as well) when invoking `project()`. + +### `psn00bsdk_target_incbin_a` + +```cmake +psn00bsdk_target_incbin_a( + + + + +
+ +) +``` -When compiling executables and libraries using the above commands the following -preprocessor macros are automatically `#define`'d: +Advanced variant of `psn00bsdk_target_incbin()` that allows specifying a custom +name for the size symbol and changing the default alignment setting. The value +of the size integer is always rounded up to a multiple of 4 bytes. -- `PLAYSTATION` +See `psn00bsdk_target_incbin()` above for more details. - Always set to 1. Can be used to implement different options or code paths for - libraries, so they can target both the host and PS1 (as it won't be defined - when compiling outside of the SDK). +## Target properties -- `DEBUG` +Each of the following properties can be set individually for each executable or +library using CMake's `set_property()` and `set_target_properties()` commands. - Defined and set to 1 in a debug configuration, i.e. when the - `CMAKE_BUILD_TYPE` variable is set to `Debug`. This value is used by the - PSn00bSDK libraries, and should be used in executables, to enable additional - debug logging. +### `PSN00BSDK_TARGET_TYPE` - Note that the default CMake configuration is usually debug, so it's - recommended to specify `-DCMAKE_BUILD_TYPE=Release` to get rid of the logging - overhead in release builds and reduce executable size. +Determines which SDK libraries are linked to and which compiler flags are added +to the target. Must be set to `EXECUTABLE_GPREL`, `EXECUTABLE_NOGPREL` or +`SHARED_LIBRARY`. -## Cached settings +This property is initialized automatically on executables and DLLs created via +`psn00bsdk_add_executable()` or `psn00bsdk_add_library()`, but *not* on static +libraries as CMake has no way to know about their intended usage (i.e. whether +they are going to be linked to an executable with or without $gp-relative +addressing, or to a DLL). Thus, `PSN00BSDK_TARGET_TYPE` must be set manually on +all static libraries and must match the value set on any executable or DLL the +static library is going to be linked to. + +There is no way to build a "hybrid" static library that can be linked to +multiple target types, short of building multiple copies of it. A workaround +(used internally by PSn00bSDK) is to create a virtual target and use CMake +generator expressions to link to one of the copies depending on the value of +`PSN00BSDK_TARGET_TYPE`. -These variables are stored in CMake's cache and can be edited by the project's -build script, from the CMake command line when configuring the project -(`-Dname=value`) or using an editor such as the CMake GUI. +## Preprocessor definitions -- `PSN00BSDK_TARGET` (`STRING`) +When compiling executables and libraries using the commands listed above the +following C/C++ preprocessor macros are automatically `#define`d: - The GCC toolchain's target triplet. PSn00bSDK assumes the toolchain targets - `mipsel-none-elf` by default, however this can be changed to e.g. use a MIPS - toolchain that was compiled for a slightly-different-but-equivalent target. +### `PSN00BSDK` - The following GCC target triplets have been confirmed to work with PSn00bSDK: +Always set to 1. Can be used to implement different options or code paths for +projects that target both PSn00bSDK and other platforms. - - `mipsel-none-elf` - - `mipsel-unknown-elf` - - ~~`mipsel-linux-gnu`~~ (has issues with linking) +### `NDEBUG` -- `PSN00BSDK_TC` (`PATH`) +Defined and set to 1 in a release configuration, i.e. when `CMAKE_BUILD_TYPE` +is set to `Release` or when a multi-configuration generator is building the +project in release mode; not defined if the project is being built in debug +mode. This value is used by the PSn00bSDK libraries, and should be used in +projects, to enable assertions and additional debug logging (the `assert()` +macro already resolves to a no-op in release mode). - Path to the GCC toolchain's installation prefix/directory. If not set, CMake - will attempt to find the toolchain in the `PATH` environment variable and - store its path in the project's variable cache (so the search does not have - to be repeated). It is recommended to add the toolchain's `bin` subfolder to - `PATH` rather than setting this variable. +Note that the default CMake configuration is usually debug. It is recommended +to build a project in release mode whenever appropriate (by specifying +`-DCMAKE_BUILD_TYPE=Release` or using the Ninja multi-configuration generator) +to get rid of logging overhead. - **IMPORTANT**: if the toolchain's target is not `mipsel-none-elf`, - `PSN00BSDK_TARGET` must be set regardless of whether or not `PSN00BSDK_TC` is - also set. +## Cached settings + +These variables are stored in CMake's cache and are meant to be set by the end +user when building the project (rather than by the project itself). They can be +modified by the build script after invoking `project()`, from the CMake command +line when configuring (`-Dname=value`) or using an IDE or other editor such as +the CMake GUI. + +### `PSN00BSDK_TARGET` (`STRING`) + +The GCC toolchain's target triplet. PSn00bSDK assumes the toolchain targets +`mipsel-none-elf` by default, however this can be changed to e.g. use a MIPS +toolchain that was compiled for `mipsel-unknown-elf` (as used by previous +versions of PSn00bSDK). + +Toolchains that target `mipsel-linux-gnu` are not supported by PSn00bSDK. + +### `PSN00BSDK_TC` (`PATH`) -- `PSN00BSDK_LIBGCC` (`FILEPATH`) +Path to the GCC toolchain's installation prefix/directory. If not set, CMake +will attempt to find the toolchain in the `PATH` environment variable and store +its path in the project's variable cache (so the search does not have to be +repeated). It is recommended to add the toolchain's `bin` subfolder to `PATH` +rather than setting this variable. - Path to the `libgcc.a` library bundled with the GCC toolchain. The contents - of this library are merged into `libc` when building the SDK, so this - variable is only actually needed when compiling `libpsn00b`. Setting this - variable manually usually isn't necessary as CMake will locate `libgcc.a` - automatically after finding the toolchain. +**IMPORTANT**: if the toolchain's target triplet is not `mipsel-none-elf`, +`PSN00BSDK_TARGET` must be set regardless of whether or not `PSN00BSDK_TC` is +also set. + +### `PSN00BSDK_LIBGCC` (`FILEPATH`) + +Path to the `libgcc` library bundled with the GCC toolchain. As required by GCC +this library is always linked to all targets, regardless of whether any SDK +libraries are linked or not. CMake will attempt to locate `libgcc` +automatically after finding the toolchain, so setting this variable manually is +not required in most cases. ## Internal settings These settings are not stored in CMake's cache and can only be set from within -the build script. +the build script after invoking `project()`. + +### `PSN00BSDK_EXECUTABLE_LINK_LIBRARIES`, `PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES` (list of `STRING`) -- `PSN00BSDK_LIBRARIES` +Lists of SDK libraries to be linked automatically to all new executables and +DLLs, respectively. By default `PSN00BSDK_EXECUTABLE_LINK_LIBRARIES` includes +all libraries that ship with PSn00bSDK while +`PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES` is empty. - List of libraries to link all created targets against. By default this - includes all PSn00bSDK libraries. +These variables can be modified before invoking `psn00bsdk_add_executable()` or +`psn00bsdk_add_library()` to only link a subset of the SDK. Static libraries +are *not* automatically linked to any SDK libraries. -- `PSN00BSDK_EXECUTABLE_SUFFIX`, `PSN00BSDK_SHARED_LIBRARY_SUFFIX`, - `PSN00BSDK_SYMBOL_MAP_SUFFIX` +### `PSN00BSDK_EXECUTABLE_SUFFIX`, `PSN00BSDK_SHARED_LIBRARY_SUFFIX`, `PSN00BSDK_SYMBOL_MAP_SUFFIX` (`STRING`) - File extensions to use for generated PS1 files. The default values are - `.exe`, `.dll` and `.map` respectively. Note that file names and extensions - can be changed anyway when building a CD image. +File extensions to use for generated PS1 files. The default values are `.exe`, +`.dll` and `.map` respectively. These extensions do not have to match the ones +used in the CD image (if any). ## Read-only variables -- `PSN00BSDK_VERSION`, `PSN00BSDK_BUILD_DATE`, `PSN00BSDK_GIT_TAG`, - `PSN00BSDK_GIT_COMMIT` +### `PSN00BSDK_VERSION`, `PSN00BSDK_BUILD_DATE`, `PSN00BSDK_GIT_TAG`, `PSN00BSDK_GIT_COMMIT` (`STRING`) + +These variables are loaded from `lib/libpsn00b/build.json` and contain +information about the SDK's version. `PSN00BSDK_GIT_TAG` and +`PSN00BSDK_GIT_COMMIT` might be empty strings as they are only populated in CI +builds of PSn00bSDK. + +### `PSN00BSDK_LIBRARIES` (list of `STRING`) - These variables are loaded from `lib/libpsn00b/build.json` and contain - information about the SDK's version. Note that `PSN00BSDK_GIT_TAG` and - `PSN00BSDK_GIT_COMMIT` are not populated by default when building PSn00bSDK - manually from source, so they might be empty strings. +List of all libraries that ship with PSn00bSDK, excluding `libgcc`. Each +library in this list is also defined as a target. See the targets section for +more details. -- `PSN00BSDK_TOOLS`, `PSN00BSDK_INCLUDE`, `PSN00BSDK_LDSCRIPTS` +### `PSN00BSDK_TOOLS`, `PSN00BSDK_INCLUDE`, `PSN00BSDK_LDSCRIPTS` (list of `PATH`) - Lists of paths used internally. Should not be set, manipulated or overridden - by scripts. +Lists of paths used internally. Should not be set, manipulated or overridden by +scripts. -- `TOOLCHAIN_NM` +### `TOOLCHAIN_NM` (`FILEPATH`) - Path to the `nm` executable used to generate symbol maps. Although not used - internally by CMake, this program is part of the GCC toolchain. +Path to the `nm` executable used to generate symbol maps. Although not used +internally by CMake, this program is part of the GCC toolchain. -- `ELF2X`, `ELF2CPE`, `MKPSXISO`, `LZPACK`, `SMXLINK` +### `ELF2X`, `ELF2CPE`, `MKPSXISO`, `LZPACK`, `SMXLINK` (`FILEPATH`) - Paths to the PSn00bSDK tools' executables. As no functions are currently - provided for building assets, `LZPACK` and `SMXLINK` can be used with - `add_custom_command()`/`add_custom_target()` to convert models and generate - LZP archives as part of the build pipeline. +Paths to the PSn00bSDK tools' executables. As no functions are currently +provided for building assets, `LZPACK` and `SMXLINK` can be used manually with +CMake's `add_custom_command()` and `add_custom_target()` to convert models and +generate LZP archives as part of the build pipeline. ----------------------------------------- -_Last updated on 2022-02-26 by spicyjpeg_ +_Last updated on 2022-10-11 by spicyjpeg_ diff --git a/doc/installation.md b/doc/installation.md index 382c721..70b7f3e 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -5,7 +5,7 @@ 1. Install prerequisites. Currently CMake is the only external dependency; you can install it from [here](https://cmake.org/download) or using MSys2 or - your distro's package manager. Make sure you have at least CMake 3.20. + your distro's package manager. Make sure you have at least CMake 3.21. 2. Head over to the releases page, download the latest release's ZIP for your operating system and extract its contents to a directory of your choice, @@ -44,7 +44,7 @@ being built without support for ripping CD audio tracks to FLAC, however the - `git` - `build-essential`, `base-devel` or similar - `make` or `ninja-build` - - `cmake` (3.20+ is required, download it from + - `cmake` (3.21 or later is required, download it from [here](https://cmake.org/download) if your package manager only provides older versions) @@ -185,4 +185,4 @@ The toolchain script defines a few CMake macros to create PS1 executables, DLLs and CD images. See the [reference](cmake_reference.md) for details. ----------------------------------------- -_Last updated on 2022-09-21 by spicyjpeg_ +_Last updated on 2022-10-11 by spicyjpeg_ diff --git a/doc/known_bugs.md b/doc/known_bugs.md index 3fbfdc2..9e4785c 100644 --- a/doc/known_bugs.md +++ b/doc/known_bugs.md @@ -7,14 +7,15 @@ fixed. ## Toolchain -- It is currently not possible to link static libraries (including the SDK - libraries themselves) with DLLs, since the build scripts currently assume that - static library object files are always going to be linked into executables. - This can be worked around by linking all static libraries as part of the main - executable rather than the DLLs: the dynamic linker will automatically search - the executable for undefined symbols used by a DLL and patch the code to use - them. It might be necessary to list such symbols in a dummy array to prevent - the compiler from stripping them away from the executable. +- ~~It is currently not possible to link static libraries (including the SDK~~ + ~~libraries themselves) with DLLs, since the build scripts currently assume~~ + ~~that static library object files are always going to be linked into~~ + ~~executables. This can be worked around by linking all static libraries as~~ + ~~part of the main executable rather than the DLLs: the dynamic linker will~~ + ~~automatically search the executable for undefined symbols used by a DLL~~ + ~~and patch the code to use them.~~ Static libraries are now fully supported, + and SDK libraries can be linked to both executables and DLLs. See the CMake + reference for more details. - Link-time optimization is broken due to GCC not supporting it when linking weak functions written in assembly. @@ -28,7 +29,7 @@ fixed. the length of the data *must* be a multiple of 32 bytes. Attempting to transfer any data whose length isn't a multiple of 32 bytes will result in `DrawSync()` hanging and never returning, however a warning will be printed - on the debug console. + on the debug console if the executable is built in debug mode. `psxspu`: @@ -36,6 +37,11 @@ fixed. due to the SPU status register being emulated incorrectly. They work as expected on other emulators as well as on real hardware. +`psxcd`: + +- Custom callbacks registered using `CdReadyCallback()` seem to be unstable on + DuckStation (and possibly on real hardware), occasionally dropping sectors. + `psxetc`: - `DL_LoadSymbolMapFromFile()`, `DL_LoadDLLFromFile()` and `dlopen()` have been @@ -48,4 +54,4 @@ fixed. See [README.md in the examples directory](../examples/README.md#examples-summary). ----------------------------------------- -_Last updated on 2022-08-21 by spicyjpeg_ +_Last updated on 2022-10-11 by spicyjpeg_ diff --git a/examples/README.md b/examples/README.md index 82d7698..b63b2a9 100644 --- a/examples/README.md +++ b/examples/README.md @@ -48,7 +48,7 @@ Notes: ## Building the examples -The instructions below assume that PSn00bSDK, CMake 3.20+ and a GCC toolchain +The instructions below assume that PSn00bSDK, CMake 3.21+ and a GCC toolchain are already installed. Refer to the [installation guide](../doc/installation.md) for details. @@ -84,4 +84,4 @@ are for rebuilding the examples *after* the SDK has been installed. CD images for each example. ----------------------------------------- -_Last updated on 2022-08-11 by spicyjpeg_ +_Last updated on 2022-10-11 by spicyjpeg_ diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index 6fecb9f..e78355f 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -173,7 +173,6 @@ function(psn00bsdk_add_executable name type) #$<${_repl},${PSN00BSDK_SYMBOL_MAP_SUFFIX}> ${CMAKE_CURRENT_BINARY_DIR}/${name}${PSN00BSDK_EXECUTABLE_SUFFIX} ${CMAKE_CURRENT_BINARY_DIR}/${name}${PSN00BSDK_SYMBOL_MAP_SUFFIX} - VERBATIM ) endfunction() @@ -201,7 +200,6 @@ function(psn00bsdk_add_library name type) $ #BYPRODUCTS $<${_repl},${PSN00BSDK_SHARED_LIBRARY_SUFFIX}> BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${name}${PSN00BSDK_SHARED_LIBRARY_SUFFIX} - VERBATIM ) else() message(FATAL_ERROR "Invalid library type: ${type} (must be STATIC, OBJECT, SHARED or MODULE)") diff --git a/template/CMakePresets.json b/template/CMakePresets.json index d08b334..97d8428 100644 --- a/template/CMakePresets.json +++ b/template/CMakePresets.json @@ -1,22 +1,25 @@ { - "version": 2, + "version": 3, "cmakeMinimumRequired": { "major": 3, - "minor": 20, + "minor": 21, "patch": 0 }, "configurePresets": [ { - "name": "default", - "displayName": "Default configuration", - "description": "Use this preset to build the project using PSn00bSDK.", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build", + "name": "default", + "displayName": "Default configuration", + "description": "Use this preset to build the project using PSn00bSDK.", + "generator": "Ninja", + "toolchainFile": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake", + "binaryDir": "${sourceDir}/build", "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_TOOLCHAIN_FILE": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake", - "PSN00BSDK_TC": "", - "PSN00BSDK_TARGET": "mipsel-none-elf" + "CMAKE_BUILD_TYPE": "Debug", + "PSN00BSDK_TC": "", + "PSN00BSDK_TARGET": "mipsel-none-elf" + }, + "warnings": { + "dev": false } } ] -- cgit v1.2.3