-
Notifications
You must be signed in to change notification settings - Fork 39
/
CMakeLists.txt
272 lines (237 loc) · 9.04 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
cmake_minimum_required (VERSION 3.8)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules" )
macro(gm_folder targetname)
set_target_properties(${targetname} PROPERTIES FOLDER ${PROJECT_NAME})
endmacro(gm_folder)
macro(gm_folder_with_name targetname foldername)
set_target_properties(${targetname} PROPERTIES FOLDER ${foldername})
endmacro(gm_folder_with_name)
macro(gm_source_group_by_dir source_files)
foreach(sgbd_file ${${source_files}})
string(REGEX REPLACE "(.*)/(.*)" \\1 sgbd_group_name ${sgbd_file})
string(COMPARE EQUAL ${sgbd_file} ${sgbd_group_name} sgbd_nogroup)
string(REPLACE "/" "\\" sgbd_group_name ${sgbd_group_name})
if(sgbd_nogroup)
set(sgbd_group_name ".")
endif(sgbd_nogroup)
source_group(${sgbd_group_name} FILES ${sgbd_file})
endforeach(sgbd_file)
endmacro(gm_source_group_by_dir)
macro(gm_add_msvc_precompiled_header PrecompiledHeader PrecompiledSource SourcesVar)
if(MSVC)
get_filename_component(PrecompiledBasename ${PrecompiledHeader} NAME_WE)
set(PrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${PrecompiledBasename}.pch")
set(Sources ${${SourcesVar}})
set_source_files_properties(${PrecompiledSource}
PROPERTIES COMPILE_FLAGS "/Yc\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\""
OBJECT_OUTPUTS "${PrecompiledBinary}"
)
set_source_files_properties(${Sources}
PROPERTIES COMPILE_FLAGS "/Yu\"${PrecompiledHeader}\" /FI\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\""
OBJECT_DEPENDS "${PrecompiledBinary}"
)
# Add precompiled header to SourcesVar
list(APPEND ${SourcesVar} ${PrecompiledSource})
endif(MSVC)
endmacro(gm_add_msvc_precompiled_header)
#Runtime library
set(RUNTIME_LIBRARY MD)
macro(gm_apply_runtime_library)
if (WIN32)
if (${RUNTIME_LIBRARY} STREQUAL MD)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
elseif(${RUNTIME_LIBRARY} STREQUAL MT)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
endif(${RUNTIME_LIBRARY} STREQUAL MD)
endif(WIN32)
endmacro(gm_apply_runtime_library)
gm_apply_runtime_library()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(GM_TARGET_X86 TRUE)
else(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(GM_TARGET_X86 FALSE)
endif(CMAKE_SIZEOF_VOID_P EQUAL 4)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(GM_TARGET_64 TRUE)
else(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(GM_TARGET_64 FALSE)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
macro(gm_use_gamemachine_dll libraryName)
target_compile_definitions(${libraryName} PRIVATE GM_USE_DLL GM_USE_MEDIA_DLL)
endmacro(gm_use_gamemachine_dll libraryName)
macro(gm_use_gamemachine_qt_dll libraryName)
target_compile_definitions(${libraryName} PRIVATE GM_USE_QT_DLL)
endmacro(gm_use_gamemachine_qt_dll)
macro(gm_link_bullet3 libraryName ACCESS)
target_link_libraries(${libraryName} ${ACCESS} Bullet3Collision)
target_link_libraries(${libraryName} ${ACCESS} Bullet3Common)
target_link_libraries(${libraryName} ${ACCESS} Bullet3Dynamics)
target_link_libraries(${libraryName} ${ACCESS} BulletCollision)
target_link_libraries(${libraryName} ${ACCESS} BulletDynamics)
target_link_libraries(${libraryName} ${ACCESS} BulletInverseDynamics)
target_link_libraries(${libraryName} ${ACCESS} BulletSoftBody)
target_link_libraries(${libraryName} ${ACCESS} LinearMath)
message("GameMachine: ${libraryName} was linked against bullet3.")
endmacro(gm_link_bullet3)
macro(gm_set_target_properties libraryName)
if(MSVC)
set_target_properties(${libraryName} PROPERTIES COMPILE_FLAGS "/W3" )
set_target_properties(${libraryName} PROPERTIES COMPILE_FLAGS "/WX" )
endif(MSVC)
endmacro(gm_set_target_properties)
macro(gm_link_libraries libraryName ACCESS)
message("GameMachine: ${libraryName} was linked against necessary libraries.")
target_link_libraries(${libraryName} ${ACCESS} glew_s)
target_link_libraries(${libraryName} ${ACCESS} lua)
target_link_libraries(${libraryName} ${ACCESS} png_static)
target_link_libraries(${libraryName} ${ACCESS} zlibstatic)
target_link_libraries(${libraryName} ${ACCESS} libjpeg)
target_link_libraries(${libraryName} ${ACCESS} freetype)
target_link_libraries(${libraryName} ${ACCESS} assimp)
target_link_libraries(${libraryName} ${ACCESS} libmad)
target_link_libraries(${libraryName} ${ACCESS} OpenAL)
target_link_libraries(${libraryName} ${ACCESS} tiff)
target_link_libraries(${libraryName} ${ACCESS} tiffxx)
endmacro(gm_link_libraries)
macro(gm_link_x11 libraryName ACCESS)
if(UNIX)
find_package(X11 REQUIRED)
target_link_libraries(${libraryName} ${ACCESS} "X11")
message("GameMachine: ${libraryName} was linked against x11.")
endif(UNIX)
endmacro(gm_link_x11)
macro(gm_link_pthread libraryName ACCESS)
if(UNIX)
# Use pthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
message("GameMachine: ${libraryName} was linked against pthread.")
target_link_libraries(${libraryName} ${ACCESS} pthread)
endif(UNIX)
endmacro(gm_link_pthread)
macro(gm_begin_project)
if(APPLE)
if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif()
endif(APPLE)
if(WIN32)
message("GameMachine: Windows system detected.")
add_definitions(-DGM_WINDOWS)
endif(WIN32)
if(GM_RASPBERRYPI)
message("GameMachine: RespberryPi detected.")
add_definitions(-DGM_RASPBERRYPI)
endif(GM_RASPBERRYPI)
if(UNIX)
message("GameMachine: Unix-Like system (except APPLE) detected.")
add_definitions(-DGM_UNIX)
endif(UNIX)
set(CMAKE_CXX_STANDARD 14)
add_definitions(-DFPM_DEFAULT)
add_definitions(-DUNICODE -D_UNICODE)
if(MSVC)
add_definitions(-DGM_MSVC)
elseif(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-DGM_GCC)
add_definitions(-D_GLIBCXX_USE_WCHAR_T)
endif(MSVC)
# DirectX Environments:
if(GM_USE_DX11 OR GM_BUILD_WRAPPER)
set(GM_DX11_SDK_PATH ${DirectX_D3D11_INCLUDE_DIR})
include_directories(
${GM_DX11_SDK_PATH}
)
link_libraries(
${DirectX_D3D11_LIBRARIES}
shlwapi.lib
)
endif()
endmacro(gm_begin_project)
macro(gm_link_gamemachine_libraries libraryName ACCESS)
gm_link_bullet3(${libraryName} ${ACCESS})
gm_link_x11(${libraryName} ${ACCESS})
gm_link_pthread(${libraryName} ${ACCESS})
gm_link_libraries(${libraryName} ${ACCESS})
endmacro(gm_link_gamemachine_libraries)
macro(gm_copy_resource targetName)
add_custom_command(
TARGET ${targetName}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E tar cv
"$<TARGET_FILE_DIR:${targetName}>/gm.pk0"
--format=zip --
"."
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/media/gmpk"
VERBATIM
)
endmacro(gm_copy_resource)
macro(gm_end_project libraryName)
# do nothing
endmacro(gm_end_project)
macro(gm_gamemachine_project libraryName is_static)
if (${is_static})
message("GameMachine: ${libraryName} is a static gamemachine program.")
target_link_libraries(${libraryName} PUBLIC gamemachine_static)
target_link_libraries(${libraryName} PUBLIC gamemachinemedia_static)
gm_link_gamemachine_libraries(${libraryName} PUBLIC)
else(${is_static})
message("GameMachine: ${libraryName} is a dynamic gamemachine program.")
target_link_libraries(${libraryName} PUBLIC gamemachine)
target_link_libraries(${libraryName} PUBLIC gamemachinemedia)
gm_use_gamemachine_dll(${libraryName})
endif(${is_static})
endmacro(gm_gamemachine_project)
# Options:
option(GM_BUILD_DOCS "Build GameMachine documentation" ON)
option(GM_BUILD_DEMO "Build GameMachine Demos" ON)
option(GM_BUILD_UNITTEST "Build GameMachine Unit Tests" ON)
option(GM_DETECT_MEMORY_LEAK "Detect memory leaking" OFF)
option(GM_RASPBERRYPI "You have to check this if you compile the code in RespberryPi" OFF)
if(WIN32)
find_package( DirectX )
if (${DirectX_FOUND})
message("GameMachine: DirectX found.")
endif()
option(GM_USE_DX11 "Use DirectX11 (SDK required)" ${DirectX_FOUND})
endif(WIN32)
if (WIN32 AND NOT GM_USE_DX11)
option(GM_BUILD_WRAPPER "Build GameMachine Wrapper" ON)
endif()
#About QT
find_package(Qt5Core)
if (${Qt5Core_FOUND})
message("Qt5 Core detected.")
endif(${Qt5Core_FOUND})
find_package(Qt5Widgets)
if (${Qt5Widgets_FOUND})
message("Qt5 Widgets detected.")
endif(${Qt5Widgets_FOUND})
# Environments:
if(GM_BUILD_DOCS)
set (DOXYGEN_SKIP_DOT TRUE)
find_package(Doxygen)
endif(GM_BUILD_DOCS)
if(GM_DETECT_MEMORY_LEAK)
add_definitions(-DGM_DETECT_MEMORY_LEAK)
endif(GM_DETECT_MEMORY_LEAK)
if(GM_USE_DX11)
add_definitions(-DGM_USE_DX11)
endif(GM_USE_DX11)
if(UNIX)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message("GameMachine: Debug build type detected.")
add_definitions(-DGM_DEBUG_FLAG)
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif(UNIX)
# Includes:
set(GM_ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty/zlib")
set(GM_LIBPNG_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty/libpng")
# Projects:
add_subdirectory(src)
if (DOXYGEN_FOUND AND GM_BUILD_DOCS)
add_subdirectory(doc gamemachinedocs)
endif(DOXYGEN_FOUND AND GM_BUILD_DOCS)