blob: c6614f3feca42e9576a95060834eeeae245acf28 [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)
mtkleine0f06a42015-08-28 11:51:06 -070050
51# Skia sure ships a lot of code no one uses.
52remove_srcs (../src/animator/* ../src/*nacl* ../src/svg/* ../src/views/* ../src/xml/*)
53
mtkleine0f06a42015-08-28 11:51:06 -070054# Remove OS-specific source files.
mtklein56c6a112015-09-30 11:06:53 -070055if (NOT UNIX)
mtklein1ee76512015-11-02 10:20:27 -080056 remove_srcs(../src/ports/*_posix.cpp
mtklein56c6a112015-09-30 11:06:53 -070057 ../src/ports/SkTLS_pthread.cpp
58 ../src/ports/SkTime_Unix.cpp
mtkleina1bde7d2015-10-20 11:05:06 -070059 ../src/utils/SkThreadUtils_pthread.cpp)
mtklein56c6a112015-09-30 11:06:53 -070060endif()
mtklein2409abb2015-08-31 06:59:21 -070061if (APPLE OR NOT UNIX)
62 remove_srcs(../src/gpu/gl/glx/*
63 ../src/images/SkImageDecoder_FactoryDefault.cpp
64 ../src/ports/SkFontMgr_fontconfig*.cpp
65 ../src/*FreeType*)
mtkleine0f06a42015-08-28 11:51:06 -070066endif()
mtkleine0f06a42015-08-28 11:51:06 -070067
68# Remove processor-specific source files.
mtklein0faed582015-09-14 12:02:32 -070069if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ARM)
mtkleine0f06a42015-08-28 11:51:06 -070070 remove_srcs(../src/*arm* ../src/*ARM* ../src/*neon* ../src/*NEON*)
71endif()
mtklein0faed582015-09-14 12:02:32 -070072if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL MIPS)
mtkleine0f06a42015-08-28 11:51:06 -070073 remove_srcs(../src/*mips* ../src/*MIPS*)
74endif()
75
76# Make our ports choices.
77remove_srcs(
78 ../src/*moz* # We're probably not Mozilla.
79 ../src/gpu/GrContextFactory.cpp # For internal testing only.
80 ../src/gpu/gl/GrGLCreateNativeInterface_none.cpp
81 ../src/gpu/gl/GrGLDefaultInterface_none.cpp
82 ../src/gpu/gl/SkCreatePlatformGLContext*.cpp # For internal testing only.
83 ../src/gpu/gl/command_buffer/*
84 ../src/gpu/gl/egl/*
mtkleine0f06a42015-08-28 11:51:06 -070085 ../src/gpu/gl/iOS/*
mtkleine0f06a42015-08-28 11:51:06 -070086 ../src/opts/SkBitmapProcState_opts_none.cpp
87 ../src/opts/SkBlitMask_opts_none.cpp
88 ../src/opts/SkBlitRow_opts_none.cpp
89 ../src/ports/SkFontMgr_empty_factory.cpp
90 ../src/ports/SkGlobalInitialization_chromium.cpp
91 ../src/ports/SkImageDecoder_empty.cpp
92 ../src/ports/SkImageGenerator_none.cpp
mtklein2409abb2015-08-31 06:59:21 -070093 ../src/ports/SkTLS_none.cpp)
mtkleine0f06a42015-08-28 11:51:06 -070094
mtklein56c6a112015-09-30 11:06:53 -070095if (WIN32)
96 if(SKIA_GDI)
97 remove_srcs(../src/ports/SkFontMgr_win_dw_factory.cpp)
98 else()
99 remove_srcs(../src/ports/SkFontMgr_win_gdi_factory.cpp)
100 endif()
101endif()
102
103remove_srcs(../src/gpu/gl/angle/*) # TODO
mtkleine0f06a42015-08-28 11:51:06 -0700104remove_srcs(../src/codec/*) # TODO: Requires Chromium's libjpeg-turbo, and incompatible giflib.
105
106# Certain files must be compiled with support for SSSE3 or SSE4.1 intrinsics.
107file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp)
108file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp)
109set_source_files_properties(${ssse3_srcs} PROPERTIES COMPILE_FLAGS -mssse3)
110set_source_files_properties(${sse41_srcs} PROPERTIES COMPILE_FLAGS -msse4.1)
111
112# Detect our optional dependencies.
113# If we can't find them, don't build the parts of Skia that use them.
mtklein1ee76512015-11-02 10:20:27 -0800114find_package (EXPAT)
mtklein2409abb2015-08-31 06:59:21 -0700115find_package (Lua)
mtkleine0f06a42015-08-28 11:51:06 -0700116find_package (ZLIB)
117# No find_package for libwebp as far as I can tell, so simulate it here.
118find_path (WEBP_INCLUDE_DIRS "webp/decode.h")
119find_library (WEBP_LIBRARIES webp)
halcanary4ae26252015-09-21 09:42:23 -0700120find_path (OSMESA_INCLUDE_DIRS "GL/osmesa.h")
121find_library(OSMESA_LIBRARIES "OSMesa")
mtkleine0f06a42015-08-28 11:51:06 -0700122
mtklein2409abb2015-08-31 06:59:21 -0700123if (UNIX AND NOT APPLE)
124 find_package (Freetype)
125 # Same deal for fontconfig.
126 find_path (FONTCONFIG_INCLUDE_DIRS "fontconfig/fontconfig.h")
127 find_library (FONTCONFIG_LIBRARIES fontconfig)
128 find_package (GIF)
129 find_package (JPEG)
130 find_package (PNG)
131endif()
132
133# TODO: macro away this if (found) ... else() ... endif() stuff.
134
mtklein1ee76512015-11-02 10:20:27 -0800135if (EXPAT_FOUND)
136 list (APPEND private_includes ${EXPAT_INCLUDE_DIRS})
137 list (APPEND libs ${EXPAT_LIBRARIES})
138else()
139 remove_srcs (../src/ports/SkFontMgr_android_parser.cpp)
140endif()
141
mtklein2409abb2015-08-31 06:59:21 -0700142if (GIF_FOUND)
143 list (APPEND private_includes ${GIF_INCLUDE_DIRS})
144 list (APPEND libs ${GIF_LIBRARIES})
145else()
mtkleine0f06a42015-08-28 11:51:06 -0700146 remove_srcs(../src/images/*gif*)
147endif()
mtklein2409abb2015-08-31 06:59:21 -0700148
149if (JPEG_FOUND)
150 list (APPEND private_includes ${JPEG_INCLUDE_DIRS})
151 list (APPEND libs ${JPEG_LIBRARIES})
152else()
mtkleine0f06a42015-08-28 11:51:06 -0700153 remove_srcs(../src/images/*jpeg*)
154endif()
mtklein2409abb2015-08-31 06:59:21 -0700155
156if (LUA_FOUND)
157 list (APPEND private_includes ${LUA_INCLUDE_DIR})
158 list (APPEND libs ${LUA_LIBRARIES})
159else()
160 remove_srcs(../src/utils/*Lua*)
mtkleine0f06a42015-08-28 11:51:06 -0700161endif()
mtklein2409abb2015-08-31 06:59:21 -0700162
163if (PNG_FOUND)
164 list (APPEND private_includes ${PNG_INCLUDE_DIRS})
165 list (APPEND libs ${PNG_LIBRARIES})
166else()
mtkleine0f06a42015-08-28 11:51:06 -0700167 remove_srcs(../src/images/*png*)
168endif()
mtklein2409abb2015-08-31 06:59:21 -0700169
170if (ZLIB_FOUND)
171 list (APPEND private_includes ${ZLIB_INCLUDE_DIRS})
172 list (APPEND libs ${ZLIB_LIBRARIES})
mtkleine0f06a42015-08-28 11:51:06 -0700173 remove_srcs(../src/doc/SkDocument_PDF_None.cpp)
mtklein2409abb2015-08-31 06:59:21 -0700174else()
175 remove_srcs(../src/pdf/*.cpp ../src/doc/SkDocument_PDF.cpp)
mtkleine0f06a42015-08-28 11:51:06 -0700176endif()
mtklein2409abb2015-08-31 06:59:21 -0700177
178if (WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES)
179 list (APPEND private_includes ${WEBP_INCLUDE_DIRS})
180 list (APPEND libs ${WEBP_LIBRARIES})
181else()
mtkleine0f06a42015-08-28 11:51:06 -0700182 remove_srcs(../src/images/*webp*)
183endif()
184
mtklein2409abb2015-08-31 06:59:21 -0700185if (FREETYPE_FOUND)
186 list (APPEND private_includes ${FREETYPE_INCLUDE_DIRS})
187 list (APPEND libs ${FREETYPE_LIBRARIES})
188endif()
189
190if (FONTCONFIG_INCLUDE_DIRS AND FONTCONFIG_LIBRARIES)
191 list (APPEND private_includes ${FONTCONFIG_INCLUDE_DIRS})
192 list (APPEND libs ${FONTCONFIG_LIBRARIES})
193endif()
194
mtkleine0f06a42015-08-28 11:51:06 -0700195if (APPLE)
mtklein2409abb2015-08-31 06:59:21 -0700196 find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices REQUIRED)
197 list (APPEND libs ${APPLICATION_SERVICES_FRAMEWORK})
mtkleine0f06a42015-08-28 11:51:06 -0700198endif()
199
halcanary4ae26252015-09-21 09:42:23 -0700200if (OSMESA_LIBRARIES AND OSMESA_INCLUDE_DIRS)
201 list (APPEND libs ${OSMESA_LIBRARIES})
202 list (APPEND private_includes ${OSMESA_INCLUDE_DIRS})
203 list (APPEND public_defines "-DSK_MESA=1")
halcanary4ae26252015-09-21 09:42:23 -0700204else()
205 remove_srcs(../src/gpu/gl/mesa/*)
halcanary4ae26252015-09-21 09:42:23 -0700206endif()
207
mtklein56c6a112015-09-30 11:06:53 -0700208if (WIN32)
209 list (APPEND libs FontSub.lib Usp10.lib)
210endif()
211
halcanary2a4a4212015-09-01 10:11:44 -0700212find_package(OpenGL REQUIRED)
213list (APPEND libs ${OPENGL_LIBRARIES})
214
mtkleine0f06a42015-08-28 11:51:06 -0700215# This is our main output, libskia.so.
216# We mostly build an .so here because it helps test we've linked everything,
217# not so much that we think Skia is a good candidate to ship as a shared library.
218add_library (skia SHARED ${srcs})
219
220target_compile_definitions(skia
halcanary4ae26252015-09-21 09:42:23 -0700221 PUBLIC ${public_defines}
mtklein56c6a112015-09-30 11:06:53 -0700222 PRIVATE -DSKIA_DLL -DSKIA_IMPLEMENTATION=1)
mtkleine0f06a42015-08-28 11:51:06 -0700223
224target_include_directories(skia
225 PUBLIC ${public_includes}
mtklein2409abb2015-08-31 06:59:21 -0700226 PRIVATE ${private_includes})
mtkleine0f06a42015-08-28 11:51:06 -0700227
228target_link_libraries(skia
229 PUBLIC
mtklein2409abb2015-08-31 06:59:21 -0700230 PRIVATE ${libs})
231
mtklein56c6a112015-09-30 11:06:53 -0700232if (MSVC)
233 set(cc_flags "/w /GR-")
234else()
235 set(cc_flags "-w -fno-rtti -fno-exceptions")
236endif()
mtkleine0f06a42015-08-28 11:51:06 -0700237
238set_target_properties(skia PROPERTIES
mtklein56c6a112015-09-30 11:06:53 -0700239 COMPILE_FLAGS ${cc_flags}
mtkleine0f06a42015-08-28 11:51:06 -0700240 CXX_VISIBILITY_PRESET hidden
241 VISIBILITY_INLINES_HIDDEN true)
242
halcanary5a9a5b32015-09-03 14:23:17 -0700243# Experimental C API install:
mtkleina5b0f032015-09-29 13:16:33 -0700244file(GLOB c_headers "../include/c/*.h")
245install(FILES ${c_headers} DESTINATION include)
halcanary5a9a5b32015-09-03 14:23:17 -0700246install(TARGETS skia DESTINATION lib)
247
mtkleine0f06a42015-08-28 11:51:06 -0700248# Now build a simple example app that uses Skia via libskia.so.
mtkleine0f06a42015-08-28 11:51:06 -0700249add_executable(example example.cpp)
250target_link_libraries(example skia ${OPENGL_LIBRARIES})