blob: 751361a92796e246508ee6f275735f3b71c65db1 [file] [log] [blame]
mtkleine0f06a42015-08-28 11:51:06 -07001# Boilerplate.
mtklein0ce744e2015-09-01 09:22:31 -07002cmake_minimum_required (VERSION 3.1) # First version with CMAKE_CXX_STANDARD.
mtkleine0f06a42015-08-28 11:51:06 -07003project (skimake)
4set (CMAKE_CXX_STANDARD 11)
5
6# Default to Release mode. We're mainly targeting Skia users, not Skia developers.
7if (NOT CMAKE_BUILD_TYPE)
8 set (CMAKE_BUILD_TYPE Release)
9endif ()
10
11# To first approximation, the Skia library comprises all .cpp files under src/.
12file (GLOB_RECURSE srcs ../src/*.cpp)
13
14function (find_include_dirs out)
mtklein2409abb2015-08-31 06:59:21 -070015 file (GLOB_RECURSE headers ${ARGN})
mtkleine0f06a42015-08-28 11:51:06 -070016 foreach (path ${headers})
17 get_filename_component (dir ${path} PATH)
18 list (APPEND include_dirs ${dir})
19 endforeach()
20 list (REMOVE_DUPLICATES include_dirs)
21 set (${out} ${include_dirs} PARENT_SCOPE)
22endfunction()
23
24# We need src/ directories and include/private on our path when building Skia.
25# Users should be able to use Skia with only include/ directories that are not include/private.
26find_include_dirs(private_includes ../src/*.h ../include/private/*.h)
27find_include_dirs(public_includes ../include/*.h)
28list (REMOVE_ITEM public_includes ${private_includes}) # Easiest way to exclude private.
halcanary0cf5ecb2015-11-30 10:29:25 -080029file (GLOB default_include_config "../include/config")
30list (REMOVE_ITEM public_includes ${default_include_config})
halcanaryd1c94a42015-11-30 12:42:58 -080031set (userconfig_directory ${CMAKE_BINARY_DIR}/include)
halcanary0cf5ecb2015-11-30 10:29:25 -080032list (APPEND public_includes ${userconfig_directory})
mtkleine0f06a42015-08-28 11:51:06 -070033
34# These guys are third_party but provided by a Skia checkout.
35list (APPEND srcs ../third_party/etc1/etc1.cpp ../third_party/ktx/ktx.cpp)
36list (APPEND private_includes ../third_party/etc1 ../third_party/ktx)
37
38function (remove_srcs)
mtklein2409abb2015-08-31 06:59:21 -070039 file (GLOB_RECURSE to_remove ${ARGN})
mtkleine0f06a42015-08-28 11:51:06 -070040 list (REMOVE_ITEM srcs ${to_remove})
41 set (srcs ${srcs} PARENT_SCOPE)
42endfunction()
43
44# This file is empty and is only used to trick GYP.
45remove_srcs (../src/core/SkForceCPlusPlusLinking.cpp)
46# This file forces linking for all our supported image decoders. We're more fine-grained.
47remove_srcs (../src/images/SkForceLinking.cpp)
mtklein2409abb2015-08-31 06:59:21 -070048# Chrome only?
49remove_srcs (../src/ports/SkFontHost_fontconfig.cpp
50 ../src/fonts/SkFontMgr_fontconfig.cpp
bungemanc1da4d02015-12-01 14:26:28 -050051 ../src/ports/SkFontConfigInterface_direct.cpp
52 ../src/ports/SkFontConfigInterface_direct_factory.cpp
53 ../src/ports/SkFontConfigInterface_direct_google3.cpp
54 ../src/ports/SkFontConfigInterface_direct_google3_factory.cpp)
mtklein2409abb2015-08-31 06:59:21 -070055# Alternative font managers.
56remove_srcs (../src/ports/SkFontMgr_custom*.cpp)
mtkleine0f06a42015-08-28 11:51:06 -070057
58# Skia sure ships a lot of code no one uses.
59remove_srcs (../src/animator/* ../src/*nacl* ../src/svg/* ../src/views/* ../src/xml/*)
halcanary0cbe7ee2015-12-01 09:02:49 -080060foreach (include animator svg svg/parser views views/animated xml)
61 file (GLOB globed_include ../include/${include})
62 list (REMOVE_ITEM public_includes ${globed_include})
63endforeach()
mtkleine0f06a42015-08-28 11:51:06 -070064
mtkleine0f06a42015-08-28 11:51:06 -070065# Remove OS-specific source files.
mtklein56c6a112015-09-30 11:06:53 -070066if (NOT UNIX)
mtklein1ee76512015-11-02 10:20:27 -080067 remove_srcs(../src/ports/*_posix.cpp
mtklein56c6a112015-09-30 11:06:53 -070068 ../src/ports/SkTLS_pthread.cpp
69 ../src/ports/SkTime_Unix.cpp
mtkleina1bde7d2015-10-20 11:05:06 -070070 ../src/utils/SkThreadUtils_pthread.cpp)
mtklein56c6a112015-09-30 11:06:53 -070071endif()
mtklein2409abb2015-08-31 06:59:21 -070072if (APPLE OR NOT UNIX)
73 remove_srcs(../src/gpu/gl/glx/*
74 ../src/images/SkImageDecoder_FactoryDefault.cpp
75 ../src/ports/SkFontMgr_fontconfig*.cpp
Ben Wagnera182b802016-01-21 17:38:13 -050076 ../src/ports/SkFontMgr_android*.cpp
mtklein2409abb2015-08-31 06:59:21 -070077 ../src/*FreeType*)
mtkleine0f06a42015-08-28 11:51:06 -070078endif()
mtkleine0f06a42015-08-28 11:51:06 -070079
80# Remove processor-specific source files.
mtklein0faed582015-09-14 12:02:32 -070081if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ARM)
mtkleine0f06a42015-08-28 11:51:06 -070082 remove_srcs(../src/*arm* ../src/*ARM* ../src/*neon* ../src/*NEON*)
83endif()
mtklein0faed582015-09-14 12:02:32 -070084if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL MIPS)
mtkleine0f06a42015-08-28 11:51:06 -070085 remove_srcs(../src/*mips* ../src/*MIPS*)
86endif()
87
88# Make our ports choices.
89remove_srcs(
90 ../src/*moz* # We're probably not Mozilla.
91 ../src/gpu/GrContextFactory.cpp # For internal testing only.
92 ../src/gpu/gl/GrGLCreateNativeInterface_none.cpp
93 ../src/gpu/gl/GrGLDefaultInterface_none.cpp
94 ../src/gpu/gl/SkCreatePlatformGLContext*.cpp # For internal testing only.
95 ../src/gpu/gl/command_buffer/*
96 ../src/gpu/gl/egl/*
mtkleine0f06a42015-08-28 11:51:06 -070097 ../src/gpu/gl/iOS/*
mtkleine0f06a42015-08-28 11:51:06 -070098 ../src/opts/SkBitmapProcState_opts_none.cpp
99 ../src/opts/SkBlitMask_opts_none.cpp
100 ../src/opts/SkBlitRow_opts_none.cpp
101 ../src/ports/SkFontMgr_empty_factory.cpp
102 ../src/ports/SkGlobalInitialization_chromium.cpp
103 ../src/ports/SkImageDecoder_empty.cpp
104 ../src/ports/SkImageGenerator_none.cpp
mtklein2409abb2015-08-31 06:59:21 -0700105 ../src/ports/SkTLS_none.cpp)
mtkleine0f06a42015-08-28 11:51:06 -0700106
mtklein56c6a112015-09-30 11:06:53 -0700107if (WIN32)
108 if(SKIA_GDI)
109 remove_srcs(../src/ports/SkFontMgr_win_dw_factory.cpp)
110 else()
111 remove_srcs(../src/ports/SkFontMgr_win_gdi_factory.cpp)
112 endif()
113endif()
114
115remove_srcs(../src/gpu/gl/angle/*) # TODO
mtkleine0f06a42015-08-28 11:51:06 -0700116
mtkleinf6d8d282015-12-17 10:18:04 -0800117# Certain files must be compiled with support for SSSE3, SSE4.1, AVX, or AVX2 intrinsics.
mtkleine0f06a42015-08-28 11:51:06 -0700118file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp)
119file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp)
mtkleinf6d8d282015-12-17 10:18:04 -0800120file (GLOB_RECURSE avx_srcs ../src/*_avx.cpp)
121file (GLOB_RECURSE avx2_srcs ../src/*_avx2.cpp)
mtkleine0f06a42015-08-28 11:51:06 -0700122set_source_files_properties(${ssse3_srcs} PROPERTIES COMPILE_FLAGS -mssse3)
123set_source_files_properties(${sse41_srcs} PROPERTIES COMPILE_FLAGS -msse4.1)
mtkleinf6d8d282015-12-17 10:18:04 -0800124set_source_files_properties(${avx_srcs} PROPERTIES COMPILE_FLAGS -mavx)
125set_source_files_properties(${avx2_srcs} PROPERTIES COMPILE_FLAGS -mavx2)
mtkleine0f06a42015-08-28 11:51:06 -0700126
127# Detect our optional dependencies.
128# If we can't find them, don't build the parts of Skia that use them.
mtklein1ee76512015-11-02 10:20:27 -0800129find_package (EXPAT)
mtklein2409abb2015-08-31 06:59:21 -0700130find_package (Lua)
mtkleine0f06a42015-08-28 11:51:06 -0700131find_package (ZLIB)
132# No find_package for libwebp as far as I can tell, so simulate it here.
133find_path (WEBP_INCLUDE_DIRS "webp/decode.h")
134find_library (WEBP_LIBRARIES webp)
halcanary4ae26252015-09-21 09:42:23 -0700135find_path (OSMESA_INCLUDE_DIRS "GL/osmesa.h")
136find_library(OSMESA_LIBRARIES "OSMesa")
mtkleine0f06a42015-08-28 11:51:06 -0700137
mtklein2409abb2015-08-31 06:59:21 -0700138if (UNIX AND NOT APPLE)
139 find_package (Freetype)
140 # Same deal for fontconfig.
141 find_path (FONTCONFIG_INCLUDE_DIRS "fontconfig/fontconfig.h")
142 find_library (FONTCONFIG_LIBRARIES fontconfig)
143 find_package (GIF)
144 find_package (JPEG)
145 find_package (PNG)
146endif()
147
msarett4691d992016-02-16 13:16:39 -0800148# Decide whether to turn on SkCodec.
149# TODO (skbug.com/4956): We should be able to turn specific codecs on and off rather than
150# disabling all of them if one library is missing.
151if (NOT (GIF_FOUND AND JPEG_FOUND AND PNG_FOUND AND WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES))
152 remove_srcs(../src/codec/* ../src/android/*)
153endif()
154
155# Do not compile SkRawCodec.
156remove_srcs(../src/codec/*Raw*.cpp)
157
mtklein2409abb2015-08-31 06:59:21 -0700158# TODO: macro away this if (found) ... else() ... endif() stuff.
159
mtklein1ee76512015-11-02 10:20:27 -0800160if (EXPAT_FOUND)
161 list (APPEND private_includes ${EXPAT_INCLUDE_DIRS})
162 list (APPEND libs ${EXPAT_LIBRARIES})
163else()
164 remove_srcs (../src/ports/SkFontMgr_android_parser.cpp)
165endif()
166
mtklein2409abb2015-08-31 06:59:21 -0700167if (GIF_FOUND)
168 list (APPEND private_includes ${GIF_INCLUDE_DIRS})
169 list (APPEND libs ${GIF_LIBRARIES})
170else()
mtkleine0f06a42015-08-28 11:51:06 -0700171 remove_srcs(../src/images/*gif*)
172endif()
mtklein2409abb2015-08-31 06:59:21 -0700173
174if (JPEG_FOUND)
175 list (APPEND private_includes ${JPEG_INCLUDE_DIRS})
176 list (APPEND libs ${JPEG_LIBRARIES})
177else()
mtkleine0f06a42015-08-28 11:51:06 -0700178 remove_srcs(../src/images/*jpeg*)
179endif()
mtklein2409abb2015-08-31 06:59:21 -0700180
181if (LUA_FOUND)
182 list (APPEND private_includes ${LUA_INCLUDE_DIR})
183 list (APPEND libs ${LUA_LIBRARIES})
184else()
185 remove_srcs(../src/utils/*Lua*)
mtkleine0f06a42015-08-28 11:51:06 -0700186endif()
mtklein2409abb2015-08-31 06:59:21 -0700187
188if (PNG_FOUND)
189 list (APPEND private_includes ${PNG_INCLUDE_DIRS})
190 list (APPEND libs ${PNG_LIBRARIES})
msarett4691d992016-02-16 13:16:39 -0800191 add_definitions(-DPNG_SKIP_SETJMP_CHECK)
192 add_definitions(-DPNG_SKIP_SKIA_OPTS)
mtklein2409abb2015-08-31 06:59:21 -0700193else()
mtkleine0f06a42015-08-28 11:51:06 -0700194 remove_srcs(../src/images/*png*)
195endif()
mtklein2409abb2015-08-31 06:59:21 -0700196
197if (ZLIB_FOUND)
198 list (APPEND private_includes ${ZLIB_INCLUDE_DIRS})
199 list (APPEND libs ${ZLIB_LIBRARIES})
mtkleine0f06a42015-08-28 11:51:06 -0700200 remove_srcs(../src/doc/SkDocument_PDF_None.cpp)
mtklein2409abb2015-08-31 06:59:21 -0700201else()
202 remove_srcs(../src/pdf/*.cpp ../src/doc/SkDocument_PDF.cpp)
mtkleine0f06a42015-08-28 11:51:06 -0700203endif()
mtklein2409abb2015-08-31 06:59:21 -0700204
205if (WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES)
206 list (APPEND private_includes ${WEBP_INCLUDE_DIRS})
207 list (APPEND libs ${WEBP_LIBRARIES})
208else()
mtkleine0f06a42015-08-28 11:51:06 -0700209 remove_srcs(../src/images/*webp*)
210endif()
211
mtklein2409abb2015-08-31 06:59:21 -0700212if (FREETYPE_FOUND)
213 list (APPEND private_includes ${FREETYPE_INCLUDE_DIRS})
214 list (APPEND libs ${FREETYPE_LIBRARIES})
215endif()
216
217if (FONTCONFIG_INCLUDE_DIRS AND FONTCONFIG_LIBRARIES)
218 list (APPEND private_includes ${FONTCONFIG_INCLUDE_DIRS})
219 list (APPEND libs ${FONTCONFIG_LIBRARIES})
220endif()
221
mtkleine0f06a42015-08-28 11:51:06 -0700222if (APPLE)
mtklein2409abb2015-08-31 06:59:21 -0700223 find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices REQUIRED)
224 list (APPEND libs ${APPLICATION_SERVICES_FRAMEWORK})
mtkleine0f06a42015-08-28 11:51:06 -0700225endif()
226
halcanary4ae26252015-09-21 09:42:23 -0700227if (OSMESA_LIBRARIES AND OSMESA_INCLUDE_DIRS)
228 list (APPEND libs ${OSMESA_LIBRARIES})
229 list (APPEND private_includes ${OSMESA_INCLUDE_DIRS})
230 list (APPEND public_defines "-DSK_MESA=1")
mtklein014f06b2016-01-05 08:32:32 -0800231 set (SK_MESA 1)
halcanary4ae26252015-09-21 09:42:23 -0700232else()
233 remove_srcs(../src/gpu/gl/mesa/*)
halcanary4ae26252015-09-21 09:42:23 -0700234endif()
235
mtklein56c6a112015-09-30 11:06:53 -0700236if (WIN32)
237 list (APPEND libs FontSub.lib Usp10.lib)
238endif()
239
halcanary2a4a4212015-09-01 10:11:44 -0700240find_package(OpenGL REQUIRED)
241list (APPEND libs ${OPENGL_LIBRARIES})
242
mtkleine0f06a42015-08-28 11:51:06 -0700243# This is our main output, libskia.so.
244# We mostly build an .so here because it helps test we've linked everything,
245# not so much that we think Skia is a good candidate to ship as a shared library.
246add_library (skia SHARED ${srcs})
247
248target_compile_definitions(skia
halcanary4ae26252015-09-21 09:42:23 -0700249 PUBLIC ${public_defines}
mtklein56c6a112015-09-30 11:06:53 -0700250 PRIVATE -DSKIA_DLL -DSKIA_IMPLEMENTATION=1)
mtkleine0f06a42015-08-28 11:51:06 -0700251
252target_include_directories(skia
253 PUBLIC ${public_includes}
mtklein2409abb2015-08-31 06:59:21 -0700254 PRIVATE ${private_includes})
mtkleine0f06a42015-08-28 11:51:06 -0700255
256target_link_libraries(skia
257 PUBLIC
mtklein2409abb2015-08-31 06:59:21 -0700258 PRIVATE ${libs})
259
mtklein56c6a112015-09-30 11:06:53 -0700260if (MSVC)
261 set(cc_flags "/w /GR-")
262else()
263 set(cc_flags "-w -fno-rtti -fno-exceptions")
264endif()
mtkleine0f06a42015-08-28 11:51:06 -0700265
266set_target_properties(skia PROPERTIES
mtklein56c6a112015-09-30 11:06:53 -0700267 COMPILE_FLAGS ${cc_flags}
mtkleine0f06a42015-08-28 11:51:06 -0700268 CXX_VISIBILITY_PRESET hidden
269 VISIBILITY_INLINES_HIDDEN true)
270
halcanary5a9a5b32015-09-03 14:23:17 -0700271# Experimental C API install:
mtkleina5b0f032015-09-29 13:16:33 -0700272file(GLOB c_headers "../include/c/*.h")
273install(FILES ${c_headers} DESTINATION include)
halcanary5a9a5b32015-09-03 14:23:17 -0700274install(TARGETS skia DESTINATION lib)
275
halcanaryd1c94a42015-11-30 12:42:58 -0800276# SkUserConfig.h
halcanaryd1c94a42015-11-30 12:42:58 -0800277if (CMAKE_BUILD_TYPE STREQUAL Release)
mtklein014f06b2016-01-05 08:32:32 -0800278 set (SK_RELEASE 1)
mtklein95bc09b2016-01-07 06:56:11 -0800279else()
280 set (SK_RELEASE 0)
halcanaryd1c94a42015-11-30 12:42:58 -0800281endif()
mtklein014f06b2016-01-05 08:32:32 -0800282configure_file ("SkUserConfig.h.in" "${userconfig_directory}/SkUserConfig.h")
halcanaryd1c94a42015-11-30 12:42:58 -0800283
284# skia_link_arguments.txt
285set (link_arguments ${CMAKE_BINARY_DIR}/skia_link_arguments.txt)
286file (WRITE ${link_arguments} "-L${CMAKE_BINARY_DIR}\n")
287file (APPEND ${link_arguments} "-lskia\n")
288file (APPEND ${link_arguments} "-Wl,-rpath,${CMAKE_BINARY_DIR}\n")
289
290# skia_compile_arguments.txt
291set (compile_arguments ${CMAKE_BINARY_DIR}/skia_compile_arguments.txt)
292file (WRITE ${compile_arguments} "--std=c++11\n")
293foreach (include ${public_includes})
294 get_filename_component (abs_include ${include} ABSOLUTE)
295 file (APPEND ${compile_arguments} "-I${abs_include}\n")
296endforeach()
297
298# cmake .
299# cmake --build . --target skia
300# c++ -c @skia_compile_arguments.txt example.cpp
301# c++ example.o @skia_link_arguments.txt
302
303# skia.h
halcanary0cbe7ee2015-12-01 09:02:49 -0800304set (bad_files GrGLConfig_chrome.h SkJSONCPP.h SkParsePaint.h)
305# make `c++ @skia_compile_arguments.txt include/skia.h` work.
halcanaryd1c94a42015-11-30 12:42:58 -0800306set (skia_h_path ${userconfig_directory}/skia.h)
307file (WRITE ${skia_h_path} "// skia.h generated by CMake.\n")
308file(APPEND ${skia_h_path} "#ifndef skia_DEFINED\n")
309file(APPEND ${skia_h_path} "#define skia_DEFINED\n")
310foreach (include ${public_includes})
311 if (NOT include STREQUAL userconfig_directory)
312 file (APPEND ${skia_h_path} "\n")
313 file (GLOB all_public_headers ${include}/*.h)
314 foreach (public_header ${all_public_headers})
315 get_filename_component (filename_component ${public_header} NAME)
halcanary0cbe7ee2015-12-01 09:02:49 -0800316 if (NOT ";${bad_files};" MATCHES ";${filename_component};")
317 file (APPEND ${skia_h_path} "#include \"${filename_component}\"\n")
318 endif ()
halcanaryd1c94a42015-11-30 12:42:58 -0800319 endforeach()
320 endif()
321endforeach()
322file(APPEND ${skia_h_path} "\n#endif // skia_DEFINED\n")
323
mtkleine0f06a42015-08-28 11:51:06 -0700324# Now build a simple example app that uses Skia via libskia.so.
mtkleine0f06a42015-08-28 11:51:06 -0700325add_executable(example example.cpp)
326target_link_libraries(example skia ${OPENGL_LIBRARIES})