blob: 9fc4ea5a427cdd9240045ea2f9c058d2eeeec2c2 [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/*)
jcgregorio3fc3fea2016-03-03 12:46:12 -080060foreach (include animator svg svg/parser views xml gpu/vk)
halcanary0cbe7ee2015-12-01 09:02:49 -080061 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/*
egdanielb6ce10a2016-02-22 07:19:10 -080098 ../src/gpu/vk/*
mtkleine0f06a42015-08-28 11:51:06 -070099 ../src/opts/SkBitmapProcState_opts_none.cpp
100 ../src/opts/SkBlitMask_opts_none.cpp
101 ../src/opts/SkBlitRow_opts_none.cpp
102 ../src/ports/SkFontMgr_empty_factory.cpp
103 ../src/ports/SkGlobalInitialization_chromium.cpp
104 ../src/ports/SkImageDecoder_empty.cpp
105 ../src/ports/SkImageGenerator_none.cpp
mtklein2409abb2015-08-31 06:59:21 -0700106 ../src/ports/SkTLS_none.cpp)
mtkleine0f06a42015-08-28 11:51:06 -0700107
msarettfdd52c42016-03-09 15:12:31 -0800108if (NOT APPLE)
109 remove_srcs(../src/ports/SkImageGeneratorCG.cpp)
110endif()
111
msarettfc0b6d12016-03-17 13:50:17 -0700112if (NOT WIN32)
113 remove_srcs(../src/ports/SkImageGeneratorWIC.cpp)
114endif()
115
mtklein56c6a112015-09-30 11:06:53 -0700116if (WIN32)
117 if(SKIA_GDI)
118 remove_srcs(../src/ports/SkFontMgr_win_dw_factory.cpp)
119 else()
120 remove_srcs(../src/ports/SkFontMgr_win_gdi_factory.cpp)
121 endif()
122endif()
123
124remove_srcs(../src/gpu/gl/angle/*) # TODO
mtkleine0f06a42015-08-28 11:51:06 -0700125
mtkleinf6d8d282015-12-17 10:18:04 -0800126# Certain files must be compiled with support for SSSE3, SSE4.1, AVX, or AVX2 intrinsics.
mtkleine0f06a42015-08-28 11:51:06 -0700127file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp)
128file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp)
mtkleinf6d8d282015-12-17 10:18:04 -0800129file (GLOB_RECURSE avx_srcs ../src/*_avx.cpp)
130file (GLOB_RECURSE avx2_srcs ../src/*_avx2.cpp)
mtkleine0f06a42015-08-28 11:51:06 -0700131set_source_files_properties(${ssse3_srcs} PROPERTIES COMPILE_FLAGS -mssse3)
132set_source_files_properties(${sse41_srcs} PROPERTIES COMPILE_FLAGS -msse4.1)
mtkleinf6d8d282015-12-17 10:18:04 -0800133set_source_files_properties(${avx_srcs} PROPERTIES COMPILE_FLAGS -mavx)
134set_source_files_properties(${avx2_srcs} PROPERTIES COMPILE_FLAGS -mavx2)
mtkleine0f06a42015-08-28 11:51:06 -0700135
136# Detect our optional dependencies.
137# If we can't find them, don't build the parts of Skia that use them.
mtklein1ee76512015-11-02 10:20:27 -0800138find_package (EXPAT)
mtklein2409abb2015-08-31 06:59:21 -0700139find_package (Lua)
mtkleine0f06a42015-08-28 11:51:06 -0700140find_package (ZLIB)
141# No find_package for libwebp as far as I can tell, so simulate it here.
142find_path (WEBP_INCLUDE_DIRS "webp/decode.h")
143find_library (WEBP_LIBRARIES webp)
halcanary4ae26252015-09-21 09:42:23 -0700144find_path (OSMESA_INCLUDE_DIRS "GL/osmesa.h")
145find_library(OSMESA_LIBRARIES "OSMesa")
mtkleine0f06a42015-08-28 11:51:06 -0700146
mtklein2409abb2015-08-31 06:59:21 -0700147if (UNIX AND NOT APPLE)
148 find_package (Freetype)
149 # Same deal for fontconfig.
150 find_path (FONTCONFIG_INCLUDE_DIRS "fontconfig/fontconfig.h")
151 find_library (FONTCONFIG_LIBRARIES fontconfig)
152 find_package (GIF)
153 find_package (JPEG)
154 find_package (PNG)
155endif()
156
msarett4691d992016-02-16 13:16:39 -0800157# Do not compile SkRawCodec.
158remove_srcs(../src/codec/*Raw*.cpp)
159
mtklein2409abb2015-08-31 06:59:21 -0700160# TODO: macro away this if (found) ... else() ... endif() stuff.
161
mtklein1ee76512015-11-02 10:20:27 -0800162if (EXPAT_FOUND)
163 list (APPEND private_includes ${EXPAT_INCLUDE_DIRS})
164 list (APPEND libs ${EXPAT_LIBRARIES})
165else()
166 remove_srcs (../src/ports/SkFontMgr_android_parser.cpp)
167endif()
168
mtklein2409abb2015-08-31 06:59:21 -0700169if (GIF_FOUND)
170 list (APPEND private_includes ${GIF_INCLUDE_DIRS})
171 list (APPEND libs ${GIF_LIBRARIES})
msarett39b2d5a2016-02-17 08:26:31 -0800172 add_definitions(-DSK_CODEC_DECODES_GIF)
mtklein2409abb2015-08-31 06:59:21 -0700173else()
mtkleine0f06a42015-08-28 11:51:06 -0700174 remove_srcs(../src/images/*gif*)
msarett39b2d5a2016-02-17 08:26:31 -0800175 remove_srcs(../src/codec/*Gif*)
mtkleine0f06a42015-08-28 11:51:06 -0700176endif()
mtklein2409abb2015-08-31 06:59:21 -0700177
178if (JPEG_FOUND)
179 list (APPEND private_includes ${JPEG_INCLUDE_DIRS})
180 list (APPEND libs ${JPEG_LIBRARIES})
msarett39b2d5a2016-02-17 08:26:31 -0800181 add_definitions(-DSK_CODEC_DECODES_JPEG)
mtklein2409abb2015-08-31 06:59:21 -0700182else()
mtkleine0f06a42015-08-28 11:51:06 -0700183 remove_srcs(../src/images/*jpeg*)
msarett39b2d5a2016-02-17 08:26:31 -0800184 remove_srcs(../src/images/*Jpeg*)
185 remove_srcs(../src/codec/*Jpeg*)
mtkleine0f06a42015-08-28 11:51:06 -0700186endif()
mtklein2409abb2015-08-31 06:59:21 -0700187
188if (LUA_FOUND)
189 list (APPEND private_includes ${LUA_INCLUDE_DIR})
190 list (APPEND libs ${LUA_LIBRARIES})
191else()
192 remove_srcs(../src/utils/*Lua*)
mtkleine0f06a42015-08-28 11:51:06 -0700193endif()
mtklein2409abb2015-08-31 06:59:21 -0700194
195if (PNG_FOUND)
196 list (APPEND private_includes ${PNG_INCLUDE_DIRS})
197 list (APPEND libs ${PNG_LIBRARIES})
msarett4691d992016-02-16 13:16:39 -0800198 add_definitions(-DPNG_SKIP_SETJMP_CHECK)
199 add_definitions(-DPNG_SKIP_SKIA_OPTS)
msarett39b2d5a2016-02-17 08:26:31 -0800200 add_definitions(-DSK_CODEC_DECODES_PNG)
mtklein2409abb2015-08-31 06:59:21 -0700201else()
mtkleine0f06a42015-08-28 11:51:06 -0700202 remove_srcs(../src/images/*png*)
msarett39b2d5a2016-02-17 08:26:31 -0800203 remove_srcs(../src/images/*ico*)
204 remove_srcs(../src/codec/*Png*)
205 remove_srcs(../src/codec/*Ico*)
mtkleine0f06a42015-08-28 11:51:06 -0700206endif()
mtklein2409abb2015-08-31 06:59:21 -0700207
208if (ZLIB_FOUND)
209 list (APPEND private_includes ${ZLIB_INCLUDE_DIRS})
210 list (APPEND libs ${ZLIB_LIBRARIES})
halcanary23f4d4d2016-03-12 05:59:39 -0800211 remove_srcs(../src/pdf/SkDocument_PDF_None.cpp)
mtklein2409abb2015-08-31 06:59:21 -0700212else()
halcanary23f4d4d2016-03-12 05:59:39 -0800213 remove_srcs(../src/pdf/*.cpp)
214 set (srcs ${srcs} ../src/pdf/SkDocument_PDF_None.cpp)
mtkleine0f06a42015-08-28 11:51:06 -0700215endif()
mtklein2409abb2015-08-31 06:59:21 -0700216
217if (WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES)
218 list (APPEND private_includes ${WEBP_INCLUDE_DIRS})
219 list (APPEND libs ${WEBP_LIBRARIES})
msarett39b2d5a2016-02-17 08:26:31 -0800220 add_definitions(-DSK_CODEC_DECODES_WEBP)
mtklein2409abb2015-08-31 06:59:21 -0700221else()
mtkleine0f06a42015-08-28 11:51:06 -0700222 remove_srcs(../src/images/*webp*)
msarett39b2d5a2016-02-17 08:26:31 -0800223 remove_srcs(../src/codec/*Webp*)
mtkleine0f06a42015-08-28 11:51:06 -0700224endif()
225
mtklein2409abb2015-08-31 06:59:21 -0700226if (FREETYPE_FOUND)
227 list (APPEND private_includes ${FREETYPE_INCLUDE_DIRS})
228 list (APPEND libs ${FREETYPE_LIBRARIES})
229endif()
230
231if (FONTCONFIG_INCLUDE_DIRS AND FONTCONFIG_LIBRARIES)
232 list (APPEND private_includes ${FONTCONFIG_INCLUDE_DIRS})
233 list (APPEND libs ${FONTCONFIG_LIBRARIES})
234endif()
235
mtkleine0f06a42015-08-28 11:51:06 -0700236if (APPLE)
mtklein2409abb2015-08-31 06:59:21 -0700237 find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices REQUIRED)
238 list (APPEND libs ${APPLICATION_SERVICES_FRAMEWORK})
mtkleine0f06a42015-08-28 11:51:06 -0700239endif()
240
halcanary4ae26252015-09-21 09:42:23 -0700241if (OSMESA_LIBRARIES AND OSMESA_INCLUDE_DIRS)
242 list (APPEND libs ${OSMESA_LIBRARIES})
243 list (APPEND private_includes ${OSMESA_INCLUDE_DIRS})
244 list (APPEND public_defines "-DSK_MESA=1")
mtklein014f06b2016-01-05 08:32:32 -0800245 set (SK_MESA 1)
halcanary4ae26252015-09-21 09:42:23 -0700246else()
247 remove_srcs(../src/gpu/gl/mesa/*)
halcanary4ae26252015-09-21 09:42:23 -0700248endif()
249
mtklein56c6a112015-09-30 11:06:53 -0700250if (WIN32)
251 list (APPEND libs FontSub.lib Usp10.lib)
252endif()
253
halcanary2a4a4212015-09-01 10:11:44 -0700254find_package(OpenGL REQUIRED)
255list (APPEND libs ${OPENGL_LIBRARIES})
256
mtkleine0f06a42015-08-28 11:51:06 -0700257# This is our main output, libskia.so.
258# We mostly build an .so here because it helps test we've linked everything,
259# not so much that we think Skia is a good candidate to ship as a shared library.
260add_library (skia SHARED ${srcs})
261
262target_compile_definitions(skia
halcanary4ae26252015-09-21 09:42:23 -0700263 PUBLIC ${public_defines}
mtklein56c6a112015-09-30 11:06:53 -0700264 PRIVATE -DSKIA_DLL -DSKIA_IMPLEMENTATION=1)
mtkleine0f06a42015-08-28 11:51:06 -0700265
266target_include_directories(skia
267 PUBLIC ${public_includes}
mtklein2409abb2015-08-31 06:59:21 -0700268 PRIVATE ${private_includes})
mtkleine0f06a42015-08-28 11:51:06 -0700269
270target_link_libraries(skia
271 PUBLIC
mtklein2409abb2015-08-31 06:59:21 -0700272 PRIVATE ${libs})
273
mtklein56c6a112015-09-30 11:06:53 -0700274if (MSVC)
275 set(cc_flags "/w /GR-")
276else()
277 set(cc_flags "-w -fno-rtti -fno-exceptions")
278endif()
mtkleine0f06a42015-08-28 11:51:06 -0700279
280set_target_properties(skia PROPERTIES
mtklein56c6a112015-09-30 11:06:53 -0700281 COMPILE_FLAGS ${cc_flags}
mtkleine0f06a42015-08-28 11:51:06 -0700282 CXX_VISIBILITY_PRESET hidden
283 VISIBILITY_INLINES_HIDDEN true)
284
halcanary5a9a5b32015-09-03 14:23:17 -0700285# Experimental C API install:
mtkleina5b0f032015-09-29 13:16:33 -0700286file(GLOB c_headers "../include/c/*.h")
287install(FILES ${c_headers} DESTINATION include)
halcanary5a9a5b32015-09-03 14:23:17 -0700288install(TARGETS skia DESTINATION lib)
289
halcanaryd1c94a42015-11-30 12:42:58 -0800290# SkUserConfig.h
halcanaryd1c94a42015-11-30 12:42:58 -0800291if (CMAKE_BUILD_TYPE STREQUAL Release)
mtklein014f06b2016-01-05 08:32:32 -0800292 set (SK_RELEASE 1)
mtklein95bc09b2016-01-07 06:56:11 -0800293else()
294 set (SK_RELEASE 0)
halcanaryd1c94a42015-11-30 12:42:58 -0800295endif()
mtklein014f06b2016-01-05 08:32:32 -0800296configure_file ("SkUserConfig.h.in" "${userconfig_directory}/SkUserConfig.h")
halcanaryd1c94a42015-11-30 12:42:58 -0800297
298# skia_link_arguments.txt
299set (link_arguments ${CMAKE_BINARY_DIR}/skia_link_arguments.txt)
300file (WRITE ${link_arguments} "-L${CMAKE_BINARY_DIR}\n")
301file (APPEND ${link_arguments} "-lskia\n")
302file (APPEND ${link_arguments} "-Wl,-rpath,${CMAKE_BINARY_DIR}\n")
303
304# skia_compile_arguments.txt
305set (compile_arguments ${CMAKE_BINARY_DIR}/skia_compile_arguments.txt)
306file (WRITE ${compile_arguments} "--std=c++11\n")
307foreach (include ${public_includes})
308 get_filename_component (abs_include ${include} ABSOLUTE)
309 file (APPEND ${compile_arguments} "-I${abs_include}\n")
310endforeach()
311
312# cmake .
313# cmake --build . --target skia
314# c++ -c @skia_compile_arguments.txt example.cpp
315# c++ example.o @skia_link_arguments.txt
316
317# skia.h
halcanary0cbe7ee2015-12-01 09:02:49 -0800318set (bad_files GrGLConfig_chrome.h SkJSONCPP.h SkParsePaint.h)
319# make `c++ @skia_compile_arguments.txt include/skia.h` work.
halcanaryd1c94a42015-11-30 12:42:58 -0800320set (skia_h_path ${userconfig_directory}/skia.h)
321file (WRITE ${skia_h_path} "// skia.h generated by CMake.\n")
322file(APPEND ${skia_h_path} "#ifndef skia_DEFINED\n")
323file(APPEND ${skia_h_path} "#define skia_DEFINED\n")
324foreach (include ${public_includes})
325 if (NOT include STREQUAL userconfig_directory)
326 file (APPEND ${skia_h_path} "\n")
327 file (GLOB all_public_headers ${include}/*.h)
328 foreach (public_header ${all_public_headers})
329 get_filename_component (filename_component ${public_header} NAME)
halcanary0cbe7ee2015-12-01 09:02:49 -0800330 if (NOT ";${bad_files};" MATCHES ";${filename_component};")
331 file (APPEND ${skia_h_path} "#include \"${filename_component}\"\n")
332 endif ()
halcanaryd1c94a42015-11-30 12:42:58 -0800333 endforeach()
334 endif()
335endforeach()
336file(APPEND ${skia_h_path} "\n#endif // skia_DEFINED\n")
337
mtkleine0f06a42015-08-28 11:51:06 -0700338# Now build a simple example app that uses Skia via libskia.so.
mtkleine0f06a42015-08-28 11:51:06 -0700339add_executable(example example.cpp)
340target_link_libraries(example skia ${OPENGL_LIBRARIES})