975b9a0b8d18a518c7589f344f5f5fde67f0d846
[WebKit-https.git] / cmake / WebKitGenerators.cmake
1 # This file provides various generators used by webkit.
2 # It will check for the programs and define the given executables:
3 #    PERL_EXECUTABLE
4 #    BISON_EXECUTABLE
5 #    GPERF_EXECUTABLE
6 #    FLEX_EXECUTABLE
7
8 INCLUDE (WebKitFS)
9
10 FIND_PACKAGE(Perl REQUIRED)
11
12 # - Create hash table *.lut.h
13 # GENERATE_HASH_LUT(input_file output_file)
14 MACRO(GENERATE_HASH_LUT _input _output)
15     SET(HASH_LUT_GENERATOR "${JAVASCRIPTCORE_DIR}/create_hash_table")
16
17     FOREACH (_tmp ${ARGN})
18         IF (${_tmp} STREQUAL "MAIN_DEPENDENCY")
19             SET(_main_dependency ${_input})
20         ENDIF ()
21     ENDFOREACH ()
22
23     ADD_CUSTOM_COMMAND(
24         OUTPUT ${_output}
25         MAIN_DEPENDENCY ${_main_dependency}
26         DEPENDS ${_input} ${HASH_LUT_GENERATOR}
27         COMMAND ${PERL_EXECUTABLE} ${HASH_LUT_GENERATOR} ${_input} > ${_output}
28         VERBATIM)
29 ENDMACRO()
30
31 # - Create hash table *.lut.h using at JavaScriptCore/runtime
32 # GENERATE_HASH_LUT_RUNTIME(source)
33 #
34 # The generated files lives in ${CMAKE_BINARY_DIR}/JavaScriptCore/runtime/
35 # and will have suffix ".lut.h"
36 #
37 # Input file is assumed to be in JavaScriptCore/runtime/${source}.cpp
38 MACRO(GENERATE_HASH_LUT_RUNTIME _file)
39   ADD_CUSTOM_COMMAND(
40     OUTPUT  ${CMAKE_BINARY_DIR}/JavaScriptCore/runtime/${_file}.lut.h
41     DEPENDS ${JAVASCRIPTCORE_DIR}/runtime/${_file}.cpp  ${HASH_LUT_GENERATOR}
42     COMMAND ${PERL_EXECUTABLE} ${HASH_LUT_GENERATOR} ${JAVASCRIPTCORE_DIR}/runtime/${_file}.cpp -i > ${CMAKE_BINARY_DIR}/JavaScriptCore/runtime/${_file}.lut.h
43     VERBATIM)
44   LIST(APPEND GENERATED_HASH_LUT_RUNTIME_FILES "${CMAKE_BINARY_DIR}/JavaScriptCore/runtime/${_file}.lut.h")
45 ENDMACRO()
46
47
48 FIND_PROGRAM (BISON_EXECUTABLE bison)
49 IF (NOT BISON_EXECUTABLE)
50   MESSAGE(FATAL_ERROR "Missing bison")
51 ENDIF (NOT BISON_EXECUTABLE)
52 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Bison DEFAULT_MSG BISON_EXECUTABLE)
53
54 # - Create a grammar using bison.
55 # GENERATE_GRAMMAR(prefix source_file)
56 #
57 # Reads a source_file (*.y) Generates the .cpp and .h files in
58 # ${DERIVED_SOURCES_DIR}
59 MACRO(GENERATE_GRAMMAR _prefix _source)
60   GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
61   SET(_out_base ${DERIVED_SOURCES_DIR}/${_name})
62   ADD_CUSTOM_COMMAND(
63     OUTPUT  ${_out_base}.cpp ${_out_base}.h
64     DEPENDS ${_source}
65     COMMAND ${BISON_EXECUTABLE} -p ${_prefix} ${_source} -o ${_out_base}.cpp --defines=${_out_base}.h
66     VERBATIM)
67   UNSET(_out_base)
68   UNSET(_name)
69 ENDMACRO ()
70
71
72 FIND_PROGRAM(GPERF_EXECUTABLE gperf)
73 IF (NOT GPERF_EXECUTABLE)
74   MESSAGE(FATAL_ERROR "Missing gperf")
75 ENDIF ()
76 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GPerf DEFAULT_MSG GPERF_EXECUTABLE)
77 SET(PERF_HASH_GENERATOR ${WEBCORE_DIR}/make-hash-tools.pl)
78
79 # - Create perfect hash tables using gperf
80 # GENERATE_GPERF(extension source_file)
81 #
82 # The generated files lives in ${DERIVED_SOURCES_DIR} and ends in .cpp
83 MACRO(GENERATE_GPERF _source)
84   GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
85   ADD_CUSTOM_COMMAND(
86     OUTPUT ${DERIVED_SOURCES_DIR}/${_name}.cpp
87     DEPENDS ${_source}
88     COMMAND ${PERL_EXECUTABLE} ${PERF_HASH_GENERATOR} ${DERIVED_SOURCES_DIR} ${_source}
89     VERBATIM)
90 ENDMACRO ()
91
92
93 # Modules that the bindings generator scripts may use
94 SET(SCRIPTS_BINDINGS
95   ${WEBCORE_DIR}/bindings/scripts/CodeGenerator.pm
96   ${WEBCORE_DIR}/bindings/scripts/IDLParser.pm
97   ${WEBCORE_DIR}/bindings/scripts/IDLStructure.pm
98   ${WEBCORE_DIR}/bindings/scripts/InFilesParser.pm)
99 SET(BINDING_CODE_GENERATOR ${WEBCORE_DIR}/bindings/scripts/generate-bindings.pl)
100 SET(JS_IDL_FILES "")
101 SET(Inspector_IDL_FILES "")
102
103 # - Create JS C++ code given an IDL input
104 # GENERATE_FROM_IDL(generator idl_source)
105 #
106 # The generated files (.cpp, .h) lives in ${DERIVED_SOURCES_DIR}.
107 #
108 # This function also appends the generated cpp file to JS_IDL_FILES list.
109 MACRO(GENERATE_JS_FROM_IDL _source)
110   SET(FEATURE_DEFINES_STR "")
111   FOREACH (f ${FEATURE_DEFINES})
112     SET(FEATURE_DEFINES_STR "${FEATURE_DEFINES_STR} ${f}")
113   ENDFOREACH ()
114
115   GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
116   ADD_CUSTOM_COMMAND(
117     OUTPUT  ${DERIVED_SOURCES_DIR}/JS${_name}.cpp ${DERIVED_SOURCES_DIR}/JS${_name}.h
118     DEPENDS ${BINDING_CODE_GENERATOR} ${SCRIPTS_BINDINGS} ${WEBCORE_DIR}/${_source}
119     COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${BINDING_CODE_GENERATOR} ${IDL_INCLUDES} --outputDir "${DERIVED_SOURCES_DIR}" --defines "LANGUAGE_JAVASCRIPT=1 ${FEATURE_DEFINES_STR}" --generator JS ${WEBCORE_DIR}/${_source}
120     VERBATIM)
121   LIST(APPEND JS_IDL_FILES ${DERIVED_SOURCES_DIR}/JS${_name}.cpp)
122   UNSET(_name)
123   UNSET(_defines)
124 ENDMACRO()
125
126
127 # - Create Inspector C++ code given an IDL input
128 # GENERATE_FROM_IDL(generator idl_source)
129 #
130 # The generated files (.cpp, .h) lives in ${DERIVED_SOURCES_DIR}.
131 #
132 # This function also appends the generated cpp file to Inspector_IDL_FILES list.
133 MACRO(GENERATE_INSPECTOR_FROM_IDL _source)
134   SET(FEATURE_DEFINES_STR "")
135   FOREACH (f ${FEATURE_DEFINES})
136     SET(FEATURE_DEFINES_STR "${FEATURE_DEFINES_STR} ${f}")
137   ENDFOREACH ()
138
139   GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
140   ADD_CUSTOM_COMMAND(
141     OUTPUT  ${DERIVED_SOURCES_DIR}/Remote${_name}Frontend.cpp ${DERIVED_SOURCES_DIR}/Remote${_name}Frontend.h
142     DEPENDS ${BINDING_CODE_GENERATOR} ${SCRIPTS_BINDINGS} ${WEBCORE_DIR}/${_source}
143     COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts -I${WEBCORE_DIR}/inspector ${BINDING_CODE_GENERATOR} ${IDL_INCLUDES} --outputDir "${DERIVED_SOURCES_DIR}" --defines "LANGUAGE_JAVASCRIPT=1 ${FEATURE_DEFINES_STR}" --generator Inspector ${WEBCORE_DIR}/${_source}
144     VERBATIM)
145   LIST(APPEND Inspector_IDL_FILES ${DERIVED_SOURCES_DIR}/Remote${_name}Frontend.cpp)
146   UNSET(_name)
147   UNSET(_defines)
148 ENDMACRO()
149
150
151
152 # - Create pure JavaScript functions (does nothing so far)
153 MACRO(GENERATE_JS_FROM_IDL_PURE _source)
154    GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
155    ADD_CUSTOM_COMMAND(
156      OUTPUT  ${DERIVED_SOURCES_DIR}/JS${_name}.cpp ${DERIVED_SOURCES_DIR}/JS${_name}.h
157      DEPENDS ${BINDING_CODE_GENERATOR} ${SCRIPTS_BINDINGS} ${WEBCORE_DIR}/${_source}
158      COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${BINDING_CODE_GENERATOR} ${IDL_INCLUDES} --outputDir "${DERIVED_SOURCES_DIR}" --defines "LANGUAGE_JAVASCRIPT=1 ${FEATURE_DEFINES_STR}" --generator JS ${WEBCORE_DIR}/${_source}
159      VERBATIM)
160    UNSET(_name)
161 ENDMACRO()
162
163 SET(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
164 # - Create DOM names and factory given tags and attributes as source.
165 # GENERATE_DOM_NAMES_FACTORY(namespace tags_source attributes_source [defines])
166 #
167 # The generated files lives in ${DERIVED_SOURCES_DIR}. The files will
168 # be named using the given namespace, such as:
169 #   - ${namespace}Names.cpp, ${namespace}Names.h;
170 #   - ${namespace}ElementFactory.cpp, ${namespace}ElementFactory.h;
171 #   - ${namespace}ElementWrapperFactory.cpp; ${namespace}ElementWrapperFactory.h
172 #
173 # If optional defines are given, then they will be speficied using
174 # --extraDefines directive to the generator script.
175 MACRO(GENERATE_DOM_NAMES_FACTORY _namespace _tags _attrs)
176   UNSET(_extradef)
177   FOREACH (f ${ARGN})
178     SET(_extradef "${_extradef} ${f}")
179   ENDFOREACH ()
180   IF (_extradef)
181     SET(_extradef --extraDefines=${_extradef})
182   ENDIF ()
183   ADD_CUSTOM_COMMAND(
184     OUTPUT ${DERIVED_SOURCES_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_DIR}/${_namespace}Names.h ${DERIVED_SOURCES_DIR}/${_namespace}ElementFactory.cpp ${DERIVED_SOURCES_DIR}/${_namespace}ElementFactory.h ${DERIVED_SOURCES_DIR}/JS${_namespace}ElementWrapperFactory.cpp ${DERIVED_SOURCES_DIR}/JS${_namespace}ElementWrapperFactory.h
185     DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_tags} ${_attrs}
186     COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --tags ${_tags} --attrs ${_attrs} ${_extradef} --factory --wrapperFactory --outputDir ${DERIVED_SOURCES_DIR}
187     VERBATIM)
188   UNSET(_extradef)
189 ENDMACRO ()
190
191 # - Create DOM names only (no factories)
192 # GENERATE_DOM_NAMES_ONLY(namespace attributes_source)
193 #
194 # The generated files lives in ${DERIVED_SOURCES_DIR}. The files will
195 # be named using the given namespace, such as:
196 #   - ${namespace}Names.cpp, ${namespace}Names.h;
197 MACRO(GENERATE_DOM_NAMES_ONLY _namespace _attrs)
198   ADD_CUSTOM_COMMAND(
199     OUTPUT ${DERIVED_SOURCES_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_DIR}/${_namespace}Names.h
200     DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_attrs}
201     COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --attrs ${_attrs} --outputDir ${DERIVED_SOURCES_DIR}
202     VERBATIM)
203 ENDMACRO()
204
205 # - Create ${CMAKE_BINARY_DIR}/JavaScriptCore/pcre/chartables.c
206 # GENERATE_DFTABLES()
207 MACRO(GENERATE_DFTABLES)
208   ADD_CUSTOM_COMMAND(
209     OUTPUT  ${CMAKE_BINARY_DIR}/JavaScriptCore/pcre/chartables.c
210     DEPENDS ${JAVASCRIPTCORE_DIR}/pcre/dftables
211     COMMAND ${PERL_EXECUTABLE} ${JAVASCRIPTCORE_DIR}/pcre/dftables ${CMAKE_BINARY_DIR}/JavaScriptCore/pcre/chartables.c
212     VERBATIM)
213 ENDMACRO()
214
215
216 FIND_PROGRAM(FLEX_EXECUTABLE flex)
217 IF (NOT FLEX_EXECUTABLE)
218   MESSAGE(FATAL_ERROR "Missing flex")
219 ENDIF ()
220 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Flex DEFAULT_MSG FLEX_EXECUTABLE)
221
222 SET(MAKE_TOKENIZER ${WEBCORE_DIR}/css/maketokenizer)
223 # - Create ${DERIVED_SOURCES_DIR}/tokenizer.cpp
224 # GENERATE_TOKENIZER()
225 MACRO(GENERATE_TOKENIZER)
226   ADD_CUSTOM_COMMAND(
227     OUTPUT ${DERIVED_SOURCES_DIR}/tokenizer.cpp
228     DEPENDS ${WEBCORE_DIR}/css/tokenizer.flex ${MAKE_TOKENIZER}
229     COMMAND ${FLEX_EXECUTABLE} -t ${WEBCORE_DIR}/css/tokenizer.flex | ${PERL_EXECUTABLE} ${MAKE_TOKENIZER} > ${DERIVED_SOURCES_DIR}/tokenizer.cpp
230     VERBATIM)
231 ENDMACRO()
232
233
234 SET(USER_AGENT_STYLE_SHEETS
235   ${WEBCORE_DIR}/css/html.css
236   ${WEBCORE_DIR}/css/mathml.css
237   ${WEBCORE_DIR}/css/quirks.css
238   ${WEBCORE_DIR}/css/view-source.css
239   ${WEBCORE_DIR}/css/svg.css
240   ${WEBCORE_DIR}/css/wml.css
241   ${WEBCORE_DIR}/css/mediaControls.css)
242 SET(USER_AGENT_STYLE_SHEETS_GENERATOR ${WEBCORE_DIR}/css/make-css-file-arrays.pl)
243 # - Create ${DERIVED_SOURCES_DIR}/UserAgentStyleSheetsData.cpp and
244 #   ${DERIVED_SOURCES_DIR}/UserAgentStyleSheets.h
245 # GENERATE_USER_AGENT_STYLES()
246 MACRO(GENERATE_USER_AGENT_STYLES)
247   ADD_CUSTOM_COMMAND(
248     OUTPUT ${DERIVED_SOURCES_DIR}/UserAgentStyleSheetsData.cpp ${DERIVED_SOURCES_DIR}/UserAgentStyleSheets.h
249     DEPENDS ${USER_AGENT_STYLE_SHEETS_GENERATOR} ${USER_AGENT_STYLE_SHEETS}
250     COMMAND ${PERL_EXECUTABLE} ${USER_AGENT_STYLE_SHEETS_GENERATOR} ${DERIVED_SOURCES_DIR}/UserAgentStyleSheets.h ${DERIVED_SOURCES_DIR}/UserAgentStyleSheetsData.cpp ${USER_AGENT_STYLE_SHEETS}
251     VERBATIM)
252 ENDMACRO ()
253
254
255 SET(CSS_VALUE_KEYWORDS
256   ${WEBCORE_DIR}/css/CSSValueKeywords.in
257   ${WEBCORE_DIR}/css/SVGCSSValueKeywords.in)
258 SET(CSS_VALUE_GENERATOR ${WEBCORE_DIR}/css/makevalues.pl)
259 # - Create ${DERIVED_SOURCES_DIR}/CSSValueKeywords.*
260 # GENERATE_CSS_VALUE_KEYWORDS()
261 MACRO(GENERATE_CSS_VALUE_KEYWORDS)
262   ADD_CUSTOM_COMMAND(
263     OUTPUT ${DERIVED_SOURCES_DIR}/CSSValueKeywords.h ${DERIVED_SOURCES_DIR}/CSSValueKeywords.cpp ${DERIVED_SOURCES_DIR}/CSSValueKeywords.in ${DERIVED_SOURCES_DIR}/CSSValueKeywords.gperf
264     DEPENDS ${CSS_VALUE_KEYWORDS} ${CSS_VALUE_GENERATOR}
265     WORKING_DIRECTORY ${DERIVED_SOURCES_DIR}
266     COMMAND ${PERL_EXECUTABLE} -ne "print lc" ${CSS_VALUE_KEYWORDS} > ${DERIVED_SOURCES_DIR}/CSSValueKeywords.in
267     COMMAND ${PERL_EXECUTABLE} ${CSS_VALUE_GENERATOR}
268     VERBATIM)
269 ENDMACRO ()
270
271 SET(CSS_PROPERTY_NAMES
272   ${WEBCORE_DIR}/css/CSSPropertyNames.in
273   ${WEBCORE_DIR}/css/SVGCSSPropertyNames.in)
274 SET(MAKE_CSS_PROP ${WEBCORE_DIR}/css/makeprop.pl)
275 # - Create ${DERIVED_SOURCES_DIR}/CSSPropertyNames.*
276 # GENERATE_CSS_PROPERTY_NAMES()
277 MACRO(GENERATE_CSS_PROPERTY_NAMES)
278   ADD_CUSTOM_COMMAND(
279     OUTPUT ${DERIVED_SOURCES_DIR}/CSSPropertyNames.h ${DERIVED_SOURCES_DIR}/CSSPropertyNames.cpp ${DERIVED_SOURCES_DIR}/CSSPropertyNames.in ${DERIVED_SOURCES_DIR}/CSSPropertyNames.gperf
280     DEPENDS ${MAKE_CSS_PROP} ${CSS_PROPERTY_NAMES}
281     WORKING_DIRECTORY ${DERIVED_SOURCES_DIR}
282     COMMAND cat ${CSS_PROPERTY_NAMES} > ${DERIVED_SOURCES_DIR}/CSSPropertyNames.in
283     COMMAND ${PERL_EXECUTABLE} ${MAKE_CSS_PROP}
284     VERBATIM)
285 ENDMACRO ()