forked from LibreSprite/LibreSprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
370 lines (299 loc) · 11.5 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
# Aseprite | Copyright (C) 2001-2016 David Capello
# LibreSprite | Copyright (C) 2022 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)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# 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(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)
option(USE_SDL2_BACKEND "Use SDL2 backend" on)
option(USE_V8_SANDBOX "Use V8 Sandbox" off)
######################################################################
# 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(EASYTAB_DIR ${CMAKE_SOURCE_DIR}/third_party/EasyTab)
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)
set(QOI_DIR ${CMAKE_SOURCE_DIR}/third_party/qoi)
# 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)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0 -g")
else()
add_definitions(-DNDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O3")
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()
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
# qoi
include_directories(${QOI_DIR})
# tinyxml2
find_library(TINYXML2_LIBRARY NAMES tinyxml2)
find_path(TINYXML2_INCLUDE_DIR NAMES tinyxml2.h)
include_directories(${TINYXML2_INCLUDE_DIR})
if(NOT GEN_ONLY)
# zlib
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
# libArchive
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Homebrew ships libarchive keg only, include dirs have to be set manually
execute_process(
COMMAND brew --prefix libarchive
OUTPUT_VARIABLE LIBARCHIVE_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY
)
set(LibArchive_INCLUDE_DIR "${LIBARCHIVE_PREFIX}/include")
endif()
find_package(LibArchive REQUIRED)
include_directories(${LibArchive_INCLUDE_DIR})
# libpng
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIRS})
# libwebp
find_package(WEBP QUIET)
if(WEBP_FOUND)
message(STATUS "Enabling WEBP support")
include_directories(${WEBP_INCLUDE_DIR})
else()
find_package(PkgConfig)
if (PkgConfig_FOUND)
pkg_search_module(WEBP libwebp)
if (WEBP_FOUND)
message(STATUS "Enabling WEBP support")
include_directories(${WEBP_INCLUDE_DIRS})
set(WEB_LIBRARIES ${WEBP_LDFLAGS})
endif()
endif()
endif()
# 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(JPEG REQUIRED)
include_directories(${JPEG_INCLUDE_DIRS})
# v8
find_package(V8 QUIET)
if(V8_FOUND)
include_directories(${V8_INCLUDE_DIR})
add_definitions(-DSCRIPT_ENGINE_V8=1)
include(CheckCXXSourceRuns)
set(CMAKE_REQUIRED_LIBRARIES ${V8_LIBRARY} ${V8_LIBBASE_LIBRARY} ${V8_LIBPLATFORM_LIBRARY})
set(CMAKE_REQUIRED_INCLUDES ${V8_INCLUDE_DIR})
message(STATUS ${V8_POINTER_COMPRESSION_OUTPUT})
# Since V8_COMPRESS_POINTERS is not defined here, the resulting program would
# die if the system v8 library had enabled pointer compression.
check_cxx_source_runs("
#include <v8.h>
#include <libplatform/libplatform.h>
int main(void) {
v8::V8::InitializeICU();
static std::unique_ptr<v8::Platform> m_platform;
m_platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(m_platform.get());
v8::V8::Initialize();
return 0;
}
" DISABLE_POINTER_COMPRESSION)
# pointers compression doesn't work on 32bit machines
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
if(DISABLE_POINTER_COMPRESSION EQUAL 1)
message(STATUS "Disabling V8 pointer compression")
else()
message(STATUS "Enabling V8 pointer compression")
add_definitions(-DV8_COMPRESS_POINTERS)
endif()
endif()
if (USE_V8_SANDBOX)
add_definitions(-DV8_ENABLE_SANDBOX)
endif()
message(STATUS "Optional V8 library found. Enabling V8 scripting engine.")
else()
message(STATUS "Optional V8 library NOT found. Disabling V8 scripting engine.")
endif()
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})
endif()
# simpleini
include_directories(${SIMPLEINI_DIR})
######################################################################
# Platform specific stuff
set(PLATFORM_LIBS)
# 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 AND NOT GEN_ONLY)
# 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(X11_Xi_FOUND)
list(APPEND PLATFORM_LIBS ${X11_Xi_LIB})
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)