f45cc2d91aa50145a25d516ad817bc1abdb3b7ab
[WebKit-https.git] / Source / cmake / OptionsGTK.cmake
1 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
3 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
4
5 include(GNUInstallDirs)
6
7 set(PROJECT_VERSION_MAJOR 2)
8 set(PROJECT_VERSION_MINOR 3)
9 set(PROJECT_VERSION_PATCH 3)
10 set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
11 set(WEBKITGTK_API_VERSION 3.0)
12
13 # Libtool library version, not to be confused with API version.
14 # See http://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
15 CALCULATE_LIBRARY_VERSIONS_FROM_LIBTOOL_TRIPLE(WEBKIT 22 0 22)
16 CALCULATE_LIBRARY_VERSIONS_FROM_LIBTOOL_TRIPLE(WEBKIT2 32 0 7)
17 CALCULATE_LIBRARY_VERSIONS_FROM_LIBTOOL_TRIPLE(JAVASCRIPTCORE 16 2 16)
18
19 set(ENABLE_CREDENTIAL_STORAGE ON CACHE BOOL "Whether or not to enable support for credential storage using libsecret.")
20
21 # FIXME: We want to expose fewer options to downstream, but for now everything is public.
22 WEBKIT_OPTION_BEGIN()
23 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_3D_RENDERING ON)
24 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ACCESSIBILITY ON)
25 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_API_TESTS ON)
26 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_BATTERY_STATUS OFF)
27 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_BLOB ON)
28 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS3_TEXT ON)
29 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS_DEVICE_ADAPTATION ON)
30 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS_GRID_LAYOUT OFF)
31 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS_IMAGE_SET ON)
32 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS_REGIONS ON)
33 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS_STICKY_POSITION ON)
34 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CUSTOM_SCHEME_HANDLER OFF)
35 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_DATALIST_ELEMENT ON)
36 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_DOWNLOAD_ATTRIBUTE ON)
37 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_DRAG_SUPPORT ON)
38 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ENCRYPTED_MEDIA OFF)
39 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ENCRYPTED_MEDIA_V2 OFF)
40 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FAST_MOBILE_SCROLLING ON)
41 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FILTERS ON)
42 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FULLSCREEN_API ON)
43 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_GAMEPAD OFF)
44 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_INDEXED_DATABASE ON)
45 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_INDEXED_DATABASE_IN_WORKERS OFF)
46 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_INPUT_TYPE_COLOR OFF)
47 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_LINK_PREFETCH ON)
48 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_LLINT ON)
49 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEDIA_CAPTURE ON)
50 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEDIA_CONTROLS_SCRIPT ON)
51 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEMORY_SAMPLER ON)
52 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MHTML ON)
53 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NAVIGATOR_CONTENT_UTILS OFF)
54 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NETSCAPE_PLUGIN_API ON)
55 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PAGE_VISIBILITY_API ON)
56 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_QUOTA OFF)
57 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_RESOLUTION_MEDIA_QUERY OFF)
58 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_REQUEST_ANIMATION_FRAME ON)
59 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_SECCOMP_FILTERS OFF)
60 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_SHARED_WORKERS ON)
61 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_SPELLCHECK ON)
62 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_TEMPLATE_ELEMENT ON)
63 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_TOUCH_EVENTS ON)
64 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_USERSELECT_ALL ON)
65 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_VIBRATION OFF)
66 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_VIDEO ON)
67 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_VIDEO_TRACK ON)
68 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_VIEW_MODE_CSS_MEDIA ON)
69 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEB_AUDIO ON)
70 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEB_TIMING ON)
71 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEBGL OFF)
72 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_XHR_TIMEOUT ON)
73 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NETWORK_PROCESS ON)
74 WEBKIT_OPTION_DEFAULT_PORT_VALUE(WTF_USE_TILED_BACKING_STORE OFF)
75
76 # FIXME: Perhaps we need a more generic way of defining dependencies between features.
77 # VIDEO_TRACK depends on VIDEO.
78 if (NOT ENABLE_VIDEO AND ENABLE_VIDEO_TRACK)
79     message(STATUS "Disabling VIDEO_TRACK since VIDEO support is disabled.")
80     set(ENABLE_VIDEO_TRACK OFF)
81 endif ()
82
83 if (DEVELOPER_MODE)
84     set(ENABLE_TOOLS ON)
85     set(ENABLE_API_TESTS ON)
86 else ()
87     set(ENABLE_TOOLS OFF)
88     set(ENABLE_API_TESTS OFF)
89     set(VERSION_SCRIPT "-Wl,--version-script,${CMAKE_SOURCE_DIR}/Source/autotools/symbols.filter")
90 endif ()
91
92 WEBKIT_OPTION_END()
93
94 set(ENABLE_WEBCORE ON)
95 set(ENABLE_INSPECTOR ON)
96 set(ENABLE_WEBKIT OFF)
97 set(ENABLE_WEBKIT2 ON)
98 set(ENABLE_PLUGIN_PROCESS ON)
99
100 set(GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_6)
101 set(GTK_API_VERSION 3.0)
102
103 # These are used to generate the pkg-config files.
104 set(prefix ${CMAKE_INSTALL_PREFIX})
105 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
106 set(libdir "${prefix}/${CMAKE_INSTALL_LIBDIR}")
107 set(includedir "${prefix}/include")
108 set(VERSION ${PROJECT_VERSION})
109
110 set(WTF_USE_SOUP 1)
111 set(WTF_USE_UDIS86 1)
112
113 set(WTF_OUTPUT_NAME WTFGTK)
114 set(JavaScriptCore_OUTPUT_NAME javascriptcoregtk-${WEBKITGTK_API_VERSION})
115 set(WebCore_OUTPUT_NAME WebCoreGTK)
116 set(WebKit_OUTPUT_NAME webkitgtk-${WEBKITGTK_API_VERSION})
117 set(WebKit2_OUTPUT_NAME webkit2gtk-${WEBKITGTK_API_VERSION})
118 set(WebKit2_WebProcess_OUTPUT_NAME WebKitWebProcess)
119 set(WebKit2_NetworkProcess_OUTPUT_NAME WebKitNetworkProcess)
120 set(WebKit2_PluginProcess_OUTPUT_NAME WebKitPluginProcess)
121
122 set(DATA_BUILD_DIR "${CMAKE_BINARY_DIR}/share/${WebKit_OUTPUT_NAME}")
123 set(DATA_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/webkitgtk-${WEBKITGTK_API_VERSION}")
124 set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Where to install libraries")
125 set(EXEC_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH "Where to install executables")
126 set(LIBEXEC_INSTALL_DIR "${CMAKE_INSTALL_LIBEXECDIR}" CACHE PATH "Where to install executables executed by the library")
127 set(WEBKITGTK_HEADER_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/webkitgtk-${WEBKITGTK_API_VERSION}")
128
129 add_definitions(-DBUILDING_GTK__=1)
130 add_definitions(-DGETTEXT_PACKAGE="WebKitGTK-${WEBKITGTK_API_VERSION}")
131 add_definitions(-DDATA_DIR="${CMAKE_INSTALL_DATADIR}")
132 add_definitions(-DUSER_AGENT_GTK_MAJOR_VERSION=537)
133 add_definitions(-DUSER_AGENT_GTK_MINOR_VERSION=30)
134 add_definitions(-DWEBKITGTK_API_VERSION_STRING="${WEBKITGTK_API_VERSION}")
135
136 if (ENABLE_VIDEO OR ENABLE_WEB_AUDIO)
137     set(GSTREAMER_COMPONENTS app pbutils)
138     add_definitions(-DWTF_USE_GSTREAMER)
139     if (ENABLE_VIDEO)
140         list(APPEND GSTREAMER_COMPONENTS video mpegts tag)
141     endif ()
142
143     if (ENABLE_WEB_AUDIO)
144         list(APPEND GSTREAMER_COMPONENTS audio fft)
145         add_definitions(-DWTF_USE_WEBAUDIO_GSTREAMER)
146     endif ()
147
148     find_package(GStreamer 1.0.3 REQUIRED COMPONENTS ${GSTREAMER_COMPONENTS})
149
150     if (PC_GSTREAMER_MPEGTS_FOUND)
151         add_definitions(-DWTF_USE_GSTREAMER_MPEGTS)
152         set(USE_GSTREAMER_MPEGTS TRUE)
153     endif ()
154 endif ()
155
156 # FIXME: These need to be configurable.
157 add_definitions(-DWTF_PLATFORM_X11=1)
158 add_definitions(-DMOZ_X11)
159
160 find_package(Cairo 1.10.2 REQUIRED)
161 find_package(Fontconfig 2.8.0 REQUIRED)
162 find_package(Freetype2 2.4.2 REQUIRED)
163 find_package(GTK2 2.24.10 REQUIRED)
164 find_package(GDK2 2.24.10 REQUIRED)
165 find_package(HarfBuzz 0.9.2 REQUIRED)
166 find_package(ICU REQUIRED)
167 find_package(JPEG REQUIRED)
168 find_package(LibSoup 2.40.3 REQUIRED)
169 find_package(LibXml2 2.8.0 REQUIRED)
170 find_package(LibXslt 1.1.7 REQUIRED)
171 find_package(PNG REQUIRED)
172 find_package(Sqlite REQUIRED)
173 find_package(Threads REQUIRED)
174 find_package(ZLIB REQUIRED)
175 find_package(ATK REQUIRED)
176 find_package(WebP REQUIRED)
177 find_package(ATSPI 2.5.3)
178 find_package(GObjectIntrospection)
179
180 if (NOT USE_GTK2)
181     find_package(GTK3 3.6.0 REQUIRED)
182     find_package(GDK3 3.6.0 REQUIRED)
183     set(GTK_LIBRARIES ${GTK3_LIBRARIES})
184     set(GTK_INCLUDE_DIRS ${GTK3_INCLUDE_DIRS})
185     set(GDK_LIBRARIES ${GDK3_LIBRARIES})
186     set(GDK_INCLUDE_DIRS ${GDK3_INCLUDE_DIRS})
187 else ()
188     set(GTK_LIBRARIES ${GTK2_LIBRARIES})
189     set(GTK_INCLUDE_DIRS ${GTK2_INCLUDE_DIRS})
190     set(GDK_LIBRARIES ${GDK2_LIBRARIES})
191     set(GDK_INCLUDE_DIRS ${GDK2_INCLUDE_DIRS})
192     add_definitions(-DGTK_API_VERSION_2)
193     add_definitions(-DWEBKITGTK_API_VERSION_STRING="2.0")
194 endif ()
195
196 set(glib_components gio gobject gthread gmodule)
197 if (ENABLE_GAMEPAD)
198     list(APPEND glib_components gio-unix)
199 endif ()
200 find_package(GLIB 2.33.2 REQUIRED COMPONENTS ${glib_components})
201
202 if (ENABLE_GEOLOCATION)
203     find_package(GeoClue2 2.1.5)
204     if (GEOCLUE2_FOUND)
205       set(WTF_USE_GEOCLUE2 1)
206     else ()
207       find_package(GeoClue)
208       set(WTF_USE_GEOCLUE2 0)
209     endif ()
210 endif ()
211
212 find_package(GTKUnixPrint)
213 if (GTK_UNIX_PRINT_FOUND)
214     set(HAVE_GTK_UNIX_PRINTING 1)
215 endif ()
216
217 if (ENABLE_CREDENTIAL_STORAGE)
218     find_package(Libsecret)
219     set(ENABLE_CREDENTIAL_STORAGE 1)
220 endif ()
221
222 find_package(OpenGL)
223
224 # This part can be simplified once CMake 2.8.6 is required and
225 # CMakePushCheckState can be used. We need to have OPENGL_INCLUDE_DIR as part
226 # of the directories check_include_files() looks for in case OpenGL is
227 # installed into a non-standard location.
228 set(REQUIRED_INCLUDES_OLD ${CMAKE_REQUIRED_INCLUDES})
229 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENGL_INCLUDE_DIR})
230 # We don't use find_package for GLX because it is part of -lGL, unlike EGL.
231 check_include_files("GL/glx.h" GLX_FOUND)
232 set(CMAKE_REQUIRED_INCLUDES ${REQUIRED_INCLUDES_OLD})
233
234 find_package(EGL)
235 if (EGL_FOUND)
236     set(WTF_USE_EGL 1)
237 endif ()
238
239 if (ENABLE_SPELLCHECK)
240     find_package(Enchant REQUIRED)
241 endif ()
242
243 if (OPENGL_FOUND AND (GLX_FOUND OR EGL_FOUND))
244     set(ENABLE_WEBGL 1)
245     set(ENABLE_TEXTURE_MAPPER 1)
246     set(WTF_USE_3D_GRAPHICS 1)
247
248     add_definitions(-DWTF_USE_OPENGL=1)
249     add_definitions(-DWTF_USE_ACCELERATED_COMPOSITING=1)
250     add_definitions(-DWTF_USE_3D_GRAPHICS=1)
251     add_definitions(-DWTF_USE_TEXTURE_MAPPER=1)
252     add_definitions(-DWTF_USE_TEXTURE_MAPPER_GL=1)
253     add_definitions(-DENABLE_3D_RENDERING=1)
254
255     if (EGL_FOUND)
256         add_definitions(-DWTF_USE_EGL=1)
257     endif ()
258
259     if (GLX_FOUND)
260         add_definitions(-DWTF_USE_GLX=1)
261     endif ()
262 endif ()
263
264 if (ENABLE_INDEXED_DATABASE)
265     set(WTF_USE_LEVELDB 1)
266     add_definitions(-DWTF_USE_LEVELDB=1)
267 endif ()
268
269 if (ENABLE_GAMEPAD)
270     find_package(GUdev)
271 endif ()
272
273 set(CPACK_SOURCE_GENERATOR TBZ2)
274
275 set(DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR ${DERIVED_SOURCES_DIR}/webkitdom)
276 set(DERIVED_SOURCES_WEBKITGTK_DIR ${DERIVED_SOURCES_DIR}/webkitgtk)
277 set(DERIVED_SOURCES_WEBKITGTK_API_DIR ${DERIVED_SOURCES_WEBKITGTK_DIR}/webkit)
278 set(DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR ${DERIVED_SOURCES_DIR}/webkitdom)
279 set(DERIVED_SOURCES_WEBKIT2GTK_DIR ${DERIVED_SOURCES_DIR}/webkit2gtk)
280 set(DERIVED_SOURCES_WEBKIT2GTK_API_DIR ${DERIVED_SOURCES_WEBKIT2GTK_DIR}/webkit2)
281 set(FORWARDING_HEADERS_DIR ${DERIVED_SOURCES_DIR}/ForwardingHeaders)
282 set(FORWARDING_HEADERS_WEBKIT2GTK_DIR ${FORWARDING_HEADERS_DIR}/webkit2gtk)
283 set(FORWARDING_HEADERS_WEBKIT2GTK_EXTENSION_DIR ${FORWARDING_HEADERS_DIR}/webkit2gtk-webextension)
284
285 set(WebKit_PKGCONFIG_FILE ${CMAKE_BINARY_DIR}/Source/WebKit/gtk/webkitgtk-${WEBKITGTK_API_VERSION}.pc)
286 set(WebKit2_PKGCONFIG_FILE ${CMAKE_BINARY_DIR}/Source/WebKit2/webkit2gtk-${WEBKITGTK_API_VERSION}.pc)
287 set(WebKit2WebExtension_PKGCONFIG_FILE ${CMAKE_BINARY_DIR}/Source/WebKit2/webkit2gtk-web-extension-${WEBKITGTK_API_VERSION}.pc)
288
289 set(SHOULD_INSTALL_JS_SHELL ON)
290
291 # Push of rbp is needed after JSC JIT uses CStack. See http://wkbug.com/127777.
292 if (UNIX AND NOT APPLE)
293     if (CMAKE_COMPILER_IS_GNUCXX)
294         set(CMAKE_C_FLAGS_RELEASE "-fno-omit-frame-pointer -fno-tree-dce ${CMAKE_C_FLAGS_RELEASE}")
295         set(CMAKE_CXX_FLAGS_RELEASE "-fno-omit-frame-pointer -fno-tree-dce ${CMAKE_CXX_FLAGS_RELEASE}")
296     endif ()
297     if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
298         set(CMAKE_C_FLAGS_RELEASE "-fno-omit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}")
299         set(CMAKE_CXX_FLAGS_RELEASE "-fno-omit-frame-pointer ${CMAKE_CXX_FLAGS_RELEASE}")
300     endif ()
301 endif ()
302
303 # Add a typelib file to the list of all typelib dependencies. This makes it easy to
304 # expose a 'gir' target with all gobject-introspection files.
305 macro(ADD_TYPELIB typelib)
306     get_filename_component(target_name ${typelib} NAME_WE)
307     add_custom_target(${target_name}-gir ALL DEPENDS ${typelib})
308     list(APPEND GObjectIntrospectionTargets ${target_name}-gir)
309     set(GObjectIntrospectionTargets ${GObjectIntrospectionTargets} PARENT_SCOPE)
310 endmacro()
311
312 # CMake does not automatically add --whole-archive when building shared objects from
313 # a list of convenience libraries. This can lead to missing symbols in the final output.
314 # We add --whole-archive to all libraries manually to prevent the linker from trimming
315 # symbols that we actually need later.
316 macro(ADD_WHOLE_ARCHIVE_TO_LIBRARIES _list_name)
317     foreach (library IN LISTS ${_list_name})
318       list(APPEND ${_list_name}_TMP -Wl,--whole-archive ${library} -Wl,--no-whole-archive)
319     endforeach ()
320     set(${_list_name} "${${_list_name}_TMP}")
321 endmacro()
322
323 build_command(COMMAND_LINE_TO_BUILD)
324 # build_command unconditionally adds -i (ignore errors) for make, and there's
325 # no reasonable way to turn that off, so we just replace it with -k, which has
326 # the same effect, except that the return code will indicate that an error occurred.
327 # See: http://www.cmake.org/cmake/help/v3.0/command/build_command.html
328 string(REPLACE " -i" " -k" COMMAND_LINE_TO_BUILD ${COMMAND_LINE_TO_BUILD})
329 file(WRITE
330     ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/build.sh
331     "#!/bin/sh\n"
332     "${COMMAND_LINE_TO_BUILD} $@"
333 )
334 file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/build.sh
335   DESTINATION ${CMAKE_BINARY_DIR}
336   FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)