[ContentChangeObserver] Move away from WKContentChange values
[WebKit-https.git] / Source / WebCore / WebCoreMacros.cmake
1 macro(MAKE_HASH_TOOLS _source)
2     get_filename_component(_name ${_source} NAME_WE)
3
4     if (${_source} STREQUAL "DocTypeStrings")
5         set(_hash_tools_h "${DERIVED_SOURCES_WEBCORE_DIR}/HashTools.h")
6     else ()
7         set(_hash_tools_h "")
8     endif ()
9
10     add_custom_command(
11         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_name}.cpp ${_hash_tools_h}
12         MAIN_DEPENDENCY ${_source}.gperf
13         COMMAND ${PERL_EXECUTABLE} ${WEBCORE_DIR}/make-hash-tools.pl ${DERIVED_SOURCES_WEBCORE_DIR} ${_source}.gperf ${GPERF_EXECUTABLE}
14         VERBATIM)
15
16     unset(_name)
17     unset(_hash_tools_h)
18 endmacro()
19
20
21 # Append the given dependencies to the source file
22 # This one consider the given dependencies are in ${DERIVED_SOURCES_WEBCORE_DIR}
23 # and prepends this to every member of dependencies list
24 macro(ADD_SOURCE_WEBCORE_DERIVED_DEPENDENCIES _source _deps)
25     set(_tmp "")
26     foreach (f ${_deps})
27         list(APPEND _tmp "${DERIVED_SOURCES_WEBCORE_DIR}/${f}")
28     endforeach ()
29
30     WEBKIT_ADD_SOURCE_DEPENDENCIES(${_source} ${_tmp})
31     unset(_tmp)
32 endmacro()
33
34
35 macro(MAKE_JS_FILE_ARRAYS _output_cpp _output_h _namespace _scripts _scripts_dependencies)
36     add_custom_command(
37         OUTPUT ${_output_h} ${_output_cpp}
38         DEPENDS ${JavaScriptCore_SCRIPTS_DIR}/make-js-file-arrays.py ${${_scripts}}
39         COMMAND ${PYTHON_EXECUTABLE} ${JavaScriptCore_SCRIPTS_DIR}/make-js-file-arrays.py -n ${_namespace} ${_output_h} ${_output_cpp} ${${_scripts}}
40         VERBATIM)
41     WEBKIT_ADD_SOURCE_DEPENDENCIES(${${_scripts_dependencies}} ${_output_h} ${_output_cpp})
42 endmacro()
43
44
45 option(SHOW_BINDINGS_GENERATION_PROGRESS "Show progress of generating bindings" OFF)
46
47 # Helper macro which wraps generate-bindings-all.pl script.
48 #   target is a new target name to be added
49 #   OUTPUT_SOURCE is a list name which will contain generated sources.(eg. WebCore_SOURCES)
50 #   INPUT_FILES are IDL files to generate.
51 #   BASE_DIR is base directory where script is called.
52 #   IDL_INCLUDES is value of --include argument. (eg. ${WEBCORE_DIR}/bindings/js)
53 #   FEATURES is a value of --defines argument.
54 #   DESTINATION is a value of --outputDir argument.
55 #   GENERATOR is a value of --generator argument.
56 #   SUPPLEMENTAL_DEPFILE is a value of --supplementalDependencyFile. (optional)
57 #   PP_EXTRA_OUTPUT is extra outputs of preprocess-idls.pl. (optional)
58 #   PP_EXTRA_ARGS is extra arguments for preprocess-idls.pl. (optional)
59 function(GENERATE_BINDINGS target)
60     set(options)
61     set(oneValueArgs OUTPUT_SOURCE BASE_DIR FEATURES DESTINATION GENERATOR SUPPLEMENTAL_DEPFILE)
62     set(multiValueArgs INPUT_FILES IDL_INCLUDES PP_EXTRA_OUTPUT PP_EXTRA_ARGS)
63     cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
64     set(binding_generator ${WEBCORE_DIR}/bindings/scripts/generate-bindings-all.pl)
65     set(idl_attributes_file ${WEBCORE_DIR}/bindings/scripts/IDLAttributes.json)
66     set(idl_files_list ${CMAKE_CURRENT_BINARY_DIR}/idl_files_${target}.tmp)
67     set(_supplemental_dependency)
68
69     set(content)
70     foreach (f ${arg_INPUT_FILES})
71         if (NOT IS_ABSOLUTE ${f})
72             set(f ${CMAKE_CURRENT_SOURCE_DIR}/${f})
73         endif ()
74         set(content "${content}${f}\n")
75     endforeach ()
76     file(WRITE ${idl_files_list} ${content})
77
78     set(args
79         --defines ${arg_FEATURES}
80         --generator ${arg_GENERATOR}
81         --outputDir ${arg_DESTINATION}
82         --idlFilesList ${idl_files_list}
83         --preprocessor "${CODE_GENERATOR_PREPROCESSOR}"
84         --idlAttributesFile ${idl_attributes_file}
85     )
86     if (arg_SUPPLEMENTAL_DEPFILE)
87         list(APPEND args --supplementalDependencyFile ${arg_SUPPLEMENTAL_DEPFILE})
88     endif ()
89     ProcessorCount(PROCESSOR_COUNT)
90     if (PROCESSOR_COUNT)
91         list(APPEND args --numOfJobs ${PROCESSOR_COUNT})
92     endif ()
93     foreach (i IN LISTS arg_IDL_INCLUDES)
94         if (IS_ABSOLUTE ${i})
95             list(APPEND args --include ${i})
96         else ()
97             list(APPEND args --include ${CMAKE_CURRENT_SOURCE_DIR}/${i})
98         endif ()
99     endforeach ()
100     foreach (i IN LISTS arg_PP_EXTRA_OUTPUT)
101         list(APPEND args --ppExtraOutput ${i})
102     endforeach ()
103     foreach (i IN LISTS arg_PP_EXTRA_ARGS)
104         list(APPEND args --ppExtraArgs ${i})
105     endforeach ()
106
107     set(common_generator_dependencies
108         ${WEBCORE_DIR}/bindings/scripts/generate-bindings.pl
109         ${SCRIPTS_BINDINGS}
110         # Changing enabled features should trigger recompiling all IDL files
111         # because some of them use #if.
112         ${CMAKE_BINARY_DIR}/cmakeconfig.h
113     )
114     if (EXISTS ${WEBCORE_DIR}/bindings/scripts/CodeGenerator${arg_GENERATOR}.pm)
115         list(APPEND common_generator_dependencies ${WEBCORE_DIR}/bindings/scripts/CodeGenerator${arg_GENERATOR}.pm)
116     endif ()
117     if (EXISTS ${arg_BASE_DIR}/CodeGenerator${arg_GENERATOR}.pm)
118         list(APPEND common_generator_dependencies ${arg_BASE_DIR}/CodeGenerator${arg_GENERATOR}.pm)
119     endif ()
120     foreach (i IN LISTS common_generator_dependencies)
121         list(APPEND args --generatorDependency ${i})
122     endforeach ()
123
124     set(gen_sources)
125     set(gen_headers)
126     foreach (_file ${arg_INPUT_FILES})
127         get_filename_component(_name ${_file} NAME_WE)
128         list(APPEND gen_sources ${arg_DESTINATION}/JS${_name}.cpp)
129         list(APPEND gen_headers ${arg_DESTINATION}/JS${_name}.h)
130     endforeach ()
131     set(${arg_OUTPUT_SOURCE} ${${arg_OUTPUT_SOURCE}} ${gen_sources} PARENT_SCOPE)
132     set(act_args)
133     if (SHOW_BINDINGS_GENERATION_PROGRESS)
134         list(APPEND args --showProgress)
135     endif ()
136     list(APPEND act_args BYPRODUCTS ${gen_sources} ${gen_headers})
137     if (SHOW_BINDINGS_GENERATION_PROGRESS)
138         list(APPEND act_args USES_TERMINAL)
139     endif ()
140     add_custom_target(${target}
141         COMMAND ${PERL_EXECUTABLE} ${binding_generator} ${args}
142         WORKING_DIRECTORY ${arg_BASE_DIR}
143         COMMENT "Generate bindings (${target})"
144         VERBATIM ${act_args})
145 endfunction()
146
147
148 macro(GENERATE_FONT_NAMES _infile)
149     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
150     set(_arguments  --fonts ${_infile})
151     set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.h)
152
153     add_custom_command(
154         OUTPUT  ${_outputfiles}
155         MAIN_DEPENDENCY ${_infile}
156         DEPENDS ${MAKE_NAMES_DEPENDENCIES} ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
157         COMMAND ${PERL_EXECUTABLE} ${NAMES_GENERATOR} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments}
158         VERBATIM)
159 endmacro()
160
161
162 macro(GENERATE_EVENT_FACTORY _infile _namespace)
163     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_event_factory.pl)
164     set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Interfaces.h ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Factory.cpp)
165
166     add_custom_command(
167         OUTPUT  ${_outputfiles}
168         MAIN_DEPENDENCY ${_infile}
169         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
170         COMMAND ${PERL_EXECUTABLE} ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
171         VERBATIM)
172 endmacro()
173
174
175 macro(GENERATE_SETTINGS_MACROS _infile _outfile)
176     set(NAMES_GENERATOR ${WEBCORE_DIR}/Scripts/GenerateSettings.rb)
177
178     # Do not list the output in more than one independent target that may
179     # build in parallel or the two instances of the rule may conflict.
180     # <https://cmake.org/cmake/help/v3.0/command/add_custom_command.html>
181     set(_extra_output
182         ${DERIVED_SOURCES_WEBCORE_DIR}/Settings.cpp
183         ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.h
184         ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.cpp
185         ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.idl
186     )
187
188     set(GENERATE_SETTINGS_SCRIPTS
189         ${WEBCORE_DIR}/Scripts/SettingsTemplates/InternalSettingsGenerated.cpp.erb
190         ${WEBCORE_DIR}/Scripts/SettingsTemplates/InternalSettingsGenerated.idl.erb
191         ${WEBCORE_DIR}/Scripts/SettingsTemplates/InternalSettingsGenerated.h.erb
192         ${WEBCORE_DIR}/Scripts/SettingsTemplates/Settings.cpp.erb
193         ${WEBCORE_DIR}/Scripts/SettingsTemplates/Settings.h.erb
194     )
195
196     set(_args BYPRODUCTS ${_extra_output})
197     add_custom_command(
198         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
199         MAIN_DEPENDENCY ${_infile}
200         DEPENDS ${NAMES_GENERATOR} ${GENERATE_SETTINGS_SCRIPTS} ${SCRIPTS_BINDINGS}
201         COMMAND ${RUBY_EXECUTABLE} ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
202         VERBATIM ${_args})
203 endmacro()
204
205
206 macro(GENERATE_DOM_NAMES _namespace _attrs)
207     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
208     set(_arguments  --attrs ${_attrs})
209     set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.h)
210     set(_extradef)
211     set(_tags)
212
213     foreach (f ${ARGN})
214         if (_tags)
215             set(_extradef "${_extradef} ${f}")
216         else ()
217             set(_tags ${f})
218         endif ()
219     endforeach ()
220
221     if (_tags)
222         set(_arguments "${_arguments}" --tags ${_tags} --factory --wrapperFactory)
223         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)
224     endif ()
225
226     if (_extradef)
227         set(_additionArguments "${_additionArguments}" --extraDefines=${_extradef})
228     endif ()
229
230     add_custom_command(
231         OUTPUT  ${_outputfiles}
232         DEPENDS ${MAKE_NAMES_DEPENDENCIES} ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_attrs} ${_tags}
233         COMMAND ${PERL_EXECUTABLE} ${NAMES_GENERATOR} --preprocessor "${CODE_GENERATOR_PREPROCESSOR_WITH_LINEMARKERS}" --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments} ${_additionArguments}
234         VERBATIM)
235 endmacro()