From 223cd31b6c41414265f453f9a463a7562cb70163 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Mon, 29 Aug 2022 00:34:55 +0200 Subject: [PATCH] fxsdk: compatibility with CMake 3.24 --- fxsdk/cmake/CMakeDetermineFXCONVCompiler.cmake | 18 ++++++++++++++++++ fxsdk/cmake/CMakeFXCONVCompiler.cmake.in | 4 ++++ fxsdk/cmake/CMakeFXCONVInformation.cmake | 15 +++++++++++++++ fxsdk/cmake/CMakeTestFXCONVCompiler.cmake | 1 + fxsdk/cmake/Fxconv.cmake | 15 ++++++++------- 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 fxsdk/cmake/CMakeDetermineFXCONVCompiler.cmake create mode 100644 fxsdk/cmake/CMakeFXCONVCompiler.cmake.in create mode 100644 fxsdk/cmake/CMakeFXCONVInformation.cmake create mode 100644 fxsdk/cmake/CMakeTestFXCONVCompiler.cmake diff --git a/fxsdk/cmake/CMakeDetermineFXCONVCompiler.cmake b/fxsdk/cmake/CMakeDetermineFXCONVCompiler.cmake new file mode 100644 index 0000000..112529c --- /dev/null +++ b/fxsdk/cmake/CMakeDetermineFXCONVCompiler.cmake @@ -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") diff --git a/fxsdk/cmake/CMakeFXCONVCompiler.cmake.in b/fxsdk/cmake/CMakeFXCONVCompiler.cmake.in new file mode 100644 index 0000000..5e8725d --- /dev/null +++ b/fxsdk/cmake/CMakeFXCONVCompiler.cmake.in @@ -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@") diff --git a/fxsdk/cmake/CMakeFXCONVInformation.cmake b/fxsdk/cmake/CMakeFXCONVInformation.cmake new file mode 100644 index 0000000..d7d03f0 --- /dev/null +++ b/fxsdk/cmake/CMakeFXCONVInformation.cmake @@ -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 +# 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 + " --toolchain=sh-elf --${FXSDK_PLATFORM} \ + -o ") +set(CMAKE_FXCONV_INFORMATION_LOADED 1) diff --git a/fxsdk/cmake/CMakeTestFXCONVCompiler.cmake b/fxsdk/cmake/CMakeTestFXCONVCompiler.cmake new file mode 100644 index 0000000..e4ec4a9 --- /dev/null +++ b/fxsdk/cmake/CMakeTestFXCONVCompiler.cmake @@ -0,0 +1 @@ +set(CMAKE_FXCONV_COMPILER_WORKS 1 CACHE INTERNAL "") diff --git a/fxsdk/cmake/Fxconv.cmake b/fxsdk/cmake/Fxconv.cmake index f65db0e..9998262 100644 --- a/fxsdk/cmake/Fxconv.cmake +++ b/fxsdk/cmake/Fxconv.cmake @@ -1,5 +1,7 @@ -set(CMAKE_FXCONV_COMPILE_OBJECT - "fxconv -o --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 -o --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()