Skip to content

Commit 78be7dd

Browse files
TheRedDaemonsourcehold
authored andcommitted
[PROJECT] restructure build flows
1 parent 7d5a12a commit 78be7dd

6 files changed

Lines changed: 55 additions & 34 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/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: 30 additions & 24 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

@@ -126,6 +134,7 @@ endif()
126134
# Add source to this project's executable.
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

@@ -145,42 +154,39 @@ target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/shfolder.dll" "$<TARG
145154

146155

147156
# 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")
157+
set(OPEN_SHC_DLL_DEST "${CRUSADER_DIR}/ucp/modules/${OPEN_SHC_NAME}-${OPEN_SHC_VERSION}")
149158

150159
add_library(OpenSHC.dll SHARED src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES})
151160
set_target_properties(OpenSHC.dll PROPERTIES OUTPUT_NAME ${OPEN_SHC_NAME})
161+
set_target_properties(OpenSHC.dll PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/DLL")
152162
target_compile_definitions(OpenSHC.dll PRIVATE OPEN_SHC_DLL)
153163
target_precompile_headers(OpenSHC.dll PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${PCH_FILE}>)
154164

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})
157165

158-
# Ensure the module folder exists
159-
file(MAKE_DIRECTORY ${OPEN_SHC_DLL_DEST})
160-
file_add_depends("${OPEN_SHC_DLL_DEST}")
161166

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")
165167
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
168+
OpenSHC.dll.deploy
169+
DEPENDS OpenSHC.dll
170+
)
171+
172+
# Ensure the module folder exists
173+
add_custom_command(TARGET OpenSHC.dll.deploy POST_BUILD
174+
COMMAND ${CMAKE_COMMAND} -E make_directory "${OPEN_SHC_DLL_DEST}"
172175
)
173-
target_sources(OpenSHC.dll PRIVATE ${BUILD_TRIGGER_FILE})
174-
add_dependencies(OpenSHC.dll OpenSHC.dll.trigger)
176+
177+
# Copy exe and pdb is possible
178+
target_file_copy_if_different(OpenSHC.dll.deploy "$<TARGET_FILE:OpenSHC.dll>" "${OPEN_SHC_DLL_DEST}/$<TARGET_FILE_NAME:OpenSHC.dll>")
179+
target_file_copy_if_different(OpenSHC.dll.deploy "$<TARGET_PDB_FILE:OpenSHC.dll>" "${OPEN_SHC_DLL_DEST}/$<TARGET_PDB_FILE_NAME:OpenSHC.dll>")
175180

176181
# Copy ucp definition files
177182
file_dependent_read_list("${CMAKE_SOURCE_DIR}/cmake/ucp-definition.txt" UCP_DEFINITION)
178183
foreach(FILE IN LISTS UCP_DEFINITION)
179184
get_filename_component(DIR "${FILE}" DIRECTORY)
180185
if (DIR)
181-
add_custom_command(TARGET OpenSHC.dll POST_BUILD
182-
COMMAND ${CMAKE_COMMAND} -E make_directory "${OPEN_SHC_DLL_DEST}/${DIR}"
186+
set(DEST_FILE_DIR "${OPEN_SHC_DLL_DEST}/${DIR}")
187+
add_custom_command(TARGET OpenSHC.dll.deploy POST_BUILD
188+
COMMAND ${CMAKE_COMMAND} -E make_directory "${DEST_FILE_DIR}"
183189
)
184190
endif()
185-
target_file_copy_if_different(OpenSHC.dll "${CMAKE_SOURCE_DIR}/ucp/${FILE}" "${OPEN_SHC_DLL_DEST}/${FILE}")
191+
target_file_copy_if_different(OpenSHC.dll.deploy "${CMAKE_SOURCE_DIR}/ucp/${FILE}" "${DEST_FILE_DIR}/${FILE}")
186192
endforeach()

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,8 @@ 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.exe.deploy` will prepare the modules folder in the UCP setup of the bound SHC.

reccmp/reccmp-build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project: .
2+
targets:
3+
STRONGHOLDCRUSADER:
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

0 commit comments

Comments
 (0)