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/* |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 103 | ../src/opts/SkBitmapProcState_opts_none.cpp |
| 104 | ../src/opts/SkBlitMask_opts_none.cpp |
| 105 | ../src/opts/SkBlitRow_opts_none.cpp |
| 106 | ../src/ports/SkFontMgr_empty_factory.cpp |
| 107 | ../src/ports/SkGlobalInitialization_chromium.cpp |
| 108 | ../src/ports/SkImageDecoder_empty.cpp |
| 109 | ../src/ports/SkImageGenerator_none.cpp |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 110 | ../src/ports/SkTLS_none.cpp) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 111 | |
| 112 | remove_srcs(../src/codec/*) # TODO: Requires Chromium's libjpeg-turbo, and incompatible giflib. |
| 113 | |
| 114 | # Certain files must be compiled with support for SSSE3 or SSE4.1 intrinsics. |
| 115 | file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp) |
| 116 | file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp) |
| 117 | set_source_files_properties(${ssse3_srcs} PROPERTIES COMPILE_FLAGS -mssse3) |
| 118 | set_source_files_properties(${sse41_srcs} PROPERTIES COMPILE_FLAGS -msse4.1) |
| 119 | |
| 120 | # Detect our optional dependencies. |
| 121 | # 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] | 122 | find_package (Lua) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 123 | find_package (ZLIB) |
| 124 | # No find_package for libwebp as far as I can tell, so simulate it here. |
| 125 | find_path (WEBP_INCLUDE_DIRS "webp/decode.h") |
| 126 | find_library (WEBP_LIBRARIES webp) |
halcanary | 4ae2625 | 2015-09-21 09:42:23 -0700 | [diff] [blame] | 127 | find_path (OSMESA_INCLUDE_DIRS "GL/osmesa.h") |
| 128 | find_library(OSMESA_LIBRARIES "OSMesa") |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 129 | |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 130 | if (UNIX AND NOT APPLE) |
| 131 | find_package (Freetype) |
| 132 | # Same deal for fontconfig. |
| 133 | find_path (FONTCONFIG_INCLUDE_DIRS "fontconfig/fontconfig.h") |
| 134 | find_library (FONTCONFIG_LIBRARIES fontconfig) |
| 135 | find_package (GIF) |
| 136 | find_package (JPEG) |
| 137 | find_package (PNG) |
| 138 | endif() |
| 139 | |
| 140 | # TODO: macro away this if (found) ... else() ... endif() stuff. |
| 141 | |
| 142 | if (GIF_FOUND) |
| 143 | list (APPEND private_includes ${GIF_INCLUDE_DIRS}) |
| 144 | list (APPEND libs ${GIF_LIBRARIES}) |
| 145 | else() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 146 | remove_srcs(../src/images/*gif*) |
| 147 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 148 | |
| 149 | if (JPEG_FOUND) |
| 150 | list (APPEND private_includes ${JPEG_INCLUDE_DIRS}) |
| 151 | list (APPEND libs ${JPEG_LIBRARIES}) |
| 152 | else() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 153 | remove_srcs(../src/images/*jpeg*) |
| 154 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 155 | |
| 156 | if (LUA_FOUND) |
| 157 | list (APPEND private_includes ${LUA_INCLUDE_DIR}) |
| 158 | list (APPEND libs ${LUA_LIBRARIES}) |
| 159 | else() |
| 160 | remove_srcs(../src/utils/*Lua*) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 161 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 162 | |
| 163 | if (PNG_FOUND) |
| 164 | list (APPEND private_includes ${PNG_INCLUDE_DIRS}) |
| 165 | list (APPEND libs ${PNG_LIBRARIES}) |
| 166 | else() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 167 | remove_srcs(../src/images/*png*) |
| 168 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 169 | |
| 170 | if (ZLIB_FOUND) |
| 171 | list (APPEND private_includes ${ZLIB_INCLUDE_DIRS}) |
| 172 | list (APPEND libs ${ZLIB_LIBRARIES}) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 173 | remove_srcs(../src/doc/SkDocument_PDF_None.cpp) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 174 | else() |
| 175 | remove_srcs(../src/pdf/*.cpp ../src/doc/SkDocument_PDF.cpp) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 176 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 177 | |
| 178 | if (WEBP_INCLUDE_DIRS AND WEBP_LIBRARIES) |
| 179 | list (APPEND private_includes ${WEBP_INCLUDE_DIRS}) |
| 180 | list (APPEND libs ${WEBP_LIBRARIES}) |
| 181 | else() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 182 | remove_srcs(../src/images/*webp*) |
| 183 | endif() |
| 184 | |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 185 | if (FREETYPE_FOUND) |
| 186 | list (APPEND private_includes ${FREETYPE_INCLUDE_DIRS}) |
| 187 | list (APPEND libs ${FREETYPE_LIBRARIES}) |
| 188 | endif() |
| 189 | |
| 190 | if (FONTCONFIG_INCLUDE_DIRS AND FONTCONFIG_LIBRARIES) |
| 191 | list (APPEND private_includes ${FONTCONFIG_INCLUDE_DIRS}) |
| 192 | list (APPEND libs ${FONTCONFIG_LIBRARIES}) |
| 193 | endif() |
| 194 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 195 | if (APPLE) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 196 | find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices REQUIRED) |
| 197 | list (APPEND libs ${APPLICATION_SERVICES_FRAMEWORK}) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 198 | endif() |
| 199 | |
halcanary | 4ae2625 | 2015-09-21 09:42:23 -0700 | [diff] [blame] | 200 | if (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") |
| 204 | message("-- Found OSMesa: " ${OSMESA_LIBRARIES}) |
| 205 | else() |
| 206 | remove_srcs(../src/gpu/gl/mesa/*) |
| 207 | message("-- Could NOT find OSMesa") |
| 208 | endif() |
| 209 | |
halcanary | 2a4a421 | 2015-09-01 10:11:44 -0700 | [diff] [blame] | 210 | find_package(OpenGL REQUIRED) |
| 211 | list (APPEND libs ${OPENGL_LIBRARIES}) |
| 212 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 213 | # This is our main output, libskia.so. |
| 214 | # We mostly build an .so here because it helps test we've linked everything, |
| 215 | # not so much that we think Skia is a good candidate to ship as a shared library. |
| 216 | add_library (skia SHARED ${srcs}) |
| 217 | |
halcanary | 4ae2625 | 2015-09-21 09:42:23 -0700 | [diff] [blame] | 218 | list (APPEND private_defines "-DSKIA_DLL") |
| 219 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 220 | target_compile_definitions(skia |
halcanary | 4ae2625 | 2015-09-21 09:42:23 -0700 | [diff] [blame] | 221 | PUBLIC ${public_defines} |
| 222 | PRIVATE ${private_defines}) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 223 | |
| 224 | target_include_directories(skia |
| 225 | PUBLIC ${public_includes} |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 226 | PRIVATE ${private_includes}) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 227 | |
| 228 | target_link_libraries(skia |
| 229 | PUBLIC |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 230 | PRIVATE ${libs}) |
| 231 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 232 | |
| 233 | set_target_properties(skia PROPERTIES |
| 234 | COMPILE_FLAGS "-fno-exceptions -fno-rtti -Wno-deprecated-declarations" |
| 235 | CXX_VISIBILITY_PRESET hidden |
| 236 | VISIBILITY_INLINES_HIDDEN true) |
| 237 | |
halcanary | 5a9a5b3 | 2015-09-03 14:23:17 -0700 | [diff] [blame] | 238 | # Experimental C API install: |
| 239 | file(GLOB cheaders "../include/c/*.h") |
| 240 | install(FILES ${cheaders} DESTINATION include) |
| 241 | install(TARGETS skia DESTINATION lib) |
| 242 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 243 | # Now build a simple example app that uses Skia via libskia.so. |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 244 | add_executable(example example.cpp) |
| 245 | target_link_libraries(example skia ${OPENGL_LIBRARIES}) |