-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
649 lines (517 loc) · 28.8 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
#*******************************************************************************
#* O P E N S O U R C E -- V I N I F E R A **
#*******************************************************************************
#*
#* @project Vinifera
#*
#* @file CMAKELISTS.TXT
#*
#* @author CCHyper
#*
#* @brief Main CMake configuration for the project.
#*
#* @license Vinifera is free software: you can redistribute it and/or
#* modify it under the terms of the GNU General Public License
#* as published by the Free Software Foundation, either version
#* 3 of the License, or (at your option) any later version.
#*
#* Vinifera is distributed in the hope that it will be
#* useful, but WITHOUT ANY WARRANTY; without even the implied
#* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
#* PURPOSE. See the GNU General Public License for more details.
#*
#* You should have received a copy of the GNU General Public
#* License along with this program.
#* If not, see <http://www.gnu.org/licenses/>.
#*
#******************************************************************************/
# Visual Studio 2017 requires at least 3.7.
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
set(CMAKE_SUPPRESS_REGENERATION true) # Remove ZERO_CHECK project.
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Organize projects into folders within the VS solution.
# Prevent incremental linking.
# This line has to go before "project"!
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND MSVC)
set(MSVC_INCREMENTAL_DEFAULT OFF)
endif()
# Set available project configurations.
SET(CMAKE_CONFIGURATION_TYPES "Debug;RelWithDebInfo" CACHE STRING "Configs" FORCE)
# Declare the project.
project(Vinifera VERSION 1.00 LANGUAGES CXX)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW) #policy for <PackageName>_ROOT variables.
endif()
# Check supported generators
if(NOT MSVC)
message(FATAL_ERROR "This project can only be built using Visual Studio!")
endif()
if(MSVC AND MSVC_VERSION LESS 1910)
message(FATAL_ERROR "This version of Visual Studio is not supported: ${CMAKE_GENERATOR}.")
endif()
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
message(FATAL_ERROR "This project can only be built as Win32!")
endif()
################################################################################
# Set a default build type if none was specified.
################################################################################
# Default to a Release build.
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug RelWithDebInfo." FORCE)
message(STATUS "Setting build type default to RelWithDebInfo")
endif()
################################################################################
# Configure C++ standard
################################################################################
# Require that we have at least C++14.
# We can not use C++ 17 due to a issue with MSVC and COM
# See: https://developercommunity.visualstudio.com/content/problem/297914/c-intellisense-not-working-for-com-ptr-t-with-c17.html
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
#enable_language(C)
enable_language(CXX)
################################################################################
# Set custom module path.
################################################################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules)
set(CMAKE_NO_SYSTEM_FROM_IMPORTED TRUE) # Needed to prevent FindDirectX screwing up a MinGW build.
################################################################################
# Hack to get around the "Debug", "Release", etc directories CMake tries to add on Windows.
################################################################################
set(OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Set output directory for LIB files.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
# Set output directory for DLL files.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
# Set output directory for executable files.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
################################################################################
# We don't support in tree builds, so help people make the right choice.
################################################################################
if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
message(FATAL_ERROR "Building in-source is not supported! Create a build directory and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
endif()
################################################################################
# Available CMake options.
################################################################################
# Option for producing Release builds.
# DO NOT USE: This is for the CI build system only.
option(OPTION_TS_CLIENT_BUILD "Produce configurations for building a TS Client compatibility build." OFF)
option(OPTION_RELEASE_BUILD "Produce configurations for building a release build." OFF)
# These are for debugging purposes only.
option(OPTION_CUSTOM_DEBUGGER_DIRECTORY "Define custom debugger working path and target to copy binaries to on build." OFF)
option(OPTION_CUSTOM_DEBUGGER_TARGET "Define custom debugger target binary name (only use with modified EXE which loads the DLL via an import)." OFF)
# Both of these options must be enabled to setup the post-build script and debugger target.
if(${OPTION_CUSTOM_DEBUGGER_DIRECTORY} AND ${OPTION_CUSTOM_DEBUGGER_TARGET})
set(OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH " " CACHE STRING "")
set(OPTION_CUSTOM_DEBUGGER_TARGET_NAME " " CACHE STRING "")
if(${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH} STREQUAL " " OR ${OPTION_CUSTOM_DEBUGGER_TARGET_NAME})
message(NOTICE "Warning: Please set the custom debugging path and target name for Tiberian Sun!")
endif()
endif()
if(NOT ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH} STREQUAL " ")
message(STATUS " - Custom debugging path: ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH}")
endif()
if(NOT ${OPTION_CUSTOM_DEBUGGER_TARGET_NAME} STREQUAL " ")
message(STATUS " - Custom debugging target: ${OPTION_CUSTOM_DEBUGGER_TARGET_NAME}")
endif()
option(OPTION_CHECK_TARGET_BINARIES "This option controls if the launcher should check target binaries before injection." ON)
################################################################################
# Some general Windows definitions to keep the MSVC compiler happy with our code.
################################################################################
if(WIN32)
add_compile_definitions(__STDC_FORMAT_MACROS)
add_compile_definitions(__STDC_LIMIT_MACROS)
add_compile_definitions(_CRT_SECURE_NO_DEPRECATE)
add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE)
add_compile_definitions(_WINSOCK_DEPRECATED_NO_WARNINGS)
add_compile_definitions(_USE_32BIT_TIME_T) # This is for ABI compatibility with a few functions.
add_compile_definitions(WIN32_LEAN_AND_MEAN) # Go lean and mean on windows.
add_compile_definitions(NOMINMAX) # Windows min/max clashes with std::min/max
endif()
################################################################################
# Disable warnings.
################################################################################
# Set warning level 4
add_compile_options(/W4)
# For catching unreferenced local variables, we do not need to worry about this when compiling debug builds.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4189")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4101")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4700") # uninitialized local variable 'x' used.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244") # disable C4244: conversion from 'double' to 'float', possible loss of data
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4800") # disable C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4351") # disable C4351: "new behavior: elements of array will be default initialized"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4514") # disable C4514: "unreferenced inline function has been removed" Yea, so what?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4065") # disable C4065: "switch statement contains 'default' but no 'case' labels"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4514") # disable C4514: "unreferenced inline function has been removed" Yea, so what?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4065") # disable C4065: "switch statement contains 'default' but no 'case' labels"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244") # disable C4244: "conversion from 'double' to 'float', possible loss of data" Yea, so what?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4530") # disable C4530: Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4056") # disable C4056: "overflow in floating-point constant arithmetic" This warning occurs even if the loss of precision is insignificant.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4710") # disable C4710: "function not inlined" This warning is typically useless. The inline keyword only serves as a suggestion to the compiler and it may or may not inline a function on a case by case basis. No need to be told of this.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4355") # disable C4355: "'this' used in base member initializer list" Using "this" in a base member initializer is valid -- no need for this warning.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4097") # disable C4097: "typedef-name used as a synonym for class-name". This is by design and should not be a warning.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4091") # disable C4091: 'typedef ': ignored on left of '' when no variable is declared
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4505") # disable C4505: Unreferenced local function removed.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4511") # disable C4511: 'copy constructor could not be generated'
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4711") # disable C4711: 'function selected for automatic inline expansion'. Cool, but since we're treating warnings as errors, don't warn us about this!
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4512") # disable C4512: 'assignment operator could not be generated'
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100") # disable C4100: 'unreferenced formal parameter'
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4786") # disable C4786: "identifier was truncated to '255' characters in the browser information" Templates create long identifiers...
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4800") # disable C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996") # disable C4996: 'This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.'
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4324") # disable C4324: 'structure was padded due to alignment specifier.' Safe to ignore this.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4102") # disable C4102: 'unreferenced label.' Yea, so what?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4646") # disable C4646: 'function declared with 'noreturn' has non-void return type' Yea, so what?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4731") # disable C4731: 'frame pointer register 'ebp' modified by inline assembly code' Nothing to worry about.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4740") # disable C4740: 'flow in or out of inline asm code suppresses global optimization' Nothing to worry about.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4239") # disable C4239: 'nonstandard extension used: 'default argument': conversion from 'value' to 'value &'. Shoosh...
# disable D9035: 'option 'QIfist' has been deprecated and will be removed in a future release.' Yeah yeah, we need it for now though...
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd9035") # Not allowed to disable command line warnings.
################################################################################
# Set global configuration definitions.
################################################################################
# Define the string build type.
if(CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)
add_compile_definitions(BUILD_TYPE="${CMAKE_BUILD_TYPE_UPPERCASE}")
endif()
################################################################################
# Set some handy defines we can use for error messages etc.
################################################################################
set(PROJECT_DLL "${PROJECT_NAME}.dll")
set(UNSUPPORTED_TARGET_ERROR "(Only TS203EN, Freeware-TS, and TUC-TS (2024 release) is currently supported)")
set(TARGET_EXE "GAME.EXE") # Define the EXE to launch.
set(TARGET_PDB "GAME.PDB") # Define the PDB for the target.
set(TARGET_EDB "GAME.EDB") # Define the EDB (exception database) for the target.
set(TARGET_NAME "Tiberian Sun")
# Standard TS203EN 'GAME.EXE'.
set(TARGET_SIZE 3457296)
set(TARGET_ENTRY 0x006B7E21) # Entry point (start).
set(TARGET_HASH "E1B997B4A83B84B5481F773B0B001E3186D02990") # SHA hash
# "The First Decade" 'GAME.EXE'.
set(TARGET_TFD_SIZE 4677437)
set(TARGET_TFD_ENTRY 0x006B7E21) # Entry point (start).
set(TARGET_TFD_HASH "2309D215AC10A0F331009A02EEBFAC4001755A99") # SHA hash
# "The Ultimate Collection (2012 release)" 'GAME.EXE'.
set(TARGET_OLD_TUC_SIZE 3465936)
set(TARGET_OLD_TUC_ENTRY 0x0086D830) # Origin activation changes the entry point (start).
set(TARGET_OLD_TUC_HASH "BEE10E9A55614D134D513909A44BBCC2830B607F") # SHA hash
# "The Ultimate Collection (2024 release)" 'GAME.EXE'.
set(TARGET_TUC_SIZE 3850240)
set(TARGET_TUC_ENTRY 0x006B7E21) # Entry point (start).
set(TARGET_TUC_HASH "AC408535113C221E26C7CF2AAF69AF06FB447CD2") # SHA hash
# "Freeware TS" 'GAME.EXE'.
set(TARGET_FTS_SIZE 3457296)
set(TARGET_FTS_ENTRY 0x006B7E21) # Entry point (start).
set(TARGET_FTS_HASH "846F0077129CB390BB206431A63E9246E3D8DA72") # SHA hash
# Debug option for the launcher to skip target checksum.
if (OPTION_CHECK_TARGET_BINARIES)
set(CHECK_TARGET_BINARIES "true")
else()
set(CHECK_TARGET_BINARIES "false")
endif()
# Compatibility mode overrides this.
if(OPTION_TS_CLIENT_BUILD)
set(CHECK_TARGET_BINARIES "false")
endif()
################################################################################
# Glob all the headers, source files and include directories.
################################################################################
include(GlobUtil)
set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
message(STATUS "Pulling in Vinifera sources.")
GlobDirectories(GLOB_RECURSE VINIFERA_INCLUDE_DIRS ${PROJECT_SOURCE_DIR})
GlobHeaders(GLOB_RECURSE VINIFERA_HEADERS ${PROJECT_SOURCE_DIR})
GlobSources(GLOB_RECURSE VINIFERA_SOURCES ${PROJECT_SOURCE_DIR})
message(STATUS "Pulling in Hooker sources.")
set(HOOKER_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/hooker")
GlobHeaders(GLOB HOOKER_HEADERS ${HOOKER_INCLUDE_DIR})
GlobSources(GLOB HOOKER_SOURCES ${HOOKER_INCLUDE_DIR})
################################################################################
# Fetch the latest TS++ source code
################################################################################
include(FetchContent)
FetchContent_Declare(
TSpp
GIT_REMOTE_UPDATE_STRATEGY CHECKOUT
GIT_REPOSITORY https://github.com/Vinifera-Developers/TSpp.git
GIT_TAG origin/master
)
FetchContent_GetProperties(TSpp)
if(NOT tspp_POPULATED)
FetchContent_Populate(TSpp)
add_subdirectory(${tspp_SOURCE_DIR} ${tspp_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
################################################################################
# Embed some git version information in the binary.
################################################################################
message(STATUS "Fetching git repository information.")
# Locate git binary to provide information to the build environment.
# find_package(Git) # Removed, GitWatcher does this quietly.
# The following two defines are automatically picked up by GitWatcher.
set(GIT_PRE_CONFIGURE_FILE "${CMAKE_SOURCE_DIR}/src/vinifera/vinifera_gitinfo.cpp.in")
set(GIT_POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/generated/vinifera_gitinfo.cpp")
set(GIT_STATE_FILE "${CMAKE_CURRENT_BINARY_DIR}/vinifera-git-state-hash")
set(GIT_WORKING_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
include(GitWatcher)
GitWatcher_SetupInitial() # Running the script function again forces the file to be
# created locally so the file can be added to the filters.
################################################################################
# Build the launcher.
################################################################################
set(LAUNCHER_NAME Launch${PROJECT_NAME})
message(STATUS "Configuring launcher as ${LAUNCHER_NAME} using entry at ${TARGET_ENTRY} to inject ${PROJECT_DLL} into ${TARGET_EXE}")
configure_file(${PROJECT_SOURCE_DIR}/hooker/launcher.cpp.in
${CMAKE_CURRENT_BINARY_DIR}/generated/launcher.cpp @ONLY
)
add_executable(${LAUNCHER_NAME} WIN32
${CMAKE_CURRENT_BINARY_DIR}/generated/launcher.cpp # Configured launcher source file.
${PROJECT_SOURCE_DIR}/core/sha.h
${PROJECT_SOURCE_DIR}/core/sha.cpp
${CMAKE_SOURCE_DIR}/res/resource.h
${CMAKE_SOURCE_DIR}/res/icon.rc
${CMAKE_SOURCE_DIR}/res/vinifera.ico
)
target_include_directories(${LAUNCHER_NAME} PUBLIC
${VINIFERA_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/res/
)
# Filter the configured git version source file manually.
include(ProjectFilters)
# Filter the configured launcher config file manually.
SetCustomProjectFilters("Generated Files" # "Source Files"
${CMAKE_CURRENT_BINARY_DIR}/launcher.cpp
)
SetCustomProjectFilters("Resource Files"
${CMAKE_SOURCE_DIR}/res/resource.h
${CMAKE_SOURCE_DIR}/res/icon.rc
${CMAKE_SOURCE_DIR}/res/vinifera.ico
)
# Set custom debugging target name (only works if the custom path option has been set!).
if(NOT ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH} STREQUAL " " AND
NOT ${OPTION_CUSTOM_DEBUGGER_TARGET_NAME} STREQUAL " ")
set_target_properties(${LAUNCHER_NAME} PROPERTIES
VS_DEBUGGER_COMMAND "${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH}/${LAUNCHER_NAME}.exe")
# message(STATUS "Custom VS_DEBUGGER_COMMAND set to '${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH}/${LAUNCHER_NAME}.exe'")
endif()
# Set the custom debugging target directory.
if(NOT ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH} STREQUAL " ")
set_target_properties(${LAUNCHER_NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH}")
# message(STATUS "Custom VS_DEBUGGER_WORKING_DIRECTORY set to '${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH}'")
endif()
# Create post build script to copy the DLL to the custom debugger directory.
if(NOT ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH} STREQUAL " ")
# Set input and output paths.
set(COPY_SOURCE_FILE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/)
set(COPY_DESTINATION_PATH ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH})
# Create the post build script.
include(WindowsCopyFiles)
PostBuild_WindowsCopyFiles(${LAUNCHER_NAME}
${COPY_SOURCE_FILE}
${COPY_DESTINATION_PATH}
"${LAUNCHER_NAME}.exe"
)
endif()
################################################################################
# Build the DLL.
################################################################################
message(STATUS "Configuring ${PROJECT_NAME} DLL.")
add_library(${PROJECT_NAME} SHARED
${VINIFERA_HEADERS}
${VINIFERA_SOURCES}
${HOOKER_HEADERS} ${HOOKER_SOURCES}
${VINIFERA_RESOURCES}
${GIT_POST_CONFIGURE_FILE}
${CMAKE_SOURCE_DIR}/res/resource.h
${CMAKE_SOURCE_DIR}/res/dialog.rc
${CMAKE_SOURCE_DIR}/res/icon.rc
)
target_include_directories(${PROJECT_NAME} BEFORE PUBLIC
${VINIFERA_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/hooker/
${CMAKE_SOURCE_DIR}/res
)
# Set custom debugging target name (only works if the custom path option has been set!).
if(NOT ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH} STREQUAL " " AND
NOT ${OPTION_CUSTOM_DEBUGGER_TARGET_NAME} STREQUAL " ")
set_target_properties(${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_COMMAND "${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH}/${OPTION_CUSTOM_DEBUGGER_TARGET_NAME}")
# message(STATUS "Custom VS_DEBUGGER_COMMAND set to '${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH}/${OPTION_CUSTOM_DEBUGGER_TARGET_NAME}'")
endif()
# Set the custom debugging target directory.
if(NOT ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH} STREQUAL " ")
set_target_properties(${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH}")
# message(STATUS "Custom VS_DEBUGGER_WORKING_DIRECTORY set to '${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH}'")
endif()
# Set input and output paths.
set(PDB_COPY_SOURCE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/_deps/tspp-src/pdb/)
set(EDB_COPY_SOURCE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/_deps/tspp-src/edb/)
set(PDB_COPY_DESTINATION_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/)
set(EDB_COPY_DESTINATION_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/)
# Create post build script to copy the Target Fake PDB to the build output directory.
include(WindowsCopyFiles)
PostBuild_WindowsCopyFiles(${PROJECT_NAME}
${PDB_COPY_SOURCE_PATH}
${PDB_COPY_DESTINATION_PATH}
"${TARGET_PDB}"
)
# Create post build script to copy the EDB (exception database) to the build output directory.
include(WindowsCopyFiles)
PostBuild_WindowsCopyFiles(${PROJECT_NAME}
${EDB_COPY_SOURCE_PATH}
${EDB_COPY_DESTINATION_PATH}
"${TARGET_EDB}"
)
# Create post build script to copy the DLL to the custom debugger directory.
if(NOT ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH} STREQUAL " ")
# Set input and output paths.
set(COPY_SOURCE_FILE_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/)
set(COPY_DESTINATION_PATH ${OPTION_CUSTOM_DEBUGGER_DIRECTORY_PATH})
# Create the post build script.
include(WindowsCopyFiles)
PostBuild_WindowsCopyFiles(${PROJECT_NAME}
${COPY_SOURCE_FILE_PATH}
${COPY_DESTINATION_PATH}
"${PROJECT_NAME}.dll"
)
# Create the post build script.
include(WindowsCopyFiles)
PostBuild_WindowsCopyFiles(${PROJECT_NAME}
${COPY_SOURCE_FILE_PATH}
${COPY_DESTINATION_PATH}
"${PROJECT_NAME}.pdb"
)
# Create the post build script.
include(WindowsCopyFiles)
PostBuild_WindowsCopyFiles(${PROJECT_NAME}
${COPY_SOURCE_FILE_PATH}
${COPY_DESTINATION_PATH}
"${TARGET_PDB}"
)
# Create the post build script.
include(WindowsCopyFiles)
PostBuild_WindowsCopyFiles(${PROJECT_NAME}
${COPY_SOURCE_FILE_PATH}
${COPY_DESTINATION_PATH}
"${TARGET_EDB}"
)
endif()
# Set the custom project name.
set_target_properties("${PROJECT_NAME}" PROPERTIES PROJECT_LABEL "${PROJECT_NAME}")
# Set some handy defines we can use for error messages etc.
target_compile_definitions(${PROJECT_NAME} PUBLIC VINIFERA_PROJECT_NAME="${PROJECT_NAME}")
target_compile_definitions(${PROJECT_NAME} PUBLIC VINIFERA_TARGET_NAME="${TARGET_NAME}")
target_compile_definitions(${PROJECT_NAME} PUBLIC VINIFERA_UNSUPPORTED_TARGET_ERROR="${UNSUPPORTED_TARGET_ERROR}")
target_compile_definitions(${PROJECT_NAME} PUBLIC VINIFERA_DLL="${PROJECT_DLL}")
target_compile_definitions(${PROJECT_NAME} PUBLIC VINIFERA_TARGET_EXE="${TARGET_EXE}")
target_compile_definitions(${PROJECT_NAME} PUBLIC VINIFERA_TARGET_EDB="${TARGET_EDB}")
target_compile_definitions(${PROJECT_NAME} PUBLIC VINIFERA_TARGET_PDB="${TARGET_PDB}")
target_compile_definitions(${PROJECT_NAME} PUBLIC VINIFERA_TARGET_SIZE=${TARGET_SIZE})
target_compile_definitions(${PROJECT_NAME} PUBLIC VINIFERA_TARGET_HASH="${TARGET_HASH}")
# Set the build type defines.
if(OPTION_TS_CLIENT_BUILD)
target_compile_definitions(${PROJECT_NAME} PUBLIC "$<$<CONFIG:RelWithDebInfo>:TS_CLIENT>")
target_compile_definitions(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Debug>:TS_CLIENT>")
message(STATUS "Build: TS Client Compatibility")
endif()
if(RELEASE OR OPTION_RELEASE_BUILD)
target_compile_definitions(${PROJECT_NAME} PUBLIC "$<$<CONFIG:RelWithDebInfo>:RELEASE>")
message(STATUS "Build: Release")
elseif(NIGHTLY)
target_compile_definitions(${PROJECT_NAME} PUBLIC "$<$<CONFIG:RelWithDebInfo>:NIGHTLY>")
message(STATUS "Build: Nightly")
elseif(PREVIEW)
target_compile_definitions(${PROJECT_NAME} PUBLIC "$<$<CONFIG:RelWithDebInfo>:PREVIEW>")
message(STATUS "Build: Preview")
else()
message(STATUS "Build: Unofficial")
endif()
#
# Add/Remove flags required for trying matching pre-compiled game code.
#
# Disable the random address rebasing on module load.
target_link_options(${PROJECT_NAME} PUBLIC /DYNAMICBASE:NO)
# Disable Data Execution Prevention.
target_link_options(${PROJECT_NAME} PUBLIC /NXCOMPAT:NO)
# Prevent incremental linking.
target_link_options(${PROJECT_NAME} PUBLIC /INCREMENTAL:NO)
# disable SAFESEH to avoid linker issues with 3rd party libraries.
target_link_options(${PROJECT_NAME} PUBLIC /SAFESEH:NO)
# Disable Run Time Checking.
foreach(flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_MINSIZEREL)
if(${flag_var} MATCHES "/RTC")
string(REGEX REPLACE "/RTC[^ ]*" "" ${flag_var} "${${flag_var}}")
endif()
endforeach(flag_var)
# Specifies no enhanced instructions and also specifies x87 for floating-point calculations.
target_compile_options(${PROJECT_NAME} PUBLIC /arch:IA32)
# Specify floating-point behaviour.
target_compile_options(${PROJECT_NAME} PUBLIC /fp:fast)
# Suppresses _ftol when a conversion from a floating-point type to an integer type is required (x86 only).
target_compile_options(${PROJECT_NAME} PUBLIC /QIfist)
# Force generates fast transcendentals.
target_compile_options(${PROJECT_NAME} PUBLIC /Qfast_transcendentals)
# forces __fastcall as default calling convention.
target_compile_options(${PROJECT_NAME} PUBLIC /Gr)
# Disables buffer security overrun checks.
target_compile_options(${PROJECT_NAME} PUBLIC /GS-)
# Disables buffer security overrun checks.
target_compile_options(${PROJECT_NAME} PUBLIC /GS-)
# Align structures to 4-byte boundaries.
# target_compile_options(${PROJECT_NAME} PUBLIC /Zp4)
# Replaces some function calls with intrinsic or otherwise special forms of the function.
# target_compile_options(${PROJECT_NAME} PUBLIC /Oi)
# (Non-debug only) Optimisation. (1) Minimize Size, (2) Maximize Speed.
string(REPLACE "/O2" "/O1" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/O2" "/O1" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/O2" "/O1" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REPLACE "/O2" "/O1" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REPLACE "/O2" "/O1" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
string(REPLACE "/O2" "/O1" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
# (Non-debug only) Disable frame pointer omission (FPO).
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy-")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy-")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /Oy-")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Oy-")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /Oy-")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Oy-")
# Inline function expansion.
target_compile_options(${PROJECT_NAME} PUBLIC
$<$<CONFIG:Debug>:/Ob0>
$<$<CONFIG:Release>:/Ob1>
$<$<CONFIG:RelWithDebInfo>:/Ob1>
$<$<CONFIG:MinSizeRel>:/Ob1>)
# Build with multiple processes.
target_compile_options(${PROJECT_NAME} PUBLIC /MP2)
# Link to the TS++ static library.
target_link_libraries(${PROJECT_NAME} TSpp)
add_dependencies(${PROJECT_NAME} TSpp)
# Ensure the launcher is built with the main project.
add_dependencies(${PROJECT_NAME} Launch${PROJECT_NAME})
set(REQUIRED_LIBRARIES ws2_32 dbghelp shlwapi version comctl32)
# Link to any required libraries.
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBRARIES})
# Make build check state of git to check for uncommitted changes.
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_check_git)
################################################################################
# Setup project IDE filters.
################################################################################
message(STATUS "Setting up project file filters.")
include(ProjectFilters)
SetupProjectFilters("Vinifera" ${VINIFERA_HEADERS} ${VINIFERA_SOURCES} ${VINIFERA_RESOURCES})
SetCustomProjectFilters("Hooker Files"
${HOOKER_HEADERS} ${HOOKER_SOURCES}
)
SetCustomProjectFilters("Resource Files"
${CMAKE_SOURCE_DIR}/res/resource.h
${CMAKE_SOURCE_DIR}/res/dialog.rc
)
# Filter the configured git version source file manually.
SetCustomProjectFilters("Generated Files" ${GIT_POST_CONFIGURE_FILE})
# Force the default startup project.
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Vinifera)