From e31d053a088d94712415d5aeee55f345bbf49cff Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Fri, 25 Nov 2022 10:56:59 +0100 Subject: [PATCH] fxsdk: handle parentheses in paths for fxgxa Quotes are still impossible because CMake is unredeemable in that regard. --- fxsdk/cmake/FxsdkUtils.cmake | 7 +++++++ fxsdk/cmake/GenerateG1A.cmake | 6 +++++- fxsdk/cmake/GenerateG3A.cmake | 12 ++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 fxsdk/cmake/FxsdkUtils.cmake diff --git a/fxsdk/cmake/FxsdkUtils.cmake b/fxsdk/cmake/FxsdkUtils.cmake new file mode 100644 index 0000000..10316d2 --- /dev/null +++ b/fxsdk/cmake/FxsdkUtils.cmake @@ -0,0 +1,7 @@ +# Who doesn't love to deal with escaping?! +function(shell_escape _str _out) + string(REPLACE "'" "\\'" _str "${_str}") + string(REPLACE "(" "\\(" _str "${_str}") + string(REPLACE ")" "\\)" _str "${_str}") + set("${_out}" "${_str}" PARENT_SCOPE) +endfunction() diff --git a/fxsdk/cmake/GenerateG1A.cmake b/fxsdk/cmake/GenerateG1A.cmake index dd0aa7a..073cce4 100644 --- a/fxsdk/cmake/GenerateG1A.cmake +++ b/fxsdk/cmake/GenerateG1A.cmake @@ -1,3 +1,5 @@ +include(FxsdkUtils) + function(generate_g1a) cmake_parse_arguments(G1A "" "TARGET;OUTPUT;NAME;INTERNAL;VERSION;DATE;ICON" "" ${ARGN}) @@ -16,6 +18,7 @@ function(generate_g1a) if(DEFINED G1A_OUTPUT) get_filename_component(G1A_OUTPUT "${G1A_OUTPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + shell_escape("${G1A_OUTPUT}" G1A_OUTPUT) else() set(G1A_OUTPUT "${G1A_TARGET}.g1a") endif() @@ -32,7 +35,8 @@ function(generate_g1a) if(DEFINED G1A_ICON) get_filename_component(G1A_ICON "${G1A_ICON}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - list(APPEND FXGXA_ARGS "-i" "${G1A_ICON}") + shell_escape("${G1A_ICON}" G1A_ICONB) + list(APPEND FXGXA_ARGS "-i" "${G1A_ICONB}") endif() if(DEFINED G1A_INTERNAL) diff --git a/fxsdk/cmake/GenerateG3A.cmake b/fxsdk/cmake/GenerateG3A.cmake index ddfd28d..9eb40ce 100644 --- a/fxsdk/cmake/GenerateG3A.cmake +++ b/fxsdk/cmake/GenerateG3A.cmake @@ -1,3 +1,5 @@ +include(FxsdkUtils) + function(generate_g3a) cmake_parse_arguments(G3A "" "TARGET;OUTPUT;NAME;VERSION" "ICONS" ${ARGN}) @@ -21,8 +23,7 @@ function(generate_g3a) if(DEFINED G3A_OUTPUT) get_filename_component(G3A_OUTPUT "${G3A_OUTPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - # Who doesn't love to deal with escaping - string(REPLACE "'" "\\'" G3A_OUTPUT "${G3A_OUTPUT}") + shell_escape("${G3A_OUTPUT}" G3A_OUTPUT) else() set(G3A_OUTPUT "${G3A_TARGET}.g3a") endif() @@ -52,9 +53,8 @@ function(generate_g3a) BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") get_filename_component(G3A_ICON2 "${G3A_ICON2}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - # Who doesn't REALLY love to deal with escaping - string(REPLACE "'" "\\'" G3A_ICON1B "${G3A_ICON1}") - string(REPLACE "'" "\\'" G3A_ICON2B "${G3A_ICON2}") + shell_escape("${G3A_ICON1}" G3A_ICON1B) + shell_escape("${G3A_ICON2}" G3A_ICON2B) list(APPEND FXGXA_ARGS "--icon-uns=${G3A_ICON1B}" "--icon-sel=${G3A_ICON2B}") endif() @@ -63,7 +63,7 @@ function(generate_g3a) add_custom_command( TARGET "${G3A_TARGET}" POST_BUILD COMMAND ${OBJCOPY} -O binary -R .bss -R .gint_bss ${G3A_TARGET} ${G3A_TARGET}.bin - COMMAND fxgxa --g3a ${FXGXA_ARGS} "${G3A_TARGET}.bin" -o "${G3A_OUTPUT}" + COMMAND fxgxa --g3a ${FXGXA_ARGS} ${G3A_TARGET}.bin -o ${G3A_OUTPUT} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) if(DEFINED G3A_ICONS)