2010-09-29 Joseph Pecoraro <joepeck@webkit.org>
[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 # Modules that the bindings generator scripts may use
11 SET(SCRIPTS_BINDINGS
12   ${WEBCORE_DIR}/bindings/scripts/CodeGenerator.pm
13   ${WEBCORE_DIR}/bindings/scripts/IDLParser.pm
14   ${WEBCORE_DIR}/bindings/scripts/IDLStructure.pm
15   ${WEBCORE_DIR}/bindings/scripts/InFilesParser.pm)
16 SET(BINDING_CODE_GENERATOR ${WEBCORE_DIR}/bindings/scripts/generate-bindings.pl)
17 SET(JS_IDL_FILES "")
18 SET(Inspector_IDL_FILES "")
19
20 # - Create JS C++ code given an IDL input
21 # GENERATE_FROM_IDL(generator idl_source)
22 #
23 # The generated files (.cpp, .h) lives in ${DERIVED_SOURCES_DIR}.
24 #
25 # This function also appends the generated cpp file to JS_IDL_FILES list.
26 MACRO(GENERATE_JS_FROM_IDL _source)
27   SET(FEATURE_DEFINES_STR "")
28   FOREACH (f ${FEATURE_DEFINES})
29     SET(FEATURE_DEFINES_STR "${FEATURE_DEFINES_STR} ${f}")
30   ENDFOREACH ()
31
32   GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
33   ADD_CUSTOM_COMMAND(
34     OUTPUT  ${DERIVED_SOURCES_DIR}/JS${_name}.cpp ${DERIVED_SOURCES_DIR}/JS${_name}.h
35     DEPENDS ${BINDING_CODE_GENERATOR} ${SCRIPTS_BINDINGS} ${WEBCORE_DIR}/${_source}
36     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}
37     VERBATIM)
38   LIST(APPEND JS_IDL_FILES ${DERIVED_SOURCES_DIR}/JS${_name}.cpp)
39   UNSET(_name)
40   UNSET(_defines)
41 ENDMACRO()
42
43
44 # - Create Inspector C++ code given an IDL input
45 # GENERATE_FROM_IDL(generator idl_source)
46 #
47 # The generated files (.cpp, .h) lives in ${DERIVED_SOURCES_DIR}.
48 #
49 # This function also appends the generated cpp file to Inspector_IDL_FILES list.
50 MACRO(GENERATE_INSPECTOR_FROM_IDL _source)
51   SET(FEATURE_DEFINES_STR "")
52   FOREACH (f ${FEATURE_DEFINES})
53     SET(FEATURE_DEFINES_STR "${FEATURE_DEFINES_STR} ${f}")
54   ENDFOREACH ()
55
56   GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
57   ADD_CUSTOM_COMMAND(
58     OUTPUT  ${DERIVED_SOURCES_DIR}/${_name}Frontend.cpp ${DERIVED_SOURCES_DIR}/${_name}Frontend.h ${DERIVED_SOURCES_DIR}/${_name}BackendDispatcher.cpp ${DERIVED_SOURCES_DIR}/${_name}BackendDispatcher.h
59     DEPENDS ${BINDING_CODE_GENERATOR} ${SCRIPTS_BINDINGS} ${WEBCORE_DIR}/${_source}
60     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}
61     VERBATIM)
62   LIST(APPEND Inspector_IDL_FILES ${DERIVED_SOURCES_DIR}/${_name}Frontend.cpp)
63   UNSET(_name)
64   UNSET(_defines)
65 ENDMACRO()
66
67
68
69 # - Create pure JavaScript functions (does nothing so far)
70 MACRO(GENERATE_JS_FROM_IDL_PURE _source)
71    GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
72    ADD_CUSTOM_COMMAND(
73      OUTPUT  ${DERIVED_SOURCES_DIR}/JS${_name}.cpp ${DERIVED_SOURCES_DIR}/JS${_name}.h
74      DEPENDS ${BINDING_CODE_GENERATOR} ${SCRIPTS_BINDINGS} ${WEBCORE_DIR}/${_source}
75      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}
76      VERBATIM)
77    UNSET(_name)
78 ENDMACRO()
79
80 SET(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
81 # - Create DOM names and factory given tags and attributes as source.
82 # GENERATE_DOM_NAMES_FACTORY(namespace tags_source attributes_source [defines])
83 #
84 # The generated files lives in ${DERIVED_SOURCES_DIR}. The files will
85 # be named using the given namespace, such as:
86 #   - ${namespace}Names.cpp, ${namespace}Names.h;
87 #   - ${namespace}ElementFactory.cpp, ${namespace}ElementFactory.h;
88 #   - ${namespace}ElementWrapperFactory.cpp; ${namespace}ElementWrapperFactory.h
89 #
90 # If optional defines are given, then they will be speficied using
91 # --extraDefines directive to the generator script.
92 MACRO(GENERATE_DOM_NAMES_FACTORY _namespace _tags _attrs)
93   UNSET(_extradef)
94   FOREACH (f ${ARGN})
95     SET(_extradef "${_extradef} ${f}")
96   ENDFOREACH ()
97   IF (_extradef)
98     SET(_extradef --extraDefines=${_extradef})
99   ENDIF ()
100   ADD_CUSTOM_COMMAND(
101     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
102     DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_tags} ${_attrs}
103     COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --tags ${_tags} --attrs ${_attrs} ${_extradef} --factory --wrapperFactory --outputDir ${DERIVED_SOURCES_DIR}
104     VERBATIM)
105   UNSET(_extradef)
106 ENDMACRO ()
107
108 # - Create DOM names only (no factories)
109 # GENERATE_DOM_NAMES_ONLY(namespace attributes_source)
110 #
111 # The generated files lives in ${DERIVED_SOURCES_DIR}. The files will
112 # be named using the given namespace, such as:
113 #   - ${namespace}Names.cpp, ${namespace}Names.h;
114 MACRO(GENERATE_DOM_NAMES_ONLY _namespace _attrs)
115   ADD_CUSTOM_COMMAND(
116     OUTPUT ${DERIVED_SOURCES_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_DIR}/${_namespace}Names.h
117     DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_attrs}
118     COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --attrs ${_attrs} --outputDir ${DERIVED_SOURCES_DIR}
119     VERBATIM)
120 ENDMACRO()
121
122 # - Create ${CMAKE_BINARY_DIR}/JavaScriptCore/pcre/chartables.c
123 # GENERATE_DFTABLES()
124 MACRO(GENERATE_DFTABLES)
125   ADD_CUSTOM_COMMAND(
126     OUTPUT  ${CMAKE_BINARY_DIR}/JavaScriptCore/pcre/chartables.c
127     DEPENDS ${JAVASCRIPTCORE_DIR}/pcre/dftables
128     COMMAND ${PERL_EXECUTABLE} ${JAVASCRIPTCORE_DIR}/pcre/dftables ${CMAKE_BINARY_DIR}/JavaScriptCore/pcre/chartables.c
129     VERBATIM)
130 ENDMACRO()
131
132
133 SET(MAKE_TOKENIZER ${WEBCORE_DIR}/css/maketokenizer)
134 # - Create ${DERIVED_SOURCES_DIR}/tokenizer.cpp
135 # GENERATE_TOKENIZER()
136 MACRO(GENERATE_TOKENIZER)
137   ADD_CUSTOM_COMMAND(
138     OUTPUT ${DERIVED_SOURCES_DIR}/tokenizer.cpp
139     DEPENDS ${WEBCORE_DIR}/css/tokenizer.flex ${MAKE_TOKENIZER}
140     COMMAND ${FLEX_EXECUTABLE} -t ${WEBCORE_DIR}/css/tokenizer.flex | ${PERL_EXECUTABLE} ${MAKE_TOKENIZER} > ${DERIVED_SOURCES_DIR}/tokenizer.cpp
141     VERBATIM)
142 ENDMACRO()
143
144
145 SET(USER_AGENT_STYLE_SHEETS
146   ${WEBCORE_DIR}/css/html.css
147   ${WEBCORE_DIR}/css/mathml.css
148   ${WEBCORE_DIR}/css/quirks.css
149   ${WEBCORE_DIR}/css/view-source.css
150   ${WEBCORE_DIR}/css/svg.css
151   ${WEBCORE_DIR}/css/wml.css
152   ${WEBCORE_DIR}/css/mediaControls.css)
153 SET(USER_AGENT_STYLE_SHEETS_GENERATOR ${WEBCORE_DIR}/css/make-css-file-arrays.pl)
154 # - Create ${DERIVED_SOURCES_DIR}/UserAgentStyleSheetsData.cpp and
155 #   ${DERIVED_SOURCES_DIR}/UserAgentStyleSheets.h
156 # GENERATE_USER_AGENT_STYLES()
157 MACRO(GENERATE_USER_AGENT_STYLES)
158   ADD_CUSTOM_COMMAND(
159     OUTPUT ${DERIVED_SOURCES_DIR}/UserAgentStyleSheetsData.cpp ${DERIVED_SOURCES_DIR}/UserAgentStyleSheets.h
160     DEPENDS ${USER_AGENT_STYLE_SHEETS_GENERATOR} ${USER_AGENT_STYLE_SHEETS}
161     COMMAND ${PERL_EXECUTABLE} ${USER_AGENT_STYLE_SHEETS_GENERATOR} ${DERIVED_SOURCES_DIR}/UserAgentStyleSheets.h ${DERIVED_SOURCES_DIR}/UserAgentStyleSheetsData.cpp ${USER_AGENT_STYLE_SHEETS}
162     VERBATIM)
163 ENDMACRO ()
164
165
166 SET(CSS_VALUE_KEYWORDS
167   ${WEBCORE_DIR}/css/CSSValueKeywords.in
168   ${WEBCORE_DIR}/css/SVGCSSValueKeywords.in)
169 SET(CSS_VALUE_GENERATOR ${WEBCORE_DIR}/css/makevalues.pl)
170 # - Create ${DERIVED_SOURCES_DIR}/CSSValueKeywords.*
171 # GENERATE_CSS_VALUE_KEYWORDS()
172 MACRO(GENERATE_CSS_VALUE_KEYWORDS)
173   ADD_CUSTOM_COMMAND(
174     OUTPUT ${DERIVED_SOURCES_DIR}/CSSValueKeywords.h ${DERIVED_SOURCES_DIR}/CSSValueKeywords.cpp ${DERIVED_SOURCES_DIR}/CSSValueKeywords.in ${DERIVED_SOURCES_DIR}/CSSValueKeywords.gperf
175     DEPENDS ${CSS_VALUE_KEYWORDS} ${CSS_VALUE_GENERATOR}
176     WORKING_DIRECTORY ${DERIVED_SOURCES_DIR}
177     COMMAND ${PERL_EXECUTABLE} -ne "print lc" ${CSS_VALUE_KEYWORDS} > ${DERIVED_SOURCES_DIR}/CSSValueKeywords.in
178     COMMAND ${PERL_EXECUTABLE} ${CSS_VALUE_GENERATOR}
179     VERBATIM)
180 ENDMACRO ()
181
182 SET(CSS_PROPERTY_NAMES
183   ${WEBCORE_DIR}/css/CSSPropertyNames.in
184   ${WEBCORE_DIR}/css/SVGCSSPropertyNames.in)
185 SET(MAKE_CSS_PROP ${WEBCORE_DIR}/css/makeprop.pl)
186 # - Create ${DERIVED_SOURCES_DIR}/CSSPropertyNames.*
187 # GENERATE_CSS_PROPERTY_NAMES()
188 MACRO(GENERATE_CSS_PROPERTY_NAMES)
189   ADD_CUSTOM_COMMAND(
190     OUTPUT ${DERIVED_SOURCES_DIR}/CSSPropertyNames.h ${DERIVED_SOURCES_DIR}/CSSPropertyNames.cpp ${DERIVED_SOURCES_DIR}/CSSPropertyNames.in ${DERIVED_SOURCES_DIR}/CSSPropertyNames.gperf
191     DEPENDS ${MAKE_CSS_PROP} ${CSS_PROPERTY_NAMES}
192     WORKING_DIRECTORY ${DERIVED_SOURCES_DIR}
193     COMMAND cat ${CSS_PROPERTY_NAMES} > ${DERIVED_SOURCES_DIR}/CSSPropertyNames.in
194     COMMAND ${PERL_EXECUTABLE} ${MAKE_CSS_PROP}
195     VERBATIM)
196 ENDMACRO ()