2011-05-18 Gyuyoung Kim <gyuyoung.kim@samsung.com>
[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_DOM_NAMES _namespace _attrs)
28     SET(NAMES_GENERATOR ${WEBCORE_DIR}/dom/make_names.pl)
29     SET(_arguments  --attrs ${_attrs})
30     SET(_outputfiles ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.cpp ${DERIVED_SOURCES_WEBCORE_DIR}/${_namespace}Names.h)
31     SET(_extradef)
32     SET(_tags)
33
34     FOREACH (f ${ARGN})
35         IF (_tags)
36             SET(_extradef "${_extradef} ${f}")
37         ELSE ()
38             SET(_tags ${f})
39         ENDIF ()
40     ENDFOREACH ()
41
42     IF (_tags)
43         SET(_arguments "${_arguments}" --tags ${_tags} --factory --wrapperFactory)
44         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)
45     ENDIF ()
46
47     IF (_extradef)
48         SET(_additionArguments "${_additionArguments}" --extraDefines=${_extradef})
49     ENDIF ()
50
51     ADD_CUSTOM_COMMAND(
52         OUTPUT  ${_outputfiles}
53         DEPENDS ${NAMES_GENERATOR} ${SCRIPTS_BINDINGS} ${_attrs} ${_tags}
54         COMMAND ${PERL_EXECUTABLE} -I${WEBCORE_DIR}/bindings/scripts ${NAMES_GENERATOR} --preprocessor "${CODE_GENERATOR_PREPROCESSOR}" --outputDir ${DERIVED_SOURCES_WEBCORE_DIR} ${_arguments} ${_additionArguments}
55         VERBATIM)
56 ENDMACRO ()
57
58
59 # - Create hash table *.lut.h
60 # GENERATE_HASH_LUT(input_file output_file)
61 MACRO (GENERATE_HASH_LUT _input _output)
62     SET(HASH_LUT_GENERATOR "${JAVASCRIPTCORE_DIR}/create_hash_table")
63
64     FOREACH (_tmp ${ARGN})
65         IF (${_tmp} STREQUAL "MAIN_DEPENDENCY")
66             SET(_main_dependency ${_input})
67         ENDIF ()
68     ENDFOREACH ()
69
70     ADD_CUSTOM_COMMAND(
71         OUTPUT ${_output}
72         MAIN_DEPENDENCY ${_main_dependency}
73         DEPENDS ${_input} ${HASH_LUT_GENERATOR}
74         COMMAND ${PERL_EXECUTABLE} ${HASH_LUT_GENERATOR} ${_input} -i > ${_output}
75         VERBATIM)
76 ENDMACRO ()
77
78
79 MACRO (GENERATE_GRAMMAR _prefix _input _output_header _output_source)
80     ADD_CUSTOM_COMMAND(
81         OUTPUT ${_output_header} ${_output_source}
82         MAIN_DEPENDENCY ${_input}
83         COMMAND ${BISON_EXECUTABLE} -p ${_prefix} ${_input} -o ${_output_source} --defines=${_output_header}
84         VERBATIM)
85 ENDMACRO ()
86
87 MACRO(MAKE_HASH_TOOLS _source)
88     GET_FILENAME_COMPONENT(_name ${_source} NAME_WE)
89
90     IF (${_source} STREQUAL "DocTypeStrings")
91         SET(_hash_tools_h "${DERIVED_SOURCES_WEBCORE_DIR}/HashTools.h")
92     ELSE ()
93         SET(_hash_tools_h "")
94     ENDIF ()
95
96     ADD_CUSTOM_COMMAND(
97         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/${_name}.cpp ${_hash_tools_h}
98         MAIN_DEPENDENCY ${_source}.gperf 
99         COMMAND ${PERL_EXECUTABLE} ${WEBCORE_DIR}/make-hash-tools.pl ${DERIVED_SOURCES_WEBCORE_DIR} ${_source}.gperf
100         VERBATIM)
101
102     UNSET(_name)
103     UNSET(_hash_tools_h)
104 ENDMACRO()
105
106 MACRO (WEBKIT_WRAP_SOURCELIST)
107     FOREACH (_file ${ARGN})
108         GET_FILENAME_COMPONENT(_basename ${_file} NAME_WE)
109         GET_FILENAME_COMPONENT(_path ${_file} PATH)
110
111                 IF (NOT _file MATCHES "${DERIVED_SOURCES_WEBCORE_DIR}")
112             STRING(REGEX REPLACE "/" "\\\\\\\\" _sourcegroup "${_path}")
113             SOURCE_GROUP("${_sourcegroup}" FILES ${_file})
114                 ENDIF ()
115
116         IF (WTF_PLATFORM_QT)
117             SET(_moc_filename ${DERIVED_SOURCES_WEBCORE_DIR}/${_basename}.moc)
118
119             FILE(READ ${_file} _contents)
120
121             STRING(REGEX MATCHALL "#include[ ]+\"${_basename}\\.moc\"" _match "${_contents}")
122             IF (_match)
123                 QT4_GENERATE_MOC(${_file} ${_moc_filename})
124                 ADD_SOURCE_DEPENDENCIES(${_file} ${_moc_filename})
125             ENDIF ()
126         ENDIF ()
127     ENDFOREACH ()
128
129     SOURCE_GROUP("DerivedSources" REGULAR_EXPRESSION "${DERIVED_SOURCES_WEBCORE_DIR}")
130 ENDMACRO ()