Skip to content

Commit e79e931

Browse files
committed
[PROJECT] restructure build flows
1 parent d69ae4a commit e79e931

6 files changed

Lines changed: 50 additions & 35 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: 28 additions & 23 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

@@ -144,45 +153,41 @@ target_file_copy_if_different(OpenSHC.exe "${CRUSADER_DIR}/shfolder.dll" "$<TARG
144153

145154

146155

147-
set(OPEN_SHC_DLL_DEST "${CRUSADER_DIR}/ucp/modules/${OPEN_SHC_NAME}-${OPEN_SHC_VERSION}" CACHE PATH "Path for OpenSHC.dll and OpenSHC.pdb")
156+
set(OPEN_SHC_DLL_DEST "${CRUSADER_DIR}/ucp/modules/${OPEN_SHC_NAME}-${OPEN_SHC_VERSION}")
148157

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

154-
# Using module folder as runtime output to properly place the dll and other libs
155-
set_target_properties(OpenSHC.dll PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OPEN_SHC_DLL_DEST})
156164

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

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

175180
# Copy ucp definition files
176181
file_dependent_read_list("${CMAKE_SOURCE_DIR}/cmake/ucp-definition.txt" UCP_DEFINITION)
177182
foreach(FILE IN LISTS UCP_DEFINITION)
178183
get_filename_component(DIR "${FILE}" DIRECTORY)
179184
if (DIR)
180185
set(DEST_FILE_DIR "${OPEN_SHC_DLL_DEST}/${DIR}")
181-
add_custom_command(TARGET OpenSHC.dll POST_BUILD
186+
add_custom_command(TARGET OpenSHC.dll.deploy POST_BUILD
182187
COMMAND ${CMAKE_COMMAND} -E make_directory "${DEST_FILE_DIR}"
183188
)
184189
else()
185190
set(DEST_FILE_DIR "${OPEN_SHC_DLL_DEST}")
186191
endif()
187-
target_file_copy_if_different(OpenSHC.dll "${CMAKE_SOURCE_DIR}/ucp/${FILE}" "${DEST_FILE_DIR}/${FILE}")
192+
target_file_copy_if_different(OpenSHC.dll.deploy "${CMAKE_SOURCE_DIR}/ucp/${FILE}" "${DEST_FILE_DIR}/${FILE}")
188193
endforeach()

README.md

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

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

97-
##### Output folder of dll
98-
99-
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.
100-
101-
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`.
102-
10397
##### Building
10498

105-
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll`
99+
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.dll` will create the dll in `build-RelWithDebInfo/DLL`.
100+
Build using `cmake --build --preset RelWithDebInfo --target OpenSHC.exe` will create the exe in `build-RelWithDebInfo/EXE`.
101+
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: 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

0 commit comments

Comments
 (0)