2023-01-31 14:19:43 -05:00
|
|
|
set(GEODE_CLI_MINIMUM_VERSION 1.0.5)
|
2022-10-14 14:04:59 -04:00
|
|
|
|
2022-10-14 14:22:51 -04:00
|
|
|
# Find Geode CLI
|
2023-10-08 15:02:22 -04:00
|
|
|
if (NOT DEFINED GEODE_CLI OR GEODE_CLI STREQUAL "GEODE_CLI-NOTFOUND")
|
2023-03-21 03:23:26 -04:00
|
|
|
find_program(GEODE_CLI NAMES geode.exe geode-cli.exe geode geode-cli PATHS ${CLI_PATH})
|
2022-07-30 12:24:03 -04:00
|
|
|
endif()
|
|
|
|
|
2022-10-14 14:22:51 -04:00
|
|
|
# Check if CLI was found
|
2022-07-30 12:24:03 -04:00
|
|
|
if (GEODE_CLI STREQUAL "GEODE_CLI-NOTFOUND")
|
2023-01-31 07:48:34 -05:00
|
|
|
message(WARNING "Unable to find Geode CLI")
|
2022-07-30 12:24:03 -04:00
|
|
|
else()
|
2022-10-14 14:22:51 -04:00
|
|
|
# `geode --version` returns `geode x.x.x\n` so gotta do some wacky shit
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${GEODE_CLI} --version
|
|
|
|
OUTPUT_VARIABLE GEODE_CLI_VERSION
|
2024-02-01 05:37:23 -05:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2022-10-14 14:22:51 -04:00
|
|
|
)
|
|
|
|
# Remove trailing newline
|
|
|
|
string(STRIP ${GEODE_CLI_VERSION} GEODE_CLI_VERSION)
|
|
|
|
# Remove program name
|
|
|
|
string(REPLACE "geode " "" GEODE_CLI_VERSION ${GEODE_CLI_VERSION})
|
2022-10-14 14:04:59 -04:00
|
|
|
|
|
|
|
# Need at least v1.0.5 (--shut-up arg in geode package resources)
|
|
|
|
if (${GEODE_CLI_VERSION} VERSION_LESS ${GEODE_CLI_MINIMUM_VERSION})
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Found Geode CLI: ${GEODE_CLI}, however it is version ${GEODE_CLI_VERSION} "
|
|
|
|
"while minimum required is version ${GEODE_CLI_MINIMUM_VERSION}. Please update: "
|
|
|
|
"https://github.com/geode-sdk/cli/releases/latest"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-01-31 14:19:43 -05:00
|
|
|
# Cache version so it's available to other functions
|
|
|
|
set(GEODE_CLI_VERSION "${GEODE_CLI_VERSION}" CACHE INTERNAL "GEODE_CLI_VERSION")
|
|
|
|
|
2022-10-14 14:04:59 -04:00
|
|
|
message(STATUS "Found Geode CLI: ${GEODE_CLI} (version ${GEODE_CLI_VERSION})")
|
2022-07-30 12:24:03 -04:00
|
|
|
endif()
|
|
|
|
|
2023-01-31 07:48:34 -05:00
|
|
|
# Clear cache of mods being built so mods from earlier
|
|
|
|
# configures dont appear on the list
|
|
|
|
set(GEODE_MODS_BEING_BUILT "" CACHE INTERNAL "GEODE_MODS_BEING_BUILT")
|
|
|
|
|
|
|
|
# todo: add EXTERNAL argument that takes a list of external mod ids
|
|
|
|
# current workaround is to manually append to GEODE_MODS_BEING_BUILT before
|
|
|
|
# calling setup_geode_mod if the mod depends on external dependencies that
|
|
|
|
# aren't being built
|
|
|
|
function(setup_geode_mod proname)
|
|
|
|
# Get DONT_INSTALL argument
|
|
|
|
set(options DONT_INSTALL)
|
|
|
|
set(multiValueArgs EXTERNALS)
|
|
|
|
cmake_parse_arguments(SETUP_GEODE_MOD "${options}" "" "${multiValueArgs}" ${ARGN})
|
2022-09-01 02:35:18 -04:00
|
|
|
|
2023-03-21 02:54:11 -04:00
|
|
|
# Link Geode to the mod
|
|
|
|
target_link_libraries(${proname} geode-sdk)
|
|
|
|
|
2023-12-12 19:01:58 -05:00
|
|
|
if (ANDROID)
|
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
add_custom_command(
|
2024-01-27 20:39:54 -05:00
|
|
|
TARGET "${proname}" POST_BUILD
|
|
|
|
DEPENDS "${proname}"
|
2023-12-12 19:01:58 -05:00
|
|
|
COMMAND $<$<CONFIG:release>:${CMAKE_STRIP}>
|
2024-01-27 20:39:54 -05:00
|
|
|
ARGS -S $<TARGET_FILE:${proname}>
|
2023-12-12 19:01:58 -05:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2022-10-03 07:01:08 -04:00
|
|
|
if (GEODE_DISABLE_CLI_CALLS)
|
2023-01-31 07:48:34 -05:00
|
|
|
message("Skipping setting up geode mod ${proname}")
|
2022-10-03 07:01:08 -04:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2022-09-01 05:46:37 -04:00
|
|
|
if(GEODE_CLI STREQUAL "GEODE_CLI-NOTFOUND")
|
2023-01-31 07:48:34 -05:00
|
|
|
message(FATAL_ERROR
|
|
|
|
"setup_geode_mod called, but Geode CLI was not found - "
|
2023-10-08 15:07:24 -04:00
|
|
|
"Please install CLI: https://docs.geode-sdk.org/"
|
2022-09-01 05:46:37 -04:00
|
|
|
)
|
2022-10-03 07:01:08 -04:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2022-10-09 09:24:24 -04:00
|
|
|
# what is this for
|
2022-08-31 13:15:56 -04:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mod.json ${CMAKE_CURRENT_BINARY_DIR}/what.txt)
|
|
|
|
set_target_properties(${proname} PROPERTIES CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/mod.json)
|
|
|
|
|
2023-01-31 07:48:34 -05:00
|
|
|
message(STATUS "Setting up ${proname}")
|
|
|
|
|
|
|
|
# Read mod.json
|
|
|
|
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/mod.json" MOD_JSON)
|
|
|
|
string(JSON MOD_ID GET "${MOD_JSON}" "id")
|
|
|
|
string(JSON MOD_VERSION GET "${MOD_JSON}" "version")
|
2024-04-12 16:02:28 -04:00
|
|
|
string(JSON TARGET_GEODE_VERSION GET "${MOD_JSON}" "geode")
|
2023-01-31 07:48:34 -05:00
|
|
|
string(JSON MOD_HAS_API ERROR_VARIABLE MOD_DOESNT_HAVE_API GET "${MOD_JSON}" "api")
|
2023-01-31 14:19:43 -05:00
|
|
|
string(JSON MOD_HAS_DEPS ERROR_VARIABLE MOD_DOESNT_HAVE_DEPS GET "${MOD_JSON}" "dependencies")
|
2022-10-09 09:24:24 -04:00
|
|
|
|
2024-04-12 17:56:33 -04:00
|
|
|
if ("${TARGET_GEODE_VERSION}" STREQUAL "${GEODE_VERSION_FULL}")
|
|
|
|
message(STATUS "Mod ${MOD_ID} is compiling for Geode version ${GEODE_VERSION_FULL}")
|
2024-04-12 16:02:28 -04:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR
|
2024-04-12 17:56:33 -04:00
|
|
|
"Mod ${MOD_ID} is made for Geode version ${TARGET_GEODE_VERSION} but you have ${GEODE_VERSION_FULL} SDK installed. Please change the Geode version in your mod.json. "
|
2024-04-12 16:02:28 -04:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2024-05-16 11:08:16 -04:00
|
|
|
target_compile_definitions(${proname} PRIVATE GEODE_MOD_ID="${MOD_ID}")
|
|
|
|
|
2023-01-31 07:48:34 -05:00
|
|
|
# Add this mod to the list of known externals mods
|
|
|
|
list(APPEND GEODE_MODS_BEING_BUILT "${MOD_ID}:${MOD_VERSION}")
|
|
|
|
# Ensure that the list of mods being built is global (persists between setup_geode_mod calls)
|
|
|
|
set(GEODE_MODS_BEING_BUILT ${GEODE_MODS_BEING_BUILT} CACHE INTERNAL "GEODE_MODS_BEING_BUILT")
|
|
|
|
|
|
|
|
# Add function arg externals to the list but don't cache that
|
|
|
|
if (SETUP_GEODE_MOD_EXTERNALS)
|
|
|
|
list(APPEND GEODE_MODS_BEING_BUILT ${SETUP_GEODE_MOD_EXTERNALS})
|
|
|
|
endif()
|
2022-10-09 09:24:24 -04:00
|
|
|
|
2023-04-22 03:23:01 -04:00
|
|
|
# For CLI >=v2.4.0, there's an option to disable updating index because
|
|
|
|
# Github Actions on Mac just returns 403 for no reason
|
|
|
|
if (GEODE_DONT_UPDATE_INDEX AND (${GEODE_CLI_VERSION} VERSION_GREATER_EQUAL "2.4.0"))
|
2023-04-22 03:38:47 -04:00
|
|
|
set(DONT_UPDATE_INDEX_ARG "--dont-update-index")
|
2023-04-22 03:23:01 -04:00
|
|
|
else()
|
2023-04-22 03:38:47 -04:00
|
|
|
set(DONT_UPDATE_INDEX_ARG "")
|
2023-04-22 03:23:01 -04:00
|
|
|
endif()
|
|
|
|
|
2023-01-31 07:48:34 -05:00
|
|
|
# Check dependencies using CLI
|
2024-07-16 06:21:58 -04:00
|
|
|
if (${GEODE_CLI_VERSION} VERSION_GREATER_EQUAL "3.2.0")
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${GEODE_CLI} project check ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
--externals ${GEODE_MODS_BEING_BUILT} ${DONT_UPDATE_INDEX_ARG}
|
|
|
|
--platform ${GEODE_TARGET_PLATFORM_SHORT}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
|
|
|
)
|
|
|
|
elseif (${GEODE_CLI_VERSION} VERSION_GREATER_EQUAL "2.0.0")
|
|
|
|
message(WARNING "If you use platform-specific dependencies, upgrade Geode CLI to version 3.2.0 or greater!")
|
2023-01-31 14:19:43 -05:00
|
|
|
execute_process(
|
2023-02-26 08:09:10 -05:00
|
|
|
COMMAND ${GEODE_CLI} project check ${CMAKE_CURRENT_BINARY_DIR}
|
2023-04-22 03:38:47 -04:00
|
|
|
--externals ${GEODE_MODS_BEING_BUILT} ${DONT_UPDATE_INDEX_ARG}
|
2023-02-26 08:09:10 -05:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
2024-02-01 05:37:23 -05:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2023-01-31 14:19:43 -05:00
|
|
|
)
|
2023-02-26 11:01:41 -05:00
|
|
|
elseif (${GEODE_CLI_VERSION} VERSION_GREATER_EQUAL "1.4.0")
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${GEODE_CLI} package setup ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
--externals ${GEODE_MODS_BEING_BUILT}
|
2024-02-01 05:37:23 -05:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2023-02-26 11:01:41 -05:00
|
|
|
)
|
2023-01-31 14:19:43 -05:00
|
|
|
elseif (MOD_HAS_DEPS)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"CLI is version ${GEODE_CLI_VERSION}, but using dependencies "
|
|
|
|
"requires at least 1.4.0 - please update your CLI"
|
|
|
|
)
|
|
|
|
endif()
|
2023-01-31 07:48:34 -05:00
|
|
|
|
|
|
|
# Check if --install should be passed
|
2023-03-21 03:19:19 -04:00
|
|
|
if (SETUP_GEODE_MOD_DONT_INSTALL OR GEODE_DONT_INSTALL_MODS)
|
2023-01-31 07:48:34 -05:00
|
|
|
message(STATUS "Skipping installing ${proname}")
|
2022-10-14 14:04:59 -04:00
|
|
|
set(INSTALL_ARG "")
|
|
|
|
else()
|
|
|
|
set(INSTALL_ARG "--install")
|
|
|
|
endif()
|
|
|
|
|
2023-01-31 07:48:34 -05:00
|
|
|
# The lib binary should be passed only if some headers were provided
|
|
|
|
if (MOD_HAS_API)
|
|
|
|
message(STATUS "Including library & headers with ${proname}")
|
|
|
|
set(HAS_HEADERS On)
|
|
|
|
else()
|
|
|
|
set(HAS_HEADERS Off)
|
|
|
|
endif()
|
|
|
|
|
2023-10-15 12:40:24 -04:00
|
|
|
if (HAS_HEADERS AND WIN32)
|
|
|
|
# this adds the .lib file on windows, which is needed for linking with the headers
|
|
|
|
add_custom_target(${proname}_PACKAGE ALL
|
|
|
|
DEPENDS ${proname} ${CMAKE_CURRENT_SOURCE_DIR}/mod.json
|
|
|
|
COMMAND ${GEODE_CLI} package new ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
--binary $<TARGET_FILE:${proname}> $<TARGET_LINKER_FILE:${proname}>
|
|
|
|
--output ${CMAKE_CURRENT_BINARY_DIR}/${MOD_ID}.geode
|
|
|
|
${INSTALL_ARG}
|
|
|
|
VERBATIM USES_TERMINAL
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
add_custom_target(${proname}_PACKAGE ALL
|
|
|
|
DEPENDS ${proname} ${CMAKE_CURRENT_SOURCE_DIR}/mod.json
|
|
|
|
COMMAND ${GEODE_CLI} package new ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
--binary $<TARGET_FILE:${proname}>
|
|
|
|
--output ${CMAKE_CURRENT_BINARY_DIR}/${MOD_ID}.geode
|
|
|
|
${INSTALL_ARG}
|
|
|
|
VERBATIM USES_TERMINAL
|
|
|
|
)
|
|
|
|
endif()
|
2023-01-31 07:48:34 -05:00
|
|
|
|
|
|
|
# Add dependency dir to include path
|
|
|
|
if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/geode-deps")
|
|
|
|
|
2023-02-01 06:04:23 -05:00
|
|
|
file(GLOB dirs ${CMAKE_CURRENT_BINARY_DIR}/geode-deps/*)
|
|
|
|
|
|
|
|
set(libs_to_link "")
|
|
|
|
|
|
|
|
# Iterate dependency directories
|
|
|
|
foreach(dir ${dirs})
|
|
|
|
if (IS_DIRECTORY ${dir})
|
|
|
|
|
|
|
|
# v1.4.1 fixes optional dependencies
|
|
|
|
if (${GEODE_CLI_VERSION} VERSION_GREATER_EQUAL "1.4.1")
|
|
|
|
# Read dep info
|
|
|
|
file(READ "${dir}/geode-dep-options.json" DEP_JSON)
|
|
|
|
string(JSON required GET "${DEP_JSON}" "required")
|
|
|
|
|
|
|
|
# If this is not a required dependency, don't link it
|
|
|
|
if (NOT ${required})
|
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(WARNING
|
|
|
|
"You are using CLI v1.4.0, which has a bug with optional "
|
|
|
|
"dependencies - update to v1.4.1 if you want to use "
|
|
|
|
"optional dependencies!"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Otherwise add all .libs or whatever the platform's library type is
|
2023-12-20 05:47:44 -05:00
|
|
|
if (WIN32 OR LINUX)
|
2023-02-01 06:04:23 -05:00
|
|
|
file(GLOB libs ${dir}/*.lib)
|
|
|
|
list(APPEND libs_to_link ${libs})
|
|
|
|
elseif (APPLE)
|
|
|
|
file(GLOB libs ${dir}/*.dylib)
|
|
|
|
list(APPEND libs_to_link ${libs})
|
2023-10-08 09:38:17 -04:00
|
|
|
elseif (ANDROID)
|
2024-02-07 14:29:43 -05:00
|
|
|
if (CMAKE_ANDROID_ARCH_ABI STREQUAL "arm64-v8a")
|
|
|
|
file(GLOB libs ${dir}/*.android64.so)
|
|
|
|
else()
|
|
|
|
file(GLOB libs ${dir}/*.android32.so)
|
|
|
|
endif()
|
2023-10-08 09:38:17 -04:00
|
|
|
list(APPEND libs_to_link ${libs})
|
2023-02-01 06:04:23 -05:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Library extension not defined on this platform")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Link libs
|
2023-01-31 07:48:34 -05:00
|
|
|
target_include_directories(${proname} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/geode-deps")
|
2023-02-01 06:04:23 -05:00
|
|
|
target_link_libraries(${proname} ${libs_to_link})
|
2023-01-31 07:48:34 -05:00
|
|
|
|
|
|
|
endif()
|
|
|
|
|
2023-03-21 02:55:13 -04:00
|
|
|
# Add package target + make output name the mod id
|
|
|
|
set_target_properties(${proname} PROPERTIES PREFIX "")
|
2023-12-25 08:45:53 -05:00
|
|
|
if (DEFINED GEODE_MOD_BINARY_SUFFIX)
|
|
|
|
set_target_properties(${proname} PROPERTIES SUFFIX ${GEODE_MOD_BINARY_SUFFIX})
|
|
|
|
endif()
|
2023-03-21 02:55:13 -04:00
|
|
|
set_target_properties(${proname} PROPERTIES OUTPUT_NAME ${MOD_ID})
|
2023-01-31 07:48:34 -05:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(create_geode_file proname)
|
|
|
|
# todo: deprecate at some point ig
|
|
|
|
# message(DEPRECATION
|
|
|
|
# "create_geode_file has been replaced with setup_geode_mod - "
|
|
|
|
# "please replace the function call"
|
|
|
|
# )
|
|
|
|
|
|
|
|
# forward all args
|
|
|
|
setup_geode_mod(${proname} ${ARGN})
|
2022-09-01 02:35:18 -04:00
|
|
|
endfunction()
|
|
|
|
|
2022-10-03 06:51:48 -04:00
|
|
|
function(package_geode_resources proname src dest)
|
2022-10-03 07:01:08 -04:00
|
|
|
if (GEODE_DISABLE_CLI_CALLS)
|
|
|
|
message("Skipping packaging resources from ${src} into ${dest}")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2022-10-03 06:51:48 -04:00
|
|
|
message(STATUS "Packaging resources from ${src} into ${dest}")
|
2022-08-01 11:18:03 -04:00
|
|
|
|
|
|
|
if(GEODE_CLI STREQUAL "GEODE_CLI-NOTFOUND")
|
2022-10-14 14:04:59 -04:00
|
|
|
message(WARNING
|
|
|
|
"package_geode_resources called, but Geode CLI was "
|
|
|
|
"not found - You will need to manually package the resources"
|
|
|
|
)
|
2022-08-01 11:18:03 -04:00
|
|
|
else()
|
|
|
|
|
|
|
|
add_custom_target(${proname}_PACKAGE ALL
|
|
|
|
DEPENDS ${proname}
|
2022-10-03 06:51:48 -04:00
|
|
|
COMMAND ${GEODE_CLI} package resources ${src} ${dest}
|
2022-08-01 11:18:03 -04:00
|
|
|
VERBATIM USES_TERMINAL
|
|
|
|
)
|
2022-10-14 14:04:59 -04:00
|
|
|
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(package_geode_resources_now proname src dest header_dest)
|
|
|
|
if (GEODE_DISABLE_CLI_CALLS)
|
2022-10-14 14:22:51 -04:00
|
|
|
message(WARNING
|
2022-10-14 14:04:59 -04:00
|
|
|
"package_geode_resources_now called, but GEODE_DISABLE_CLI_CALLS
|
2022-12-30 17:50:12 -05:00
|
|
|
is set to true - Faking output result in case you only wish to
|
|
|
|
analyze the project statically, do not expect built project to
|
|
|
|
function properly"
|
2022-10-14 14:04:59 -04:00
|
|
|
)
|
2022-12-30 17:50:12 -05:00
|
|
|
set(HEADER_FILE
|
|
|
|
"#include <unordered_map>\n\n"
|
|
|
|
"static const std::unordered_map<std::string, std::string> "
|
2022-12-30 18:00:14 -05:00
|
|
|
"LOADER_RESOURCE_HASHES {}\;\n"
|
2022-12-30 17:50:12 -05:00
|
|
|
)
|
|
|
|
file(WRITE ${header_dest} ${HEADER_FILE})
|
|
|
|
message(STATUS "Wrote fake resource hashes to ${header_dest}")
|
|
|
|
return()
|
2022-08-01 11:18:03 -04:00
|
|
|
endif()
|
2022-10-14 14:04:59 -04:00
|
|
|
|
|
|
|
if(GEODE_CLI STREQUAL "GEODE_CLI-NOTFOUND")
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"package_geode_resources_now called, but Geode CLI "
|
|
|
|
"was not found - Please install Geode CLI from "
|
|
|
|
"https://github.com/geode-sdk/cli/releases/latest"
|
|
|
|
)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "Packaging resources now from ${src} into ${dest}")
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${GEODE_CLI} package resources ${src} ${dest} --shut-up
|
|
|
|
RESULT_VARIABLE GEODE_PACKAGE_RES
|
2024-02-01 05:37:23 -05:00
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
2022-10-14 14:04:59 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
if (NOT GEODE_PACKAGE_RES EQUAL "0")
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Command \"${GEODE_CLI} package resources ${src} ${dest}\" returned "
|
|
|
|
"${GEODE_PACKAGE_RES} - Expected 0"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(GLOB RESOURCE_FILES "${dest}/*.*")
|
|
|
|
|
|
|
|
set(HEADER_FILE
|
2022-10-20 14:47:29 -04:00
|
|
|
"#include <unordered_map>\n\n"
|
|
|
|
"static const std::unordered_map<std::string, std::string> "
|
|
|
|
"LOADER_RESOURCE_HASHES {\n"
|
|
|
|
# "#include <vector>\n\n"
|
|
|
|
# "static const std::vector<std::string> "
|
|
|
|
# "LOADER_RESOURCE_FILES {\n"
|
2022-10-14 14:04:59 -04:00
|
|
|
)
|
|
|
|
|
2023-10-04 06:50:16 -04:00
|
|
|
# yeah don't think we need to check too many stuff
|
|
|
|
# list(APPEND HASHED_EXTENSIONS ".png")
|
|
|
|
# list(APPEND HASHED_EXTENSIONS ".mp3")
|
|
|
|
# list(APPEND HASHED_EXTENSIONS ".ogg")
|
2024-01-22 12:42:11 -05:00
|
|
|
list(APPEND HASHED_TEXT_EXTENSIONS ".md")
|
2022-10-20 14:47:29 -04:00
|
|
|
|
2022-10-14 14:04:59 -04:00
|
|
|
foreach(file ${RESOURCE_FILES})
|
|
|
|
cmake_path(GET file FILENAME FILE_NAME)
|
2022-10-20 14:47:29 -04:00
|
|
|
get_filename_component(FILE_EXTENSION ${file} EXT)
|
2024-01-22 12:42:11 -05:00
|
|
|
|
2022-10-20 14:47:29 -04:00
|
|
|
list(FIND HASHED_EXTENSIONS "${FILE_EXTENSION}" FILE_SHOULD_HASH)
|
|
|
|
|
|
|
|
if (NOT FILE_NAME STREQUAL ".geode_cache" AND NOT FILE_SHOULD_HASH EQUAL -1)
|
2022-10-14 14:04:59 -04:00
|
|
|
|
2022-10-20 14:47:29 -04:00
|
|
|
file(SHA256 ${file} COMPUTED_HASH)
|
2023-09-16 04:14:08 -04:00
|
|
|
file(SIZE ${file} FILE_SIZE)
|
|
|
|
message(STATUS "Hashed ${file} to ${COMPUTED_HASH} (${FILE_SIZE} bytes)")
|
2022-10-20 14:47:29 -04:00
|
|
|
list(APPEND HEADER_FILE "\t{ \"${FILE_NAME}\", \"${COMPUTED_HASH}\" },\n")
|
2022-10-19 06:33:48 -04:00
|
|
|
|
2022-10-20 14:47:29 -04:00
|
|
|
# list(APPEND HEADER_FILE "\t\"${FILE_NAME}\",\n")
|
2022-10-14 14:04:59 -04:00
|
|
|
|
|
|
|
endif()
|
|
|
|
|
2024-01-22 12:42:11 -05:00
|
|
|
list(FIND HASHED_TEXT_EXTENSIONS "${FILE_EXTENSION}" FILE_SHOULD_TEXT_HASH)
|
|
|
|
|
|
|
|
if (NOT FILE_NAME STREQUAL ".geode_cache" AND NOT FILE_SHOULD_TEXT_HASH EQUAL -1)
|
|
|
|
|
|
|
|
# create list of lines form the contens of a file
|
|
|
|
file(STRINGS ${file} LINES)
|
|
|
|
list(JOIN LINES "" JOINED)
|
|
|
|
# compute hash of the lines
|
|
|
|
string(LENGTH "${JOINED}" FILE_SIZE)
|
|
|
|
string(SHA256 COMPUTED_HASH "${JOINED}")
|
|
|
|
|
|
|
|
message(STATUS "Hashed ${file} to ${COMPUTED_HASH} (${FILE_SIZE} bytes)")
|
|
|
|
list(APPEND HEADER_FILE "\t{ \"${FILE_NAME}\", \"${COMPUTED_HASH}\" },\n")
|
|
|
|
|
|
|
|
# list(APPEND HEADER_FILE "\t\"${FILE_NAME}\",\n")
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
2022-10-14 14:04:59 -04:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
list(APPEND HEADER_FILE "}\;\n")
|
|
|
|
|
|
|
|
file(WRITE ${header_dest} ${HEADER_FILE})
|
|
|
|
message(STATUS "Wrote resource hashes to ${header_dest}")
|
|
|
|
|
2022-08-01 11:18:03 -04:00
|
|
|
endfunction()
|