2010-05-15 Leandro Pereira <leandro@profusion.mobi>
[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
78 # - Create perfect hash tables using gperf
79 # GENERATE_GPERF(extension source_file find_function gperf_options)
80 #
81 # The generated files lives in ${DERIVED_SOURCES_DIR} and ends in the
82 # given extension.
83 MACRO(GENERATE_GPERF _ext _source _func _opts)
84   GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
85   ADD_CUSTOM_COMMAND(
86     OUTPUT ${DERIVED_SOURCES_DIR}/${_name}.${_ext}
87     DEPENDS ${_source}
88     COMMAND ${GPERF_EXECUTABLE} -CDEGIot -L ANSI-C -k * -s 2 -N ${_func} ${_opts} --output-file=${DERIVED_SOURCES_DIR}/${_name}.${_ext} ${_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(JS_CODE_GENERATOR ${WEBCORE_DIR}/bindings/scripts/generate-bindings.pl)
100 SET(JS_IDL_FILES "")
101 # - Create JavaScript C++ code given an IDL input
102 # GENERATE_JS_FROM_IDL(idl_source)
103 #
104 # The generated files (.cpp, .h) lives in ${DERIVED_SOURCES_DIR}.
105 #
106 # This function also appends the generated cpp file to JS_IDL_FILES list.
107 MACRO(GENERATE_JS_FROM_IDL _source)
108   SET(FEATURE_DEFINES_STR "")
109   FOREACH (f ${FEATURE_DEFINES})
110     SET(FEATURE_DEFINES_STR "${FEATURE_DEFINES_STR} ${f}")
111   ENDFOREACH ()
112
113   GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
114   ADD_CUSTOM_COMMAND(
115     OUTPUT  ${DERIVED_SOURCES_DIR}/JS${_name}.cpp ${DERIVED_SOURCES_DIR}/JS${_name}.h
116     DEPENDS ${JS_CODE_GENERATOR} ${SCRIPTS_BINDINGS} ${WEBCORE_DIR}/${_source}
117     COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${JS_CODE_GENERATOR} ${IDL_INCLUDES} --outputDir "${DERIVED_SOURCES_DIR}" --defines "LANGUAGE_JAVASCRIPT=1 ${FEATURE_DEFINES_STR}" --generator JS ${WEBCORE_DIR}/${_source}
118     VERBATIM)
119   LIST(APPEND JS_IDL_FILES ${DERIVED_SOURCES_DIR}/JS${_name}.cpp)
120   UNSET(_name)
121   UNSET(_defines)
122 ENDMACRO()
123
124 # - Create pure JavaScript functions (does nothing so far)
125 MACRO(GENERATE_JS_FROM_IDL_PURE _source)
126    GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
127    ADD_CUSTOM_COMMAND(
128      OUTPUT  ${DERIVED_SOURCES_DIR}/JS${_name}.cpp ${DERIVED_SOURCES_DIR}/JS${_name}.h
129      DEPENDS ${JS_CODE_GENERATOR} ${SCRIPTS_BINDINGS} ${WEBCORE_DIR}/${_source}
130      COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${JS_CODE_GENERATOR} ${IDL_INCLUDES} --outputDir "${DERIVED_SOURCES_DIR}" --defines "LANGUAGE_JAVASCRIPT=1 ${FEATURE_DEFINES_STR}" --generator JS ${WEBCORE_DIR}/${_source}
131      VERBATIM)
132    UNSET(_name)
133 ENDMACRO()
134
135 SET(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
136 # - Create DOM names and factory given tags and attributes as source.
137 # GENERATE_DOM_NAMES_FACTORY(namespace tags_source attributes_source [defines])
138 #
139 # The generated files lives in ${DERIVED_SOURCES_DIR}. The files will
140 # be named using the given namespace, such as:
141 #   - ${namespace}Names.cpp, ${namespace}Names.h;
142 #   - ${namespace}ElementFactory.cpp, ${namespace}ElementFactory.h;
143 #   - ${namespace}ElementWrapperFactory.cpp; ${namespace}ElementWrapperFactory.h
144 #
145 # If optional defines are given, then they will be speficied using
146 # --extraDefines directive to the generator script.
147 MACRO(GENERATE_DOM_NAMES_FACTORY _namespace _tags _attrs)
148   UNSET(_extradef)
149   FOREACH (f ${ARGN})
150     SET(_extradef "${_extradef} ${f}")
151   ENDFOREACH ()
152   IF (_extradef)
153     SET(_extradef --extraDefines=${_extradef})
154   ENDIF ()
155   ADD_CUSTOM_COMMAND(
156     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
157     DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_tags} ${_attrs}
158     COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --tags ${_tags} --attrs ${_attrs} ${_extradef} --factory --wrapperFactory --outputDir ${DERIVED_SOURCES_DIR}
159     VERBATIM)
160   UNSET(_extradef)
161 ENDMACRO ()
162
163 # - Create DOM names only (no factories)
164 # GENERATE_DOM_NAMES_ONLY(namespace attributes_source)
165 #
166 # The generated files lives in ${DERIVED_SOURCES_DIR}. The files will
167 # be named using the given namespace, such as:
168 #   - ${namespace}Names.cpp, ${namespace}Names.h;
169 MACRO(GENERATE_DOM_NAMES_ONLY _namespace _attrs)
170   ADD_CUSTOM_COMMAND(
171     OUTPUT ${DERIVED_SOURCES_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_DIR}/${_namespace}Names.h
172     DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_attrs}
173     COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --attrs ${_attrs} --outputDir ${DERIVED_SOURCES_DIR}
174     VERBATIM)
175 ENDMACRO()
176
177 # - Create ${CMAKE_BINARY_DIR}/JavaScriptCore/pcre/chartables.c
178 # GENERATE_DFTABLES()
179 MACRO(GENERATE_DFTABLES)
180   ADD_CUSTOM_COMMAND(
181     OUTPUT  ${CMAKE_BINARY_DIR}/JavaScriptCore/pcre/chartables.c
182     DEPENDS ${JAVASCRIPTCORE_DIR}/pcre/dftables
183     COMMAND ${PERL_EXECUTABLE} ${JAVASCRIPTCORE_DIR}/pcre/dftables ${CMAKE_BINARY_DIR}/JavaScriptCore/pcre/chartables.c
184     VERBATIM)
185 ENDMACRO()
186
187
188 FIND_PROGRAM(FLEX_EXECUTABLE flex)
189 IF (NOT FLEX_EXECUTABLE)
190   MESSAGE(FATAL_ERROR "Missing flex")
191 ENDIF ()
192 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Flex DEFAULT_MSG FLEX_EXECUTABLE)
193
194 SET(MAKE_TOKENIZER ${WEBCORE_DIR}/css/maketokenizer)
195 # - Create ${DERIVED_SOURCES_DIR}/tokenizer.cpp
196 # GENERATE_TOKENIZER()
197 MACRO(GENERATE_TOKENIZER)
198   ADD_CUSTOM_COMMAND(
199     OUTPUT ${DERIVED_SOURCES_DIR}/tokenizer.cpp
200     DEPENDS ${WEBCORE_DIR}/css/tokenizer.flex ${MAKE_TOKENIZER}
201     COMMAND ${FLEX_EXECUTABLE} -t ${WEBCORE_DIR}/css/tokenizer.flex | ${PERL_EXECUTABLE} ${MAKE_TOKENIZER} > ${DERIVED_SOURCES_DIR}/tokenizer.cpp
202     VERBATIM)
203 ENDMACRO()
204
205
206 SET(USER_AGENT_STYLE_SHEETS
207   ${WEBCORE_DIR}/css/html.css
208   ${WEBCORE_DIR}/css/mathml.css
209   ${WEBCORE_DIR}/css/quirks.css
210   ${WEBCORE_DIR}/css/view-source.css
211   ${WEBCORE_DIR}/css/svg.css
212   ${WEBCORE_DIR}/css/wml.css
213   ${WEBCORE_DIR}/css/mediaControls.css
214   ${WEBCORE_DIR}/css/mediaControlsGtk.css)
215 SET(USER_AGENT_STYLE_SHEETS_GENERATOR ${WEBCORE_DIR}/css/make-css-file-arrays.pl)
216 # - Create ${DERIVED_SOURCES_DIR}/UserAgentStyleSheetsData.cpp and
217 #   ${DERIVED_SOURCES_DIR}/UserAgentStyleSheets.h
218 # GENERATE_USER_AGENT_STYLES()
219 MACRO(GENERATE_USER_AGENT_STYLES)
220   ADD_CUSTOM_COMMAND(
221     OUTPUT ${DERIVED_SOURCES_DIR}/UserAgentStyleSheetsData.cpp ${DERIVED_SOURCES_DIR}/UserAgentStyleSheets.h
222     DEPENDS ${USER_AGENT_STYLE_SHEETS_GENERATOR} ${USER_AGENT_STYLE_SHEETS}
223     COMMAND ${PERL_EXECUTABLE} ${USER_AGENT_STYLE_SHEETS_GENERATOR} ${DERIVED_SOURCES_DIR}/UserAgentStyleSheets.h ${DERIVED_SOURCES_DIR}/UserAgentStyleSheetsData.cpp ${USER_AGENT_STYLE_SHEETS}
224     VERBATIM)
225 ENDMACRO ()
226
227
228 SET(CSS_VALUE_KEYWORDS
229   ${WEBCORE_DIR}/css/CSSValueKeywords.in
230   ${WEBCORE_DIR}/css/SVGCSSValueKeywords.in)
231 SET(CSS_VALUE_GENERATOR ${WEBCORE_DIR}/css/makevalues.pl)
232 # - Create ${DERIVED_SOURCES_DIR}/CSSValueKeywords.*
233 # GENERATE_CSS_VALUE_KEYWORDS()
234 MACRO(GENERATE_CSS_VALUE_KEYWORDS)
235   ADD_CUSTOM_COMMAND(
236     OUTPUT ${DERIVED_SOURCES_DIR}/CSSValueKeywords.h ${DERIVED_SOURCES_DIR}/CSSValueKeywords.c ${DERIVED_SOURCES_DIR}/CSSValueKeywords.in ${DERIVED_SOURCES_DIR}/CSSValueKeywords.gperf
237     DEPENDS ${CSS_VALUE_KEYWORDS} ${CSS_VALUE_GENERATOR}
238     WORKING_DIRECTORY ${DERIVED_SOURCES_DIR}
239     COMMAND ${PERL_EXECUTABLE} -ne "print lc" ${CSS_VALUE_KEYWORDS} > ${DERIVED_SOURCES_DIR}/CSSValueKeywords.in
240     COMMAND ${PERL_EXECUTABLE} ${CSS_VALUE_GENERATOR}
241     VERBATIM)
242 ENDMACRO ()
243
244 SET(CSS_PROPERTY_NAMES
245   ${WEBCORE_DIR}/css/CSSPropertyNames.in
246   ${WEBCORE_DIR}/css/SVGCSSPropertyNames.in)
247 SET(MAKE_CSS_PROP ${WEBCORE_DIR}/css/makeprop.pl)
248 # - Create ${DERIVED_SOURCES_DIR}/CSSPropertyNames.*
249 # GENERATE_CSS_PROPERTY_NAMES()
250 MACRO(GENERATE_CSS_PROPERTY_NAMES)
251   ADD_CUSTOM_COMMAND(
252     OUTPUT ${DERIVED_SOURCES_DIR}/CSSPropertyNames.h ${DERIVED_SOURCES_DIR}/CSSPropertyNames.cpp ${DERIVED_SOURCES_DIR}/CSSPropertyNames.in ${DERIVED_SOURCES_DIR}/CSSPropertyNames.gperf
253     DEPENDS ${MAKE_CSS_PROP} ${CSS_PROPERTY_NAMES}
254     WORKING_DIRECTORY ${DERIVED_SOURCES_DIR}
255     COMMAND cat ${CSS_PROPERTY_NAMES} > ${DERIVED_SOURCES_DIR}/CSSPropertyNames.in
256     COMMAND ${PERL_EXECUTABLE} ${MAKE_CSS_PROP}
257     VERBATIM)
258 ENDMACRO ()