blob: 67cdb1d7193ee3bef3b767d39541a2adfee59deb (
plain)
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
|
# Boilerplate.
cmake_minimum_required (VERSION 3.1) # First version with CMAKE_CXX_STANDARD.
project (skimake)
set (CMAKE_CXX_STANDARD 11)
# Default to Release mode. We're mainly targeting Skia users, not Skia developers.
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release)
endif ()
# To first approximation, the Skia library comprises all .cpp files under src/.
file (GLOB_RECURSE srcs ../src/*.cpp)
function (find_include_dirs out)
file (GLOB_RECURSE headers ${ARGN})
foreach (path ${headers})
get_filename_component (dir ${path} PATH)
list (APPEND include_dirs ${dir})
endforeach()
list (REMOVE_DUPLICATES include_dirs)
set (${out} ${include_dirs} PARENT_SCOPE)
endfunction()
# We need src/ directories and include/private on our path when building Skia.
# Users should be able to use Skia with only include/ directories that are not include/private.
find_include_dirs(private_includes ../src/*.h ../include/private/*.h)
find_include_dirs(public_includes ../include/*.h)
list (REMOVE_ITEM public_includes ${private_includes}) # Easiest way to exclude private.
file (GLOB default_include_config "../include/config")
list (REMOVE_ITEM public_includes ${default_include_config})
set (userconfig_directory ${CMAKE_BINARY_DIR}/include)
list (APPEND public_includes ${userconfig_directory})
# These guys are third_party but provided by a Skia checkout.
list (APPEND srcs ../third_party/etc1/etc1.cpp ../third_party/ktx/ktx.cpp)
list (APPEND private_includes ../third_party/etc1 ../third_party/ktx)
function (remove_srcs)
file (GLOB_RECURSE to_remove ${ARGN})
list (REMOVE_ITEM srcs ${to_remove})
set (srcs ${srcs} PARENT_SCOPE)
endfunction()
# This file is empty and is only used to trick GYP.
remove_srcs (../src/core/SkForceCPlusPlusLinking.cpp)
# This file forces linking for all our supported image decoders. We're more fine-grained.
remove_srcs (../src/images/SkForceLinking.cpp)
# Chrome only?
remove_srcs (../src/ports/SkFontHost_fontconfig.cpp
../src/fonts/SkFontMgr_fontconfig.cpp
../src/ports/SkFontConfigInterface_direct.cpp
../src/ports/SkFontConfigInterface_direct_factory.cpp
../src/ports/SkFontConfigInterface_direct_google3.cpp
../src/ports/SkFontConfigInterface_direct_google3_factory.cpp)
# Alternative font managers.
remove_srcs (../src/ports/SkFontMgr_custom*.cpp)
# Skia sure ships a lot of code no one uses.
remove_srcs (../src/animator/* ../src/*nacl* ../src/svg/* ../src/views/* ../src/xml/*)
foreach (include animator svg svg/parser views xml gpu/vk)
file (GLOB globed_include ../include/${include})
list (REMOVE_ITEM public_includes ${globed_include})
endforeach()
# Remove OS-specific source files.
if (NOT UNIX)
remove_srcs(../src/ports/*_posix.cpp
../src/ports/SkTLS_pthread.cpp
../src/ports/SkTime_Unix.cpp
../src/utils/SkThreadUtils_pthread.cpp)
endif()
if (APPLE OR NOT UNIX)
remove_srcs(../src/gpu/gl/glx/*
../src/ports/SkFontMgr_fontconfig*.cpp
../src/ports/SkFontMgr_android*.cpp
../src/*FreeType*)
endif()
# Remove processor-specific source files.
if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ARM)
remove_srcs(../src/*arm* ../src/*ARM* ../src/*neon* ../src/*NEON*)
endif()
if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL MIPS)
remove_srcs(../src/*mips* ../src/*MIPS*)
endif()
# Make our ports choices.
remove_srcs(
../src/*moz* # We're probably not Mozilla.
../src/gpu/GrContextFactory.cpp # For internal testing only.
../src/gpu/gl/GrGLCreateNativeInterface_none.cpp
../src/gpu/gl/GrGLDefaultInterface_none.cpp
../src/gpu/gl/command_buffer/*
../src/gpu/gl/egl/*
../src/gpu/gl/glfw/*
../src/gpu/gl/iOS/*
../src/gpu/vk/*
../src/opts/SkBitmapProcState_opts_none.cpp
../src/opts/SkBlitMask_opts_none.cpp
../src/opts/SkBlitRow_opts_none.cpp
../src/ports/SkFontMgr_empty_factory.cpp
../src/ports/SkGlobalInitialization_chromium.cpp
../src/ports/SkImageEncoder_none.cpp
../src/ports/SkImageGenerator_none.cpp
../src/ports/SkTLS_none.cpp)
if (NOT APPLE)
remove_srcs(../src/ports/SkImageGeneratorCG.cpp)
endif()
if (NOT WIN32)
remove_srcs(../src/ports/SkImageGeneratorWIC.cpp)
endif()
if (WIN32)
if(SKIA_GDI)
remove_srcs(../src/ports/SkFontMgr_win_dw_factory.cpp)
else()
remove_srcs(../src/ports/SkFontMgr_win_gdi_factory.cpp)
endif()
endif()
# Certain files must be compiled with support for SSSE3, SSE4.1, AVX, or AVX2 intrinsics.
file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp)
file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp)
file (GLOB_RECURSE avx_srcs ../src/*_avx.cpp)
file (GLOB_RECURSE avx2_srcs ../src/*_avx2.cpp)
set_source_files_properties(${ssse3_srcs} PROPERTIES COMPILE_FLAGS -mssse3)
set_source_files_properties(${sse41_srcs} PROPERTIES COMPILE_FLAGS -msse4.1)
set_source_files_properties(${avx_srcs} PROPERTIES COMPILE_FLAGS -mavx)
set_source_files_properties(${avx2_srcs} PROPERTIES COMPILE_FLAGS -mavx2)
# Detect our optional dependencies.
# If we can't find them, don't build the parts of Skia that use them.
find_package (EXPAT)
find_package (Lua)
find_package (ZLIB)
# No find_package for libwebp as far as I can tell, so simulate it here.
find_path (WEBP_INCLUDE_DIRS "webp/decode.h")
find_library (WEBP_LIBRARIES webp)
find_path (OSMESA_INCLUDE_DIRS "GL/osmesa.h")
find_library(OSMESA_LIBRARIES "OSMesa")
if (UNIX AND NOT APPLE)
find_package (Freetype)
# Same deal for fontconfig.
find_path (FONTCONFIG_INCLUDE_DIRS "fontconfig/fontconfig.h")
find_library (FONTCONFIG_LIBRARIES fontconfig)
find_package (GIF)
find_package (JPEG)
find_package (PNG)
endif()
# Do not compile SkRawCodec.
remove_srcs(../src/codec/*Raw*.cpp)
# TODO: macro away this if (found) ... else() ... endif() stuff.
if (EXPAT_FOUND)
list (APPEND private_includes ${EXPAT_INCLUDE_DIRS})
list (APPEND libs ${EXPAT_LIBRARIES})
else()
remove_srcs (../src/ports/SkFontMgr_android_parser.cpp)
endif()
if (GIF_FOUND)
list (APPEND private_includes ${GIF_INCLUDE_DIRS})
list (APPEND libs ${GIF_LIBRARIES})
add_definitions(-DSK_CODEC_DECODES_GIF)
else()
remove_srcs(../src/images/*GIF*)
remove_srcs(../src/codec/*Gif*)
endif()
if (JPEG_FOUND)
list (APPEND private_includes ${JPEG_INCLUDE_DIRS})
list (APPEND libs ${JPEG_LIBRARIES})
add_definitions(-DSK_CODEC_DECODES_JPEG)
else()
remove_srcs(../src/images/*JPEG*)
remove_srcs(../src/codec/*Jpeg*)
endif()
if (LUA_FOUND)
list (APPEND private_includes ${LUA_INCLUDE_DIR})
list (APPEND libs ${LUA_LIBRARIES})
else()
remove_srcs(../src/utils/*Lua*)
endif()
if (PNG_FOUND)
list (APPEND private_includes ${PNG_INCLUDE_DIRS})
list (APPEND libs ${PNG_LIBRARIES})
add_definitions(-DPNG_SKIP_SETJMP_CHECK)
add_definitions(-DPNG_SKIP_SKIA_OPTS)
add_definitions(-DSK_CODEC_DECODES_PNG)
else()
remove_srcs(../src/images/*PNG*)
remove_srcs(../src/codec/*Png*)
remove_srcs(../src/codec/*Ico*)
endif()
if (ZLIB_FOUND)
list (APPEND private_includes ${ZLIB_INCLUDE_DIRS})
list (APPEND libs ${ZLIB_LIBRARIES})
remove_srcs(../src/pdf/SkDocument_PDF_None.cpp)
else()
remove_srcs(../src/pdf/*.cpp)
set (srcs ${srcs} ../src/pdf/SkDocument_PDF_None.cpp)
endif()
if (WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES)
list (APPEND private_includes ${WEBP_INCLUDE_DIRS})
list (APPEND libs ${WEBP_LIBRARIES})
add_definitions(-DSK_CODEC_DECODES_WEBP)
else()
remove_srcs(../src/images/*WEBP*)
remove_srcs(../src/codec/*Webp*)
endif()
if (FREETYPE_FOUND)
list (APPEND private_includes ${FREETYPE_INCLUDE_DIRS})
list (APPEND libs ${FREETYPE_LIBRARIES})
endif()
if (FONTCONFIG_INCLUDE_DIRS AND FONTCONFIG_LIBRARIES)
list (APPEND private_includes ${FONTCONFIG_INCLUDE_DIRS})
list (APPEND libs ${FONTCONFIG_LIBRARIES})
endif()
if (APPLE)
find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices REQUIRED)
list (APPEND libs ${APPLICATION_SERVICES_FRAMEWORK})
endif()
if (OSMESA_LIBRARIES AND OSMESA_INCLUDE_DIRS)
list (APPEND libs ${OSMESA_LIBRARIES})
list (APPEND private_includes ${OSMESA_INCLUDE_DIRS})
list (APPEND public_defines "-DSK_MESA=1")
set (SK_MESA 1)
else()
remove_srcs(../src/gpu/gl/mesa/*)
endif()
if (WIN32)
list (APPEND libs FontSub.lib Usp10.lib)
endif()
find_package(OpenGL REQUIRED)
list (APPEND libs ${OPENGL_LIBRARIES})
# This is our main output, libskia.so.
# We mostly build an .so here because it helps test we've linked everything,
# not so much that we think Skia is a good candidate to ship as a shared library.
add_library (skia SHARED ${srcs})
target_compile_definitions(skia
PUBLIC ${public_defines}
PRIVATE -DSKIA_DLL -DSKIA_IMPLEMENTATION=1)
target_include_directories(skia
PUBLIC ${public_includes}
PRIVATE ${private_includes})
target_link_libraries(skia
PUBLIC
PRIVATE ${libs})
if (MSVC)
set(cc_flags "/w /GR-")
else()
set(cc_flags "-w -fno-rtti -fno-exceptions")
endif()
set_target_properties(skia PROPERTIES
COMPILE_FLAGS ${cc_flags}
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN true)
# Experimental C API install:
file(GLOB c_headers "../include/c/*.h")
install(FILES ${c_headers} DESTINATION include)
install(TARGETS skia DESTINATION lib)
# SkUserConfig.h
if (CMAKE_BUILD_TYPE STREQUAL Release)
set (SK_RELEASE 1)
else()
set (SK_RELEASE 0)
endif()
if (UNIX AND NOT APPLE)
set (SK_SAMPLES_FOR_X 1)
else()
set (SK_SAMPLES_FOR_X 0)
endif()
configure_file ("SkUserConfig.h.in" "${userconfig_directory}/SkUserConfig.h")
# skia_link_arguments.txt
set (link_arguments ${CMAKE_BINARY_DIR}/skia_link_arguments.txt)
file (WRITE ${link_arguments} "-L${CMAKE_BINARY_DIR}\n")
file (APPEND ${link_arguments} "-lskia\n")
file (APPEND ${link_arguments} "-Wl,-rpath,${CMAKE_BINARY_DIR}\n")
# skia_compile_arguments.txt
set (compile_arguments ${CMAKE_BINARY_DIR}/skia_compile_arguments.txt)
file (WRITE ${compile_arguments} "--std=c++11\n")
foreach (include ${public_includes})
get_filename_component (abs_include ${include} ABSOLUTE)
file (APPEND ${compile_arguments} "-I${abs_include}\n")
endforeach()
# cmake .
# cmake --build . --target skia
# c++ -c @skia_compile_arguments.txt example.cpp
# c++ example.o @skia_link_arguments.txt
# skia.h
set (bad_files GrGLConfig_chrome.h SkJSONCPP.h SkParsePaint.h)
# make `c++ @skia_compile_arguments.txt include/skia.h` work.
set (skia_h_path ${userconfig_directory}/skia.h)
file (WRITE ${skia_h_path} "// skia.h generated by CMake.\n")
file(APPEND ${skia_h_path} "#ifndef skia_DEFINED\n")
file(APPEND ${skia_h_path} "#define skia_DEFINED\n")
foreach (include ${public_includes})
if (NOT include STREQUAL userconfig_directory)
file (APPEND ${skia_h_path} "\n")
file (GLOB all_public_headers ${include}/*.h)
foreach (public_header ${all_public_headers})
get_filename_component (filename_component ${public_header} NAME)
if (NOT ";${bad_files};" MATCHES ";${filename_component};")
file (APPEND ${skia_h_path} "#include \"${filename_component}\"\n")
endif ()
endforeach()
endif()
endforeach()
file(APPEND ${skia_h_path} "\n#endif // skia_DEFINED\n")
# Now build a simple example app that uses Skia via libskia.so.
add_executable(example example.cpp)
target_link_libraries(example skia ${OPENGL_LIBRARIES})
|