blob: 36a6d1ecf3ca947363c8197efebd4a2e5e82a64c [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.
29
30# These guys are third_party but provided by a Skia checkout.
31list (APPEND srcs ../third_party/etc1/etc1.cpp ../third_party/ktx/ktx.cpp)
32list (APPEND private_includes ../third_party/etc1 ../third_party/ktx)
33
34function (remove_srcs)
mtklein2409abb2015-08-31 06:59:21 -070035 file (GLOB_RECURSE to_remove ${ARGN})
mtkleine0f06a42015-08-28 11:51:06 -070036 list (REMOVE_ITEM srcs ${to_remove})
37 set (srcs ${srcs} PARENT_SCOPE)
38endfunction()
39
40# This file is empty and is only used to trick GYP.
41remove_srcs (../src/core/SkForceCPlusPlusLinking.cpp)
42# This file forces linking for all our supported image decoders. We're more fine-grained.
43remove_srcs (../src/images/SkForceLinking.cpp)
mtklein2409abb2015-08-31 06:59:21 -070044# Chrome only?
45remove_srcs (../src/ports/SkFontHost_fontconfig.cpp
46 ../src/fonts/SkFontMgr_fontconfig.cpp
47 ../src/ports/SkFontConfigInterface_direct.cpp)
48# Alternative font managers.
49remove_srcs (../src/ports/SkFontMgr_custom*.cpp)
50# Not actually used by Skia.
51remove_srcs (../src/utils/SkThreadUtils_pthread_*.cpp)
mtkleine0f06a42015-08-28 11:51:06 -070052
53# Skia sure ships a lot of code no one uses.
54remove_srcs (../src/animator/* ../src/*nacl* ../src/svg/* ../src/views/* ../src/xml/*)
55
56# Some files only contain code in Debug mode. This quiets down some linker warnings.
mtklein0faed582015-09-14 12:02:32 -070057if (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
mtkleine0f06a42015-08-28 11:51:06 -070058 remove_srcs (../src/core/SkDebug.cpp ../src/utils/SkDumpCanvas.cpp)
59endif()
60
61# Remove OS-specific source files.
62if (NOT WIN32)
mtklein2409abb2015-08-31 06:59:21 -070063 remove_srcs(../src/*XPS*
64 ../src/*_win*.cpp
65 ../src/gpu/gl/angle/*
66 ../src/ports/SkImageDecoder_WIC.cpp
67 ../src/utils/win/*)
mtkleine0f06a42015-08-28 11:51:06 -070068endif()
mtklein2409abb2015-08-31 06:59:21 -070069if (APPLE OR NOT UNIX)
70 remove_srcs(../src/gpu/gl/glx/*
71 ../src/images/SkImageDecoder_FactoryDefault.cpp
72 ../src/ports/SkFontMgr_fontconfig*.cpp
73 ../src/*FreeType*)
mtkleine0f06a42015-08-28 11:51:06 -070074endif()
75if (NOT ANDROID)
mtklein2409abb2015-08-31 06:59:21 -070076 remove_srcs(../src/*Hwui* ../src/*android*)
77endif()
78if (NOT APPLE)
79 remove_srcs(../src/*darwin*
80 ../src/ports/SkImageDecoder_CG.cpp
81 ../src/utils/mac/*
82 ../src/*mac*)
mtkleine0f06a42015-08-28 11:51:06 -070083endif()
84
85# Remove processor-specific source files.
mtklein0faed582015-09-14 12:02:32 -070086if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ARM)
mtkleine0f06a42015-08-28 11:51:06 -070087 remove_srcs(../src/*arm* ../src/*ARM* ../src/*neon* ../src/*NEON*)
88endif()
mtklein0faed582015-09-14 12:02:32 -070089if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL MIPS)
mtkleine0f06a42015-08-28 11:51:06 -070090 remove_srcs(../src/*mips* ../src/*MIPS*)
91endif()
92
93# Make our ports choices.
94remove_srcs(
95 ../src/*moz* # We're probably not Mozilla.
96 ../src/gpu/GrContextFactory.cpp # For internal testing only.
97 ../src/gpu/gl/GrGLCreateNativeInterface_none.cpp
98 ../src/gpu/gl/GrGLDefaultInterface_none.cpp
99 ../src/gpu/gl/SkCreatePlatformGLContext*.cpp # For internal testing only.
100 ../src/gpu/gl/command_buffer/*
101 ../src/gpu/gl/egl/*
mtkleine0f06a42015-08-28 11:51:06 -0700102 ../src/gpu/gl/iOS/*
103 ../src/gpu/gl/mesa/*
mtkleine0f06a42015-08-28 11:51:06 -0700104 ../src/opts/SkBitmapProcState_opts_none.cpp
105 ../src/opts/SkBlitMask_opts_none.cpp
106 ../src/opts/SkBlitRow_opts_none.cpp
107 ../src/ports/SkFontMgr_empty_factory.cpp
108 ../src/ports/SkGlobalInitialization_chromium.cpp
109 ../src/ports/SkImageDecoder_empty.cpp
110 ../src/ports/SkImageGenerator_none.cpp
mtklein2409abb2015-08-31 06:59:21 -0700111 ../src/ports/SkTLS_none.cpp)
mtkleine0f06a42015-08-28 11:51:06 -0700112
113remove_srcs(../src/codec/*) # TODO: Requires Chromium's libjpeg-turbo, and incompatible giflib.
114
115# Certain files must be compiled with support for SSSE3 or SSE4.1 intrinsics.
116file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp)
117file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp)
118set_source_files_properties(${ssse3_srcs} PROPERTIES COMPILE_FLAGS -mssse3)
119set_source_files_properties(${sse41_srcs} PROPERTIES COMPILE_FLAGS -msse4.1)
120
121# Detect our optional dependencies.
122# If we can't find them, don't build the parts of Skia that use them.
mtklein2409abb2015-08-31 06:59:21 -0700123find_package (Lua)
mtkleine0f06a42015-08-28 11:51:06 -0700124find_package (ZLIB)
125# No find_package for libwebp as far as I can tell, so simulate it here.
126find_path (WEBP_INCLUDE_DIRS "webp/decode.h")
127find_library (WEBP_LIBRARIES webp)
128
mtklein2409abb2015-08-31 06:59:21 -0700129if (UNIX AND NOT APPLE)
130 find_package (Freetype)
131 # Same deal for fontconfig.
132 find_path (FONTCONFIG_INCLUDE_DIRS "fontconfig/fontconfig.h")
133 find_library (FONTCONFIG_LIBRARIES fontconfig)
134 find_package (GIF)
135 find_package (JPEG)
136 find_package (PNG)
137endif()
138
139# TODO: macro away this if (found) ... else() ... endif() stuff.
140
141if (GIF_FOUND)
142 list (APPEND private_includes ${GIF_INCLUDE_DIRS})
143 list (APPEND libs ${GIF_LIBRARIES})
144else()
mtkleine0f06a42015-08-28 11:51:06 -0700145 remove_srcs(../src/images/*gif*)
146endif()
mtklein2409abb2015-08-31 06:59:21 -0700147
148if (JPEG_FOUND)
149 list (APPEND private_includes ${JPEG_INCLUDE_DIRS})
150 list (APPEND libs ${JPEG_LIBRARIES})
151else()
mtkleine0f06a42015-08-28 11:51:06 -0700152 remove_srcs(../src/images/*jpeg*)
153endif()
mtklein2409abb2015-08-31 06:59:21 -0700154
155if (LUA_FOUND)
156 list (APPEND private_includes ${LUA_INCLUDE_DIR})
157 list (APPEND libs ${LUA_LIBRARIES})
158else()
159 remove_srcs(../src/utils/*Lua*)
mtkleine0f06a42015-08-28 11:51:06 -0700160endif()
mtklein2409abb2015-08-31 06:59:21 -0700161
162if (PNG_FOUND)
163 list (APPEND private_includes ${PNG_INCLUDE_DIRS})
164 list (APPEND libs ${PNG_LIBRARIES})
165else()
mtkleine0f06a42015-08-28 11:51:06 -0700166 remove_srcs(../src/images/*png*)
167endif()
mtklein2409abb2015-08-31 06:59:21 -0700168
169if (ZLIB_FOUND)
170 list (APPEND private_includes ${ZLIB_INCLUDE_DIRS})
171 list (APPEND libs ${ZLIB_LIBRARIES})
mtkleine0f06a42015-08-28 11:51:06 -0700172 remove_srcs(../src/doc/SkDocument_PDF_None.cpp)
mtklein2409abb2015-08-31 06:59:21 -0700173else()
174 remove_srcs(../src/pdf/*.cpp ../src/doc/SkDocument_PDF.cpp)
mtkleine0f06a42015-08-28 11:51:06 -0700175endif()
mtklein2409abb2015-08-31 06:59:21 -0700176
177if (WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES)
178 list (APPEND private_includes ${WEBP_INCLUDE_DIRS})
179 list (APPEND libs ${WEBP_LIBRARIES})
180else()
mtkleine0f06a42015-08-28 11:51:06 -0700181 remove_srcs(../src/images/*webp*)
182endif()
183
mtklein2409abb2015-08-31 06:59:21 -0700184if (FREETYPE_FOUND)
185 list (APPEND private_includes ${FREETYPE_INCLUDE_DIRS})
186 list (APPEND libs ${FREETYPE_LIBRARIES})
187endif()
188
189if (FONTCONFIG_INCLUDE_DIRS AND FONTCONFIG_LIBRARIES)
190 list (APPEND private_includes ${FONTCONFIG_INCLUDE_DIRS})
191 list (APPEND libs ${FONTCONFIG_LIBRARIES})
192endif()
193
mtkleine0f06a42015-08-28 11:51:06 -0700194if (APPLE)
mtklein2409abb2015-08-31 06:59:21 -0700195 find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices REQUIRED)
196 list (APPEND libs ${APPLICATION_SERVICES_FRAMEWORK})
mtkleine0f06a42015-08-28 11:51:06 -0700197endif()
198
halcanary2a4a4212015-09-01 10:11:44 -0700199find_package(OpenGL REQUIRED)
200list (APPEND libs ${OPENGL_LIBRARIES})
201
mtkleine0f06a42015-08-28 11:51:06 -0700202# This is our main output, libskia.so.
203# We mostly build an .so here because it helps test we've linked everything,
204# not so much that we think Skia is a good candidate to ship as a shared library.
205add_library (skia SHARED ${srcs})
206
207target_compile_definitions(skia
208 PUBLIC
209 PRIVATE -DSKIA_DLL)
210
211target_include_directories(skia
212 PUBLIC ${public_includes}
mtklein2409abb2015-08-31 06:59:21 -0700213 PRIVATE ${private_includes})
mtkleine0f06a42015-08-28 11:51:06 -0700214
215target_link_libraries(skia
216 PUBLIC
mtklein2409abb2015-08-31 06:59:21 -0700217 PRIVATE ${libs})
218
mtkleine0f06a42015-08-28 11:51:06 -0700219
220set_target_properties(skia PROPERTIES
221 COMPILE_FLAGS "-fno-exceptions -fno-rtti -Wno-deprecated-declarations"
222 CXX_VISIBILITY_PRESET hidden
223 VISIBILITY_INLINES_HIDDEN true)
224
halcanary5a9a5b32015-09-03 14:23:17 -0700225# Experimental C API install:
226file(GLOB cheaders "../include/c/*.h")
227install(FILES ${cheaders} DESTINATION include)
228install(TARGETS skia DESTINATION lib)
229
mtkleine0f06a42015-08-28 11:51:06 -0700230# Now build a simple example app that uses Skia via libskia.so.
mtkleine0f06a42015-08-28 11:51:06 -0700231add_executable(example example.cpp)
232target_link_libraries(example skia ${OPENGL_LIBRARIES})