Generate internal.settings from Settings.in
[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)
38     set(BINDING_GENERATOR ${WEBCORE_DIR}/bindings/scripts/generate-bindings.pl)
39
40     set(_supplemental_dependency_file ${ARGN})
41     if (_supplemental_dependency_file)
42         set(_supplemental_dependency --supplementalDependencyFile ${_supplemental_dependency_file})
43     endif ()
44
45     foreach (_file ${_input_files})
46         get_filename_component(_name ${_file} NAME_WE)
47
48         add_custom_command(
49             OUTPUT ${_destination}/${_prefix}${_name}.cpp ${_destination}/${_prefix}${_name}.h
50             MAIN_DEPENDENCY ${_file}
51             DEPENDS ${BINDING_GENERATOR} ${SCRIPTS_BINDINGS} ${_supplemental_dependency_file}
52             COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${BINDING_GENERATOR} --defines "${_features}" --generator ${_generator} ${_idl_includes} --outputDir "${_destination}" --preprocessor "${CODE_GENERATOR_PREPROCESSOR}" ${_supplemental_dependency} ${_file}
53             WORKING_DIRECTORY ${_base_dir}
54             VERBATIM)
55
56         list(APPEND ${_output_source} ${_destination}/${_prefix}${_name}.cpp)
57     endforeach ()
58 endmacro()
59
60
61 macro(GENERATE_FONT_NAMES _infile)
62     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
63     set(_arguments  --fonts ${_infile})
64     set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.h)
65
66     add_custom_command(
67         OUTPUT  ${_outputfiles}
68         MAIN_DEPENDENCY ${_infile}
69         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
70         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments}
71         VERBATIM)
72 endmacro()
73
74
75 macro(GENERATE_EVENT_FACTORY _infile _outfile)
76     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_event_factory.pl)
77
78     add_custom_command(
79         OUTPUT  ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
80         MAIN_DEPENDENCY ${_infile}
81         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
82         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
83         VERBATIM)
84 endmacro()
85
86
87 macro(GENERATE_EXCEPTION_CODE_DESCRIPTION _infile _outfile)
88     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_dom_exceptions.pl)
89
90     add_custom_command(
91         OUTPUT  ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
92         MAIN_DEPENDENCY ${_infile}
93         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
94         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
95         VERBATIM)
96 endmacro()
97
98
99 macro(GENERATE_SETTINGS_MACROS _infile _outfile)
100     set(NAMES_GENERATOR ${WEBCORE_DIR}/page/make_settings.pl)
101
102     add_custom_command(
103         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile} ${DERIVED_SOURCES_WEBCORE_DIR}/IntenalSettingsGenerated.h ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/InternalSettingsGenerated.idl
104         MAIN_DEPENDENCY ${_infile}
105         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
106         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
107         VERBATIM)
108 endmacro()
109
110
111 macro(GENERATE_DOM_NAMES _namespace _attrs)
112     set(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
113     set(_arguments  --attrs ${_attrs})
114     set(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.h)
115     set(_extradef)
116     set(_tags)
117
118     foreach (f ${ARGN})
119         if (_tags)
120             set(_extradef "${_extradef} ${f}")
121         else ()
122             set(_tags ${f})
123         endif ()
124     endforeach ()
125
126     if (_tags)
127         set(_arguments "${_arguments}" --tags ${_tags} --factory --wrapperFactory)
128         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)
129     endif ()
130
131     if (_extradef)
132         set(_additionArguments "${_additionArguments}" --extraDefines=${_extradef})
133     endif ()
134
135     add_custom_command(
136         OUTPUT  ${_outputfiles}
137         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_attrs} ${_tags}
138         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --preprocessor "${CODE_GENERATOR_PREPROCESSOR_WITH_LINEMARKERS}" --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments} ${_additionArguments}
139         VERBATIM)
140 endmacro()
141
142
143 # - Create hash table *.lut.h
144 # GENERATE_HASH_LUT(input_file output_file)
145 macro(GENERATE_HASH_LUT _input _output)
146     set(HASH_LUT_GENERATOR "${JAVASCRIPTCORE_DIR}/create_hash_table")
147
148     foreach (_tmp ${ARGN})
149         if (${_tmp} STREQUAL "MAIN_DEPENDENCY")
150             set(_main_dependency ${_input})
151         endif ()
152     endforeach ()
153
154     add_custom_command(
155         OUTPUT ${_output}
156         MAIN_DEPENDENCY ${_main_dependency}
157         DEPENDS ${_input} ${HASH_LUT_GENERATOR}
158         COMMAND ${PERL_EXECUTABLE} ${HASH_LUT_GENERATOR} ${_input} -i > ${_output}
159         VERBATIM)
160 endmacro()
161
162
163 macro(GENERATE_GRAMMAR _prefix _input _output_header _output_source _features)
164     # This is a workaround for winflexbison, which does not work corretly when
165     # run in a different working directory than the installation directory.
166     get_filename_component(_working_directory ${BISON_EXECUTABLE} PATH)
167
168     add_custom_command(
169         OUTPUT ${_output_header} ${_output_source}
170         MAIN_DEPENDENCY ${_input}
171         DEPENDS ${_input}
172         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}
173         WORKING_DIRECTORY ${_working_directory}
174         VERBATIM)
175 endmacro()
176
177 macro(MAKE_HASH_TOOLS _source)
178     get_filename_component(_name ${_source} NAME_WE)
179
180     if (${_source} STREQUAL "DocTypeStrings")
181         set(_hash_tools_h "${DERIVED_SOURCES_WEBCORE_DIR}/HashTools.h")
182     else ()
183         set(_hash_tools_h "")
184     endif ()
185
186     add_custom_command(
187         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_name}.cpp ${_hash_tools_h}
188         MAIN_DEPENDENCY ${_source}.gperf
189         COMMAND ${PERL_EXECUTABLE} ${WEBCORE_DIR}/make-hash-tools.pl ${DERIVED_SOURCES_WEBCORE_DIR} ${_source}.gperf
190         VERBATIM)
191
192     unset(_name)
193     unset(_hash_tools_h)
194 endmacro()
195
196 macro(WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS)
197     INCLUDE_IF_EXISTS(${CMAKE_CURRENT_SOURCE_DIR}/Platform${PORT}.cmake)
198 endmacro()
199
200 macro(WEBKIT_WRAP_SOURCELIST)
201     foreach (_file ${ARGN})
202         get_filename_component(_basename ${_file} NAME_WE)
203         get_filename_component(_path ${_file} PATH)
204
205         if (NOT _file MATCHES "${DERIVED_SOURCES_WEBCORE_DIR}")
206             string(REGEX REPLACE "/" "\\\\\\\\" _sourcegroup "${_path}")
207             source_group("${_sourcegroup}" FILES ${_file})
208         endif ()
209
210         if (WTF_PLATFORM_QT)
211             set(_moc_filename ${DERIVED_SOURCES_WEBCORE_DIR}/${_basename}.moc)
212
213             file(READ ${_file} _contents)
214
215             string(REGEX MATCHALL "#include[ ]+\"${_basename}\\.moc\"" _match "${_contents}")
216             if (_match)
217                 QT4_GENERATE_MOC(${_file} ${_moc_filename})
218                 ADD_SOURCE_DEPENDENCIES(${_file} ${_moc_filename})
219             endif ()
220         endif ()
221     endforeach ()
222
223     source_group("DerivedSources" REGULAR_EXPRESSION "${DERIVED_SOURCES_WEBCORE_DIR}")
224 endmacro()
225
226
227 macro(WEBKIT_CREATE_FORWARDING_HEADER _target_directory _file)
228     get_filename_component(_absolute "${_file}" ABSOLUTE)
229     get_filename_component(_name "${_file}" NAME)
230     set(_content "#include \"${_absolute}\"\n")
231     set(_filename "${_target_directory}/${_name}")
232
233     if (EXISTS "${_filename}")
234         file(READ "${_filename}" _old_content)
235     endif ()
236
237     if (NOT _old_content STREQUAL _content)
238         file(WRITE "${_filename}" "${_content}")
239     endif ()
240 endmacro()
241
242 macro(WEBKIT_CREATE_FORWARDING_HEADERS _framework)
243     set(_processing_directories 0)
244     set(_processing_files 0)
245     set(_target_directory "${DERIVED_SOURCES_DIR}/ForwardingHeaders/${_framework}")
246
247     file(GLOB _files "${_target_directory}/*.h")
248     foreach (_file ${_files})
249         file(READ "${_file}" _content)
250         string(REGEX MATCH "^#include \"([^\"]*)\"" _matched ${_content})
251         if (_matched AND NOT EXISTS "${CMAKE_MATCH_1}")
252            file(REMOVE "${_file}")
253         endif ()
254     endforeach ()
255
256     foreach (_currentArg ${ARGN})
257         if ("${_currentArg}" STREQUAL "DIRECTORIES")
258             set(_processing_directories 1)
259             set(_processing_files 0)
260         elseif ("${_currentArg}" STREQUAL "FILES")
261             set(_processing_directories 0)
262             set(_processing_files 1)
263         elseif (_processing_directories)
264             file(GLOB _files "${_currentArg}/*.h")
265             foreach (_file ${_files})
266                 WEBKIT_CREATE_FORWARDING_HEADER(${_target_directory} ${_file})
267             endforeach ()
268         elseif (_processing_files)
269             WEBKIT_CREATE_FORWARDING_HEADER(${_target_directory} ${_currentArg})
270         endif ()
271     endforeach ()
272 endmacro()