From af86b6445d5c19b6bdc7f300999d0cbc29787f61 Mon Sep 17 00:00:00 2001 From: Wouter Wijsman Date: Thu, 31 Oct 2024 08:56:55 +0100 Subject: [PATCH] Use function with easier input for generating PRX module files --- src/base/AddPrxModule.cmake | 55 +++++++++++++++++++++++++++++++++++ src/base/CreatePRX.cmake | 57 ------------------------------------- src/base/Makefile.am | 2 +- src/base/pspdev.cmake | 2 +- 4 files changed, 57 insertions(+), 59 deletions(-) create mode 100644 src/base/AddPrxModule.cmake delete mode 100644 src/base/CreatePRX.cmake diff --git a/src/base/AddPrxModule.cmake b/src/base/AddPrxModule.cmake new file mode 100644 index 0000000000..46666ef5c0 --- /dev/null +++ b/src/base/AddPrxModule.cmake @@ -0,0 +1,55 @@ +# File defining macro outputting PSP-specific PRX module out of passed executable target. +cmake_minimum_required(VERSION 3.10) + +function(add_prx_module name) + # Initialize list for existing and generated source files + set(SRC_FILES) + + # Loop over each source file + foreach(FILE ${ARGN}) + # Get the extension of the file + get_filename_component(FILE_EXTENSION ${FILE} EXT) + + # Generate a .c file from .exp files + if (${FILE_EXTENSION} EQUAL ".exp") + # Get the filename without extension + get_filename_component(EXP_FILE_NAME ${FILE} NAME_WE) + + # Define the output .c file path + set(GENERATED_C_FILE ${CMAKE_BINARY_DIR}/${EXP_FILE_NAME}.c) + + # Add a custom command for each .exp file to generate a .c file + add_custom_command( + OUTPUT ${GENERATED_C_FILE} + COMMAND psp-build-exports -b ${EXP_FILE} > ${GENERATED_C_FILE} + DEPENDS ${EXP_FILE} + COMMENT "Generating ${EXP_FILE_NAME}.c from ${EXP_FILE_NAME}.exp" + ) + + # Add the generated .c file to the list + list(APPEND SRC_FILES ${GENERATED_C_FILE}) + else() + # Simply add other files to the list + list(APPEND SRC_FILES ${FILE}) + endif() + endforeach() + + add_executable(${name} ${SRC_FILES}) + target_link_options(${name} PRIVATE -Wl,-q,-T${PSPDEV}/psp/sdk/lib/linkfile.prx -nostartfiles -Wl,-zmax-page-size=128) + + add_custom_command( + TARGET ${name} + POST_BUILD COMMAND + "$ENV{PSPDEV}/bin/psp-fixup-imports" "$" + COMMENT "Calling psp-fixup-imports" + ) + + # Generate the .prx module from executable target + add_custom_command( + TARGET ${name} + POST_BUILD COMMAND + "${PSPDEV}/bin/psp-prxgen" "$" + "$.prx" + COMMENT "Calling prxgen" + ) +endfunction() diff --git a/src/base/CreatePRX.cmake b/src/base/CreatePRX.cmake deleted file mode 100644 index 56119b21ea..0000000000 --- a/src/base/CreatePRX.cmake +++ /dev/null @@ -1,57 +0,0 @@ -# File defining macro outputting PSP-specific PRX module out of passed executable target. -cmake_minimum_required(VERSION 3.10) - -macro(add_prx_module) - - set(OPTIONS_ARGS) - set(ONE_VALUE_ARGS - TARGET # CMake target for the prx module that is being output - ) - set(MULTI_VALUE_ARGS - SRC_FILES # Source files for the module - EXP_FILES # Export files for the module - ) - - cmake_parse_arguments("ARG" "${OPTIONS_ARGS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN} ) - - # Initialize a list to store generated .c files - set(GENERATED_C_FILES) - - # Loop over each .exp file to set up a rule to generate a corresponding .c file - foreach(EXP_FILE ${ARG_EXP_FILES}) - # Get the filename without extension - get_filename_component(EXP_FILE_NAME ${EXP_FILE} NAME_WE) - - # Define the output .c file path - set(GENERATED_C_FILE ${CMAKE_BINARY_DIR}/${EXP_FILE_NAME}.c) - - # Add a custom command for each .exp file to generate a .c file - add_custom_command( - OUTPUT ${GENERATED_C_FILE} - COMMAND psp-build-exports -b ${EXP_FILE} > ${GENERATED_C_FILE} - DEPENDS ${EXP_FILE} - COMMENT "Generating ${EXP_FILE_NAME}.c from ${EXP_FILE_NAME}.exp" - ) - - # Add the generated .c file to the list - list(APPEND GENERATED_C_FILES ${GENERATED_C_FILE}) - endforeach() - - add_executable(${ARG_TARGET} ${ARG_SRC_FILES} ${GENERATED_C_FILES}) - target_link_options(${ARG_TARGET} PRIVATE -Wl,-q,-T${PSPDEV}/psp/sdk/lib/linkfile.prx -nostartfiles -Wl,-zmax-page-size=128) - - add_custom_command( - TARGET ${ARG_TARGET} - POST_BUILD COMMAND - "$ENV{PSPDEV}/bin/psp-fixup-imports" "$" - COMMENT "Calling psp-fixup-imports" - ) - - add_custom_command( - TARGET ${ARG_TARGET} - POST_BUILD COMMAND - "${PSPDEV}/bin/psp-prxgen" "$" - "$.prx" - COMMENT "Calling prxgen" - ) -endmacro(add_prx_module) diff --git a/src/base/Makefile.am b/src/base/Makefile.am index c55ec7b054..c3fe697504 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -16,6 +16,6 @@ buildmakprx_DATA = build_prx.mak linkfile.prx ## Install the cmake toolchain config to $PSPDEV/share buildmakcmakedir = @PSPDEV_SHAREDIR@ -buildmakcmake_DATA = pspdev.cmake CreatePBP.cmake CreatePRX.cmake +buildmakcmake_DATA = pspdev.cmake CreatePBP.cmake AddPrxModule.cmake EXTRA_DIST = build.mak prxspecs build_prx.mak linkfile.prx pspdev.cmake diff --git a/src/base/pspdev.cmake b/src/base/pspdev.cmake index 85b6021855..10659c742b 100644 --- a/src/base/pspdev.cmake +++ b/src/base/pspdev.cmake @@ -35,4 +35,4 @@ SET(PLATFORM_PSP TRUE) SET(PSP TRUE) include("${PSPDEV}/psp/share/CreatePBP.cmake") -include("${PSPDEV}/psp/share/CreatePRX.cmake") +include("${PSPDEV}/psp/share/AddPrxModule.cmake")