1# Boilerplate. 2cmake_minimum_required (VERSION 3.1) # First version with CMAKE_CXX_STANDARD. 3project (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) 15 file (GLOB_RECURSE headers ${ARGN}) 16 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. 29file (GLOB default_include_config "../include/config") 30list (REMOVE_ITEM public_includes ${default_include_config}) 31set (userconfig_directory ${CMAKE_BINARY_DIR}/include) 32list (APPEND public_includes ${userconfig_directory}) 33 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) 39 file (GLOB_RECURSE to_remove ${ARGN}) 40 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) 48# Chrome only? 49remove_srcs (../src/ports/SkFontHost_fontconfig.cpp 50 ../src/fonts/SkFontMgr_fontconfig.cpp 51 ../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) 55# Alternative font managers. 56remove_srcs (../src/ports/SkFontMgr_custom*.cpp) 57 58# Skia sure ships a lot of code no one uses. 59remove_srcs (../src/animator/* ../src/*nacl* ../src/svg/* ../src/views/* ../src/xml/*) 60foreach (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() 64 65# Remove OS-specific source files. 66if (NOT UNIX) 67 remove_srcs(../src/ports/*_posix.cpp 68 ../src/ports/SkTLS_pthread.cpp 69 ../src/ports/SkTime_Unix.cpp 70 ../src/utils/SkThreadUtils_pthread.cpp) 71endif() 72if (APPLE OR NOT UNIX) 73 remove_srcs(../src/gpu/gl/glx/* 74 ../src/images/SkImageDecoder_FactoryDefault.cpp 75 ../src/ports/SkFontMgr_fontconfig*.cpp 76 ../src/ports/SkFontMgr_android*.cpp 77 ../src/*FreeType*) 78endif() 79 80# Remove processor-specific source files. 81if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ARM) 82 remove_srcs(../src/*arm* ../src/*ARM* ../src/*neon* ../src/*NEON*) 83endif() 84if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL MIPS) 85 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/* 97 ../src/gpu/gl/iOS/* 98 ../src/gpu/vk/* 99 ../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 106 ../src/ports/SkTLS_none.cpp) 107 108if (WIN32) 109 if(SKIA_GDI) 110 remove_srcs(../src/ports/SkFontMgr_win_dw_factory.cpp) 111 else() 112 remove_srcs(../src/ports/SkFontMgr_win_gdi_factory.cpp) 113 endif() 114endif() 115 116remove_srcs(../src/gpu/gl/angle/*) # TODO 117 118# Certain files must be compiled with support for SSSE3, SSE4.1, AVX, or AVX2 intrinsics. 119file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp) 120file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp) 121file (GLOB_RECURSE avx_srcs ../src/*_avx.cpp) 122file (GLOB_RECURSE avx2_srcs ../src/*_avx2.cpp) 123set_source_files_properties(${ssse3_srcs} PROPERTIES COMPILE_FLAGS -mssse3) 124set_source_files_properties(${sse41_srcs} PROPERTIES COMPILE_FLAGS -msse4.1) 125set_source_files_properties(${avx_srcs} PROPERTIES COMPILE_FLAGS -mavx) 126set_source_files_properties(${avx2_srcs} PROPERTIES COMPILE_FLAGS -mavx2) 127 128# Detect our optional dependencies. 129# If we can't find them, don't build the parts of Skia that use them. 130find_package (EXPAT) 131find_package (Lua) 132find_package (ZLIB) 133# No find_package for libwebp as far as I can tell, so simulate it here. 134find_path (WEBP_INCLUDE_DIRS "webp/decode.h") 135find_library (WEBP_LIBRARIES webp) 136find_path (OSMESA_INCLUDE_DIRS "GL/osmesa.h") 137find_library(OSMESA_LIBRARIES "OSMesa") 138 139if (UNIX AND NOT APPLE) 140 find_package (Freetype) 141 # Same deal for fontconfig. 142 find_path (FONTCONFIG_INCLUDE_DIRS "fontconfig/fontconfig.h") 143 find_library (FONTCONFIG_LIBRARIES fontconfig) 144 find_package (GIF) 145 find_package (JPEG) 146 find_package (PNG) 147endif() 148 149# Do not compile SkRawCodec. 150remove_srcs(../src/codec/*Raw*.cpp) 151 152# TODO: macro away this if (found) ... else() ... endif() stuff. 153 154if (EXPAT_FOUND) 155 list (APPEND private_includes ${EXPAT_INCLUDE_DIRS}) 156 list (APPEND libs ${EXPAT_LIBRARIES}) 157else() 158 remove_srcs (../src/ports/SkFontMgr_android_parser.cpp) 159endif() 160 161if (GIF_FOUND) 162 list (APPEND private_includes ${GIF_INCLUDE_DIRS}) 163 list (APPEND libs ${GIF_LIBRARIES}) 164 add_definitions(-DSK_CODEC_DECODES_GIF) 165else() 166 remove_srcs(../src/images/*gif*) 167 remove_srcs(../src/codec/*Gif*) 168endif() 169 170if (JPEG_FOUND) 171 list (APPEND private_includes ${JPEG_INCLUDE_DIRS}) 172 list (APPEND libs ${JPEG_LIBRARIES}) 173 add_definitions(-DSK_CODEC_DECODES_JPEG) 174else() 175 remove_srcs(../src/images/*jpeg*) 176 remove_srcs(../src/images/*Jpeg*) 177 remove_srcs(../src/codec/*Jpeg*) 178endif() 179 180if (LUA_FOUND) 181 list (APPEND private_includes ${LUA_INCLUDE_DIR}) 182 list (APPEND libs ${LUA_LIBRARIES}) 183else() 184 remove_srcs(../src/utils/*Lua*) 185endif() 186 187if (PNG_FOUND) 188 list (APPEND private_includes ${PNG_INCLUDE_DIRS}) 189 list (APPEND libs ${PNG_LIBRARIES}) 190 add_definitions(-DPNG_SKIP_SETJMP_CHECK) 191 add_definitions(-DPNG_SKIP_SKIA_OPTS) 192 add_definitions(-DSK_CODEC_DECODES_PNG) 193else() 194 remove_srcs(../src/images/*png*) 195 remove_srcs(../src/images/*ico*) 196 remove_srcs(../src/codec/*Png*) 197 remove_srcs(../src/codec/*Ico*) 198endif() 199 200if (ZLIB_FOUND) 201 list (APPEND private_includes ${ZLIB_INCLUDE_DIRS}) 202 list (APPEND libs ${ZLIB_LIBRARIES}) 203 remove_srcs(../src/doc/SkDocument_PDF_None.cpp) 204else() 205 remove_srcs(../src/pdf/*.cpp ../src/doc/SkDocument_PDF.cpp) 206endif() 207 208if (WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES) 209 list (APPEND private_includes ${WEBP_INCLUDE_DIRS}) 210 list (APPEND libs ${WEBP_LIBRARIES}) 211 add_definitions(-DSK_CODEC_DECODES_WEBP) 212else() 213 remove_srcs(../src/images/*webp*) 214 remove_srcs(../src/codec/*Webp*) 215endif() 216 217if (FREETYPE_FOUND) 218 list (APPEND private_includes ${FREETYPE_INCLUDE_DIRS}) 219 list (APPEND libs ${FREETYPE_LIBRARIES}) 220endif() 221 222if (FONTCONFIG_INCLUDE_DIRS AND FONTCONFIG_LIBRARIES) 223 list (APPEND private_includes ${FONTCONFIG_INCLUDE_DIRS}) 224 list (APPEND libs ${FONTCONFIG_LIBRARIES}) 225endif() 226 227if (APPLE) 228 find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices REQUIRED) 229 list (APPEND libs ${APPLICATION_SERVICES_FRAMEWORK}) 230endif() 231 232if (OSMESA_LIBRARIES AND OSMESA_INCLUDE_DIRS) 233 list (APPEND libs ${OSMESA_LIBRARIES}) 234 list (APPEND private_includes ${OSMESA_INCLUDE_DIRS}) 235 list (APPEND public_defines "-DSK_MESA=1") 236 set (SK_MESA 1) 237else() 238 remove_srcs(../src/gpu/gl/mesa/*) 239endif() 240 241if (WIN32) 242 list (APPEND libs FontSub.lib Usp10.lib) 243endif() 244 245find_package(OpenGL REQUIRED) 246list (APPEND libs ${OPENGL_LIBRARIES}) 247 248# This is our main output, libskia.so. 249# We mostly build an .so here because it helps test we've linked everything, 250# not so much that we think Skia is a good candidate to ship as a shared library. 251add_library (skia SHARED ${srcs}) 252 253target_compile_definitions(skia 254 PUBLIC ${public_defines} 255 PRIVATE -DSKIA_DLL -DSKIA_IMPLEMENTATION=1) 256 257target_include_directories(skia 258 PUBLIC ${public_includes} 259 PRIVATE ${private_includes}) 260 261target_link_libraries(skia 262 PUBLIC 263 PRIVATE ${libs}) 264 265if (MSVC) 266 set(cc_flags "/w /GR-") 267else() 268 set(cc_flags "-w -fno-rtti -fno-exceptions") 269endif() 270 271set_target_properties(skia PROPERTIES 272 COMPILE_FLAGS ${cc_flags} 273 CXX_VISIBILITY_PRESET hidden 274 VISIBILITY_INLINES_HIDDEN true) 275 276# Experimental C API install: 277file(GLOB c_headers "../include/c/*.h") 278install(FILES ${c_headers} DESTINATION include) 279install(TARGETS skia DESTINATION lib) 280 281# SkUserConfig.h 282if (CMAKE_BUILD_TYPE STREQUAL Release) 283 set (SK_RELEASE 1) 284else() 285 set (SK_RELEASE 0) 286endif() 287configure_file ("SkUserConfig.h.in" "${userconfig_directory}/SkUserConfig.h") 288 289# skia_link_arguments.txt 290set (link_arguments ${CMAKE_BINARY_DIR}/skia_link_arguments.txt) 291file (WRITE ${link_arguments} "-L${CMAKE_BINARY_DIR}\n") 292file (APPEND ${link_arguments} "-lskia\n") 293file (APPEND ${link_arguments} "-Wl,-rpath,${CMAKE_BINARY_DIR}\n") 294 295# skia_compile_arguments.txt 296set (compile_arguments ${CMAKE_BINARY_DIR}/skia_compile_arguments.txt) 297file (WRITE ${compile_arguments} "--std=c++11\n") 298foreach (include ${public_includes}) 299 get_filename_component (abs_include ${include} ABSOLUTE) 300 file (APPEND ${compile_arguments} "-I${abs_include}\n") 301endforeach() 302 303# cmake . 304# cmake --build . --target skia 305# c++ -c @skia_compile_arguments.txt example.cpp 306# c++ example.o @skia_link_arguments.txt 307 308# skia.h 309set (bad_files GrGLConfig_chrome.h SkJSONCPP.h SkParsePaint.h) 310# make `c++ @skia_compile_arguments.txt include/skia.h` work. 311set (skia_h_path ${userconfig_directory}/skia.h) 312file (WRITE ${skia_h_path} "// skia.h generated by CMake.\n") 313file(APPEND ${skia_h_path} "#ifndef skia_DEFINED\n") 314file(APPEND ${skia_h_path} "#define skia_DEFINED\n") 315foreach (include ${public_includes}) 316 if (NOT include STREQUAL userconfig_directory) 317 file (APPEND ${skia_h_path} "\n") 318 file (GLOB all_public_headers ${include}/*.h) 319 foreach (public_header ${all_public_headers}) 320 get_filename_component (filename_component ${public_header} NAME) 321 if (NOT ";${bad_files};" MATCHES ";${filename_component};") 322 file (APPEND ${skia_h_path} "#include \"${filename_component}\"\n") 323 endif () 324 endforeach() 325 endif() 326endforeach() 327file(APPEND ${skia_h_path} "\n#endif // skia_DEFINED\n") 328 329# Now build a simple example app that uses Skia via libskia.so. 330add_executable(example example.cpp) 331target_link_libraries(example skia ${OPENGL_LIBRARIES}) 332