Skip to content

Commit 4f8b4eb

Browse files
authored
Merge pull request #45 from sourcehold/feature/restructure-build-and-install
[PROJECT] Restructure build flows
2 parents 8c3dcc3 + bf97795 commit 4f8b4eb

9 files changed

Lines changed: 70 additions & 45 deletions

File tree

.vscode/launch.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
],
1515
"stopAtEntry": false,
1616
"cwd": "${workspaceFolder}/_original",
17-
// Note: build currently set target, so if this is the exe, nothing will change
18-
"preLaunchTask": "CMake: build",
17+
"preLaunchTask": "CMake: Prepare OpenSHC.dll Debug",
1918
}
2019
]
2120
}

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"editor.rulers": [
88
120
99
],
10+
"cmake.useCMakePresets": "always",
11+
"cmake.useVsDeveloperEnvironment": "never",
1012
"files.associations": {
1113
"*.inl": "cpp",
1214
"iostream": "cpp",

.vscode/tasks.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "cmake",
6+
"label": "CMake: Prepare OpenSHC.dll Debug",
7+
"command": "build",
8+
"targets": [
9+
"OpenSHC.dll.deploy"
10+
],
11+
"preset": "Debug",
12+
"group": "build"
13+
}
14+
]
15+
}

CMakeLists.txt

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
cmake_minimum_required (VERSION 3.21)
44

55
function(file_add_depends FILE)
6-
message(STATUS "Add file system dependency: ${FILE}")
7-
if(EXISTS "${FILE}")
8-
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${FILE}) # generally watches for changes
6+
cmake_parse_arguments(ADDITIONAL_ARGS "EXISTENCE_ONLY" "" "" ${ARGN})
7+
8+
if(ADDITIONAL_ARGS_EXISTENCE_ONLY)
9+
message(STATUS "Add file system dependency on existence: ${FILE}")
10+
file(GLOB _ CONFIGURE_DEPENDS "${FILE}")
911
else()
10-
file(GLOB _ CONFIGURE_DEPENDS ${FILE}) # trick to trigger reconfigure if the file comes into existence
12+
message(STATUS "Add file system dependency: ${FILE}")
13+
if(EXISTS "${FILE}")
14+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${FILE}")
15+
else()
16+
# Trigger reconfigure if the file comes into existence
17+
file(GLOB _ CONFIGURE_DEPENDS "${FILE}")
18+
endif()
1119
endif()
1220
endfunction()
1321

@@ -123,64 +131,64 @@ else()
123131
endif()
124132

125133

126-
# Add source to this project's executable.
134+
# Create the OpenSHC.exe target, should not require the game
127135
add_executable(OpenSHC.exe WIN32 src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES})
128136
set_target_properties(OpenSHC.exe PROPERTIES OUTPUT_NAME ${OPEN_SHC_NAME})
137+
set_target_properties(OpenSHC.exe PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/EXE")
129138
target_compile_definitions(OpenSHC.exe PRIVATE OPEN_SHC_EXE)
130139
target_precompile_headers(OpenSHC.exe PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${PCH_FILE}>)
131140

141+
142+
143+
# Create custom target that pulls in the required dependencies to run the exe
144+
# NOTE: There seems to be an issue with our naming here, causing the depends to look for "OpenSHC.exe.exe" instead
145+
add_custom_target(OpenSHC.exe.runnable DEPENDS OpenSHC.exe.exe)
146+
132147
# Checks if a binkw32_real is present and uses this instead
133148
file_add_depends("${CRUSADER_DIR}/binkw32_real.dll")
134149
if(EXISTS "${CRUSADER_DIR}/binkw32_real.dll")
135-
target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/binkw32_real.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/binkw32.dll")
150+
target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/binkw32_real.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/binkw32.dll")
136151
else()
137-
target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/binkw32.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/binkw32.dll")
152+
target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/binkw32.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/binkw32.dll")
138153
endif()
139-
target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/Mss32.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/Mss32.dll")
154+
target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/Mss32.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/Mss32.dll")
140155

141156
# shfolder is a normal windows lib, however, the game needs to work with the games version, so we still copy it
142157
# it should be checked later if the compiler emits a shfolder.dll on its own or if it statically links, which we do not want
143-
target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/shfolder.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/shfolder.dll")
158+
target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/shfolder.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/shfolder.dll")
144159

145160

146161

147-
# Place the dll and its pdb in the OpenSHC module folder for live testing
148-
set(OPEN_SHC_DLL_DEST "${CRUSADER_DIR}/ucp/modules/${OPEN_SHC_NAME}-${OPEN_SHC_VERSION}" CACHE PATH "Path for OpenSHC.dll and OpenSHC.pdb")
149-
162+
# Create the OpenSHC.dll target, should not require the game
150163
add_library(OpenSHC.dll SHARED src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES})
151164
set_target_properties(OpenSHC.dll PROPERTIES OUTPUT_NAME ${OPEN_SHC_NAME})
165+
set_target_properties(OpenSHC.dll PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/DLL")
152166
target_compile_definitions(OpenSHC.dll PRIVATE OPEN_SHC_DLL)
153167
target_precompile_headers(OpenSHC.dll PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${PCH_FILE}>)
154168

155-
# Using module folder as runtime output to properly place the dll and other libs
156-
set_target_properties(OpenSHC.dll PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OPEN_SHC_DLL_DEST})
169+
170+
171+
# Create custom target that deploys the DLL and the required UCP files to the modules folder
172+
add_custom_target(OpenSHC.dll.deploy DEPENDS OpenSHC.dll)
173+
set(OPEN_SHC_DLL_DEST "${CRUSADER_DIR}/ucp/modules/${OPEN_SHC_NAME}-${OPEN_SHC_VERSION}")
157174

158175
# Ensure the module folder exists
159-
file(MAKE_DIRECTORY ${OPEN_SHC_DLL_DEST})
160-
file_add_depends("${OPEN_SHC_DLL_DEST}")
161-
162-
# This strange workaround does ensure that the module folder is generated and that a config change regenerates the dll.
163-
# It "only" costs a file creation and a compare minimum while not changing the actual source. Found no other way.
164-
set(BUILD_TRIGGER_FILE "${OPEN_SHC_DLL_DEST}/buildtrigger.c")
165-
add_custom_target(
166-
OpenSHC.dll.trigger
167-
BYPRODUCTS ${BUILD_TRIGGER_FILE}
168-
COMMAND ${CMAKE_COMMAND} -E echo "// $<CONFIG>" > ${BUILD_TRIGGER_FILE}.tmp
169-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUILD_TRIGGER_FILE}.tmp ${BUILD_TRIGGER_FILE}
170-
COMMAND ${CMAKE_COMMAND} -E remove ${BUILD_TRIGGER_FILE}.tmp
171-
VERBATIM
176+
add_custom_command(TARGET OpenSHC.dll.deploy POST_BUILD
177+
COMMAND ${CMAKE_COMMAND} -E make_directory "${OPEN_SHC_DLL_DEST}"
172178
)
173-
target_sources(OpenSHC.dll PRIVATE ${BUILD_TRIGGER_FILE})
174-
add_dependencies(OpenSHC.dll OpenSHC.dll.trigger)
179+
180+
# Copy exe and pdb is possible
181+
target_file_copy_if_different(OpenSHC.dll.deploy "$<TARGET_FILE:OpenSHC.dll>" "${OPEN_SHC_DLL_DEST}/$<TARGET_FILE_NAME:OpenSHC.dll>")
182+
target_file_copy_if_different(OpenSHC.dll.deploy "$<TARGET_PDB_FILE:OpenSHC.dll>" "${OPEN_SHC_DLL_DEST}/$<TARGET_PDB_FILE_NAME:OpenSHC.dll>")
175183

176184
# Copy ucp definition files
177185
file_dependent_read_list("${CMAKE_SOURCE_DIR}/cmake/ucp-definition.txt" UCP_DEFINITION)
178186
foreach(FILE IN LISTS UCP_DEFINITION)
179187
get_filename_component(DIR "${FILE}" DIRECTORY)
180188
if (DIR)
181-
add_custom_command(TARGET OpenSHC.dll POST_BUILD
189+
add_custom_command(TARGET OpenSHC.dll.deploy POST_BUILD
182190
COMMAND ${CMAKE_COMMAND} -E make_directory "${OPEN_SHC_DLL_DEST}/${DIR}"
183191
)
184192
endif()
185-
target_file_copy_if_different(OpenSHC.dll "${CMAKE_SOURCE_DIR}/ucp/${FILE}" "${OPEN_SHC_DLL_DEST}/${FILE}")
193+
target_file_copy_if_different(OpenSHC.dll.deploy "${CMAKE_SOURCE_DIR}/ucp/${FILE}" "${OPEN_SHC_DLL_DEST}/${FILE}")
186194
endforeach()

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,9 @@ Extending this files name in any way, like `openshc-sources.txt.local.bak`, will
9797

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

100-
##### Output folder of dll
101-
102-
Use `cmake --preset RelWithDebInfo -D OPEN_SHC_DLL_DEST=.\build-RelWithDebInfo\dll` to specify the destination folder for the .dll and .pdb files in favor of the default.
103-
104-
Note this setting will remain present even if you remove the `-D` option later from the command. To actually clear this configuration, use `cmake --preset RelWithDebInfo --fresh`.
105-
106100
##### Building
107101

108-
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll`
102+
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll` will create the dll in `build-RelWithDebInfo/DLL`.
103+
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.exe` will create the exe in `build-RelWithDebInfo/EXE`.
104+
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll.deploy` will prepare the modules folder in the UCP setup of the bound SHC.
105+
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.exe.runnable` will prepare the runtime folder of the exe to make it runnable.

reccmp/dll/reccmp-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project: .
22
targets:
33
STRONGHOLDCRUSADER:
4-
path: ../../_original/ucp/modules/OpenSHC-1.41.0/OpenSHC.dll
5-
pdb: ../../_original/ucp/modules/OpenSHC-1.41.0/OpenSHC.pdb
4+
path: ../../build-RelWithDebInfo/DLL/OpenSHC.dll
5+
pdb: ../../build-RelWithDebInfo/DLL/OpenSHC.pdb

reccmp/exe/reccmp-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project: .
22
targets:
33
STRONGHOLDCRUSADER:
4-
path: ../../build-RelWithDebInfo/OpenSHC.exe
5-
pdb: ../../build-RelWithDebInfo/OpenSHC.pdb
4+
path: ../../build-RelWithDebInfo/EXE/OpenSHC.exe
5+
pdb: ../../build-RelWithDebInfo/EXE/OpenSHC.pdb

src/core/MainImplementation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int WINAPI Main::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCm
4242
MACRO_CALL_MEMBER(ViewportRenderState_Func::setupMouseTileXY2, ViewportRenderState_Struct::ptr)();
4343
MACRO_CALL_MEMBER(ViewportRenderState_Func::meth_0x4e5a90, ViewportRenderState_Struct::ptr)();
4444

45-
const HBINK bink = BinkOpen("..\\_original\\binks\\abbot_angry.bik", BINKNOSKIP);
45+
const HBINK bink = BinkOpen("..\\..\\_original\\binks\\abbot_angry.bik", BINKNOSKIP);
4646
std::cout << bink->Width << " " << bink->Height << " " << bink->Frames << " " << bink->FrameNum << std::endl;
4747
BinkClose(bink);
4848

src/core/ViewportRenderState.h

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

33
#include "ViewportRenderStateStruct.h"
44

5+
// WARN: Temporarily set, move to constants headers later
6+
const int MAP_XY_LIMIT = 400;
7+
const int MAP_XY_LIMIT_INCLUSIVE = 399;
8+
59
struct UnitRenderHelpStructure {
610
int param_1;
711
int param_2;

0 commit comments

Comments
 (0)