From 56a25bc39a0edf82bf6bc0788289eff0a08d6a42 Mon Sep 17 00:00:00 2001 From: Drew Gilpin Date: Sun, 8 Jun 2025 08:07:23 -0400 Subject: [PATCH] Add automatic extraction of engine assets --- CMakeLists.txt | 5 +++++ README.md | 5 ++++- cmake/UnpackEngine.cmake | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 cmake/UnpackEngine.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 147a10f..bfb50d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,11 @@ cmake_minimum_required(VERSION 3.28) project(AdvancedCMakeTitanEngineExample LANGUAGES C CXX) +# Extract engine assets/libraries from provided zip archives if needed +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +include(UnpackEngine) +unpack_engine_files() + # Global compiler settings if(MSVC) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded" CACHE STRING "" FORCE) diff --git a/README.md b/README.md index cdea9f8..c688b04 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The project now builds two executables: a **client** sample and a **server** tha ## Preparing the engine files -The large engine assets and libraries are stored in the repository as zip archives. Extract them **in place** before configuring the build: +The large engine assets and libraries are stored in the repository as zip archives. If the extracted files are missing, CMake will unpack them automatically during configuration: ``` assets/Engine.zip -> assets/Engine.pak @@ -15,6 +15,9 @@ third_party/EE/EngineDebug64DX11.zip -> third_party/EE/EngineDebug64DX11.lib third_party/EE/EngineDebug64DX11_pdb.zip-> third_party/EE/EngineDebug64DX11.pdb (optional debug symbols) ``` +The configure step automatically unpacks these archives when the extracted +files are missing, so you normally don't need to run any manual commands. + ## Building CMake presets are provided for both platforms. **The Linux presets use Clang,** diff --git a/cmake/UnpackEngine.cmake b/cmake/UnpackEngine.cmake new file mode 100644 index 0000000..9103110 --- /dev/null +++ b/cmake/UnpackEngine.cmake @@ -0,0 +1,37 @@ +function(unpack_engine_files) + set(base "${PROJECT_SOURCE_DIR}") + set(assets_dir "${base}/assets") + set(ee_dir "${base}/third_party/EE") + + # Engine.pak + set(asset_zip "${assets_dir}/Engine.zip") + set(asset_file "${assets_dir}/Engine.pak") + if(NOT EXISTS "${asset_file}" AND EXISTS "${asset_zip}") + message(STATUS "Extracting ${asset_zip}") + file(ARCHIVE_EXTRACT INPUT "${asset_zip}" DESTINATION "${assets_dir}") + endif() + + set(archives + Engine.zip + Engine64DX11.zip + EngineDebug64DX11.zip + EngineDebug64DX11_pdb.zip) + set(outputs + Engine.a + Engine64DX11.lib + EngineDebug64DX11.lib + EngineDebug64DX11.pdb) + + list(LENGTH archives count) + math(EXPR last_index "${count}-1") + foreach(i RANGE 0 ${last_index}) + list(GET archives ${i} archive) + list(GET outputs ${i} out_file) + set(zip_path "${ee_dir}/${archive}") + set(out_path "${ee_dir}/${out_file}") + if(NOT EXISTS "${out_path}" AND EXISTS "${zip_path}") + message(STATUS "Extracting ${archive}") + file(ARCHIVE_EXTRACT INPUT "${zip_path}" DESTINATION "${ee_dir}") + endif() + endforeach() +endfunction()