[SVCCTL]
[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 MACRO(spec2def _target_name _spec_file _def_file)
45
46 add_custom_command(
47 OUTPUT ${_def_file}
48 COMMAND native-winebuild -o ${_def_file} --def -E ${_spec_file} --filename ${_target_name}.dll
49 DEPENDS native-winebuild)
50 set_source_files_properties(${_def_file} PROPERTIES GENERATED TRUE)
51 add_custom_target(${_target_name}_def ALL DEPENDS ${_def_file})
52
53 ENDMACRO(spec2def _target_name _spec_file _def_file)
54
55 if (NOT MSVC)
56 MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
57
58 get_filename_component(OBJECT_PATH ${_object_file} PATH)
59 get_filename_component(OBJECT_NAME ${_object_file} NAME)
60 file(MAKE_DIRECTORY ${OBJECT_PATH})
61 get_directory_property(defines COMPILE_DEFINITIONS)
62 get_directory_property(includes INCLUDE_DIRECTORIES)
63
64 foreach(arg ${defines})
65 set(result_defs ${result_defs} -D${arg})
66 endforeach(arg ${defines})
67
68 foreach(arg ${includes})
69 set(result_incs -I${arg} ${result_incs})
70 endforeach(arg ${includes})
71
72 add_custom_command(
73 OUTPUT ${_object_file}
74 COMMAND nasm -o ${_object_file} ${result_incs} ${result_defs} -f bin ${_asm_file}
75 DEPENDS native-winebuild)
76 set_source_files_properties(${_object_file} PROPERTIES GENERATED TRUE)
77 add_custom_target(${_target_name} ALL DEPENDS ${_object_file})
78 add_minicd(${_object_file} loader ${OBJECT_NAME})
79 ENDMACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
80 else()
81 MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)
82 ENDMACRO()
83 endif()
84
85 MACRO(MACRO_IDL_COMPILE_OBJECT OBJECT SOURCE)
86 GET_PROPERTY(FLAGS SOURCE ${SOURCE} PROPERTY COMPILE_FLAGS)
87 GET_PROPERTY(DEFINES SOURCE ${SOURCE} PROPERTY COMPILE_DEFINITIONS)
88 GET_PROPERTY(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
89 FOREACH(DIR ${INCLUDE_DIRECTORIES})
90 SET(FLAGS "${FLAGS} -I${DIR}")
91 ENDFOREACH()
92
93 SET(IDL_COMMAND ${CMAKE_IDL_COMPILE_OBJECT})
94 STRING(REPLACE "<CMAKE_IDL_COMPILER>" "${CMAKE_IDL_COMPILER}" IDL_COMMAND "${IDL_COMMAND}")
95 STRING(REPLACE <FLAGS> "${FLAGS}" IDL_COMMAND "${IDL_COMMAND}")
96 STRING(REPLACE "<DEFINES>" "${DEFINES}" IDL_COMMAND "${IDL_COMMAND}")
97 STRING(REPLACE "<OBJECT>" "${OBJECT}" IDL_COMMAND "${IDL_COMMAND}")
98 STRING(REPLACE "<SOURCE>" "${SOURCE}" IDL_COMMAND "${IDL_COMMAND}")
99 SEPARATE_ARGUMENTS(IDL_COMMAND)
100
101 ADD_CUSTOM_COMMAND(
102 OUTPUT ${OBJECT}
103 COMMAND ${IDL_COMMAND}
104 DEPENDS ${SOURCE}
105 VERBATIM
106 )
107 ENDMACRO()
108
109 MACRO(ADD_INTERFACE_DEFINITIONS TARGET)
110 FOREACH(SOURCE ${ARGN})
111 GET_FILENAME_COMPONENT(FILE ${SOURCE} NAME_WE)
112 SET(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.h)
113 MACRO_IDL_COMPILE_OBJECT(${OBJECT} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE})
114 LIST(APPEND OBJECTS ${OBJECT})
115 ENDFOREACH()
116 ADD_CUSTOM_TARGET(${TARGET} ALL DEPENDS ${OBJECTS})
117 ENDMACRO()
118
119 MACRO(add_minicd_target _targetname _dir) # optional parameter: _nameoncd
120 get_target_property(FILENAME ${_targetname} LOCATION)
121
122 if("${ARGN}" STREQUAL "")
123 get_filename_component(_nameoncd ${FILENAME} NAME)
124 else()
125 set(_nameoncd ${ARGN})
126 endif()
127
128 add_custom_command(
129 OUTPUT ${BOOTCD_DIR}/${_dir}/${_nameoncd}
130 COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${BOOTCD_DIR}/${_dir}/${_nameoncd})
131
132 add_custom_target(${_targetname}_minicd DEPENDS ${BOOTCD_DIR}/${_dir}/${_nameoncd})
133
134 add_dependencies(${_targetname}_minicd ${_targetname})
135 add_dependencies(minicd ${_targetname}_minicd)
136 ENDMACRO(add_minicd_target _targetname _dir _nameoncd)
137
138 MACRO(add_minicd FILENAME _dir _nameoncd)
139 add_custom_command(
140 OUTPUT ${BOOTCD_DIR}/${_dir}/${_nameoncd}
141 DEPENDS ${FILENAME}
142 COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${BOOTCD_DIR}/${_dir}/${_nameoncd})
143
144 add_custom_target(${_nameoncd}_minicd DEPENDS ${BOOTCD_DIR}/${_dir}/${_nameoncd})
145
146 add_dependencies(minicd ${_nameoncd}_minicd)
147 ENDMACRO(add_minicd)
148
149 macro(set_cpp)
150 include_directories(BEFORE ${REACTOS_SOURCE_DIR}/lib/3rdparty/stlport/stlport)
151 set(IS_CPP 1)
152 endmacro()
153
154 MACRO(add_livecd_target _targetname _dir )# optional parameter : _nameoncd
155
156 get_target_property(FILENAME ${_targetname} LOCATION)
157
158 if("${ARGN}" STREQUAL "")
159 get_filename_component(_nameoncd ${FILENAME} NAME)
160 else()
161 set(_nameoncd ${ARGN})
162 endif()
163
164 add_custom_command(
165 OUTPUT ${LIVECD_DIR}/${_dir}/${_nameoncd}
166 COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${LIVECD_DIR}/${_dir}/${_nameoncd})
167
168 add_custom_target(${_targetname}_livecd DEPENDS ${LIVECD_DIR}/${_dir}/${_nameoncd})
169
170 add_dependencies(${_targetname}_livecd ${_targetname})
171 add_dependencies(livecd ${_targetname}_livecd)
172 ENDMACRO(add_livecd_target _targetname _dir _nameoncd)
173
174 MACRO(add_livecd FILENAME _dir _nameoncd)
175 add_custom_command(
176 OUTPUT ${LIVECD_DIR}/${_dir}/${_nameoncd}
177 DEPENDS ${FILENAME}
178 COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${LIVECD_DIR}/${_dir}/${_nameoncd})
179
180 add_custom_target(${_nameoncd}_livecd DEPENDS ${LIVECD_DIR}/${_dir}/${_nameoncd})
181
182 add_dependencies(livecd ${_nameoncd}_livecd)
183 ENDMACRO(add_livecd)
184
185 macro(custom_incdefs)
186 if(NOT DEFINED result_incs) #rpc_defines
187 get_directory_property(rpc_defines COMPILE_DEFINITIONS)
188 get_directory_property(rpc_includes INCLUDE_DIRECTORIES)
189
190 foreach(arg ${rpc_defines})
191 set(result_defs ${result_defs} -D${arg})
192 endforeach(arg ${defines})
193
194 foreach(arg ${rpc_includes})
195 set(result_incs -I${arg} ${result_incs})
196 endforeach(arg ${includes})
197 endif()
198 endmacro(custom_incdefs)
199
200 macro(rpcproxy TARGET)
201 custom_incdefs()
202 list(APPEND SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c)
203
204 foreach(_in_FILE ${ARGN})
205 get_filename_component(FILE ${_in_FILE} NAME_WE)
206 add_custom_command(
207 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c
208 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
209 DEPENDS native-widl)
210 set_source_files_properties(
211 ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c
212 PROPERTIES GENERATED TRUE)
213 list(APPEND SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c)
214 list(APPEND IDLS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl)
215 list(APPEND PROXY_DEPENDS ${TARGET}_${FILE}_p)
216 add_custom_target(${TARGET}_${FILE}_p
217 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_p.c)
218 #add_dependencies(${TARGET}_proxy ${TARGET}_${FILE}_p)
219 endforeach(_in_FILE ${ARGN})
220
221 add_custom_command(
222 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c
223 COMMAND native-widl ${result_incs} ${result_defs} -m32 --win32 --dlldata-only --dlldata=${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c ${IDLS}
224 DEPENDS native-widl)
225 set_source_files_properties(
226 ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_proxy.dlldata.c
227 PROPERTIES GENERATED TRUE)
228
229 add_library(${TARGET}_proxy ${SOURCE})
230 add_dependencies(${TARGET}_proxy psdk ${PROXY_DEPENDS})
231 endmacro(rpcproxy)
232
233 macro (MACRO_IDL_FILES)
234 custom_incdefs()
235 foreach(_in_FILE ${ARGN})
236 get_filename_component(FILE ${_in_FILE} NAME_WE)
237 add_custom_command(
238 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c
239 COMMAND native-widl ${result_incs} ${result_defs} -m32 --win32 -h -H ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h -s -S ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl
240 DEPENDS native-widl)
241 set_source_files_properties(
242 ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c
243 PROPERTIES GENERATED TRUE)
244 add_library(${FILE}_server ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c)
245 add_dependencies(${FILE}_server psdk)
246
247 add_custom_command(
248 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c
249 COMMAND native-widl ${result_incs} ${result_defs} -m32 --win32 -h -H ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h -c -C ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl
250 DEPENDS native-widl)
251 set_source_files_properties(
252 ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c
253 PROPERTIES GENERATED TRUE)
254 add_library(${FILE}_client ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c)
255 add_dependencies(${FILE}_client psdk)
256 endforeach(_in_FILE ${ARGN})
257
258 endmacro (MACRO_IDL_FILES)