Skip to content

Commit 00c5db3

Browse files
committed
[PROJECT/UTILITY] allow usage of local only openshc sources
1 parent 12349b3 commit 00c5db3

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ dist/
1010
# Softlink to game installation
1111
_original
1212

13+
# Local openshc-sources for faster tests (ignores any longer name to allow keeping backups)
14+
cmake/openshc-sources.txt.local*
15+
1316
# Allow dependency libs
1417
!dependencies/**/*.lib
1518

CMakeLists.txt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
cmake_minimum_required (VERSION 3.21)
44

5+
function(file_add_depends FILE)
6+
message(STATUS "Add file dependency: ${FILE}")
7+
if(EXISTS "${FILE}")
8+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${FILE}) # generally watches for changes
9+
else()
10+
file(GLOB _ CONFIGURE_DEPENDS ${FILE}) # trick to trigger reconfigure if the file comes into existence
11+
endif()
12+
endfunction()
13+
514
# NOTE: POST_BUILD does not run if the target is unchanged, so a config switch will not trigger them again, so clean + build if issues happen
615
function(target_file_copy_if_different TARGET FILE DEST)
716
message(STATUS "Ensure file \"${FILE}\" is copied to \"${DEST}\" if different for target: ${TARGET}")
@@ -10,7 +19,7 @@ function(target_file_copy_if_different TARGET FILE DEST)
1019
)
1120
endfunction()
1221
function(file_dependent_read_list FILE LIST)
13-
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${FILE}) # watch the file
22+
file_add_depends("${FILE}")
1423
file(STRINGS "${FILE}" TEMP_LIST)
1524
set(${LIST} "${TEMP_LIST}" PARENT_SCOPE)
1625
endfunction()
@@ -102,16 +111,26 @@ include_directories(
102111
set(PCH_FILE ${CMAKE_SOURCE_DIR}/src/precomp/pch.h)
103112
file_dependent_read_list("${CMAKE_SOURCE_DIR}/cmake/core-sources.txt" CORE_SOURCES)
104113

105-
# Include openshc source files
106-
file_dependent_read_list("${CMAKE_SOURCE_DIR}/cmake/openshc-sources.txt" OPENSHC_SOURCES)
114+
# Include openshc source files or local alternative
115+
set(OPENSHC_SOURCES_FILE "${CMAKE_SOURCE_DIR}/cmake/openshc-sources.txt")
116+
set(OPENSHC_SOURCES_FILE_LOCAL "${CMAKE_SOURCE_DIR}/cmake/openshc-sources.txt.local")
117+
if(EXISTS "${OPENSHC_SOURCES_FILE_LOCAL}")
118+
message(STATUS "WARNING: Found and using openshc-sources.txt.local")
119+
file_dependent_read_list("${OPENSHC_SOURCES_FILE_LOCAL}" OPENSHC_SOURCES)
120+
else()
121+
file_dependent_read_list("${OPENSHC_SOURCES_FILE}" OPENSHC_SOURCES)
122+
file_add_depends("${OPENSHC_SOURCES_FILE_LOCAL}") # Add to notice if it comes into existence
123+
endif()
124+
107125

108126
# Add source to this project's executable.
109127
add_executable(OpenSHC.exe WIN32 src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES})
110128
set_target_properties(OpenSHC.exe PROPERTIES OUTPUT_NAME ${OPEN_SHC_NAME})
111129
target_compile_definitions(OpenSHC.exe PRIVATE OPEN_SHC_EXE)
112130
target_precompile_headers(OpenSHC.exe PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${PCH_FILE}>)
113131

114-
# Checks if a binkw32_real is present and uses this instead; only checks on reconfigure
132+
# Checks if a binkw32_real is present and uses this instead
133+
file_add_depends("${CRUSADER_DIR}/binkw32_real.dll")
115134
if(EXISTS "${CRUSADER_DIR}/binkw32_real.dll")
116135
target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/binkw32_real.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/binkw32.dll")
117136
else()

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ If any `.cpp` or `.c` files are added to the source code, they should be listed
8787
- `cmake/pklib-sources.txt` containing the source files for compiling the pklib dependency.
8888
- `cmake/openshc-sources.txt` containing the files with reimplementations of the original game's functions.
8989

90+
You can also create a local only `cmake/openshc-sources.txt.local` file, which will be used instead of `cmake/openshc-sources.txt` if it exists, to allow faster tests.
91+
Extending this files name in any way, like `openshc-sources.txt.local.bak`, will prevent it from being used, but it is still ignored by git. This allows to keep small local file lists.
92+
9093
#### Manual configuration
9194

9295
The file `build.bat` exists for convenience. If you want more control, you can specify the following cmake options.

cmake/openshc-sources.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)