mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 1 | # Boilerplate. |
mtklein | 0ce744e | 2015-09-01 09:22:31 -0700 | [diff] [blame] | 2 | cmake_minimum_required (VERSION 3.1) # First version with CMAKE_CXX_STANDARD. |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 3 | project (skimake) |
| 4 | set (CMAKE_CXX_STANDARD 11) |
| 5 | |
| 6 | # Default to Release mode. We're mainly targeting Skia users, not Skia developers. |
| 7 | if (NOT CMAKE_BUILD_TYPE) |
| 8 | set (CMAKE_BUILD_TYPE Release) |
| 9 | endif () |
| 10 | |
| 11 | # To first approximation, the Skia library comprises all .cpp files under src/. |
| 12 | file (GLOB_RECURSE srcs ../src/*.cpp) |
| 13 | |
| 14 | function (find_include_dirs out) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 15 | file (GLOB_RECURSE headers ${ARGN}) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 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) |
| 22 | endfunction() |
| 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. |
| 26 | find_include_dirs(private_includes ../src/*.h ../include/private/*.h) |
| 27 | find_include_dirs(public_includes ../include/*.h) |
| 28 | list (REMOVE_ITEM public_includes ${private_includes}) # Easiest way to exclude private. |
| 29 | |
| 30 | # These guys are third_party but provided by a Skia checkout. |
| 31 | list (APPEND srcs ../third_party/etc1/etc1.cpp ../third_party/ktx/ktx.cpp) |
| 32 | list (APPEND private_includes ../third_party/etc1 ../third_party/ktx) |
| 33 | |
| 34 | function (remove_srcs) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 35 | file (GLOB_RECURSE to_remove ${ARGN}) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 36 | list (REMOVE_ITEM srcs ${to_remove}) |
| 37 | set (srcs ${srcs} PARENT_SCOPE) |
| 38 | endfunction() |
| 39 | |
| 40 | # This file is empty and is only used to trick GYP. |
| 41 | remove_srcs (../src/core/SkForceCPlusPlusLinking.cpp) |
| 42 | # This file forces linking for all our supported image decoders. We're more fine-grained. |
| 43 | remove_srcs (../src/images/SkForceLinking.cpp) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 44 | # Chrome only? |
| 45 | remove_srcs (../src/ports/SkFontHost_fontconfig.cpp |
| 46 | ../src/fonts/SkFontMgr_fontconfig.cpp |
| 47 | ../src/ports/SkFontConfigInterface_direct.cpp) |
| 48 | # Alternative font managers. |
| 49 | remove_srcs (../src/ports/SkFontMgr_custom*.cpp) |
| 50 | # Not actually used by Skia. |
| 51 | remove_srcs (../src/utils/SkThreadUtils_pthread_*.cpp) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 52 | |
| 53 | # Skia sure ships a lot of code no one uses. |
| 54 | remove_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. |
mtklein | 0faed58 | 2015-09-14 12:02:32 -0700 | [diff] [blame] | 57 | if (NOT CMAKE_BUILD_TYPE STREQUAL Debug) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 58 | remove_srcs (../src/core/SkDebug.cpp ../src/utils/SkDumpCanvas.cpp) |
| 59 | endif() |
| 60 | |
| 61 | # Remove OS-specific source files. |
| 62 | if (NOT WIN32) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 63 | remove_srcs(../src/*XPS* |
| 64 | ../src/*_win*.cpp |
| 65 | ../src/gpu/gl/angle/* |
| 66 | ../src/ports/SkImageDecoder_WIC.cpp |
| 67 | ../src/utils/win/*) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 68 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 69 | if (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*) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 74 | endif() |
| 75 | if (NOT ANDROID) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 76 | remove_srcs(../src/*Hwui* ../src/*android*) |
| 77 | endif() |
| 78 | if (NOT APPLE) |
| 79 | remove_srcs(../src/*darwin* |
| 80 | ../src/ports/SkImageDecoder_CG.cpp |
| 81 | ../src/utils/mac/* |
| 82 | ../src/*mac*) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 83 | endif() |
| 84 | |
| 85 | # Remove processor-specific source files. |
mtklein | 0faed58 | 2015-09-14 12:02:32 -0700 | [diff] [blame] | 86 | if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ARM) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 87 | remove_srcs(../src/*arm* ../src/*ARM* ../src/*neon* ../src/*NEON*) |
| 88 | endif() |
mtklein | 0faed58 | 2015-09-14 12:02:32 -0700 | [diff] [blame] | 89 | if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL MIPS) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 90 | remove_srcs(../src/*mips* ../src/*MIPS*) |
| 91 | endif() |
| 92 | |
| 93 | # Make our ports choices. |
| 94 | remove_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/* |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 102 | ../src/gpu/gl/iOS/* |
| 103 | ../src/gpu/gl/mesa/* |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 104 | ../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 |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 111 | ../src/ports/SkTLS_none.cpp) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 112 | |
| 113 | remove_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. |
| 116 | file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp) |
| 117 | file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp) |
| 118 | set_source_files_properties(${ssse3_srcs} PROPERTIES COMPILE_FLAGS -mssse3) |
| 119 | set_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. |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 123 | find_package (Lua) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 124 | find_package (ZLIB) |
| 125 | # No find_package for libwebp as far as I can tell, so simulate it here. |
| 126 | find_path (WEBP_INCLUDE_DIRS "webp/decode.h") |
| 127 | find_library (WEBP_LIBRARIES webp) |
| 128 | |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 129 | if (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) |
| 137 | endif() |
| 138 | |
| 139 | # TODO: macro away this if (found) ... else() ... endif() stuff. |
| 140 | |
| 141 | if (GIF_FOUND) |
| 142 | list (APPEND private_includes ${GIF_INCLUDE_DIRS}) |
| 143 | list (APPEND libs ${GIF_LIBRARIES}) |
| 144 | else() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 145 | remove_srcs(../src/images/*gif*) |
| 146 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 147 | |
| 148 | if (JPEG_FOUND) |
| 149 | list (APPEND private_includes ${JPEG_INCLUDE_DIRS}) |
| 150 | list (APPEND libs ${JPEG_LIBRARIES}) |
| 151 | else() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 152 | remove_srcs(../src/images/*jpeg*) |
| 153 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 154 | |
| 155 | if (LUA_FOUND) |
| 156 | list (APPEND private_includes ${LUA_INCLUDE_DIR}) |
| 157 | list (APPEND libs ${LUA_LIBRARIES}) |
| 158 | else() |
| 159 | remove_srcs(../src/utils/*Lua*) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 160 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 161 | |
| 162 | if (PNG_FOUND) |
| 163 | list (APPEND private_includes ${PNG_INCLUDE_DIRS}) |
| 164 | list (APPEND libs ${PNG_LIBRARIES}) |
| 165 | else() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 166 | remove_srcs(../src/images/*png*) |
| 167 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 168 | |
| 169 | if (ZLIB_FOUND) |
| 170 | list (APPEND private_includes ${ZLIB_INCLUDE_DIRS}) |
| 171 | list (APPEND libs ${ZLIB_LIBRARIES}) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 172 | remove_srcs(../src/doc/SkDocument_PDF_None.cpp) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 173 | else() |
| 174 | remove_srcs(../src/pdf/*.cpp ../src/doc/SkDocument_PDF.cpp) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 175 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 176 | |
| 177 | if (WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES) |
| 178 | list (APPEND private_includes ${WEBP_INCLUDE_DIRS}) |
| 179 | list (APPEND libs ${WEBP_LIBRARIES}) |
| 180 | else() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 181 | remove_srcs(../src/images/*webp*) |
| 182 | endif() |
| 183 | |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 184 | if (FREETYPE_FOUND) |
| 185 | list (APPEND private_includes ${FREETYPE_INCLUDE_DIRS}) |
| 186 | list (APPEND libs ${FREETYPE_LIBRARIES}) |
| 187 | endif() |
| 188 | |
| 189 | if (FONTCONFIG_INCLUDE_DIRS AND FONTCONFIG_LIBRARIES) |
| 190 | list (APPEND private_includes ${FONTCONFIG_INCLUDE_DIRS}) |
| 191 | list (APPEND libs ${FONTCONFIG_LIBRARIES}) |
| 192 | endif() |
| 193 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 194 | if (APPLE) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 195 | find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices REQUIRED) |
| 196 | list (APPEND libs ${APPLICATION_SERVICES_FRAMEWORK}) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 197 | endif() |
| 198 | |
halcanary | 2a4a421 | 2015-09-01 10:11:44 -0700 | [diff] [blame] | 199 | find_package(OpenGL REQUIRED) |
| 200 | list (APPEND libs ${OPENGL_LIBRARIES}) |
| 201 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 202 | # 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. |
| 205 | add_library (skia SHARED ${srcs}) |
| 206 | |
| 207 | target_compile_definitions(skia |
| 208 | PUBLIC |
| 209 | PRIVATE -DSKIA_DLL) |
| 210 | |
| 211 | target_include_directories(skia |
| 212 | PUBLIC ${public_includes} |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 213 | PRIVATE ${private_includes}) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 214 | |
| 215 | target_link_libraries(skia |
| 216 | PUBLIC |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 217 | PRIVATE ${libs}) |
| 218 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 219 | |
| 220 | set_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 | |
halcanary | 5a9a5b3 | 2015-09-03 14:23:17 -0700 | [diff] [blame] | 225 | # Experimental C API install: |
| 226 | file(GLOB cheaders "../include/c/*.h") |
| 227 | install(FILES ${cheaders} DESTINATION include) |
| 228 | install(TARGETS skia DESTINATION lib) |
| 229 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 230 | # Now build a simple example app that uses Skia via libskia.so. |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 231 | add_executable(example example.cpp) |
| 232 | target_link_libraries(example skia ${OPENGL_LIBRARIES}) |