fxsdk: compatibility with CMake 3.24

This commit is contained in:
Lephenixnoir 2022-08-29 00:34:55 +02:00
parent 92316b9f5a
commit 223cd31b6c
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 46 additions and 7 deletions

View File

@ -0,0 +1,18 @@
set(FXCONV_COMPILER_NAME $ENV{FXCONV_PATH})
if(NOT FXCONV_COMPILER_NAME)
set(FXCONV_COMPILER_NAME "fxconv")
endif()
find_program(FXCONV_COMPILER_PATH "${FXCONV_COMPILER_NAME}")
if(FXCONV_COMPILER_PATH STREQUAL "FXCONV_COMPILER_PATH-NOTFOUND")
message(FATAL_ERROR "'${FXCONV_COMPILER}' not found!")
endif()
set(CMAKE_FXCONV_COMPILER "${FXCONV_COMPILER_PATH}")
set(CMAKE_FXCONV_COMPILER_ENV_VAR "FXCONV_PATH")
set(CMAKE_FXCONV_OUTPUT_EXTENSION ".o")
# Save these results
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/CMakeFXCONVCompiler.cmake.in"
"${CMAKE_PLATFORM_INFO_DIR}/CMakeFXCONVCompiler.cmake")

View File

@ -0,0 +1,4 @@
set(CMAKE_FXCONV_COMPILER "@CMAKE_FXCONV_COMPILER@")
set(CMAKE_FXCONV_COMPILER_LOADED 1)
set(CMAKE_FXCONV_OUTPUT_EXTENSION "@CMAKE_FXCONV_OUTPUT_EXTENSION@")
set(CMAKE_FXCONV_COMPILER_ENV_VAR "@CMAKE_FXCONV_COMPILER_ENV_VAR@")

View File

@ -0,0 +1,15 @@
# The compiler command is a bit shaky because we want to dynamically add
# --converters flags but too much user code carelessly sets C/C++ flags for all
# languages globally, meaning our own flags are mostly unusable.
#
# We work around this problem by using CMAKE_FXCONV_COMPILER_ARG1, a special
# variable whose value is automatically inserted as an argument after the
# <CMAKE_FXCONV_COMPILER> placeholder in the COMPILE_OBJECT rule. We then
# modify CMAKE_FXCONV_COMPILER_ARG1 from the fxconv_declare_converters()
# function to supply the --converters flag.
set(CMAKE_FXCONV_COMPILER_ARG1)
set(CMAKE_FXCONV_COMPILE_OBJECT
"<CMAKE_FXCONV_COMPILER> --toolchain=sh-elf --${FXSDK_PLATFORM} \
<SOURCE> -o <OBJECT>")
set(CMAKE_FXCONV_INFORMATION_LOADED 1)

View File

@ -0,0 +1 @@
set(CMAKE_FXCONV_COMPILER_WORKS 1 CACHE INTERNAL "")

View File

@ -1,5 +1,7 @@
set(CMAKE_FXCONV_COMPILE_OBJECT
"fxconv <SOURCE> -o <OBJECT> --toolchain=sh-elf --${FXSDK_PLATFORM}")
# For the template of the custom language, see:
# - https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CMakeAddNewLanguage.txt
# - https://stackoverflow.com/questions/59536644/cmake-custom-compiler-linker-language-not-found
enable_language(FXCONV)
function(fxconv_declare_assets)
cmake_parse_arguments(CONV "WITH_METADATA" "" "" ${ARGN})
@ -27,10 +29,9 @@ function(fxconv_declare_converters)
list(APPEND FXCONV_CONVERTERS "${CONVERTER_PATH}")
endforeach()
# Record the names in the list
# Record the full list in the parent scope
set(FXCONV_CONVERTERS "${FXCONV_CONVERTERS}" PARENT_SCOPE)
# Update the compile command
set(CMAKE_FXCONV_COMPILE_OBJECT
"fxconv <SOURCE> -o <OBJECT> --toolchain=sh-elf --${FXSDK_PLATFORM} --converters=${FXCONV_CONVERTERS}" PARENT_SCOPE)
# Also push a language flag through the special "ARG1" variable
set(CMAKE_FXCONV_COMPILER_ARG1 "--converters=${FXCONV_CONVERTERS}"
PARENT_SCOPE)
endfunction()