-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
385 lines (305 loc) · 14.6 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
cmake_minimum_required ( VERSION 2.6 )
# TODO: Use CMake v2.8.12 OSX RPath features
# http://www.kitware.com/blog/home/post/510
# cmake_minimum_required ( VERSION 2.8.12 )
# CMake Environment
# Opt out of using CMake v3.0 PROJECT_VERSION variables management for the
# project.
# http://www.cmake.org/cmake/help/v3.0/command/project.html#command:project
if( POLICY CMP0048 )
cmake_policy( SET CMP0048 OLD )
endif( POLICY CMP0048 )
set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/" )
set ( CMAKE_TEMPLATE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates" )
# Set the install prefix to the current build folder if the user has not chosen
# their own prefix path.
if ( NOT CMAKE_INSTALL_PREFIX )
set ( CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}" CACHE PATH "Install path prefix" )
endif ( NOT CMAKE_INSTALL_PREFIX )
# Project configuration
set ( PROJECT_VERSION_MAJOR 0 )
set ( PROJECT_VERSION_MINOR 11 )
set ( PROJECT_VERSION_PATCH 0 )
# Project options
option ( DEBUG "Enable building with debugging features" off )
option ( DEBUG_ASSERT "Enable building with run-time assertions" off )
option ( DOCS "Generate HTML based API documentation with Doxygen" off )
project ( ttcards ) # Sets PROJECT_NAME variable for us
# Platform detection
include ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform.cmake" )
if ( DEBUG )
set ( CMAKE_VERBOSE_MAKEFILE ON )
if ( NOT PLATFORM_WINDOWS )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D NOM_DEBUG -Wall -Wunused -O0" ) #-D_GLIBCXX_DEBUG
else ( PLATFORM_WINDOWS )
# TODO: split these options up like we have for other platforms
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D NOM_DEBUG /D NOM_DEBUG_ASSERT" )
endif ( NOT PLATFORM_WINDOWS )
set ( CMAKE_BUILD_TYPE "Debug" )
message ( STATUS "Building ${PROJECT_NAME} with debugging." )
message ( STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}" )
else () # Build with optimizations for maximum speed and minimal size
set ( CMAKE_BUILD_TYPE "Release" )
message ( STATUS "Building ${PROJECT_NAME} with high speed, low drag!" )
message ( STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}" )
endif ( DEBUG )
if ( DEBUG_ASSERT )
add_definitions ( "-DNOM_DEBUG_ASSERT" ) # Enable NOM_ASSERT macros
message ( STATUS "Run-time assertions are ON." )
else ( NOT DEBUG_ASSERT )
add_definitions ( "-DNDEBUG" ) # Disable NOM_ASSERT macros
message ( STATUS "Run-time assertions are OFF." )
endif ( DEBUG_ASSERT )
# Utility macros
include ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros.cmake" )
# Relative path from project root to compiled source files
set ( SRC_DIR "src" )
# Relative path from project root to header files
set ( TTCARDS_HEADERS_DIR "include" )
# Relative path from the from project root to game resources
set ( TTCARDS_RESOURCES_DIR "Resources" )
# Additional flags to pass add_executable
set ( EXECUTABLE_FLAGS "" )
# Files used with documentation generation
set ( PROJECT_DOXYGEN_DIR "${PROJECT_SOURCE_DIR}/${TTCARDS_RESOURCES_DIR}/doxygen" )
# OS X application bundle variables used in generating the Info.plist
set ( BUNDLE_TEMPLATE_PLIST "${CMAKE_TEMPLATE_PATH}/Info.plist.in" )
set ( BUNDLE_NAME "TTcards" )
set ( BUNDLE_DESCRIPTION "Triple Triad Remake" )
set ( BUNDLE_ICON "icon.icns" )
set ( BUNDLE_IDENTIFIER "org.i8degrees.${PROJECT_NAME}" )
set ( BUNDLE_COPYRIGHT_YEAR "2013" )
set ( BUNDLE_COPYRIGHT_NAME "Jeffrey Carpenter" )
# Installation paths; CMAKE_INSTALL_PREFIX will be appended to these.
# Depending on the install profile, these paths are updated; such as when we
# are building an OS X application bundle.
set ( INSTALL_APP_PATH "bin" )
set ( INSTALL_RESOURCES_PATH "share/${PROJECT_NAME}" )
set ( INSTALL_DOCS_PATH "share/doc/${PROJECT_NAME}" )
set ( INSTALL_DOCS_HELP_PATH "${INSTALL_DOCS_PATH}" )
set ( INSTALL_GENERATED_DOCS_PATH "share/doc/${PROJECT_NAME}" )
include ( "${PROJECT_SOURCE_DIR}/cmake/uninstall.cmake" )
# CMAKE_SYSTEM_PREFIX_PATH is searched to find libraries when the find_package
# command is used
message ( STATUS "Library Search Prefix: ${CMAKE_SYSTEM_PREFIX_PATH}" )
# Installation prefix path set for our project
message ( STATUS "Installation Prefix: ${CMAKE_INSTALL_PREFIX}" )
if ( DOCS ) # Generation of documentation via doxygen option
include ( "${PROJECT_SOURCE_DIR}/cmake/doxygen.cmake" )
endif ( DOCS )
# Third-party dependencies
if( PLATFORM_WINDOWS )
# Set the search path for where to find nomlib's CMake package script
if( PLATFORM_ARCH STREQUAL "x86" )
set( NOMLIB_ROOT "$ENV{SystemDrive}/Program Files (x86)/nomlib" )
elseif( PLATFORM_ARCH STREQUAL "x64" )
set( NOMLIB_ROOT "$ENV{SystemDrive}/Program Files/nomlib" )
endif( PLATFORM_ARCH STREQUAL "x86" )
endif( PLATFORM_WINDOWS )
# External dependencies prefix (absolute path to nomlib's third-party directory)
if( NOT NOMLIB_DEPS_PREFIX )
message( FATAL_ERROR "The location of the third-party dependencies must be set. See README.md for details." )
else()
# Used by nomlib's find module
set( NOMLIB_DEPS_ROOT ${NOMLIB_DEPS_PREFIX} CACHE PATH
"nomlib's third-party dependencies path" )
message( STATUS "NOMLIB_DEPS_ROOT: ${NOMLIB_DEPS_PREFIX}" )
endif()
find_package( nomlib COMPONENTS
core file math system graphics gui ptree serializers REQUIRED
OPTIONAL_COMPONENTS audio
)
if( PLATFORM_WINDOWS )
# Redistribution paths must be absolute, a directory and end with a trailing
# slash character (these are fed to CMake's install command). Only filenames
# with the extension of '.dll' (case-insensitive) will be copied.
set( SDL2_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/SDL2/lib/${PLATFORM_ARCH}/" )
set( SDL2_IMAGE_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/SDL2_image/lib/${PLATFORM_ARCH}/" )
set( SDL2_TTF_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/SDL2_ttf/lib/${PLATFORM_ARCH}/" )
if( PLATFORM_ARCH STREQUAL "x86" )
set( OPENAL_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/OpenAL/libs/Win32/" )
elseif( PLATFORM_ARCH STREQUAL "x64" )
set( OPENAL_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/OpenAL/libs/Win64/" )
endif( PLATFORM_ARCH STREQUAL "x86" )
set( LIBSNDFILE_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/libsndfile/lib/${PLATFORM_ARCH}/" )
set( LIBROCKET_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/libRocket/lib/${PLATFORM_ARCH}/" )
set( LIBROCKET_FREETYPE_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/libRocket/bin/${PLATFORM_ARCH}/" )
set( MSVCPP_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/msvcpp2013/${PLATFORM_ARCH}/" )
elseif( PLATFORM_OSX )
# FIXME: This file needs its RPATH modified; it is **not** being used as the
# library for executables yet. We are using brew's version installed at
# /usr/local
set( LIBROCKET_FREETYPE_REDIST_DIR "${NOMLIB_DEPS_PREFIX}/librocket/bin/libfreetype.6.dylib" )
elseif( PLATFORM_LINUX )
# TODO
endif( PLATFORM_WINDOWS )
# Project source tree to build
include( "${SRC_DIR}/CMakeLists.txt" )
# Installation phase
if ( PLATFORM_OSX )
# CMAKE_INSTALL_PREFIX = ttcards.app
# Set the run-time library search path for where to find external library
# dependencies
set ( RUNTIME_LIBRARIES_SEARCH_PATH
"@executable_path/../Frameworks"
"@executable_path/../Frameworks/nomlib-core.framework/Frameworks"
"@executable_path/../Frameworks/nomlib-system.framework/Frameworks"
"@executable_path/../Frameworks/nomlib-audio.framework/Frameworks"
"@executable_path/../Frameworks/nomlib-gui.framework/Libraries"
)
if ( OSXAPP )
set ( EXECUTABLE_FLAGS "MACOSX_BUNDLE" )
add_executable ( ${PROJECT_NAME} ${EXECUTABLE_FLAGS} ${TTCARDS_SOURCE} )
set ( INSTALL_APP_PATH "${BUNDLE_NAME}.app" )
set ( INSTALL_ROOT_PATH "${INSTALL_APP_PATH}/Contents" )
set ( INSTALL_RESOURCES_PATH "${INSTALL_ROOT_PATH}" )
set ( INSTALL_DOCS_PATH "${INSTALL_RESOURCES_PATH}/Resources" )
set ( INSTALL_DOCS_HELP_PATH "${INSTALL_DOCS_PATH}" )
set ( INSTALL_GENERATED_DOCS_PATH "${INSTALL_DOCS_PATH}/Documentation" )
# Directory path to fixing up external frameworks with install_name_tool(1)
set ( INSTALL_BINARY_PATH "${INSTALL_ROOT_PATH}/MacOS/${PROJECT_NAME}" )
# Relative path for where to install our external dependencies
set ( INSTALL_FRAMEWORK_PATH "${INSTALL_ROOT_PATH}/Frameworks" )
# Generate Info.plist for distribution within our soon-to-be application bundle
set_target_properties ( ${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST
"${BUNDLE_TEMPLATE_PLIST}"
MACOSX_BUNDLE_BUNDLE_NAME
"${BUNDLE_NAME}"
MACOSX_BUNDLE_ICON_FILE
"${BUNDLE_ICON}"
MACOSX_BUNDLE_INFO_STRING
"${BUNDLE_DESCRIPTION} version ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} by ${BUNDLE_COPYRIGHT_NAME}"
MACOSX_BUNDLE_GUI_IDENTIFIER
${BUNDLE_IDENTIFIER}
MACOSX_BUNDLE_SHORT_VERSION_STRING
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
MACOSX_BUNDLE_LONG_VERSION_STRING
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-${CMAKE_BUILD_TYPE}"
MACOSX_BUNDLE_BUNDLE_VERSION
"${CMAKE_VERSION}"
MACOSX_BUNDLE_COPYRIGHT
"Copyright (c) ${BUNDLE_COPYRIGHT_YEAR} ${BUNDLE_COPYRIGHT_NAME} All rights reserved."
)
add_rpath ( "${RUNTIME_LIBRARIES_SEARCH_PATH}" "${INSTALL_BINARY_PATH}" )
# Bundle our dependencies into our application bundle
install( DIRECTORY
${NOMLIB_LIBRARIES} # nomlib-component.framework
DESTINATION "${INSTALL_FRAMEWORK_PATH}"
PATTERN ".*" EXCLUDE # do not include dotfiles
)
# CPack refuses to work with me on anything other than a single dot as the
# destination target path when we are building a package.
install ( TARGETS ${PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}" )
#set ( INSTALL_APP_PATH "${CMAKE_INSTALL_PREFIX}" )
install ( FILES
"${PROJECT_SOURCE_DIR}/${TTCARDS_RESOURCES_DIR}/config.json"
# DESTINATION "${INSTALL_APP_PATH}/Resources"
DESTINATION "$ENV{HOME}/Documents/ttcards"
)
endif ( OSXAPP )
# ...PLATFORM_OSX...
elseif ( PLATFORM_WINDOWS )
set ( INSTALL_APP_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}" )
set ( INSTALL_RESOURCES_PATH "${INSTALL_APP_PATH}" )
# TODO:
#set ( INSTALL_DOCS_PATH "share/doc/${PROJECT_NAME}" )
#set ( INSTALL_DOCS_HELP_PATH "${INSTALL_DOCS_PATH}" )
#set ( INSTALL_GENERATED_DOCS_PATH "share/doc/${PROJECT_NAME}" )
# Build as console app -- shows cmd.exe window for logging -- only when
# debugging is toggled on
if ( NOT DEBUG )
set ( EXECUTABLE_FLAGS "WIN32" ) # Implies WIN_MAIN
else ( DEBUG )
# MSVCPP should default to Console if we set EXECUTABLE_FLAGS empty
set ( EXECUTABLE_FLAGS "" )
endif ( NOT DEBUG )
add_executable ( ${PROJECT_NAME} ${EXECUTABLE_FLAGS} ${TTCARDS_SOURCE} )
# FIXME: Install binaries to our platform-dependent paths we've now set
#install ( TARGETS ${PROJECT_NAME} DESTINATION "${INSTALL_APP_PATH}" )
# Install library dependencies into binary output directory
install ( DIRECTORY
"${SDL2_REDIST_DIR}"
"${SDL2_IMAGE_REDIST_DIR}"
"${SDL2_TTF_REDIST_DIR}"
"${OPENAL_REDIST_DIR}"
"${LIBSNDFILE_REDIST_DIR}"
"${MSVCPP_REDIST_DIR}"
"${LIBROCKET_REDIST_DIR}"
"${LIBROCKET_FREETYPE_REDIST_DIR}"
DESTINATION
"${INSTALL_APP_PATH}"
FILES_MATCHING PATTERN "*.dll"
)
elseif ( PLATFORM_LINUX ) # POSIX install layout
# TODO: set paths, etc. like we do above with OSX & Windows platforms
add_executable ( ${PROJECT_NAME} ${EXECUTABLE_FLAGS} ${TTCARDS_SOURCE} )
# Install binaries to our platform-dependent paths we've now set
install ( TARGETS ${PROJECT_NAME} DESTINATION "${INSTALL_APP_PATH}" )
endif ( PLATFORM_OSX )
# FIXME: If it weren't for the infinite recursion issue we have with the OS X
# Application Bundle, we'd be able to use a single install targets line here:
#
# install ( TARGETS ${PROJECT_NAME} DESTINATION "${INSTALL_APP_PATH}" )
# Install game resources
install ( DIRECTORY "${TTCARDS_RESOURCES_DIR}"
DESTINATION "${INSTALL_RESOURCES_PATH}"
OPTIONAL
PATTERN ".*" EXCLUDE # do not include dotfiles
PATTERN "Documentation" EXCLUDE # do not include documentation here
)
# Install software license & general project information
install ( FILES
${PROJECT_SOURCE_DIR}/LICENSE.md
${PROJECT_SOURCE_DIR}/README.md
DESTINATION "${INSTALL_DOCS_PATH}"
)
# Install general game information -- rules, how to play, etc.
install ( DIRECTORY
${PROJECT_SOURCE_DIR}/${TTCARDS_RESOURCES_DIR}/Documentation
DESTINATION "${INSTALL_DOCS_HELP_PATH}"
PATTERN ".*" EXCLUDE # do not include dotfiles
)
if ( DOCS )
# Install generated documentation files
install ( DIRECTORY ${PROJECT_BINARY_DIR}/docs/html
DESTINATION "${INSTALL_GENERATED_DOCS_PATH}"
PATTERN ".*" EXCLUDE # do not include dotfiles
)
endif ( DOCS )
# Linking phase
target_link_libraries( ${PROJECT_NAME} ${NOMLIB_LIBRARIES}
${NOMLIB_DEPENDENCIES}
)
# Auto-generated build-time variables result in modification of the built
# binary's run-time execution.
#
# CMake dependency variables (of which control the location of this insert)
#
# a) PROJECT_VERSION_*
# b) CMAKE_INSTALL_PREFIX
#
# This means that we must include this configured file *AFTER* any and all
# modifications -- that matter to us -- occur in this build script.
configure_file (
"${CMAKE_TEMPLATE_PATH}/version.cpp.in"
"${PROJECT_SOURCE_DIR}/${SRC_DIR}/version.cpp"
)
configure_file ( "${CMAKE_TEMPLATE_PATH}/version.hpp.in"
"${PROJECT_SOURCE_DIR}/${SRC_DIR}/version.hpp"
)
# TODO: Windows platform support
if ( NOT PLATFORM_WINDOWS )
# CPack configuration
include ( "${PROJECT_SOURCE_DIR}/cmake/CPackConfig.cmake" )
include ( InstallRequiredSystemLibraries )
# Platform specific generator presets
if ( PLATFORM_OSX )
set ( CPACK_GENERATOR "DragNDrop" )
elseif ( PLATFORM_LINUX )
set ( CPACK_GENERATOR "DEB" )
elseif ( PLATFORM_UNKNOWN )
set ( CPACK_GENERATOR "ZIP" )
endif ( PLATFORM_OSX )
include ( CPack )
endif ( NOT PLATFORM_WINDOWS )