[STLPORT]
[reactos.git] / CMakeMacros.cmake
1
2 MACRO(_PCH_GET_COMPILE_FLAGS _target_name _out_compile_flags _header_filename)
3
4 # Add the precompiled header to the build
5 get_filename_component(FILE ${_header_filename} NAME)
6 set(_gch_filename "${_target_name}_${FILE}.gch")
7 list(APPEND ${_out_compile_flags} -c ${_header_filename} -o ${_gch_filename})
8
9 # This gets us our includes
10 get_directory_property(DIRINC INCLUDE_DIRECTORIES)
11 foreach(item ${DIRINC})
12 list(APPEND ${_out_compile_flags} -I${item})
13 endforeach(item)
14
15 # This is a particular bit of undocumented/hacky magic I'm quite proud of
16 get_directory_property(_compiler_flags DEFINITIONS)
17 string(REPLACE "\ " "\t" _compiler_flags ${_compiler_flags})
18 list(APPEND ${_out_compile_flags} ${_compiler_flags})
19
20 # This gets any specific definitions that were added with set-target-property
21 get_target_property(_target_defs ${_target_name} COMPILE_DEFINITIONS)
22 if (_target_defs)
23 foreach(item ${_target_defs})
24 list(APPEND ${_out_compile_flags} -D${item})
25 endforeach(item)
26 endif()
27
28 ENDMACRO(_PCH_GET_COMPILE_FLAGS)
29
30 MACRO(add_pch _target_name _header_filename _src_list)
31
32 get_filename_component(FILE ${_header_filename} NAME)
33 set(_gch_filename "${_target_name}_${FILE}.gch")
34 list(APPEND ${_src_list} ${_gch_filename})
35 _PCH_GET_COMPILE_FLAGS(${_target_name} _args ${_header_filename})
36 file(REMOVE ${_gch_filename})
37 add_custom_command(
38 OUTPUT ${_gch_filename}
39 COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1} ${_args}
40 DEPENDS ${_header_filename})
41
42 ENDMACRO(add_pch _target_name _header_filename _src_list)
43
44 if (NOT MSVC)
45 MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
46
47 get_filename_component(OBJECT_PATH ${_object_file} PATH)
48 get_filename_component(OBJECT_NAME ${_object_file} NAME)
49 file(MAKE_DIRECTORY ${OBJECT_PATH})
50 get_directory_property(defines COMPILE_DEFINITIONS)
51 get_directory_property(includes INCLUDE_DIRECTORIES)
52
53 foreach(arg ${defines})
54 set(result_defs ${result_defs} -D${arg})
55 endforeach(arg ${defines})
56
57 foreach(arg ${includes})
58 set(result_incs -I${arg} ${result_incs})
59 endforeach(arg ${includes})
60
61 add_custom_command(
62 OUTPUT ${_object_file}
63 COMMAND nasm -o ${_object_file} ${result_incs} ${result_defs} -f bin ${_asm_file}
64 DEPENDS native-winebuild)
65 set_source_files_properties(${_object_file} PROPERTIES GENERATED TRUE)
66 add_custom_target(${_target_name} ALL DEPENDS ${_object_file})
67 add_minicd(${_object_file} loader ${OBJECT_NAME})
68 ENDMACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
69 else()
70 MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
71 ENDMACRO()
72 endif()
73
74 MACRO(MACRO_IDL_COMPILE_OBJECT OBJECT SOURCE)
75 GET_PROPERTY(FLAGS SOURCE ${SOURCE} PROPERTY COMPILE_FLAGS)
76 GET_PROPERTY(DEFINES SOURCE ${SOURCE} PROPERTY COMPILE_DEFINITIONS)
77 GET_PROPERTY(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
78 FOREACH(DIR ${INCLUDE_DIRECTORIES})
79 SET(FLAGS "${FLAGS} -I${DIR}")
80 ENDFOREACH()
81
82 SET(IDL_COMMAND ${CMAKE_IDL_COMPILE_OBJECT})
83 STRING(REPLACE "<CMAKE_IDL_COMPILER>" "${CMAKE_IDL_COMPILER}" IDL_COMMAND "${IDL_COMMAND}")
84 STRING(REPLACE <FLAGS> "${FLAGS}" IDL_COMMAND "${IDL_COMMAND}")
85 STRING(REPLACE "<DEFINES>" "${DEFINES}" IDL_COMMAND "${IDL_COMMAND}")
86 STRING(REPLACE "<OBJECT>" "${OBJECT}" IDL_COMMAND "${IDL_COMMAND}")
87 STRING(REPLACE "<SOURCE>" "${SOURCE}" IDL_COMMAND "${IDL_COMMAND}")
88 SEPARATE_ARGUMENTS(IDL_COMMAND)
89
90 ADD_CUSTOM_COMMAND(
91 OUTPUT ${OBJECT}
92 COMMAND ${IDL_COMMAND}
93 DEPENDS ${SOURCE}
94 VERBATIM
95 )
96 ENDMACRO()
97
98 MACRO(ADD_INTERFACE_DEFINITIONS TARGET)
99 FOREACH(SOURCE ${ARGN})
100 GET_FILENAME_COMPONENT(FILE ${SOURCE} NAME_WE)
101 SET(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.h)
102 MACRO_IDL_COMPILE_OBJECT(${OBJECT} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE})
103 LIST(APPEND OBJECTS ${OBJECT})
104 ENDFOREACH()
105 ADD_CUSTOM_TARGET(${TARGET} ALL DEPENDS ${OBJECTS})
106 ENDMACRO()
107
108 MACRO(add_minicd_target _targetname _dir) # optional parameter: _nameoncd
109 if("${ARGN}" STREQUAL "")
110 get_target_property(FILENAME ${_targetname} LOCATION)
111 get_filename_component(_nameoncd ${FILENAME} NAME)
112 else()
113 set(_nameoncd ${ARGN})
114 endif()
115
116 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_minicd_target.txt "${_targetname}\t${_dir}\t${_nameoncd}\n")
117 ENDMACRO(add_minicd_target)
118
119 MACRO(add_minicd FILENAME _dir _nameoncd)
120 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_minicd.txt "${FILENAME}\t${_dir}\t${_nameoncd}\n")
121 ENDMACRO(add_minicd)
122
123 macro(set_cpp)
124 include_directories(BEFORE ${REACTOS_SOURCE_DIR}/include/stlport)
125 set(IS_CPP 1)
126 endmacro()
127
128 MACRO(add_livecd_target _targetname _dir )# optional parameter : _nameoncd
129 if("${ARGN}" STREQUAL "")
130 get_target_property(FILENAME ${_targetname} LOCATION)
131 get_filename_component(_nameoncd ${FILENAME} NAME)
132 else()
133 set(_nameoncd ${ARGN})
134 endif()
135
136 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_livecd_target.txt "${_targetname}\t${_dir}\t${_nameoncd}\n")
137 ENDMACRO(add_livecd_target)
138
139 MACRO(add_livecd FILENAME _dir)# optional parameter : _nameoncd
140 if("${ARGN}" STREQUAL "")
141 get_filename_component(_nameoncd ${FILENAME} NAME)
142 else()
143 set(_nameoncd ${ARGN})
144 endif()
145 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_livecd.txt "${FILENAME}\t${_dir}\t${_nameoncd}\n")
146 ENDMACRO(add_livecd)
147
148 macro(cab_to_dir _dir_num _var_name)
149 # 1 = system32
150 # 2 = system32\drivers
151 # 3 = Fonts
152 # 4 =
153 # 5 = system32\drivers\etc
154 # 6 = inf
155 # 7 = bin
156 # 8 = media
157 if(${_dir_num} STREQUAL "1")
158 set(${_var_name} "reactos/system32")
159 elseif(${_dir_num} STREQUAL "2")
160 set(${_var_name} "reactos/system32/drivers")
161 elseif(${_dir_num} STREQUAL "3")
162 set(${_var_name} "reactos/fonts")
163 elseif(${_dir_num} STREQUAL "4")
164 set(${_var_name} "reactos")
165 elseif(${_dir_num} STREQUAL "5")
166 set(${_var_name} "reactos/system32/drivers/etc")
167 elseif(${_dir_num} STREQUAL "6")
168 set(${_var_name} "reactos/inf")
169 elseif(${_dir_num} STREQUAL "7")
170 set(${_var_name} "reactos/bin")
171 elseif(${_dir_num} STREQUAL "8")
172 set(${_var_name} "reactos/system32/drivers")
173 else()
174 message(FATAL_ERROR "Wrong directory ${_dir_num}")
175 endif()
176 endmacro()
177
178 MACRO(add_cab_target _targetname _num )
179 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab_target.txt "${_targetname}\t${_num}\n")
180 cab_to_dir(${_num} _dir)
181 add_livecd_target(${_targetname} ${_dir})
182 ENDMACRO(add_cab_target)
183
184 MACRO(add_cab FILENAME _num)
185 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab.txt "${FILENAME}\t${_num}\n")
186 cab_to_dir(${_num} _dir)
187 add_livecd(${FILENAME} ${_dir})
188 ENDMACRO(add_cab)
189
190 macro(custom_incdefs)
191 if(NOT DEFINED result_incs) #rpc_defines
192 get_directory_property(rpc_defines COMPILE_DEFINITIONS)
193 get_directory_property(rpc_includes INCLUDE_DIRECTORIES)
194
195 foreach(arg ${rpc_defines})
196 set(result_defs ${result_defs} -D${arg})
197 endforeach(arg ${defines})
198
199 foreach(arg ${rpc_includes})
200 set(result_incs -I${arg} ${result_incs})
201 endforeach(arg ${includes})
202 endif()
203 endmacro(custom_incdefs)
204
205 macro(rpcproxy TARGET)
206 custom_incdefs()
207 list(APPEND SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c)
208
209 foreach(_in_FILE ${ARGN})
210 get_filename_component(FILE ${_in_FILE} NAME_WE)
211 add_custom_command(
212 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c
213 COMMAND native-widl ${result_incs} ${result_defs} -m32 --win32 -h -H ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.h -p -P ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl
214 DEPENDS native-widl)
215 set_source_files_properties(
216 ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c
217 PROPERTIES GENERATED TRUE)
218 list(APPEND SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c)
219 list(APPEND IDLS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl)
220 list(APPEND PROXY_DEPENDS ${TARGET}_${FILE}_p)
221 add_custom_target(${TARGET}_${FILE}_p
222 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c)
223 #add_dependencies(${TARGET}_proxy ${TARGET}_${FILE}_p)
224 endforeach(_in_FILE ${ARGN})
225
226 add_custom_command(
227 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c
228 COMMAND native-widl ${result_incs} ${result_defs} -m32 --win32 --dlldata-only --dlldata=${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c ${IDLS}
229 DEPENDS native-widl)
230 set_source_files_properties(
231 ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c
232 PROPERTIES GENERATED TRUE)
233
234 add_library(${TARGET}_proxy ${SOURCE})
235 add_dependencies(${TARGET}_proxy psdk ${PROXY_DEPENDS})
236 endmacro(rpcproxy)
237
238 macro (MACRO_IDL_FILES)
239 custom_incdefs()
240 foreach(_in_FILE ${ARGN})
241 get_filename_component(FILE ${_in_FILE} NAME_WE)
242 add_custom_command(
243 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c
244 COMMAND ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${IDL_SERVER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl
245 DEPENDS ${_in_file})
246 set_source_files_properties(
247 ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c
248 PROPERTIES GENERATED TRUE)
249 add_library(${FILE}_server ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c)
250 add_dependencies(${FILE}_server psdk)
251
252 add_custom_command(
253 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c
254 COMMAND ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${IDL_CLIENT_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl
255 DEPENDS ${_in_file})
256 set_source_files_properties(
257 ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c
258 PROPERTIES GENERATED TRUE)
259 add_library(${FILE}_client ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c)
260 add_dependencies(${FILE}_client psdk)
261 endforeach(_in_FILE ${ARGN})
262
263 endmacro (MACRO_IDL_FILES)
264
265 macro(ADD_TYPELIB TARGET)
266 custom_incdefs()
267 foreach(SOURCE ${ARGN})
268 get_filename_component(FILE ${SOURCE} NAME_WE)
269 set(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb)
270 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb
271 COMMAND ${IDL_COMPILER} ${result_incs} ${IDL_FLAGS} ${IDL_TYPELIB_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}
272 DEPENDS ${SOURCE})
273 list(APPEND OBJECTS ${OBJECT})
274 endforeach()
275 add_custom_target(${TARGET} ALL DEPENDS ${OBJECTS})
276 endmacro()