forked from TheAssemblyArmada/Chronoshift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
223 lines (191 loc) · 9.08 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
cmake_minimum_required(VERSION 3.0.0)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
if(MSVC)
set(MSVC_INCREMENTAL_DEFAULT ON)
endif()
set(PROJECT CHRONOSHIFT VERSION 3.3)
project(${PROJECT})
if(MSVC)
# Prevent incremental linking.
string(REPLACE "INCREMENTAL" "INCREMENTAL:NO" replacementFlags ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DYNAMICBASE:NO /NXCOMPAT:NO /INCREMENTAL:NO ${replacementFlags}")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "/DYNAMICBASE:NO /NXCOMPAT:NO /INCREMENTAL:NO ${replacementFlags}")
string(REPLACE "INCREMENTAL" "INCREMENTAL:NO" replacementFlags ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO})
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/INCREMENTAL:NO ${replacementFlags}")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "/INCREMENTAL:NO ${replacementFlags}")
# Disable Run Time Checking.
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
#message("Processing flags ${flag_var}")
string(REGEX REPLACE "/RTC[^ ]*" "" ${flag_var} "${${flag_var}}")
endforeach(flag_var)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
if(WATCOM)
# Removes the -br flag, similar to using -static-libgcc and -static-libstdc++ with GCC
# Removes the -xs flag, similar to using -fno-exceptions with GCC
# Changes debug level to -d1 rather than -d2 to give mangled names
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
#message("Processing flags ${flag_var}")
string(REGEX REPLACE "-br[^ ]*" "" ${flag_var} "${${flag_var}}")
string(REGEX REPLACE "-xs[^ ]*" "" ${flag_var} "${${flag_var}}")
string(REGEX REPLACE "-d2" "-d1" ${flag_var} "${${flag_var}}")
endforeach(flag_var)
# Set packing and alignment to 1 byte to match original game ABI
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -zp1")
# Dump useful debug info with -db
# Disable stack checks in debug with -s
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -db -s")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -db")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -db -s")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -db")
# Make watcom dump the debug symbols to a file with the .sym extension
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "opt symf ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "opt symf ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "opt symf ${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "opt symf ${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "opt symf ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "opt symf ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
endif()
# 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 dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
endif()
# This doesn't really work yet, work ongoing to make it usable
option(STANDALONE "Build a standalone version." OFF)
option(NO_BITFIELDS "Use standard bool type in place of bitfields." OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CHRONOSHIFT_SOURCE_DIR}/cmake/modules)
# Go lean and mean on windows.
if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows")
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT STANDALONE)
add_definitions(-D_USE_32BIT_TIME_T) #This is for ABI compatibility with a few functions, remove when original binary no longer required.
endif()
endif()
# Prevent lib prefix when built with MinGW to target windows and move to own dir.
if(MINGW)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CHRONOSHIFT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CHRONOSHIFT_BINARY_DIR}/bin)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++ -std=gnu++0x -mabi=ms -Wno-invalid-offsetof -Wall")
endif()
# Enable debug features in MSVC Debug configs.
if(MSVC)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /DGAME_DEBUG_LOG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /DGAME_DEBUG_LOG")
else()
add_definitions(-DGAME_DEBUG_LOG)
add_definitions(-D__STDC_FORMAT_MACROS)
#if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# add_definitions(-DGAME_DEBUG_LOG)
#endif()
endif()
# Locate git binary to provide information to the build environment
find_package(Git)
if(GIT_FOUND)
# Define current git branch.
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CHRONOSHIFT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
add_definitions(-DCHRONOSHIFT_BRANCH="${CHRONOSHIFT_BRANCH}")
# Define commit hash.
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CHRONOSHIFT_COMMIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
add_definitions(-DCHRONOSHIFT_COMMIT_SHA1="${CHRONOSHIFT_COMMIT_SHA1}")
# Define short commit hash.
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CHRONOSHIFT_COMMIT_SHA1_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
add_definitions(-DCHRONOSHIFT_COMMIT_SHA1_SHORT="${CHRONOSHIFT_COMMIT_SHA1_SHORT}")
# Define commit count.
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CHRONOSHIFT_COMMIT_COUNT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
add_definitions(-DCHRONOSHIFT_COMMIT_COUNT=${CHRONOSHIFT_COMMIT_COUNT})
# Define commit time stamp.
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%ct
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CHRONOSHIFT_COMMIT_TSTAMP
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
add_definitions(-DCHRONOSHIFT_COMMIT_TSTAMP=${CHRONOSHIFT_COMMIT_TSTAMP})
# Define commit author.
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:'%an'
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CHRONOSHIFT_COMMIT_AUTHOR
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
add_definitions(-DCHRONOSHIFT_COMMIT_AUTHOR="${CHRONOSHIFT_COMMIT_AUTHOR}")
# Define commit date and time. Make builds more reproducible than using __DATE__ and __TIME__
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --date=iso --pretty=format:%cd
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CHRONOSHIFT_DATE_AND_TIME
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
string(REPLACE " " ";" CHRONOSHIFT_DATE_AND_TIME ${CHRONOSHIFT_DATE_AND_TIME})
list(GET CHRONOSHIFT_DATE_AND_TIME 0 CHRONOSHIFT_DATE)
list(GET CHRONOSHIFT_DATE_AND_TIME 1 CHRONOSHIFT_TIME)
list(GET CHRONOSHIFT_DATE_AND_TIME 2 CHRONOSHIFTTZONE)
add_definitions(-DCHRONOSHIFT_COMMIT_DATE="${CHRONOSHIFT_DATE}")
add_definitions(-DCHRONOSHIFT_COMMIT_TIME="${CHRONOSHIFT_TIME} ${CHRONOSHIFT_TZONE}")
else()
add_definitions(-DCHRONOSHIFT_BRANCH="netherrealm")
add_definitions(-DCHRONOSHIFT_COMMIT_SHA1="DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF")
add_definitions(-DCHRONOSHIFT_COMMIT_SHA1_SHORT="DEADBEEF")
add_definitions(-DCHRONOSHIFT_COMMIT_COUNT=0)
add_definitions(-DCHRONOSHIFT_COMMIT_TSTAMP=0)
add_definitions(-DCHRONOSHIFT_COMMIT_DATE="1955-11-12")
add_definitions(-DCHRONOSHIFT_COMMIT_TIME="22:04:00 +0000")
add_definitions(-DCHRONOSHIFT_COMMIT_AUTHOR="Someone")
endif()
add_definitions(-DCHRONOSHIFT_MAJOR=${CHRONOSHIFT_VERSION_MAJOR})
add_definitions(-DCHRONOSHIFT_MINOR=${CHRONOSHIFT_VERSION_MINOR})
if(STANDALONE)
add_definitions(-DCHRONOSHIFT_STANDALONE)
endif()
if(NO_BITFIELDS)
add_definitions(-DCHRONOSHIFT_NO_BITFIELDS)
endif()
# Set where the build results will end up
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Build the launcher
add_subdirectory(launcher)
# Build Chronoshift
add_subdirectory(src)