[GTK] Missing API detected in GObject DOM bindings after r176630
[WebKit-https.git] / Source / cmake / WebKitMacros.cmake
1 macro(INCLUDE_IF_EXISTS _file)
2     if (EXISTS ${_file})
3         message(STATUS "Using platform-specific CMakeLists: ${_file}")
4         include(${_file})
5     else ()
6         message(STATUS "Platform-specific CMakeLists not found: ${_file}")
7     endif ()
8 endmacro()
9
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
27 # Helper macro which wraps generate-bindings.pl script.
28 #   _output_source is a list name which will contain generated sources.(eg. WebCore_SOURCES)
29 #   _input_files are IDL files to generate.
30 #   _base_dir is base directory where script is called.
31 #   _idl_includes is value of --include argument. (eg. --include=${WEBCORE_DIR}/bindings/js)
32 #   _features is a value of --defines argument.
33 #   _destination is a value of --outputDir argument.
34 #   _prefix is a prefix of output files. (eg. JS - it makes JSXXX.cpp JSXXX.h from XXX.idl)
35 #   _generator is a value of --generator argument.
36 #   _supplemental_dependency_file is a value of --supplementalDependencyFile. (optional)
37 macro(GENERATE_BINDINGS _output_source _input_files _base_dir _idl_includes _features _destination _prefix _generator _extension _idl_attributes_file)
38     set(BINDING_GENERATOR ${WEBCORE_DIR}/bindings/scripts/generate-bindings.pl)
39     set(_args ${ARGN})
40     list(LENGTH _args _argCount)
41     if (_argCount GREATER 0)
42         list(GET _args 0 _supplemental_dependency_file)
43         if (_supplemental_dependency_file)
44             set(_supplemental_dependency --supplementalDependencyFile ${_supplemental_dependency_file})
45         endif ()
46         list(GET _args 1 _additional_dependencies)
47     endif ()
48
49     set(COMMON_GENERATOR_DEPENDENCIES
50         ${BINDING_GENERATOR}
51         ${WEBCORE_DIR}/bindings/scripts/CodeGenerator.pm
52         ${SCRIPTS_BINDINGS}
53         ${_supplemental_dependency_file}
54         ${_idl_attributes_file}
55     )
56     list(APPEND COMMON_GENERATOR_DEPENDENCIES ${_additional_dependencies})
57
58     if (EXISTS ${WEBCORE_DIR}/bindings/scripts/CodeGenerator${_generator}.pm)
59         list(APPEND COMMON_GENERATOR_DEPENDENCIES ${WEBCORE_DIR}/bindings/scripts/CodeGenerator${_generator}.pm)
60     endif ()
61
62     foreach (_file ${_input_files})
63         get_filename_component(_name ${_file} NAME_WE)
64
65         add_custom_command(
66             OUTPUT ${_destination}/${_prefix}${_name}.${_extension} ${_destination}/${_prefix}${_name}.h
67             MAIN_DEPENDENCY ${_file}
68             DEPENDS ${COMMON_GENERATOR_DEPENDENCIES}
69             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}
70             WORKING_DIRECTORY ${_base_dir}
71             VERBATIM)
72
73         list(APPEND ${_output_source} ${_destination}/${_prefix}${_name}.${_extension})
74     endforeach ()
75 endmacro()
76
77
78 macro(GENERATE_FONT_NAMES _infile)
79     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
80     set(_arguments  --fonts ${_infile})
81     set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.h)
82
83     add_custom_command(
84         OUTPUT  ${_outputfiles}
85         MAIN_DEPENDENCY ${_infile}
86         DEPENDS ${MAKE_NAMES_DEPENDENCIES} ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
87         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments}
88         VERBATIM)
89 endmacro()
90
91
92 macro(GENERATE_EVENT_FACTORY _infile _outfile)
93     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_event_factory.pl)
94
95     add_custom_command(
96         OUTPUT  ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
97         MAIN_DEPENDENCY ${_infile}
98         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
99         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
100         VERBATIM)
101 endmacro()
102
103
104 macro(GENERATE_EXCEPTION_CODE_DESCRIPTION _infile _outfile)
105     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_dom_exceptions.pl)
106
107     add_custom_command(
108         OUTPUT  ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
109         MAIN_DEPENDENCY ${_infile}
110         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
111         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
112         VERBATIM)
113 endmacro()
114
115
116 macro(GENERATE_SETTINGS_MACROS _infile _outfile)
117     set(NAMES_GENERATOR ${WEBCORE_DIR}/page/make_settings.pl)
118
119     add_custom_command(
120         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile} ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.h ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.idl
121         MAIN_DEPENDENCY ${_infile}
122         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
123         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
124         VERBATIM)
125 endmacro()
126
127
128 macro(GENERATE_DOM_NAMES _namespace _attrs)
129     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
130     set(_arguments  --attrs ${_attrs})
131     set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.h)
132     set(_extradef)
133     set(_tags)
134
135     foreach (f ${ARGN})
136         if (_tags)
137             set(_extradef "${_extradef} ${f}")
138         else ()
139             set(_tags ${f})
140         endif ()
141     endforeach ()
142
143     if (_tags)
144         set(_arguments "${_arguments}" --tags ${_tags} --factory --wrapperFactory)
145         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)
146     endif ()
147
148     if (_extradef)
149         set(_additionArguments "${_additionArguments}" --extraDefines=${_extradef})
150     endif ()
151
152     add_custom_command(
153         OUTPUT  ${_outputfiles}
154         DEPENDS ${MAKE_NAMES_DEPENDENCIES} ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_attrs} ${_tags}
155         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --preprocessor "${CODE_GENERATOR_PREPROCESSOR_WITH_LINEMARKERS}" --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments} ${_additionArguments}
156         VERBATIM)
157 endmacro()
158
159
160 macro(GENERATE_GRAMMAR _prefix _input _output_header _output_source _features)
161     # This is a workaround for winflexbison, which does not work corretly when
162     # run in a different working directory than the installation directory.
163     get_filename_component(_working_directory ${BISON_EXECUTABLE} PATH)
164
165     add_custom_command(
166         OUTPUT ${_output_header} ${_output_source}
167         MAIN_DEPENDENCY ${_input}
168         DEPENDS ${_input}
169         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}
170         WORKING_DIRECTORY ${_working_directory}
171         VERBATIM)
172 endmacro()
173
174 macro(MAKE_HASH_TOOLS _source)
175     get_filename_component(_name ${_source} NAME_WE)
176
177     if (${_source} STREQUAL "DocTypeStrings")
178         set(_hash_tools_h "${DERIVED_SOURCES_WEBCORE_DIR}/HashTools.h")
179     else ()
180         set(_hash_tools_h "")
181     endif ()
182
183     add_custom_command(
184         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_name}.cpp ${_hash_tools_h}
185         MAIN_DEPENDENCY ${_source}.gperf
186         COMMAND ${PERL_EXECUTABLE} ${WEBCORE_DIR}/make-hash-tools.pl ${DERIVED_SOURCES_WEBCORE_DIR} ${_source}.gperf
187         VERBATIM)
188
189     unset(_name)
190     unset(_hash_tools_h)
191 endmacro()
192
193 macro(WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS)
194     if (PORT_FALLBACK)
195         INCLUDE_IF_EXISTS(${CMAKE_CURRENT_SOURCE_DIR}/Platform${PORT_FALLBACK}.cmake)
196     endif ()
197     INCLUDE_IF_EXISTS(${CMAKE_CURRENT_SOURCE_DIR}/Platform${PORT}.cmake)
198 endmacro()
199
200 macro(WEBKIT_WRAP_SOURCELIST)
201     foreach (_file ${ARGN})
202         get_filename_component(_basename ${_file} NAME_WE)
203         get_filename_component(_path ${_file} PATH)
204
205         if (NOT _file MATCHES "${DERIVED_SOURCES_WEBCORE_DIR}")
206             string(REGEX REPLACE "/" "\\\\\\\\" _sourcegroup "${_path}")
207             source_group("${_sourcegroup}" FILES ${_file})
208         endif ()
209     endforeach ()
210
211     source_group("DerivedSources" REGULAR_EXPRESSION "${DERIVED_SOURCES_WEBCORE_DIR}")
212 endmacro()
213
214
215 macro(WEBKIT_CREATE_FORWARDING_HEADER _target_directory _file)
216     get_filename_component(_source_path "${CMAKE_SOURCE_DIR}/Source/" ABSOLUTE)
217     get_filename_component(_absolute "${_file}" ABSOLUTE)
218     get_filename_component(_name "${_file}" NAME)
219     set(_target_filename "${_target_directory}/${_name}")
220
221     # Try to make the path in the forwarding header relative to the Source directory
222     # so that these forwarding headers are compatible with the ones created by the
223     # WebKit2 generate-forwarding-headers script.
224     string(REGEX REPLACE "${_source_path}/" "" _relative ${_absolute})
225
226     set(_content "#include \"${_relative}\"\n")
227
228     if (EXISTS "${_target_filename}")
229         file(READ "${_target_filename}" _old_content)
230     endif ()
231
232     if (NOT _old_content STREQUAL _content)
233         file(WRITE "${_target_filename}" "${_content}")
234     endif ()
235 endmacro()
236
237 macro(WEBKIT_CREATE_FORWARDING_HEADERS _framework)
238     set(_processing_directories 0)
239     set(_processing_files 0)
240     set(_target_directory "${DERIVED_SOURCES_DIR}/ForwardingHeaders/${_framework}")
241
242     file(GLOB _files "${_target_directory}/*.h")
243     foreach (_file ${_files})
244         file(READ "${_file}" _content)
245         string(REGEX MATCH "^#include \"([^\"]*)\"" _matched ${_content})
246         if (_matched AND NOT EXISTS "${CMAKE_SOURCE_DIR}/Source/${CMAKE_MATCH_1}")
247            file(REMOVE "${_file}")
248         endif ()
249     endforeach ()
250
251     foreach (_currentArg ${ARGN})
252         if ("${_currentArg}" STREQUAL "DIRECTORIES")
253             set(_processing_directories 1)
254             set(_processing_files 0)
255         elseif ("${_currentArg}" STREQUAL "FILES")
256             set(_processing_directories 0)
257             set(_processing_files 1)
258         elseif (_processing_directories)
259             file(GLOB _files "${_currentArg}/*.h")
260             foreach (_file ${_files})
261                 WEBKIT_CREATE_FORWARDING_HEADER(${_target_directory} ${_file})
262             endforeach ()
263         elseif (_processing_files)
264             WEBKIT_CREATE_FORWARDING_HEADER(${_target_directory} ${_currentArg})
265         endif ()
266     endforeach ()
267 endmacro()
268
269 # Helper macro which wraps generate-message-receiver.py and generate-message-header.py scripts
270 #   _output_source is a list name which will contain generated sources.(eg. WebKit2_SOURCES)
271 #   _input_files are messages.in files to generate.
272 macro(GENERATE_WEBKIT2_MESSAGE_SOURCES _output_source _input_files)
273     foreach (_file ${_input_files})
274         get_filename_component(_name ${_file} NAME_WE)
275         add_custom_command(
276             OUTPUT ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}MessageReceiver.cpp ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}Messages.h
277             MAIN_DEPENDENCY ${_file}
278             DEPENDS ${WEBKIT2_DIR}/Scripts/webkit/__init__.py
279                     ${WEBKIT2_DIR}/Scripts/webkit/messages.py
280                     ${WEBKIT2_DIR}/Scripts/webkit/model.py
281                     ${WEBKIT2_DIR}/Scripts/webkit/parser.py
282             COMMAND ${PYTHON_EXECUTABLE} ${WEBKIT2_DIR}/Scripts/generate-message-receiver.py ${_file} > ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}MessageReceiver.cpp
283             COMMAND ${PYTHON_EXECUTABLE} ${WEBKIT2_DIR}/Scripts/generate-messages-header.py ${_file} > ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}Messages.h
284             WORKING_DIRECTORY ${WEBKIT2_DIR}
285             VERBATIM)
286
287         list(APPEND ${_output_source} ${DERIVED_SOURCES_WEBKIT2_DIR}/${_name}MessageReceiver.cpp)
288     endforeach ()
289 endmacro()