[CMake] Do not pass -P to the preprocessor when running make_names.pl.
[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 MACRO (GENERATE_FONT_NAMES _infile)
28     SET(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
29     SET(_arguments  --fonts ${_infile})
30     SET(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/WebKitFontFamilyNames.h)
31
32     ADD_CUSTOM_COMMAND(
33         OUTPUT  ${_outputfiles}
34         MAIN_DEPENDENCY ${_infile}
35         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
36         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments}
37         VERBATIM)
38 ENDMACRO ()
39
40
41 MACRO (GENERATE_EVENT_FACTORY _infile _outfile)
42     SET(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_event_factory.pl)
43
44     ADD_CUSTOM_COMMAND(
45         OUTPUT  ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
46         MAIN_DEPENDENCY ${_infile}
47         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
48         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
49         VERBATIM)
50 ENDMACRO ()
51
52
53 MACRO (GENERATE_EXCEPTION_CODE_DESCRIPTION _infile _outfile)
54     SET(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_dom_exceptions.pl)
55
56     ADD_CUSTOM_COMMAND(
57         OUTPUT  ${DERIVED_SOURCES_WEBCORE_DIR}/${_outfile}
58         MAIN_DEPENDENCY ${_infile}
59         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS}
60         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --input ${_infile} --outputDir ${DERIVED_SOURCES_WEBCORE_DIR}
61         VERBATIM)
62 ENDMACRO ()
63
64
65 MACRO (GENERATE_DOM_NAMES _namespace _attrs)
66     SET(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
67     SET(_arguments  --attrs ${_attrs})
68     SET(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.h)
69     SET(_extradef)
70     SET(_tags)
71
72     FOREACH (f ${ARGN})
73         IF (_tags)
74             SET(_extradef "${_extradef} ${f}")
75         ELSE ()
76             SET(_tags ${f})
77         ENDIF ()
78     ENDFOREACH ()
79
80     IF (_tags)
81         SET(_arguments "${_arguments}" --tags ${_tags} --factory --wrapperFactory)
82         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)
83     ENDIF ()
84
85     IF (_extradef)
86         SET(_additionArguments "${_additionArguments}" --extraDefines=${_extradef})
87     ENDIF ()
88
89     ADD_CUSTOM_COMMAND(
90         OUTPUT  ${_outputfiles}
91         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_attrs} ${_tags}
92         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --preprocessor "${CODE_GENERATOR_PREPROCESSOR_WITH_LINEMARKERS}" --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments} ${_additionArguments}
93         VERBATIM)
94 ENDMACRO ()
95
96
97 # - Create hash table *.lut.h
98 # GENERATE_HASH_LUT(input_file output_file)
99 MACRO (GENERATE_HASH_LUT _input _output)
100     SET(HASH_LUT_GENERATOR "${JAVASCRIPTCORE_DIR}/create_hash_table")
101
102     FOREACH (_tmp ${ARGN})
103         IF (${_tmp} STREQUAL "MAIN_DEPENDENCY")
104             SET(_main_dependency ${_input})
105         ENDIF ()
106     ENDFOREACH ()
107
108     ADD_CUSTOM_COMMAND(
109         OUTPUT ${_output}
110         MAIN_DEPENDENCY ${_main_dependency}
111         DEPENDS ${_input} ${HASH_LUT_GENERATOR}
112         COMMAND ${PERL_EXECUTABLE} ${HASH_LUT_GENERATOR} ${_input} -i > ${_output}
113         VERBATIM)
114 ENDMACRO ()
115
116
117 MACRO (GENERATE_GRAMMAR _prefix _input _output_header _output_source)
118     ADD_CUSTOM_COMMAND(
119         OUTPUT ${_output_header} ${_output_source}
120         MAIN_DEPENDENCY ${_input}
121         COMMAND ${BISON_EXECUTABLE} -p ${_prefix} ${_input} -o ${_output_source} --defines=${_output_header}
122         VERBATIM)
123 ENDMACRO ()
124
125 MACRO(MAKE_HASH_TOOLS _source)
126     GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
127
128     IF (${_source} STREQUAL "DocTypeStrings")
129         SET(_hash_tools_h "${DERIVED_SOURCES_WEBCORE_DIR}/HashTools.h")
130     ELSE ()
131         SET(_hash_tools_h "")
132     ENDIF ()
133
134     ADD_CUSTOM_COMMAND(
135         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_name}.cpp ${_hash_tools_h}
136         MAIN_DEPENDENCY ${_source}.gperf 
137         COMMAND ${PERL_EXECUTABLE} ${WEBCORE_DIR}/make-hash-tools.pl ${DERIVED_SOURCES_WEBCORE_DIR} ${_source}.gperf
138         VERBATIM)
139
140     UNSET(_name)
141     UNSET(_hash_tools_h)
142 ENDMACRO()
143
144 MACRO (WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS)
145     INCLUDE_IF_EXISTS(${CMAKE_CURRENT_SOURCE_DIR}/Platform${PORT}.cmake)
146 ENDMACRO ()
147
148 MACRO (WEBKIT_WRAP_SOURCELIST)
149     FOREACH (_file ${ARGN})
150         GET_FILENAME_COMPONENT(_basename ${_file} NAME_WE)
151         GET_FILENAME_COMPONENT(_path ${_file} PATH)
152
153         IF (NOT _file MATCHES "${DERIVED_SOURCES_WEBCORE_DIR}")
154             STRING(REGEX REPLACE "/" "\\\\\\\\" _sourcegroup "${_path}")
155             SOURCE_GROUP("${_sourcegroup}" FILES ${_file})
156         ENDIF ()
157
158         IF (WTF_PLATFORM_QT)
159             SET(_moc_filename ${DERIVED_SOURCES_WEBCORE_DIR}/${_basename}.moc)
160
161             FILE(READ ${_file} _contents)
162
163             STRING(REGEX MATCHALL "#include[ ]+\"${_basename}\\.moc\"" _match "${_contents}")
164             IF (_match)
165                 QT4_GENERATE_MOC(${_file} ${_moc_filename})
166                 ADD_SOURCE_DEPENDENCIES(${_file} ${_moc_filename})
167             ENDIF ()
168         ENDIF ()
169     ENDFOREACH ()
170
171     SOURCE_GROUP("DerivedSources" REGULAR_EXPRESSION "${DERIVED_SOURCES_WEBCORE_DIR}")
172 ENDMACRO ()