forked from LibreSprite/LibreSprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
333 lines (260 loc) · 10.2 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
# Aseprite | Copyright (C) 2001-2016 David Capello
# LibreSprite | Copyright (C) 2021 LibreSprite contributors
cmake_minimum_required(VERSION 3.4)
enable_testing()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are:
None Debug Release RelWithDebInfo Profile."
FORCE)
endif()
# Restrict configuration types to the selected build type.
# Note: This needs to be done before the project command
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_BUILD_TYPE}" CACHE INTERNAL "internal")
# LibreSprite project
project(libresprite C CXX)
# This required for KDE/Qt destop integration, which sets BUILD_SHARED_LIBS to
# TRUE by default
set(BUILD_SHARED_LIBS off)
######################################################################
# Options (these can be specified in cmake command line or modifying
# CMakeCache.txt)
option(WITH_WEBP_SUPPORT "Enable support to load/save .webp files" off)
option(WITH_GTK_FILE_DIALOG_SUPPORT "Enable support for the experimental native GTK File Dialog" off)
option(WITH_DEPRECATED_GLIB_SUPPORT "Enable support for older glib versions" off)
option(WITH_DESKTOP_INTEGRATION "Enable desktop integration modules" off)
option(WITH_QT_THUMBNAILER "Enable kde5/qt5 thumnailer" off)
option(USE_SHARED_ALLEGRO4 "Use shared Allegro 4 library (without resize support)" off)
option(ENABLE_MEMLEAK "Enable memory-leaks detector (only for developers)" off)
option(ENABLE_TESTS "Enable the unit tests" off)
option(FULLSCREEN_PLATFORM "Enable fullscreen by default" off)
if(APPLE)
# On OS X Allegro isn't supported anymore
set(USE_ALLEG4_BACKEND off)
option(USE_SDL2_BACKEND "Use SDL2 backend" on)
else()
option(USE_ALLEG4_BACKEND "Use Allegro 4 backend" off)
option(USE_SDL2_BACKEND "Use SDL2 backend" on)
endif()
######################################################################
# Profile build type
list(APPEND CMAKE_BUILD_TYPES Profile)
mark_as_advanced(
CMAKE_C_FLAGS_PROFILE
CMAKE_CXX_FLAGS_PROFILE
CMAKE_EXE_LINKER_FLAGS_PROFILE)
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS_PROFILE "-pg"
CACHE STRING "Profiling C flags")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE}"
CACHE STRING "Profiling C++ flags")
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "-pg"
CACHE STRING "Profiling linker flags")
endif()
if(MSVC)
set(CMAKE_C_FLAGS_PROFILE "/MD /Zi /Ox /Gd"
CACHE STRING "Profiling C flags")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE}"
CACHE STRING "Profiling C++ flags")
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "/PROFILE /DEBUG"
CACHE STRING "Profiling linker flags")
endif()
######################################################################
# Directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
# We need to specify the output for each configuration to make it work
# on Visual Studio solutions.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_PROFILE "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_PROFILE "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_PROFILE "${CMAKE_BINARY_DIR}/bin")
set(LOADPNG_DIR ${CMAKE_SOURCE_DIR}/third_party/loadpng)
set(SIMPLEINI_DIR ${CMAKE_SOURCE_DIR}/third_party/simpleini)
set(DUKTAPE_DIR ${CMAKE_SOURCE_DIR}/third_party/duktape)
set(MODP_B64_DIR ${CMAKE_SOURCE_DIR}/third_party/modp_b64)
# Search in the "cmake" directory for additional CMake modules.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Put libraries into "lib".
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
######################################################################
# Common definitions to compile all sources (app code and third party)
# Debug C/C++ flags
if(CMAKE_BUILD_TYPE STREQUAL Debug)
add_definitions(-DDEBUGMODE -D_DEBUG)
else()
add_definitions(-DNDEBUG)
endif()
# Fix to compile gtest with VC11 (2012)
if(MSVC_VERSION EQUAL 1700)
add_definitions(-D_VARIADIC_MAX=10)
endif()
if(NOT WIN32 AND NOT APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
# zlib
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
# libpng
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIRS})
# libwebp
if(WITH_WEBP_SUPPORT)
find_package(PkgConfig)
pkg_check_modules(WEBP libwebp REQUIRED)
include_directories(${WEBP_INCLUDE_DIR})
endif()
# tinyxml
find_library(TINYXML_LIBRARY NAMES tinyxml)
find_path(TINYXML_INCLUDE_DIR NAMES tinyxml.h)
include_directories(${TINYXML_INCLUDE_DIR})
# pixman
find_library(PIXMAN_LIBRARY NAMES pixman pixman-1)
find_path(PIXMAN_INCLUDE_DIR NAMES pixman.h PATH_SUFFIXES pixman-1)
include_directories(${PIXMAN_INCLUDE_DIR})
# freetype
find_package(Freetype REQUIRED)
include_directories(${FREETYPE_INCLUDE_DIRS})
find_package(GIF REQUIRED)
include_directories(${GIF_INCLUDE_DIRS})
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
find_package(JPEG REQUIRED)
include_directories(${JPEG_INCLUDE_DIRS})
if(USE_ALLEG4_BACKEND)
set(LOADPNG_LIBRARY loadpng)
set(LOADPNG_INCLUDE_DIR ${LOADPNG_DIR})
include_directories(${LOADPNG_INCLUDE_DIR})
endif()
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})
# simpleini
include_directories(${SIMPLEINI_DIR})
######################################################################
# Platform specific stuff
set(PLATFORM_LIBS)
# Allegro 4 backend
if(USE_ALLEG4_BACKEND)
add_definitions(-DUSE_ALLEG4_BACKEND)
add_definitions(-DALLEGRO_NO_FIX_ALIASES)
if(USE_SHARED_ALLEGRO4)
# Find the shared Allegro 4 library
find_library(LIBALLEGRO4_LIBRARY alleg)
find_path(LIBALLEGRO4_INCLUDE_DIR allegro.h)
if(NOT LIBALLEGRO4_LIBRARY)
message(FATAL_ERROR "Allegro 4 not found")
endif()
# Get flags to link programs using allegro-config program
execute_process(COMMAND allegro-config --libs --shared
OUTPUT_VARIABLE LIBALLEGRO4_LINK_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(LIBALLEGRO4_LINK_FLAGS ${LIBALLEGRO4_LINK_FLAGS} ${PLATFORM_LIBS})
include_directories(${LIBALLEGRO4_INCLUDE_DIR})
else()
include_directories(${CMAKE_SOURCE_DIR}/src/allegro/include)
include_directories(${CMAKE_BINARY_DIR}/include)
add_definitions(-DALLEGRO4_WITH_RESIZE_PATCH)
add_definitions(-DALLEGRO4_WITH_EXTRA_CURSORS)
# Static Allegro (the code of Allegro library is embedded).
add_definitions(-DALLEGRO_STATICLINK)
set(LIBALLEGRO4_LINK_FLAGS allegro)
endif()
endif()
# SDL2 backend
if(USE_SDL2_BACKEND)
add_definitions(-DUSE_SDL2_BACKEND)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
find_package(SDL2_IMAGE REQUIRED)
include_directories(${SDL2_IMAGE_INCLUDE_DIRS})
endif()
# -- Unix --
if(UNIX AND NOT APPLE AND NOT BEOS)
# Pthreads
find_package(Threads REQUIRED)
list(APPEND PLATFORM_LIBS m ${CMAKE_THREAD_LIBS_INIT})
# X11
find_package(X11 REQUIRED)
include_directories(SYSTEM ${X11_INCLUDE_DIR})
list(APPEND PLATFORM_LIBS ${X11_LIBRARIES})
if(X11_XShm_FOUND)
list(APPEND PLATFORM_LIBS ${X11_Xext_LIB})
endif()
if(X11_Xcursor_FOUND)
list(APPEND PLATFORM_LIBS ${X11_Xcursor_LIB})
endif()
if(X11_Xpm_FOUND)
list(APPEND PLATFORM_LIBS ${X11_Xpm_LIB})
endif()
find_library(X11_Xxf86vm_LIB Xxf86vm ${X11_LIB_SEARCH_PATH})
mark_as_advanced(X11_Xxf86vm_LIB)
if(X11_xf86vmode_FOUND)
list(APPEND PLATFORM_LIBS ${X11_Xxf86vm_LIB})
endif()
check_library_exists(X11 XOpenIM "${X11_LIB_SEARCH_PATH}" XIM_FOUND)
check_library_exists(Xxf86dga XDGAQueryExtension
"${X11_LIB_SEARCH_PATH}" XDGA_FOUND)
if(XDGA_FOUND)
list(APPEND PLATFORM_LIBS Xxf86dga ${X11_LIBRARIES})
endif()
if(WITH_GTK_FILE_DIALOG_SUPPORT)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM gtkmm-3.0)
include_directories(${GTKMM_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS})
endif()
endif()
# -- Windows --
if(WIN32)
list(APPEND PLATFORM_LIBS
kernel32 user32 gdi32 comdlg32 ole32 winmm
shlwapi psapi wininet comctl32 dbghelp)
# Windows XP is the minimum supported platform.
add_definitions(-D_WIN32_WINNT=0x0501 -DWINVER=0x0501)
# We need Unicode support
add_definitions(-DUNICODE -D_UNICODE)
endif(WIN32)
# -- Mac OS X --
if(APPLE)
find_library(COCOA_LIBRARY Cocoa)
find_library(CARBON_LIBRARY Carbon)
find_library(IOKIT_LIBRARY IOKit)
mark_as_advanced(COCOA_LIBRARY CARBON_LIBRARY IOKIT_LIBRARY)
list(APPEND PLATFORM_LIBS
${COCOA_LIBRARY}
${CARBON_LIBRARY}
${IOKIT_LIBRARY})
# Hack to deal with Mac OS X 10.6. NSQuickDrawView is not defined by
# NSQuickDrawView.h when compiling in 64-bit mode, and 64-bit mode is the
# default when compiling on Snow Leopard.
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL i386)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch i386")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch i386")
endif()
# The Mac port simply uses too many deprecated things.
if(COMPILER_GCC)
set(WFLAGS "${WFLAGS} -Wno-deprecated-declarations")
endif(COMPILER_GCC)
endif(APPLE)
if(WITH_DESKTOP_INTEGRATION)
add_subdirectory(desktop)
endif()
######################################################################
# Main ASE targets
add_subdirectory(src)
######################################################################
# Third party libraries
add_subdirectory(third_party)