forked from OpenWarzone/Warzone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
218 lines (184 loc) · 8.53 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
cmake_minimum_required(VERSION 2.8.8)
# For checks in subdirectories
set(InWarzone TRUE)
# Project name
set(ProjectName "Warzone" CACHE STRING "Project Name")
project(${ProjectName})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
# Customizable options
option(BuildPortableVersion "Build portable version (does not read or write files from your user/home directory" OFF)
option(BuildMPEngine "Whether to create projects for the MP client (Warzone.exe)" ON)
option(BuildMPDed "Whether to create projects for the MP dedicated server (Warzoneded.exe)" ON)
option(BuildMPGame "Whether to create projects for the MP server-side gamecode (jampgamex86.dll)" ON)
option(BuildMPCGame "Whether to create projects for the MP clientside gamecode (cgamex86.dll)" ON)
option(BuildMPUI "Whether to create projects for the MP UI code (uix86.dll)" ON)
option(BuildMPWarzone "Whether to create projects for the EXPERIMENTAL MP Warzone renderer (rd-warzone_x86.dll)" ON)
# Customizable libraries
if(WIN32)
option(UseInternalOpenAL "Whether to use the included OpenAL instead of a locally installed one" ON)
option(UseInternalZlib "Whether to use the included zlib instead of a locally installed one" ON)
endif()
if(WIN32)
option(UseInternalPNG "Whether to use the included libpng instead of a locally installed one" ON)
else()
option(UseInternalPNG "Whether to use the included libpng instead of a locally installed one" OFF)
endif()
if(APPLE)
option(MakeApplicationBundles "Whether to build .app application bundles for engines built" ON)
else()
set(MakeApplicationBundles OFF)
endif()
option(PackageDir "Where to place the installer/package." "${CMAKE_SOURCE_DIR}/package")
# Custom CMake Modules needed
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/CMakeModules")
# Arch Suffix
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
set(ARCH_BITS 64)
if(WIN32)
set(Architecture "x86_64")
set(WIN64 TRUE)
else()
set(Architecture "x86_64")
endif()
else()
set(ARCH_BITS 32)
if(WIN32)
set(Architecture "x86")
set(WIN64 FALSE)
elseif(APPLE)
set(Architecture "x86")
else()
set(Architecture "i386")
endif()
endif()
message("Architecture is ${Architecture}")
# Current Git SHA1 hash
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
# TODO: actually use the Git SHA1 for something?
message("Git revision is ${GIT_SHA1}")
# Binary names
set(MPEngine "Warzone.${Architecture}")
set(MPDed "Warzoneded.${Architecture}")
set(MPGame "jampgame${Architecture}")
set(MPCGame "cgame${Architecture}")
set(MPUI "ui${Architecture}")
set(MPWarzone "rd-warzone_${Architecture}")
# Library names
set(MPBotLib "botlib")
# Paths
set(MPDir "${CMAKE_SOURCE_DIR}/codemp")
# Common settings
if(WIN32)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2 /Qvec-report:1 /MP /openmp /Ox /Ot /GT /Qpar") # enable parallel compilation
# mark 32 bit executables large address aware so they can use > 2GB address space
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
endif(MSVC)
if(WIN64)
if(MSVC)
set(SharedDefines "WIN64" "_CRT_SECURE_NO_WARNINGS")
# mark 32 bit executables large address aware so they can use > 2GB address space
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
else()
set(SharedDefines "WIN64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2 /Qvec-report:1 /openmp /Ox /Ot /GT /Qpar")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2 /Qvec-report:1 /openmp /Ox /Ot /GT /Qpar")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:SSE2 /Qvec-report:1 /openmp /MD /Ox /Ot /GT /Qpar /Ob2 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /arch:SSE2 /Qvec-report:1 /openmp /MD /Zi /Ox /Ot /GT /Qpar /Ob2 /D NDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /arch:SSE2 /Qvec-report:1 /openmp /D_DEBUG /MDd /Zi /Od /Ot /GT /Qpar /Ob0 /RTC1")
# mark 32 bit executables large address aware so they can use > 2GB address space
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
endif()
else()
if(MSVC)
set(SharedDefines "_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2 /Qvec-report:1 /openmp /Ox /Ot /GT /Qpar")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2 /Qvec-report:1 /openmp /Ox /Ot /GT /Qpar")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:SSE2 /Qvec-report:1 /openmp /MD /Ox /Ot /GT /Qpar /Ob2 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /arch:SSE2 /Qvec-report:1 /openmp /MD /Zi /Ox /Ot /GT /Qpar /Ob2 /D NDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /arch:SSE2 /Qvec-report:1 /openmp /D_DEBUG /MDd /Zi /Od /Ot /GT /Qpar /Ob0 /RTC1")
# mark 32 bit executables large address aware so they can use > 2GB address space
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
endif()
endif()
else()
if (APPLE)
set(SharedDefines "MACOS_X")
# set(SharedDefines "MACOS_X" "_M_IX86")
#else()
# set(SharedDefines "__linux__" "_M_IX86")
endif()
# removes the -rdynamic flag at linking (which causes crashes for some reason)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# additional flags for debug configuration
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -fopenmp")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -fopenmp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mAVX -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mAVX -fopenmp")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -fopenmp")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -fopenmp")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-comment")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstackrealign")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-but-set-variable")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpmath=sse")
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-comment")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-comment")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-writable-strings")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-comment")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")
endif()
endif()
if (NOT CMAKE_BUILD_TYPE)
message("No build type selected, default to RELEASE")
set(CMAKE_BUILD_TYPE "RELEASE")
endif()
# Settings
if(BuildPortableVersion)
set(SharedDefines ${SharedDefines} "_PORTABLE_VERSION")
endif()
set(WarzoneLibDir "${CMAKE_SOURCE_DIR}/lib")
if(NOT MSVC)
# CMake already defines _DEBUG for MSVC.
set(DebugDefines ${DebugDefines} "_DEBUG")
endif()
set(ReleaseDefines "FINAL_BUILD")
# Add projects
add_subdirectory(${MPDir})
# CPack for installer creation
# TODO: Which version are we?
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "1")
set(CPACK_PACKAGE_VERSION_PATCH "0")
# I'm just not appending the version for now
set(CPACK_PACKAGE_FILE_NAME "Warzone-${CMAKE_SYSTEM_NAME}-${Architecture}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An improved Jedi Academy")
set(CPACK_PACKAGE_VENDOR "JACoders")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_DIRECTORY ${PACKAGE_DIR})
set(CPACK_BINARY_ZIP ON) # always create at least a zip file
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) # prevent additional directory in zip
include(CPack)