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) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 50 | |
| 51 | # Skia sure ships a lot of code no one uses. |
| 52 | remove_srcs (../src/animator/* ../src/*nacl* ../src/svg/* ../src/views/* ../src/xml/*) |
| 53 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 54 | # Remove OS-specific source files. |
mtklein | 56c6a11 | 2015-09-30 11:06:53 -0700 | [diff] [blame] | 55 | if (NOT UNIX) |
mtklein | 1ee7651 | 2015-11-02 10:20:27 -0800 | [diff] [blame] | 56 | remove_srcs(../src/ports/*_posix.cpp |
mtklein | 56c6a11 | 2015-09-30 11:06:53 -0700 | [diff] [blame] | 57 | ../src/ports/SkTLS_pthread.cpp |
| 58 | ../src/ports/SkTime_Unix.cpp |
mtklein | a1bde7d | 2015-10-20 11:05:06 -0700 | [diff] [blame] | 59 | ../src/utils/SkThreadUtils_pthread.cpp) |
mtklein | 56c6a11 | 2015-09-30 11:06:53 -0700 | [diff] [blame] | 60 | endif() |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 61 | if (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*) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 66 | endif() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 67 | |
| 68 | # Remove processor-specific source files. |
mtklein | 0faed58 | 2015-09-14 12:02:32 -0700 | [diff] [blame] | 69 | if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ARM) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 70 | remove_srcs(../src/*arm* ../src/*ARM* ../src/*neon* ../src/*NEON*) |
| 71 | endif() |
mtklein | 0faed58 | 2015-09-14 12:02:32 -0700 | [diff] [blame] | 72 | if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL MIPS) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 73 | remove_srcs(../src/*mips* ../src/*MIPS*) |
| 74 | endif() |
| 75 | |
| 76 | # Make our ports choices. |
| 77 | remove_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/* |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 85 | ../src/gpu/gl/iOS/* |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 86 | ../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 |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 93 | ../src/ports/SkTLS_none.cpp) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 94 | |
mtklein | 56c6a11 | 2015-09-30 11:06:53 -0700 | [diff] [blame] | 95 | if (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() |
| 101 | endif() |
| 102 | |
| 103 | remove_srcs(../src/gpu/gl/angle/*) # TODO |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 104 | remove_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. |
| 107 | file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp) |
| 108 | file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp) |
| 109 | set_source_files_properties(${ssse3_srcs} PROPERTIES COMPILE_FLAGS -mssse3) |
| 110 | set_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. |
mtklein | 1ee7651 | 2015-11-02 10:20:27 -0800 | [diff] [blame] | 114 | find_package (EXPAT) |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 115 | find_package (Lua) |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 116 | find_package (ZLIB) |
| 117 | # No find_package for libwebp as far as I can tell, so simulate it here. |
| 118 | find_path (WEBP_INCLUDE_DIRS "webp/decode.h") |
| 119 | find_library (WEBP_LIBRARIES webp) |
halcanary | 4ae2625 | 2015-09-21 09:42:23 -0700 | [diff] [blame] | 120 | find_path (OSMESA_INCLUDE_DIRS "GL/osmesa.h") |
| 121 | find_library(OSMESA_LIBRARIES "OSMesa") |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 122 | |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 123 | if (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) |
| 131 | endif() |
| 132 | |
| 133 | # TODO: macro away this if (found) ... else() ... endif() stuff. |
| 134 | |
mtklein | 1ee7651 | 2015-11-02 10:20:27 -0800 | [diff] [blame] | 135 | if (EXPAT_FOUND) |
| 136 | list (APPEND private_includes ${EXPAT_INCLUDE_DIRS}) |
| 137 | list (APPEND libs ${EXPAT_LIBRARIES}) |
| 138 | else() |
| 139 | remove_srcs (../src/ports/SkFontMgr_android_parser.cpp) |
| 140 | endif() |
| 141 | |
mtklein | 2409abb | 2015-08-31 06:59:21 -0700 | [diff] [blame] | 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") |
halcanary | 4ae2625 | 2015-09-21 09:42:23 -0700 | [diff] [blame] | 204 | else() |
| 205 | remove_srcs(../src/gpu/gl/mesa/*) |
halcanary | 4ae2625 | 2015-09-21 09:42:23 -0700 | [diff] [blame] | 206 | endif() |
| 207 | |
mtklein | 56c6a11 | 2015-09-30 11:06:53 -0700 | [diff] [blame] | 208 | if (WIN32) |
| 209 | list (APPEND libs FontSub.lib Usp10.lib) |
| 210 | endif() |
| 211 | |
halcanary | 2a4a421 | 2015-09-01 10:11:44 -0700 | [diff] [blame] | 212 | find_package(OpenGL REQUIRED) |
| 213 | list (APPEND libs ${OPENGL_LIBRARIES}) |
| 214 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 215 | # 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. |
| 218 | add_library (skia SHARED ${srcs}) |
| 219 | |
| 220 | target_compile_definitions(skia |
halcanary | 4ae2625 | 2015-09-21 09:42:23 -0700 | [diff] [blame] | 221 | PUBLIC ${public_defines} |
mtklein | 56c6a11 | 2015-09-30 11:06:53 -0700 | [diff] [blame] | 222 | PRIVATE -DSKIA_DLL -DSKIA_IMPLEMENTATION=1) |
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 | 56c6a11 | 2015-09-30 11:06:53 -0700 | [diff] [blame] | 232 | if (MSVC) |
| 233 | set(cc_flags "/w /GR-") |
| 234 | else() |
| 235 | set(cc_flags "-w -fno-rtti -fno-exceptions") |
| 236 | endif() |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 237 | |
| 238 | set_target_properties(skia PROPERTIES |
mtklein | 56c6a11 | 2015-09-30 11:06:53 -0700 | [diff] [blame] | 239 | COMPILE_FLAGS ${cc_flags} |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 240 | CXX_VISIBILITY_PRESET hidden |
| 241 | VISIBILITY_INLINES_HIDDEN true) |
| 242 | |
halcanary | 5a9a5b3 | 2015-09-03 14:23:17 -0700 | [diff] [blame] | 243 | # Experimental C API install: |
mtklein | a5b0f03 | 2015-09-29 13:16:33 -0700 | [diff] [blame] | 244 | file(GLOB c_headers "../include/c/*.h") |
| 245 | install(FILES ${c_headers} DESTINATION include) |
halcanary | 5a9a5b3 | 2015-09-03 14:23:17 -0700 | [diff] [blame] | 246 | install(TARGETS skia DESTINATION lib) |
| 247 | |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 248 | # Now build a simple example app that uses Skia via libskia.so. |
mtklein | e0f06a4 | 2015-08-28 11:51:06 -0700 | [diff] [blame] | 249 | add_executable(example example.cpp) |
| 250 | target_link_libraries(example skia ${OPENGL_LIBRARIES}) |