forked from advancedfx/advancedfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
254 lines (208 loc) · 9.56 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
cmake_minimum_required (VERSION 3.24)
project ("advancedfx")
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(CMAKE_BUILD_TYPE_DEBUG 1)
endif()
set(VS_CONFIGURATION $<IF:$<CONFIG:Debug>,Debug,Release>)
#
# Get Microsoft Visual Studio related paths:
#
execute_process(
COMMAND "$ENV{ProgramFiles\(x86\)}\\Microsoft Visual Studio\\Installer\\vswhere.exe" "-latest" "-version" "[17.0,18.0)" "-property" "installationPath"
OUTPUT_VARIABLE VS_INSTALLPATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE "\\" "/" VS_INSTALLPATH ${VS_INSTALLPATH})
execute_process(
COMMAND "$ENV{ProgramFiles\(x86\)}\\Microsoft Visual Studio\\Installer\\vswhere.exe" "-latest" "-version" "[17.0,18.0)" "-requires" "Microsoft.Component.MSBuild" "-find" "MSBuild\\**\\**\\Bin\\MSBuild.exe"
OUTPUT_VARIABLE VS_MSBUILD
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE "\\" "/" VS_MSBUILD ${VS_MSBUILD})
################################################################################
#
# MultiBuild
if (NOT ${PROJECT_NAME}-MultiBuild)
include(ExternalProject)
macro (setup_arch arch)
set(CMAKE_GENERATOR_PLATFORM ${arch})
ExternalProject_Add (${PROJECT_NAME}-${arch}
DEPENDS
BINARY_DIR "${PROJECT_NAME}-${arch}"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${arch}-install"
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-D${PROJECT_NAME}-MultiBuild=ON
-DPROJECT_NAME_MULTI=${PROJECT_NAME}-${arch}
"-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${arch}-install"
BUILD_COMMAND
${CMAKE_COMMAND} --build . --config $<CONFIG> -- -r
INSTALL_COMMAND
${CMAKE_COMMAND} --install . --config $<CONFIG>
BUILD_ALWAYS true
)
endmacro()
setup_arch(Win32)
setup_arch(x64)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/dist" CACHE PATH "..." FORCE)
endif()
add_custom_target(advancedfx ALL
DEPENDS advancedfx-Win32 advancedfx-x64
)
add_custom_command(
TARGET advancedfx
POST_BUILD
COMMAND npm run build-snippets
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/misc/mirv-script
COMMENT "Transpiling mirv-script snippets"
)
install(
CODE
"
# Create directories:
execute_process( WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\" COMMAND \"${CMAKE_COMMAND}\" -E make_directory \"${CMAKE_INSTALL_PREFIX}\")
# Copy Win32 (currrent exception: old injector x64 is in here too):
execute_process( WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-Win32-install\" COMMAND \"${CMAKE_COMMAND}\" -E copy_directory \"bin\" \"${CMAKE_INSTALL_PREFIX}/bin\" )
execute_process( WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-Win32-install\" COMMAND \"${CMAKE_COMMAND}\" -E copy_directory \"pdb\" \"${CMAKE_INSTALL_PREFIX}/pdb\" )
# Copy x64:
execute_process( WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-x64-install\" COMMAND \"${CMAKE_COMMAND}\" -E copy_directory \"bin\" \"${CMAKE_INSTALL_PREFIX}/bin\" )
execute_process( WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-x64-install\" COMMAND \"${CMAKE_COMMAND}\" -E copy_directory \"pdb\" \"${CMAKE_INSTALL_PREFIX}/pdb\" )
# Copy resources:
execute_process( WORKING_DIRECTORY \"${CMAKE_SOURCE_DIR}\" COMMAND \"${CMAKE_SOURCE_DIR}/copy_resources_release.bat\" \"${CMAKE_INSTALL_PREFIX}/bin\" )
# Update translations from l10n repo (e.g. required for installer):
execute_process( WORKING_DIRECTORY \"${CMAKE_SOURCE_DIR}\" COMMAND \"${CMAKE_SOURCE_DIR}/l10n_update_to_source.bat\" \"${CMAKE_INSTALL_PREFIX}/bin\" )
# Create ZIP files:
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/bin\" COMMAND \"${CMAKE_COMMAND}\" -E tar cfv \"${CMAKE_INSTALL_PREFIX}/hlae.zip\" --format=zip -- . )
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/pdb\" COMMAND \"${CMAKE_COMMAND}\" -E tar cfv \"${CMAKE_INSTALL_PREFIX}/hlae_pdb.zip\" --format=zip -- . )
# Installer related:
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}\" COMMAND \"${CMAKE_COMMAND}\" -E make_directory installer)
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}\" COMMAND \"${CMAKE_COMMAND}\" -E make_directory installer/hlae)
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}\" COMMAND \"${CMAKE_COMMAND}\" -E copy_directory bin installer/hlae)
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}\" COMMAND \"${CMAKE_COMMAND}\" -E rm -Rf installer/hlae/ffmpeg)
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}\" COMMAND \"${CMAKE_COMMAND}\" -E rm -Rf installer/hlae/locales)
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}\" COMMAND \"${CMAKE_COMMAND}\" -E rm -f installer/hlae/HLAE.exe)
execute_process( WORKING_DIRECTORY \"${CMAKE_SOURCE_DIR}/installer/setup\" COMMAND \"${VS_MSBUILD}\" \"${CMAKE_SOURCE_DIR}/installer/setup/setup.wixproj\" \"-property:Configuration=${VS_CONFIGURATION}\" \"-property:Platform=x86\" \"-property:OutputPath=${CMAKE_INSTALL_PREFIX}/installer/build\")
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}\" COMMAND \"${CMAKE_COMMAND}\" -E copy installer/build/HLAE_Setup.exe ./HLAE_Setup.exe)
execute_process( WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}\" COMMAND \"${CMAKE_COMMAND}\" -E copy installer/build/HLAE_Setup.wixpdb ./HLAE_Setup.wixpdb)
"
)
return()
endif()
################################################################################
# set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}")
#
# Include dependencies:
#
include(FetchContent)
include(ExternalProject)
#
# Setup "corrosion" for including Rust code in our projects:
#
FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG 64289b1d79d6d19cd2e241db515381a086bb8407 # v0.5
)
FetchContent_MakeAvailable(Corrosion)
#
# Project setup
#
if(CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
add_subdirectory("deps/release/zlib")
add_subdirectory("deps/release/protobuf")
add_subdirectory("deps/release/openexr")
add_subdirectory("deps/release/injector_bin")
add_subdirectory("AfxCppCli")
add_subdirectory("ShaderBuilder")
add_subdirectory("AfxHookGoldSrc")
add_subdirectory("AfxHookSource")
add_subdirectory("hlae")
add_custom_target(advancedfx ALL
DEPENDS hlae
)
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
add_subdirectory("deps/release/zlib")
add_subdirectory("deps/release/openexr")
add_subdirectory("ShaderBuilder")
add_subdirectory("AfxHookSource2")
add_custom_target(advancedfx ALL
DEPENDS AfxHookSource2
)
endif()
#
# Install
#
set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
if(${CMAKE_BUILD_TYPE_DEBUG})
set(CMAKE_INSTALL_DEBUG_LIBRARIES TRUE)
endif()
include(InstallRequiredSystemLibraries)
if(${CMAKE_BUILD_TYPE_DEBUG})
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} "${MSVC_CRT_DIR}/vccorlib${v}d.dll" "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.CRT/vccorlib${v}.dll")
else()
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} "${MSVC_CRT_DIR}/vccorlib${v}.dll" )
endif()
if(CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
install(
PROGRAMS
${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
"${afxcppcli_BINARY_DIR}/AfxCppCli.dll"
"${afxhookgoldsrc_BINARY_DIR}/AfxHookGoldSrc.dll"
"$<TARGET_FILE:AfxHookSource>"
"${hlae_BINARY_DIR}/HLAE.exe"
"${hlae_BINARY_DIR}/NGettext.dll"
"${injector_BINARY_DIR}/injector.exe"
"${zlib_SOURCE_DIR}/zlib1.dll"
${ILMBASE_BUILD_BINARIES}
${OPENEXR_BUILD_BINARIES}
DESTINATION "bin"
)
install(
FILES
"${injector_BINARY_DIR}/AfxHook.dat"
DESTINATION "bin"
)
install(
FILES
"${afxcppcli_BINARY_DIR}/AfxCppCli.pdb"
"${afxhookgoldsrc_BINARY_DIR}/AfxHookGoldSrc.pdb"
"$<TARGET_PDB_FILE:AfxHookSource>"
"${hlae_BINARY_DIR}/HLAE.pdb"
"${injector_BINARY_DIR}/injector.pdb"
DESTINATION "pdb"
)
install(
PROGRAMS
"${injector_BINARY_DIR}/x64/injector.exe"
DESTINATION "bin/x64"
)
install(
FILES
"${injector_BINARY_DIR}/x64/AfxHook.dat"
DESTINATION "bin/x64"
)
install(
FILES
"${injector_BINARY_DIR}/x64/injector.pdb"
DESTINATION "pdb/x64"
)
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
install(
PROGRAMS
${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
"${AfxHookSource2_BINARY_DIR}/$<CONFIG>/AfxHookSource2.dll"
"${zlib_SOURCE_DIR}/zlib1.dll"
${ILMBASE_BUILD_BINARIES}
${OPENEXR_BUILD_BINARIES}
DESTINATION "bin/x64"
)
install(
FILES
"${AfxHookSource2_BINARY_DIR}/$<CONFIG>/AfxHookSource2.pdb"
DESTINATION "pdb/x64"
)
endif()