[GTK] Runtime critical warnings when closing a page containing windowed plugins
[WebKit-https.git] / Source / cmake / WebKitMacros.cmake
1 macro(WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS)
2     set(_file ${CMAKE_CURRENT_SOURCE_DIR}/Platform${PORT}.cmake)
3     if (EXISTS ${_file})
4         message(STATUS "Using platform-specific CMakeLists: ${_file}")
5         include(${_file})
6     else ()
7         message(STATUS "Platform-specific CMakeLists not found: ${_file}")
8     endif ()
9 endmacro()
10
11 # Append the given dependencies to the source file
12 macro(ADD_SOURCE_DEPENDENCIES _source _deps)
13     set(_tmp)
14     get_source_file_property(_tmp ${_source} OBJECT_DEPENDS)
15     if (NOT _tmp)
16         set(_tmp "")
17     endif ()
18
19     foreach (f ${_deps})
20         list(APPEND _tmp "${f}")
21     endforeach ()
22
23     set_source_files_properties(${_source} PROPERTIES OBJECT_DEPENDS "${_tmp}")
24 endmacro()
25
26 macro(ADD_PRECOMPILED_HEADER _header _cpp _source)
27     if (MSVC)
28         get_filename_component(PrecompiledBasename ${_header} NAME_WE)
29         set(PrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${PrecompiledBasename}.pch")
30         set(_sources ${${_source}})
31
32         set_source_files_properties(${_cpp}
33             PROPERTIES COMPILE_FLAGS "/Yc\"${_header}\" /Fp\"${PrecompiledBinary}\""
34             OBJECT_OUTPUTS "${PrecompiledBinary}")
35         set_source_files_properties(${_sources}
36             PROPERTIES COMPILE_FLAGS "/Yu\"${_header}\" /FI\"${_header}\" /Fp\"${PrecompiledBinary}\""
37             OBJECT_DEPENDS "${PrecompiledBinary}")
38         list(APPEND ${_source} ${_cpp})
39     endif ()
40     #FIXME: Add support for Xcode.
41 endmacro()
42
43 # Helper macro which wraps generate-bindings.pl script.
44 #   _output_source is a list name which will contain generated sources.(eg. WebCore_SOURCES)
45 #   _input_files are IDL files to generate.
46 #   _base_dir is base directory where script is called.
47 #   _idl_includes is value of --include argument. (eg. --include=${WEBCORE_DIR}/bindings/js)
48 #   _features is a value of --defines argument.
49 #   _destination is a value of --outputDir argument.
50 #   _prefix is a prefix of output files. (eg. JS - it makes JSXXX.cpp JSXXX.h from XXX.idl)
51 #   _generator is a value of --generator argument.
52 #   _supplemental_dependency_file is a value of --supplementalDependencyFile. (optional)
53 macro(GENERATE_BINDINGS _output_source _input_files _base_dir _idl_includes _features _destination _prefix _generator _extension _idl_attributes_file)
54     set(BINDING_GENERATOR ${WEBCORE_DIR}/bindings/scripts/generate-bindings.pl)
55     set(_args ${ARGN})
56     list(LENGTH _args _argCount)
57     if (_argCount GREATER 0)
58         list(GET _args 0 _supplemental_dependency_file)
59         if (_supplemental_dependency_file)
60             set(_supplemental_dependency --supplementalDependencyFile ${_supplemental_dependency_file})
61         endif ()
62         list(GET _args 1 _additional_dependencies)
63     endif ()
64
65     set(COMMON_GENERATOR_DEPENDENCIES
66         ${BINDING_GENERATOR}
67         ${WEBCORE_DIR}/bindings/scripts/CodeGenerator.pm
68         ${SCRIPTS_BINDINGS}
69         ${_supplemental_dependency_file}
70         ${_idl_attributes_file}
71     )
72     list(APPEND COMMON_GENERATOR_DEPENDENCIES ${_additional_dependencies})
73
74     if (EXISTS ${WEBCORE_DIR}/bindings/scripts/CodeGenerator${_generator}.pm)
75         list(APPEND COMMON_GENERATOR_DEPENDENCIES ${WEBCORE_DIR}/bindings/scripts/CodeGenerator${_generator}.pm)
76     endif ()
77
78     foreach (_file ${_input_files})
79         get_filename_component(_name ${_file} NAME_WE)
80
81         # Not all ObjC bindings generate a .mm file, and not all .mm files generated should be compiled.
82         if (${_generator} STREQUAL "ObjC")
83             list(FIND ObjC_BINDINGS_NO_MM ${_name} _no_mm_index)
84             if (${_no_mm_index} EQUAL -1)
85                 set(_no_mm 0)
86             else ()
87                 set(_no_mm 1)
88             endif ()
89         else ()
90             set(_no_mm 0)
91         endif ()
92
93         if (${_no_mm})
94             add_custom_command(
95                 OUTPUT ${_destination}/${_prefix}${_name}.h
96                 MAIN_DEPENDENCY ${_file}
97                 DEPENDS ${COMMON_GENERATOR_DEPENDENCIES}
98                 COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${BINDING_GENERATOR} --defines "${_features}" --generator ${_generator} ${_idl_includes} --outputDir "${_destination}" --preprocessor "${CODE_GENERATOR_PREPROCESSOR}" --idlAttributesFile ${_idl_attributes_file} ${_supplemental_dependency} ${_file}
99                 WORKING_DIRECTORY ${_base_dir}
100                 VERBATIM)
101
102             list(APPEND ${_output_source} ${_destination}/${_prefix}${_name}.h)
103         else ()
104             add_custom_command(
105                 OUTPUT ${_destination}/${_prefix}${_name}.${_extension} ${_destination}/${_prefix}${_name}.h
106                 MAIN_DEPENDENCY ${_file}
107                 DEPENDS ${COMMON_GENERATOR_DEPENDENCIES}
108                 COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${BINDING_GENERATOR} --defines "${_features}" --generator ${_generator} ${_idl_includes} --outputDir "${_destination}" --preprocessor "${CODE_GENERATOR_PREPROCESSOR}" --idlAttributesFile ${_idl_attributes_file} ${_supplemental_dependency} ${_file}
109                 WORKING_DIRECTORY ${_base_dir}
110                 VERBATIM)
111             list(APPEND ${_output_source} ${_destination}/${_prefix}${_name}.${_extension})
112         endif ()
113     endforeach ()
114 endmacro()
115
116 macro(GENERATE_FONT_NAMES _infile)
117     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
118     set(_arguments  --fonts ${_infile})
119     set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.h)
120
121     add_custom_command(
122         OUTPUT  ${_outputfiles}
123         MAIN_DEPENDENCY ${_infile}
124         DEPENDS ${MAKE_NAMES_DEPENDENCIES} ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
125         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments}
126         VERBATIM)
127 endmacro()
128
129
130 macro(GENERATE_EVENT_FACTORY _infile _outfile)
131     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_event_factory.pl)
132
133     add_custom_command(
134         OUTPUT  ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
135         MAIN_DEPENDENCY ${_infile}
136         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
137         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
138         VERBATIM)
139 endmacro()
140
141
142 macro(GENERATE_EXCEPTION_CODE_DESCRIPTION _infile _outfile)
143     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_dom_exceptions.pl)
144
145     add_custom_command(
146         OUTPUT  ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
147         MAIN_DEPENDENCY ${_infile}
148         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
149         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
150         VERBATIM)
151 endmacro()
152
153
154 macro(GENERATE_SETTINGS_MACROS _infile _outfile)
155     set(NAMES_GENERATOR ${WEBCORE_DIR}/page/make_settings.pl)
156
157     add_custom_command(
158         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile} ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.h ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.idl
159         MAIN_DEPENDENCY ${_infile}
160         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
161         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
162         VERBATIM)
163 endmacro()
164
165
166 macro(GENERATE_DOM_NAMES _namespace _attrs)
167     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
168     set(_arguments  --attrs ${_attrs})
169     set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.h)
170     set(_extradef)
171     set(_tags)
172
173     foreach (f ${ARGN})
174         if (_tags)
175             set(_extradef "${_extradef} ${f}")
176         else ()
177             set(_tags ${f})
178         endif ()
179     endforeach ()
180
181     if (_tags)
182         set(_arguments "${_arguments}" --tags ${_tags} --factory --wrapperFactory)
183         set(_outputfiles "${_outputfiles}" ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}ElementFactory.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}ElementFactory.h ${DERIVED_SOURCES_WEBCORE_DIR}/JS${_namespace}ElementWrapperFactory.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/JS${_namespace}ElementWrapperFactory.h)
184     endif ()
185
186     if (_extradef)
187         set(_additionArguments "${_additionArguments}" --extraDefines=${_extradef})
188     endif ()
189
190     add_custom_command(
191         OUTPUT  ${_outputfiles}
192         DEPENDS ${MAKE_NAMES_DEPENDENCIES} ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_attrs} ${_tags}
193         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --preprocessor "${CODE_GENERATOR_PREPROCESSOR_WITH_LINEMARKERS}" --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments} ${_additionArguments}
194         VERBATIM)
195 endmacro()
196
197
198 macro(GENERATE_GRAMMAR _prefix _input _output_header _output_source _features)
199     # This is a workaround for winflexbison, which does not work corretly when
200     # run in a different working directory than the installation directory.
201     get_filename_component(_working_directory ${BISON_EXECUTABLE} PATH)
202
203     add_custom_command(
204         OUTPUT ${_output_header} ${_output_source}
205         MAIN_DEPENDENCY ${_input}
206         DEPENDS ${_input}
207         COMMAND ${PERL_EXECUTABLE} -I ${WEBCORE_DIR}/bindings/scripts ${WEBCORE_DIR}/css/makegrammar.pl --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} --extraDefines "${_features}" --preprocessor "${CODE_GENERATOR_PREPROCESSOR}" --bison "${BISON_EXECUTABLE}" --symbolsPrefix ${_prefix} ${_input}
208         WORKING_DIRECTORY ${_working_directory}
209         VERBATIM)
210 endmacro()
211
212 macro(MAKE_HASH_TOOLS _source)
213     get_filename_component(_name ${_source} NAME_WE)
214
215     if (${_source} STREQUAL "DocTypeStrings")
216         set(_hash_tools_h "${DERIVED_SOURCES_WEBCORE_DIR}/HashTools.h")
217     else ()
218         set(_hash_tools_h "")
219     endif ()
220
221     add_custom_command(
222         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_name}.cpp ${_hash_tools_h}
223         MAIN_DEPENDENCY ${_source}.gperf
224         COMMAND ${PERL_EXECUTABLE} ${WEBCORE_DIR}/make-hash-tools.pl ${DERIVED_SOURCES_WEBCORE_DIR} ${_source}.gperf
225         VERBATIM)
226
227     unset(_name)
228     unset(_hash_tools_h)
229 endmacro()
230
231 macro(WEBKIT_WRAP_SOURCELIST)
232     foreach (_file ${ARGN})
233         get_filename_component(_basename ${_file} NAME_WE)
234         get_filename_component(_path ${_file} PATH)
235
236         if (NOT _file MATCHES "${DERIVED_SOURCES_WEBCORE_DIR}")
237             string(REGEX REPLACE "/" "\\\\\\\\" _sourcegroup "${_path}")
238             source_group("${_sourcegroup}" FILES ${_file})
239         endif ()
240     endforeach ()
241
242     source_group("DerivedSources" REGULAR_EXPRESSION "${DERIVED_SOURCES_WEBCORE_DIR}")
243 endmacro()
244
245 macro(WEBKIT_FRAMEWORK _target)
246     if (APPLE)
247         set_target_properties(${_target} PROPERTIES FRAMEWORK TRUE)
248         install(TARGETS ${_target} FRAMEWORK DESTINATION ${LIB_INSTALL_DIR})
249     endif ()
250 endmacro()
251
252 macro(WEBKIT_CREATE_FORWARDING_HEADER _target_directory _file)
253     get_filename_component(_source_path "${CMAKE_SOURCE_DIR}/Source/" ABSOLUTE)
254     get_filename_component(_absolute "${_file}" ABSOLUTE)
255     get_filename_component(_name "${_file}" NAME)
256     set(_target_filename "${_target_directory}/${_name}")
257
258     # Try to make the path in the forwarding header relative to the Source directory
259     # so that these forwarding headers are compatible with the ones created by the
260     # WebKit2 generate-forwarding-headers script.
261     string(REGEX REPLACE "${_source_path}/" "" _relative ${_absolute})
262
263     set(_content "#include \"${_relative}\"\n")
264
265     if (EXISTS "${_target_filename}")
266         file(READ "${_target_filename}" _old_content)
267     endif ()
268
269     if (NOT _old_content STREQUAL _content)
270         file(WRITE "${_target_filename}" "${_content}")
271     endif ()
272 endmacro()
273
274 macro(WEBKIT_CREATE_FORWARDING_HEADERS _framework)
275     # On Windows, we copy the entire contents of forwarding headers.
276     if (NOT WIN32)
277         set(_processing_directories 0)
278         set(_processing_files 0)
279         set(_target_directory "${DERIVED_SOURCES_DIR}/ForwardingHeaders/${_framework}")
280
281         file(GLOB _files "${_target_directory}/*.h")
282         foreach (_file ${_files})
283             file(READ "${_file}" _content)
284             string(REGEX MATCH "^#include \"([^\"]*)\"" _matched ${_content})
285             if (_matched AND NOT EXISTS "${CMAKE_SOURCE_DIR}/Source/${CMAKE_MATCH_1}")
286                file(REMOVE "${_file}")
287             endif ()
288         endforeach ()
289
290         foreach (_currentArg ${ARGN})
291             if ("${_currentArg}" STREQUAL "DIRECTORIES")
292                 set(_processing_directories 1)
293                 set(_processing_files 0)
294             elseif ("${_currentArg}" STREQUAL "FILES")
295                 set(_processing_directories 0)
296                 set(_processing_files 1)
297             elseif (_processing_directories)
298                 file(GLOB _files "${_currentArg}/*.h")
299                 foreach (_file ${_files})
300                     WEBKIT_CREATE_FORWARDING_HEADER(${_target_directory} ${_file})
301                 endforeach ()
302             elseif (_processing_files)
303                 WEBKIT_CREATE_FORWARDING_HEADER(${_target_directory} ${_currentArg})
304             endif ()
305         endforeach ()
306     endif ()
307 endmacro()
308
309 # Helper macro which wraps generate-message-receiver.py and generate-message-header.py scripts
310 #   _output_source is a list name which will contain generated sources.(eg. WebKit2_SOURCES)
311 #   _input_files are messages.in files to generate.
312 macro(GENERATE_WEBKIT2_MESSAGE_SOURCES _output_source _input_files)
313     foreach (_file ${_input_files})
314         get_filename_component(_name ${_file} NAME_WE)
315         add_custom_command(
316             OUTPUT ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}MessageReceiver.cpp ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}Messages.h
317             MAIN_DEPENDENCY ${_file}
318             DEPENDS ${WEBKIT2_DIR}/Scripts/webkit/__init__.py
319                     ${WEBKIT2_DIR}/Scripts/webkit/messages.py
320                     ${WEBKIT2_DIR}/Scripts/webkit/model.py
321                     ${WEBKIT2_DIR}/Scripts/webkit/parser.py
322             COMMAND ${PYTHON_EXECUTABLE} ${WEBKIT2_DIR}/Scripts/generate-message-receiver.py ${_file} > ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}MessageReceiver.cpp
323             COMMAND ${PYTHON_EXECUTABLE} ${WEBKIT2_DIR}/Scripts/generate-messages-header.py ${_file} > ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}Messages.h
324             WORKING_DIRECTORY ${WEBKIT2_DIR}
325             VERBATIM)
326
327         list(APPEND ${_output_source} ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}MessageReceiver.cpp)
328     endforeach ()
329 endmacro()
330
331 # Helper macro for using all-in-one builds
332 # This macro removes the sources included in the _all_in_one_file from the input _file_list.
333 # _file_list is a list of source files
334 # _all_in_one_file is an all-in-one cpp file includes other cpp files
335 # _result_file_list is the output file list
336 macro(PROCESS_ALLINONE_FILE _file_list _all_in_one_file _result_file_list)
337     file(STRINGS ${_all_in_one_file} _all_in_one_file_content)
338     set(${_result_file_list} ${_file_list})
339     foreach (_line ${_all_in_one_file_content})
340         string(REGEX MATCH "^#include [\"<](.*)[\">]" _found ${_line})
341         if (_found)
342             list(APPEND _allins ${CMAKE_MATCH_1})
343         endif ()
344     endforeach ()
345
346     foreach (_allin ${_allins})
347         string(REGEX REPLACE ";[^;]*/${_allin};" ";" _new_result "${${_result_file_list}}")
348         set(${_result_file_list} ${_new_result})
349     endforeach ()
350
351 endmacro()