From e24de774e553b62010f08112a4268bbdfdbae51a Mon Sep 17 00:00:00 2001 From: sourcehold Date: Thu, 15 Jan 2026 20:15:20 +0100 Subject: [PATCH 1/2] [PROJECT] resolve #37: add reimplementation function by function (manually instead of through scripts) --- CMakeLists.txt | 15 ++++++----- README.md | 6 ++--- cmake/core-sources.txt | 1 - create-include-lists.cmake | 53 -------------------------------------- src/{core => }/entry.cpp | 2 +- 5 files changed, 12 insertions(+), 65 deletions(-) delete mode 100644 create-include-lists.cmake rename src/{core => }/entry.cpp (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08db327..17eae16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,17 +93,20 @@ link_libraries( ) -# Include core source and precomp header -set(PCH_FILE ${CMAKE_SOURCE_DIR}/src/precomp/pch.h) -file_dependent_read_list("${CMAKE_SOURCE_DIR}/cmake/core-sources.txt" CORE_SOURCES) - # Make src/ a valid include directory include_directories( ${CMAKE_SOURCE_DIR}/src ) +# Include core source and precomp header +set(PCH_FILE ${CMAKE_SOURCE_DIR}/src/precomp/pch.h) +file_dependent_read_list("${CMAKE_SOURCE_DIR}/cmake/core-sources.txt" CORE_SOURCES) + +# Include openshc source files +file_dependent_read_list("${CMAKE_SOURCE_DIR}/cmake/openshc-sources.txt" OPENSHC_SOURCES) + # Add source to this project's executable. -add_executable(OpenSHC.exe WIN32 ${CORE_SOURCES}) +add_executable(OpenSHC.exe WIN32 src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES}) set_target_properties(OpenSHC.exe PROPERTIES OUTPUT_NAME ${OPEN_SHC_NAME}) target_compile_definitions(OpenSHC.exe PRIVATE OPEN_SHC_EXE) target_precompile_headers(OpenSHC.exe PRIVATE $<$:${PCH_FILE}>) @@ -124,7 +127,7 @@ target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/shfolder.dll" "$:${PCH_FILE}>) diff --git a/README.md b/README.md index 47b3548..1598a9c 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Visual Studio Code with the proper extensions only needs to open the folder and Additionally, it configures format-on-save and a debug target for the UCP3. If the scripts are preferred, the following triggers a build using the scripts: + 1. Open a terminal. 2. Navigate to this project folder 3. Execute build.bat: @@ -80,10 +81,7 @@ If CMake is installed and not in PATH, for example if installed via Visual Studi Note that any code needs to be formatted properly using the provided `clang-format`. The way to do so it up to the developer. Many IDEs support it out of the box. -Should any files be added to the source code in `src/core` or the ucp files in `ucp`, the cmake script [create-include-lists.cmake](create-include-lists.cmake) needs to be rerun and the changed list files need to be committed: -```bat -.\cmakew -P create-include-lists.cmake -``` +Should any files be added to the source code in `src/core` or the ucp files in `ucp`, the file lists in `cmake/` should be updated accordingly. #### Manual configuration diff --git a/cmake/core-sources.txt b/cmake/core-sources.txt index e82acb9..a01a1a2 100644 --- a/cmake/core-sources.txt +++ b/cmake/core-sources.txt @@ -1,4 +1,3 @@ src/core/MainImplementation.cpp src/core/Resolver.cpp src/core/ViewportRenderState.cpp -src/core/entry.cpp diff --git a/create-include-lists.cmake b/create-include-lists.cmake deleted file mode 100644 index 8d5792d..0000000 --- a/create-include-lists.cmake +++ /dev/null @@ -1,53 +0,0 @@ -# ====================================================================== -# CMake script to generate the source lists, -# since GLOB in build is discouraged. -# Rerun on source change. -# Usage: cmake -P generate_file_list.cmake -# ====================================================================== - -cmake_minimum_required(VERSION 3.21) - -function(generate_file_list SOURCE_ROOT PATTERNS_LIST OUTPUT_FILE) - set(ALL_ENTRIES "") - - # 1. Recursively collect entries for each pattern - foreach(PAT ${PATTERNS_LIST}) - file(GLOB_RECURSE ENTRIES_FOR_PAT RELATIVE "${SOURCE_ROOT}" "${SOURCE_ROOT}/${PAT}") - list(APPEND ALL_ENTRIES ${ENTRIES_FOR_PAT}) - endforeach() - - # 2. Keep only files - set(FILES_ONLY "") - foreach(entry IN LISTS ALL_ENTRIES) - if(EXISTS "${SOURCE_ROOT}/${entry}" AND NOT IS_DIRECTORY "${SOURCE_ROOT}/${entry}") - list(APPEND FILES_ONLY "${entry}") - endif() - endforeach() - - # 3. Remove duplicates (possible if patterns overlap) - list(REMOVE_DUPLICATES FILES_ONLY) - - # 4. Sort alphabetically - list(SORT FILES_ONLY) - - # 5. Generate output file - string(JOIN "\n" FILES_ONLY_STRING ${FILES_ONLY}) - file(WRITE "${OUTPUT_FILE}.temp" "${FILES_ONLY_STRING}\n") - - # 6. Convert line endings - configure_file("${OUTPUT_FILE}.temp" "${OUTPUT_FILE}" @ONLY NEWLINE_STYLE LF) - - # 7. Remove temp file - file(REMOVE "${OUTPUT_FILE}.temp") - - message(STATUS "Generated file list in: ${OUTPUT_FILE}") -endfunction() - -# core sources -generate_file_list("${CMAKE_CURRENT_LIST_DIR}" "src/core/*.c;src/core/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/cmake/core-sources.txt") - -# pklib sources -generate_file_list("${CMAKE_CURRENT_LIST_DIR}" "dependencies/pklib/*.c" "${CMAKE_CURRENT_LIST_DIR}/cmake/pklib-sources.txt") - -# ucp definition -generate_file_list("${CMAKE_CURRENT_LIST_DIR}/ucp" "*.lua;*.yml;*.md" "${CMAKE_CURRENT_LIST_DIR}/cmake/ucp-definition.txt") diff --git a/src/core/entry.cpp b/src/entry.cpp similarity index 92% rename from src/core/entry.cpp rename to src/entry.cpp index 95b60ae..9b11864 100644 --- a/src/core/entry.cpp +++ b/src/entry.cpp @@ -1,5 +1,5 @@ -#include "MainResolver.h" +#include "core/MainResolver.h" #include "lua.h" From 1292a21bc97e95d1f312ae60fd771f39380ac6cf Mon Sep 17 00:00:00 2001 From: sourcehold Date: Thu, 15 Jan 2026 20:33:03 +0100 Subject: [PATCH 2/2] [PROJECT] clarify meaning of the txt files in cmake/ --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1598a9c..28a090d 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,11 @@ If CMake is installed and not in PATH, for example if installed via Visual Studi Note that any code needs to be formatted properly using the provided `clang-format`. The way to do so it up to the developer. Many IDEs support it out of the box. -Should any files be added to the source code in `src/core` or the ucp files in `ucp`, the file lists in `cmake/` should be updated accordingly. +If any `.cpp` or `.c` files are added to the source code, they should be listed in one of the txt files in `cmake/`: + +- `cmake/core-sources.txt` containing the core sources to compile the project. +- `cmake/pklib-sources.txt` containing the source files for compiling the pklib dependency. +- `cmake/openshc-sources.txt` containing the files with reimplementations of the original game's functions. #### Manual configuration