forked from stuntrally/stuntrally3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
265 lines (207 loc) · 7.66 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
# This CMake is for CI/CD auto builds in github Actions tab.
# See in docs/Building.md and BuildingVS.md for building from sources.
# Conan is used to get SR deps, or not if using FORCE_SYSTEM_DEPENDENCIES.
cmake_minimum_required( VERSION 3.16 )
# Include path for additional CMake library finding scripts
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/" ${CMAKE_MODULE_PATH})
# Add a sensible build type default and warning because empty means no optimization and no debug info.
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release" CACHE STRING "Configuration types")
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.22")
cmake_policy(SET CMP0127 OLD)
endif ()
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
include(CMakeDependentOption)
include(Macros)
include(FeatureSummary)
if (NOT WIN32)
find_package(PkgConfig)
endif ()
project( StuntRally3 )
# User Options to disable building components --------
option(BUILD_GAME "Build the game binary." ON)
option(BUILD_EDITOR "Build the track editor." ON)
option(BUILD_GAME_SERVER "Build the game list server app." ON)
option(BUILD_TRANSL_TOOL "Build the tool for translation updating, it creates .pot" ON)
# Linux prefers lower-case exe names
if (WIN32 OR APPLE)
set(GAME_EXE StuntRally3)
set(EDITOR_EXE SR-Editor3)
set(SERVER_EXE SR-GameServer)
set(TRANSL_EXE SR-Translator)
else ()
set(GAME_EXE stuntrally3)
set(EDITOR_EXE sr-editor3)
set(SERVER_EXE sr-gameserver)
set(TRANSL_EXE sr-translator)
endif ()
# Avoid source tree pollution
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not permitted. Make a separate folder for building:\nmkdir build; cd build; cmake ..\nBefore that, remove the files already created:\nrm -rf CMakeCache.txt CMakeFiles")
endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
# exe path ----
set( EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}" )
# Set CXX compile flags
set(CMAKE_CXX_STANDARD 17)
if (CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "GCC detected, adding compile flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif ()
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
add_definitions(-DUNICODE -D_UNICODE)
endif ()
# deps ----
# Check for dependencies
include(DependenciesConfig)
macro(add_recursive dir retVal)
file(GLOB GLOB_RESULT ${dir}/*.h ${dir}/*.cpp ${dir}/*.c)
list(APPEND ${retVal} ${GLOB_RESULT})
endmacro()
message(STATUS "---------- SR sources")
# Compiler ----
set(COMMON_SRC_DIRS
# not really sources
data/gui
data/materials
data/particles
# libs
./src/btOgre2
# sources
./src/common
./src/common/data
./src/common/MessageBox
./src/road
./src/OgreCommon
./src/OgreCommon/System
./src/OgreCommon/System/Android
./src/OgreCommon/System/Desktop
./src/OgreCommon/Threading
./src/OgreCommon/Utils
./src/Terra
./src/Terra/Hlms
./src/Terra/Hlms/PbsListener
# both game and ed meh-
#./src/vdriftCommon
./src/sound
./src/vdrift
)
# game
set( GAME_SRC_DIRS ${COMMON_SRC_DIRS} )
list( APPEND GAME_SRC_DIRS ./src/game )
list( APPEND GAME_SRC_DIRS ./src/game/data )
#list( APPEND GAME_SRC_DIRS ./src/sound )
#list( APPEND GAME_SRC_DIRS ./src/vdrift )
list( APPEND GAME_SRC_DIRS ./src/oics ) # libs
list( APPEND GAME_SRC_DIRS ./src/network )
# editor
set( EDITOR_SRC_DIRS ${COMMON_SRC_DIRS} )
list( APPEND EDITOR_SRC_DIRS ./src/editor )
# exe list game and editor
if (BUILD_GAME)
list( APPEND EXE_LIST ${GAME_EXE} )
endif ()
if (BUILD_EDITOR)
list( APPEND EXE_LIST ${EDITOR_EXE} )
endif ()
## Executables
##------------------------------------------------------------------------------------------------------
foreach( EXE ${EXE_LIST} )
message(STATUS "Configuring: " ${EXE})
# sources ----
set(EXE_SOURCES "")
if (${EXE} STREQUAL ${EDITOR_EXE}) # ed
set(SRC_DIRS ${EDITOR_SRC_DIRS})
else ()
set(SRC_DIRS ${GAME_SRC_DIRS})
endif ()
foreach (subdir ${SRC_DIRS})
#message( STATUS ${subdir} )
add_recursive(${subdir} EXE_SOURCES)
endforeach ()
# exe ----
add_executable(${EXE} WIN32 ${EXE_SOURCES})
# Generate source groups for use in IDEs
source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${EXE_SOURCES})
foreach (subdir ${SRC_DIRS})
#message( STATUS ${subdir} )
target_include_directories(${EXE} PRIVATE ${subdir})
endforeach ()
# pch.h
if (${EXE} STREQUAL ${EDITOR_EXE}) # ed
set_target_properties(${EXE} PROPERTIES COMPILE_FLAGS "-DSR_EDITOR")
target_precompile_headers(${EXE} PRIVATE src/editor/pch.h)
else ()
target_precompile_headers(${EXE} PRIVATE src/game/pch.h)
endif ()
target_link_libraries(
${EXE}
PRIVATE
boost::boost
Bullet::Bullet
enet::enet
MyGUI::MyGUI
Ogg::ogg
OGRE::OGRE
OpenAL::OpenAL
rapidjson
SDL2::SDL2
Threads::Threads
tinyxml2::tinyxml2
Vorbis::vorbis
Vorbis::vorbisfile
)
if (WIN32)
install(TARGETS ${EXE} DESTINATION .)
# add a post-build command to copy DLLs beside the executable
add_custom_command(
TARGET ${EXE}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-DEXECUTABLE="$<TARGET_FILE:${EXE}>"
-DBIN_DIR="${CMAKE_BINARY_DIR}"
-DLIB_DIR="$<TARGET_FILE_DIR:${EXE}>"
-P "${CMAKE_SOURCE_DIR}/CMake/FixupBundle.cmake"
)
endif ()
endforeach ()
## Translations tool
##------------------------------------------------------------------------------------------------------
if (BUILD_TRANSL_TOOL)
message(STATUS "Configuring: " ${TRANSL_EXE})
add_executable(${TRANSL_EXE} WIN32 ./src/transl/main.cpp)
target_include_directories(${TRANSL_EXE} PRIVATE ./src/transl)
target_precompile_headers(${TRANSL_EXE} PRIVATE src/transl/pch.h)
endif()
message(STATUS "---------- SR end")
# Install targets
# -----------------------
if (WIN32)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/data/ DESTINATION . PATTERN ".git/*" EXCLUDE)
install(DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/ DESTINATION . FILES_MATCHING PATTERN "*.dll" )
install(FILES ${CMAKE_SOURCE_DIR}/dist/plugins_Windows.cfg DESTINATION . RENAME plugins.cfg)
install(FILES ${CMAKE_SOURCE_DIR}/dist/resources2.cfg DESTINATION .)
endif ()
# CPack
# -----------------------
set(CPACK_PACKAGE_NAME "Stunt Rally")
set(CPACK_PACKAGE_FILE_NAME "stunt-rally-${CMAKE_PROJECT_VERSION}")
set(CPACK_PACKAGE_DESCRIPTION "Stunt Rally is a 3D racing game with own Track Editor")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Stunt Rally is a 3D racing game with own Track Editor")
set(CPACK_PACKAGE_VENDOR "Crystal Hammer")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_EXECUTABLES "StuntRally3" "Stunt Rally 3")
if (WIN32)
set(CPACK_GENERATOR INNOSETUP)
set(CPACK_ADD_REMOVE TRUE)
set(CPACK_CREATE_DESKTOP_LINKS "StuntRally3" "Stunt Rally 3")
set(CPACK_INNOSETUP_ALLOW_CUSTOM_DIRECTORY ON)
set(CPACK_INNOSETUP_USE_MODERN_WIZARD ON)
# set(CPACK_INNOSETUP_ICON_FILE "${CMAKE_CURRENT_SOURCE_DIR}/sr3.ico")
set(CPACK_INNOSETUP_SETUP_AppId "{{67B750C8-691F-4AAB-A79C-7557314B24A4}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
# set(CPACK_INNOSETUP_SETUP_DiskSpanning True)
else ()
set(CPACK_GENERATOR 7Z)
endif ()
include(CPack)
feature_summary(WHAT ALL)