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