From 6810be731556182e939ad29f51c3e7b13d7ab491 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:59:45 +0100 Subject: [PATCH] Update bin2h to allow changing the output array type --- PowerRecomp/CMakeLists.txt | 2 +- PowerRecomp/recompiler.cpp | 2 +- cmake/bin2h.cmake | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/PowerRecomp/CMakeLists.txt b/PowerRecomp/CMakeLists.txt index 53c04e5..dafa7e4 100644 --- a/PowerRecomp/CMakeLists.txt +++ b/PowerRecomp/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.8) project("PowerRecomp") -BIN2H(SOURCE_FILE ${POWERUTILS_ROOT}/ppc_context.h HEADER_FILE "generated/ppc_context.gen.h" VARIABLE_NAME "gPPCContextText") +BIN2H(SOURCE_FILE ${POWERUTILS_ROOT}/ppc_context.h HEADER_FILE "generated/ppc_context.gen.h" ARRAY_TYPE "char" VARIABLE_NAME "g_PPCContextText") add_executable(PowerRecomp "main.cpp" "pch.h" "recompiler.cpp" "recompiler.h" "test_recompiler.cpp" "test_recompiler.h" "recompiler_config.h" "recompiler_config.cpp") target_precompile_headers(PowerRecomp PUBLIC "pch.h") diff --git a/PowerRecomp/recompiler.cpp b/PowerRecomp/recompiler.cpp index 7bfc65c..36c2f16 100644 --- a/PowerRecomp/recompiler.cpp +++ b/PowerRecomp/recompiler.cpp @@ -2393,7 +2393,7 @@ void Recompiler::Recompile() println("#pragma once"); println("#include \"ppc_config.h\"\n"); - println("{}", std::string_view{gPPCContextText, gPPCContextText_SIZE}); + println("{}", std::string_view{g_PPCContextText, g_PPCContextText_size}); SaveCurrentOutData("ppc_context.h"); } diff --git a/cmake/bin2h.cmake b/cmake/bin2h.cmake index b33e652..5324081 100644 --- a/cmake/bin2h.cmake +++ b/cmake/bin2h.cmake @@ -37,16 +37,17 @@ endfunction() # VARIABLE_NAME - The name of the variable for the byte array. The string "_SIZE" will be append # to this name and will be used a variable name for size variable. # HEADER_FILE - The path of header file. +# ARRAY_TYPE - The type of each element of the array in the header file. # APPEND - If specified appends to the header file instead of overwriting it # NULL_TERMINATE - If specified a null byte(zero) will be append to the byte array. This will be # useful if the source file is a text file and we want to use the file contents # as string. But the size variable holds size of the byte array without this # null byte. # Usage: -# bin2h(SOURCE_FILE "Logo.png" HEADER_FILE "Logo.h" VARIABLE_NAME "LOGO_PNG") +# bin2h(SOURCE_FILE "Logo.png" HEADER_FILE "Logo.h" ARRAY_TYPE "char" VARIABLE_NAME "LOGO_PNG") function(BIN2H) set(options APPEND NULL_TERMINATE) - set(oneValueArgs SOURCE_FILE VARIABLE_NAME HEADER_FILE) + set(oneValueArgs SOURCE_FILE VARIABLE_NAME HEADER_FILE ARRAY_TYPE) cmake_parse_arguments(BIN2H "${options}" "${oneValueArgs}" "" ${ARGN}) # reads source file contents as hex string @@ -71,8 +72,8 @@ function(BIN2H) string(MAKE_C_IDENTIFIER "${BIN2H_VARIABLE_NAME}" BIN2H_VARIABLE_NAME) # declares byte array and the length variables - set(arrayDefinition "const char ${BIN2H_VARIABLE_NAME}[] = { ${arrayValues} };") - set(arraySizeDefinition "const size_t ${BIN2H_VARIABLE_NAME}_SIZE = ${arraySize};") + set(arrayDefinition "const ${BIN2H_ARRAY_TYPE} ${BIN2H_VARIABLE_NAME}[] = { ${arrayValues} };") + set(arraySizeDefinition "const size_t ${BIN2H_VARIABLE_NAME}_size = ${arraySize};") set(declarations "${arrayDefinition}\n\n${arraySizeDefinition}\n\n") if(BIN2H_APPEND) @@ -80,4 +81,4 @@ function(BIN2H) else() file(WRITE ${BIN2H_HEADER_FILE} "${declarations}") endif() -endfunction() +endfunction()