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