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