[CMAKE] unset EXPORT_SYMBOL for modules and shared libraries
[reactos.git] / sdk / cmake / CMakeMacros.cmake
1
2 # set_cpp
3 # Marks the current folder as containing C++ modules, additionally enabling
4 # specific C++ language features as specified (all of these default to off):
5 #
6 # WITH_RUNTIME
7 # Links with the C++ runtime. Enable this for modules which use new/delete or
8 # RTTI, but do not require STL. This is the right choice if you see undefined
9 # references to operator new/delete, vector constructor/destructor iterator,
10 # type_info::vtable, ...
11 # Note: this only affects linking, so cannot be used for static libraries.
12 # WITH_RTTI
13 # Enables run-time type information. Enable this if the module uses typeid or
14 # dynamic_cast. You will probably need to enable WITH_RUNTIME as well, if
15 # you're not already using STL.
16 # WITH_EXCEPTIONS
17 # Enables C++ exception handling. Enable this if the module uses try/catch or
18 # throw. You might also need this if you use a standard operator new (the one
19 # without nothrow).
20 # WITH_STL
21 # Enables standard C++ headers and links to the Standard Template Library.
22 # Use this for modules using anything from the std:: namespace, e.g. maps,
23 # strings, vectors, etc.
24 # Note: this affects both compiling (via include directories) and
25 # linking (by adding STL). Implies WITH_RUNTIME.
26 # FIXME: WITH_STL is currently also required for runtime headers such as
27 # <new> and <exception>. This is not a big issue because in stl-less
28 # environments you usually don't want those anyway; but we might want
29 # to have modules like this in the future.
30 #
31 # Examples:
32 # set_cpp()
33 # Enables the C++ language, but will cause errors if any runtime or standard
34 # library features are used. This should be the default for C++ in kernel
35 # mode or otherwise restricted environments.
36 # Note: this is required to get libgcc (for multiplication/division) linked
37 # in for C++ modules, and to set the correct language for precompiled
38 # header files, so it IS required even with no features specified.
39 # set_cpp(WITH_RUNTIME)
40 # Links with the C++ runtime, so that e.g. custom operator new implementations
41 # can be used in a restricted environment. This is also required for linking
42 # with libraries (such as ATL) which have RTTI enabled, even if the module in
43 # question does not use WITH_RTTI.
44 # set_cpp(WITH_RTTI WITH_EXCEPTIONS WITH_STL)
45 # The full package. This will adjust compiler and linker so that all C++
46 # features can be used.
47 macro(set_cpp)
48 cmake_parse_arguments(__cppopts "WITH_RUNTIME;WITH_RTTI;WITH_EXCEPTIONS;WITH_STL" "" "" ${ARGN})
49 if(__cppopts_UNPARSED_ARGUMENTS)
50 message(FATAL_ERROR "set_cpp: unparsed arguments ${__cppopts_UNPARSED_ARGUMENTS}")
51 endif()
52
53 if(__cppopts_WITH_RUNTIME)
54 set(CPP_USE_RT 1)
55 endif()
56 if(__cppopts_WITH_RTTI)
57 if(MSVC)
58 replace_compile_flags("/GR-" "/GR")
59 else()
60 replace_compile_flags_language("-fno-rtti" "-frtti" "CXX")
61 endif()
62 endif()
63 if(__cppopts_WITH_EXCEPTIONS)
64 if(MSVC)
65 replace_compile_flags("/EHs-c-" "/EHsc")
66 else()
67 replace_compile_flags_language("-fno-exceptions" "-fexceptions" "CXX")
68 endif()
69 endif()
70 if(__cppopts_WITH_STL)
71 set(CPP_USE_STL 1)
72 if(MSVC)
73 add_definitions(-DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/sdk/include/c++)
74 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/c++/stlport)
75 else()
76 replace_compile_flags("-nostdinc" " ")
77 endif()
78 endif()
79
80 set(IS_CPP 1)
81 endmacro()
82
83 function(add_dependency_node _node)
84 if(GENERATE_DEPENDENCY_GRAPH)
85 get_target_property(_type ${_node} TYPE)
86 if(_type MATCHES SHARED_LIBRARY|MODULE_LIBRARY OR ${_node} MATCHES ntoskrnl)
87 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <node id=\"${_node}\"/>\n")
88 endif()
89 endif()
90 endfunction()
91
92 function(add_dependency_edge _source _target)
93 if(GENERATE_DEPENDENCY_GRAPH)
94 get_target_property(_type ${_source} TYPE)
95 if(_type MATCHES SHARED_LIBRARY|MODULE_LIBRARY)
96 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <edge source=\"${_source}\" target=\"${_target}\"/>\n")
97 endif()
98 endif()
99 endfunction()
100
101 function(add_dependency_header)
102 file(WRITE ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")
103 endfunction()
104
105 function(add_dependency_footer)
106 add_dependency_node(ntdll)
107 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " </graph>\n</graphml>\n")
108 endfunction()
109
110 function(add_message_headers _type)
111 if(${_type} STREQUAL UNICODE)
112 set(_flag "-U")
113 else()
114 set(_flag "-A")
115 endif()
116 foreach(_file ${ARGN})
117 get_filename_component(_file_name ${_file} NAME_WE)
118 set(_converted_file ${CMAKE_CURRENT_BINARY_DIR}/${_file}) ## ${_file_name}.mc
119 set(_source_file ${CMAKE_CURRENT_SOURCE_DIR}/${_file}) ## ${_file_name}.mc
120 add_custom_command(
121 OUTPUT "${_converted_file}"
122 COMMAND native-utf16le "${_source_file}" "${_converted_file}" nobom
123 DEPENDS native-utf16le "${_source_file}")
124 macro_mc(${_flag} ${_converted_file})
125 add_custom_command(
126 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.h ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.rc
127 COMMAND ${COMMAND_MC}
128 DEPENDS "${_converted_file}")
129 set_source_files_properties(
130 ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.h ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.rc
131 PROPERTIES GENERATED TRUE)
132 add_custom_target(${_file_name} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.h ${CMAKE_CURRENT_BINARY_DIR}/${_file_name}.rc)
133 endforeach()
134 endfunction()
135
136 function(add_link)
137 cmake_parse_arguments(_LINK "MINIMIZE" "NAME;PATH;CMD_LINE_ARGS;ICON;GUID" "" ${ARGN})
138 if(NOT _LINK_NAME OR NOT _LINK_PATH)
139 message(FATAL_ERROR "You must provide name and path")
140 endif()
141
142 if(_LINK_CMD_LINE_ARGS)
143 set(_LINK_CMD_LINE_ARGS -c ${_LINK_CMD_LINE_ARGS})
144 endif()
145
146 if(_LINK_ICON)
147 set(_LINK_ICON -i ${_LINK_ICON})
148 endif()
149
150 if(_LINK_GUID)
151 set(_LINK_GUID -g ${_LINK_GUID})
152 endif()
153
154 if(_LINK_MINIMIZE)
155 set(_LINK_MINIMIZE "-m")
156 endif()
157
158 add_custom_command(
159 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk
160 COMMAND native-mkshelllink -o ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk ${_LINK_CMD_LINE_ARGS} ${_LINK_ICON} ${_LINK_GUID} ${_LINK_MINIMIZE} ${_LINK_PATH}
161 DEPENDS native-mkshelllink)
162 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk PROPERTIES GENERATED TRUE)
163 endfunction()
164
165 #
166 # WARNING!
167 # Please keep the numbering in this list in sync with
168 # boot/bootdata/packages/reactos.dff.in
169 #
170 macro(dir_to_num dir var)
171 if(${dir} STREQUAL reactos)
172 set(${var} 1)
173 elseif(${dir} STREQUAL reactos/system32)
174 set(${var} 2)
175 elseif(${dir} STREQUAL reactos/system32/drivers)
176 set(${var} 3)
177 elseif(${dir} STREQUAL reactos/Fonts)
178 set(${var} 4)
179 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
180 set(${var} 5)
181 elseif(${dir} STREQUAL reactos/inf)
182 set(${var} 6)
183 elseif(${dir} STREQUAL reactos/bin)
184 set(${var} 7)
185 elseif(${dir} STREQUAL reactos/bin/testdata)
186 set(${var} 8)
187 elseif(${dir} STREQUAL reactos/bin/suppl)
188 set(${var} 80)
189 elseif(${dir} STREQUAL reactos/media)
190 set(${var} 9)
191 elseif(${dir} STREQUAL reactos/Microsoft.NET)
192 set(${var} 10)
193 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework)
194 set(${var} 11)
195 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.0.3705)
196 set(${var} 12)
197 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.1.4322)
198 set(${var} 13)
199 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v2.0.50727)
200 set(${var} 14)
201 elseif(${dir} STREQUAL reactos/Resources)
202 set(${var} 15)
203 elseif(${dir} STREQUAL reactos/Resources/Themes)
204 set(${var} 16)
205 elseif(${dir} STREQUAL reactos/system32/wbem)
206 set(${var} 17)
207 elseif(${dir} STREQUAL reactos/Resources/Themes/Lautus)
208 set(${var} 18)
209 elseif(${dir} STREQUAL reactos/Help)
210 set(${var} 19)
211 elseif(${dir} STREQUAL reactos/Config)
212 set(${var} 20)
213 elseif(${dir} STREQUAL reactos/Cursors)
214 set(${var} 21)
215 elseif(${dir} STREQUAL reactos/system32/ShellExt)
216 set(${var} 22)
217 elseif(${dir} STREQUAL reactos/Temp)
218 set(${var} 23)
219 elseif(${dir} STREQUAL reactos/system32/spool)
220 set(${var} 24)
221 elseif(${dir} STREQUAL reactos/system32/spool/drivers)
222 set(${var} 25)
223 elseif(${dir} STREQUAL reactos/system32/spool/drivers/color)
224 set(${var} 26)
225 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86)
226 set(${var} 27)
227 elseif(${dir} STREQUAL reactos/system32/spool/drivers/w32x86/3)
228 set(${var} 28)
229 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs)
230 set(${var} 29)
231 elseif(${dir} STREQUAL reactos/system32/spool/prtprocs/w32x86)
232 set(${var} 30)
233 elseif(${dir} STREQUAL reactos/system32/spool/PRINTERS)
234 set(${var} 31)
235 elseif(${dir} STREQUAL reactos/system32/wbem/Repository)
236 set(${var} 32)
237 elseif(${dir} STREQUAL reactos/system32/wbem/Repository/FS)
238 set(${var} 33)
239 elseif(${dir} STREQUAL reactos/system32/wbem/mof/good)
240 set(${var} 34)
241 elseif(${dir} STREQUAL reactos/system32/wbem/mof/bad)
242 set(${var} 35)
243 elseif(${dir} STREQUAL reactos/system32/wbem/AdStatus)
244 set(${var} 36)
245 elseif(${dir} STREQUAL reactos/system32/wbem/xml)
246 set(${var} 37)
247 elseif(${dir} STREQUAL reactos/system32/wbem/Logs)
248 set(${var} 38)
249 elseif(${dir} STREQUAL reactos/system32/wbem/AutoRecover)
250 set(${var} 39)
251 elseif(${dir} STREQUAL reactos/system32/wbem/snmp)
252 set(${var} 40)
253 elseif(${dir} STREQUAL reactos/system32/wbem/Performance)
254 set(${var} 41)
255 elseif(${dir} STREQUAL reactos/twain_32)
256 set(${var} 42)
257 elseif(${dir} STREQUAL reactos/repair)
258 set(${var} 43)
259 elseif(${dir} STREQUAL reactos/Web)
260 set(${var} 44)
261 elseif(${dir} STREQUAL reactos/Web/Wallpaper)
262 set(${var} 45)
263 elseif(${dir} STREQUAL reactos/Prefetch)
264 set(${var} 46)
265 elseif(${dir} STREQUAL reactos/security)
266 set(${var} 47)
267 elseif(${dir} STREQUAL reactos/security/Database)
268 set(${var} 48)
269 elseif(${dir} STREQUAL reactos/security/logs)
270 set(${var} 49)
271 elseif(${dir} STREQUAL reactos/security/templates)
272 set(${var} 50)
273 elseif(${dir} STREQUAL reactos/system32/CatRoot)
274 set(${var} 51)
275 elseif(${dir} STREQUAL reactos/system32/CatRoot2)
276 set(${var} 52)
277 elseif(${dir} STREQUAL reactos/AppPatch)
278 set(${var} 53)
279 elseif(${dir} STREQUAL reactos/winsxs)
280 set(${var} 54)
281 elseif(${dir} STREQUAL reactos/winsxs/manifests)
282 set(${var} 55)
283 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.2600.2982_none_deadbeef)
284 set(${var} 56)
285 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2982_none_deadbeef)
286 set(${var} 57)
287 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.23038_none_deadbeef)
288 set(${var} 58)
289 elseif(${dir} STREQUAL reactos/winsxs/x86_reactos.apisets_6595b64144ccf1df_1.0.0.0_none_deadbeef)
290 set(${var} 59)
291 elseif(${dir} STREQUAL reactos/winsxs/x86_reactos.newapi_6595b64144ccf1df_1.0.0.0_none_deadbeef)
292 set(${var} 60)
293 elseif(${dir} STREQUAL reactos/winsxs/x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.0.14393.0_none_deadbeef)
294 set(${var} 61)
295 elseif(${dir} STREQUAL reactos/Resources/Themes/Modern)
296 set(${var} 62)
297 elseif(${dir} STREQUAL reactos/3rdParty)
298 set(${var} 63)
299 elseif(${dir} STREQUAL reactos/Resources/Themes/Lunar)
300 set(${var} 64)
301 else()
302 message(FATAL_ERROR "Wrong destination: ${dir}")
303 endif()
304 endmacro()
305
306 function(add_cd_file)
307 cmake_parse_arguments(_CD "NO_CAB;NOT_IN_HYBRIDCD" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
308 if(NOT (_CD_TARGET OR _CD_FILE))
309 message(FATAL_ERROR "You must provide a target or a file to install!")
310 endif()
311
312 if(NOT _CD_DESTINATION)
313 message(FATAL_ERROR "You must provide a destination")
314 elseif(${_CD_DESTINATION} STREQUAL root)
315 set(_CD_DESTINATION "")
316 endif()
317
318 if(NOT _CD_FOR)
319 message(FATAL_ERROR "You must provide a cd name (or \"all\" for all of them) to install the file on!")
320 endif()
321
322 # get file if we need to
323 if(NOT _CD_FILE)
324 set(_CD_FILE "$<TARGET_FILE:${_CD_TARGET}>")
325 if(NOT _CD_NAME_ON_CD)
326 set(_CD_NAME_ON_CD "$<TARGET_FILE_NAME:${_CD_TARGET}>")
327 endif()
328 endif()
329
330 # do we add it to all CDs?
331 list(FIND _CD_FOR all __cd)
332 if(NOT __cd EQUAL -1)
333 list(REMOVE_AT _CD_FOR __cd)
334 list(INSERT _CD_FOR __cd "bootcd;livecd;regtest")
335 endif()
336
337 # do we add it to bootcd?
338 list(FIND _CD_FOR bootcd __cd)
339 if(NOT __cd EQUAL -1)
340 # whether or not we should put it in reactos.cab or directly on cd
341 if(_CD_NO_CAB)
342 # directly on cd
343 foreach(item ${_CD_FILE})
344 if(_CD_NAME_ON_CD)
345 # rename it in the cd tree
346 set(__file ${_CD_NAME_ON_CD})
347 else()
348 get_filename_component(__file ${item} NAME)
349 endif()
350 set_property(GLOBAL APPEND PROPERTY BOOTCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
351 # add it also into the hybridcd if not specified otherwise
352 if(NOT _CD_NOT_IN_HYBRIDCD)
353 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "bootcd/${_CD_DESTINATION}/${__file}=${item}")
354 endif()
355 endforeach()
356 # manage dependency
357 if(_CD_TARGET)
358 add_dependencies(bootcd ${_CD_TARGET} registry_inf)
359 endif()
360 else()
361 # add it in reactos.cab
362 dir_to_num(${_CD_DESTINATION} _num)
363 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.cmake "\"${_CD_FILE}\" ${_num}\n")
364 # manage dependency - target level
365 if(_CD_TARGET)
366 add_dependencies(reactos_cab_inf ${_CD_TARGET})
367 endif()
368 # manage dependency - file level
369 set_property(GLOBAL APPEND PROPERTY REACTOS_CAB_DEPENDS ${_CD_FILE})
370 endif()
371 endif() #end bootcd
372
373 # do we add it to livecd?
374 list(FIND _CD_FOR livecd __cd)
375 if(NOT __cd EQUAL -1)
376 # manage dependency
377 if(_CD_TARGET)
378 add_dependencies(livecd ${_CD_TARGET} registry_inf)
379 endif()
380 foreach(item ${_CD_FILE})
381 if(_CD_NAME_ON_CD)
382 # rename it in the cd tree
383 set(__file ${_CD_NAME_ON_CD})
384 else()
385 get_filename_component(__file ${item} NAME)
386 endif()
387 set_property(GLOBAL APPEND PROPERTY LIVECD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
388 # add it also into the hybridcd if not specified otherwise
389 if(NOT _CD_NOT_IN_HYBRIDCD)
390 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "livecd/${_CD_DESTINATION}/${__file}=${item}")
391 endif()
392 endforeach()
393 endif() #end livecd
394
395 # do we need also to add it to hybridcd?
396 list(FIND _CD_FOR hybridcd __cd)
397 if(NOT __cd EQUAL -1)
398 # manage dependency
399 if(_CD_TARGET)
400 add_dependencies(hybridcd ${_CD_TARGET})
401 endif()
402 foreach(item ${_CD_FILE})
403 if(_CD_NAME_ON_CD)
404 # rename it in the cd tree
405 set(__file ${_CD_NAME_ON_CD})
406 else()
407 get_filename_component(__file ${item} NAME)
408 endif()
409 set_property(GLOBAL APPEND PROPERTY HYBRIDCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
410 endforeach()
411 endif() #end hybridcd
412
413 # do we add it to regtest?
414 list(FIND _CD_FOR regtest __cd)
415 if(NOT __cd EQUAL -1)
416 # whether or not we should put it in reactos.cab or directly on cd
417 if(_CD_NO_CAB)
418 # directly on cd
419 foreach(item ${_CD_FILE})
420 if(_CD_NAME_ON_CD)
421 # rename it in the cd tree
422 set(__file ${_CD_NAME_ON_CD})
423 else()
424 get_filename_component(__file ${item} NAME)
425 endif()
426 set_property(GLOBAL APPEND PROPERTY BOOTCDREGTEST_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
427 endforeach()
428 # manage dependency
429 if(_CD_TARGET)
430 add_dependencies(bootcdregtest ${_CD_TARGET} registry_inf)
431 endif()
432 else()
433 #add it in reactos.cab
434 #dir_to_num(${_CD_DESTINATION} _num)
435 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
436 #if(_CD_TARGET)
437 # #manage dependency
438 # add_dependencies(reactos_cab ${_CD_TARGET})
439 #endif()
440 endif()
441 endif() #end bootcd
442 endfunction()
443
444 function(create_iso_lists)
445 # generate reactos.cab before anything else
446 get_property(_filelist GLOBAL PROPERTY REACTOS_CAB_DEPENDS)
447
448 # begin with reactos.inf. We want this command to be always executed, so we pretend it generates another file although it will never do.
449 add_custom_command(
450 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/__some_non_existent_file
451 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf
452 DEPENDS ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.inf reactos_cab_inf)
453
454 add_custom_command(
455 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
456 COMMAND native-cabman -C ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff -RC ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf -N -P ${REACTOS_SOURCE_DIR}
457 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.inf native-cabman ${_filelist})
458
459 add_custom_target(reactos_cab DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab)
460 add_dependencies(reactos_cab reactos_cab_inf)
461
462 add_cd_file(
463 TARGET reactos_cab
464 FILE ${CMAKE_CURRENT_BINARY_DIR}/reactos.cab
465 DESTINATION reactos
466 NO_CAB FOR bootcd regtest)
467
468 add_cd_file(
469 FILE ${CMAKE_CURRENT_BINARY_DIR}/livecd.iso
470 DESTINATION livecd
471 FOR hybridcd)
472
473 get_property(_filelist GLOBAL PROPERTY BOOTCD_FILE_LIST)
474 string(REPLACE ";" "\n" _filelist "${_filelist}")
475 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst "${_filelist}")
476 unset(_filelist)
477 file(GENERATE
478 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcd.$<CONFIG>.lst
479 INPUT ${REACTOS_BINARY_DIR}/boot/bootcd.cmake.lst)
480
481 get_property(_filelist GLOBAL PROPERTY LIVECD_FILE_LIST)
482 string(REPLACE ";" "\n" _filelist "${_filelist}")
483 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst "${_filelist}")
484 unset(_filelist)
485 file(GENERATE
486 OUTPUT ${REACTOS_BINARY_DIR}/boot/livecd.$<CONFIG>.lst
487 INPUT ${REACTOS_BINARY_DIR}/boot/livecd.cmake.lst)
488
489 get_property(_filelist GLOBAL PROPERTY HYBRIDCD_FILE_LIST)
490 string(REPLACE ";" "\n" _filelist "${_filelist}")
491 file(APPEND ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst "${_filelist}")
492 unset(_filelist)
493 file(GENERATE
494 OUTPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.$<CONFIG>.lst
495 INPUT ${REACTOS_BINARY_DIR}/boot/hybridcd.cmake.lst)
496
497 get_property(_filelist GLOBAL PROPERTY BOOTCDREGTEST_FILE_LIST)
498 string(REPLACE ";" "\n" _filelist "${_filelist}")
499 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst "${_filelist}")
500 unset(_filelist)
501 file(GENERATE
502 OUTPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.$<CONFIG>.lst
503 INPUT ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake.lst)
504 endfunction()
505
506 # Create module_clean targets
507 function(add_clean_target _target)
508 set(_clean_working_directory ${CMAKE_CURRENT_BINARY_DIR})
509 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
510 set(_clean_command make clean)
511 elseif(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
512 set(_clean_command nmake /nologo clean)
513 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
514 set(_clean_command ninja -t clean ${_target})
515 set(_clean_working_directory ${REACTOS_BINARY_DIR})
516 endif()
517 add_custom_target(${_target}_clean
518 COMMAND ${_clean_command}
519 WORKING_DIRECTORY ${_clean_working_directory}
520 COMMENT "Cleaning ${_target}")
521 endfunction()
522
523 if(NOT MSVC_IDE)
524 function(add_library name)
525 _add_library(${name} ${ARGN})
526 add_clean_target(${name})
527 # cmake adds a module_EXPORTS define when compiling a module or a shared library. We don't use that.
528 get_target_property(_type ${name} TYPE)
529 if (_type MATCHES SHARED_LIBRARY|MODULE_LIBRARY)
530 set_target_properties(${name} PROPERTIES DEFINE_SYMBOL "")
531 endif()
532 endfunction()
533
534 function(add_executable name)
535 _add_executable(${name} ${ARGN})
536 add_clean_target(${name})
537 endfunction()
538 elseif(USE_FOLDER_STRUCTURE)
539 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
540 string(LENGTH ${CMAKE_SOURCE_DIR} CMAKE_SOURCE_DIR_LENGTH)
541
542 function(add_custom_target name)
543 _add_custom_target(${name} ${ARGN})
544 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
545 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
546 endfunction()
547
548 function(add_library name)
549 _add_library(${name} ${ARGN})
550 get_target_property(_target_excluded ${name} EXCLUDE_FROM_ALL)
551 if(_target_excluded AND ${name} MATCHES "^lib.*")
552 set_property(TARGET "${name}" PROPERTY FOLDER "Importlibs")
553 else()
554 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
555 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
556 endif()
557 # cmake adds a module_EXPORTS define when compiling a module or a shared library. We don't use that.
558 get_target_property(_type ${name} TYPE)
559 if (_type MATCHES SHARED_LIBRARY|MODULE_LIBRARY)
560 set_target_properties(${name} PROPERTIES DEFINE_SYMBOL "")
561 endif()
562 endfunction()
563
564 function(add_executable name)
565 _add_executable(${name} ${ARGN})
566 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
567 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
568 endfunction()
569 else()
570 function(add_library name)
571 _add_library(${name} ${ARGN})
572 # cmake adds a module_EXPORTS define when compiling a module or a shared library. We don't use that.
573 get_target_property(_type ${name} TYPE)
574 if (_type MATCHES SHARED_LIBRARY|MODULE_LIBRARY)
575 set_target_properties(${name} PROPERTIES DEFINE_SYMBOL "")
576 endif()
577 endfunction()
578 endif()
579
580 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
581 function(concatenate_files _output _file1)
582 file(TO_NATIVE_PATH "${_output}" _real_output)
583 file(TO_NATIVE_PATH "${_file1}" _file_list)
584 foreach(_file ${ARGN})
585 file(TO_NATIVE_PATH "${_file}" _real_file)
586 set(_file_list "${_file_list} + ${_real_file}")
587 endforeach()
588 add_custom_command(
589 OUTPUT ${_output}
590 COMMAND cmd.exe /C "copy /Y /B ${_file_list} ${_real_output} > nul"
591 DEPENDS ${_file1} ${ARGN})
592 endfunction()
593 else()
594 macro(concatenate_files _output)
595 add_custom_command(
596 OUTPUT ${_output}
597 COMMAND cat ${ARGN} > ${_output}
598 DEPENDS ${ARGN})
599 endmacro()
600 endif()
601
602 function(add_importlibs _module)
603 add_dependency_node(${_module})
604 foreach(LIB ${ARGN})
605 if("${LIB}" MATCHES "msvcrt")
606 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
607 target_link_libraries(${_module} msvcrtex)
608 endif()
609 target_link_libraries(${_module} lib${LIB})
610 add_dependencies(${_module} lib${LIB})
611 add_dependency_edge(${_module} ${LIB})
612 endforeach()
613 endfunction()
614
615 function(set_module_type MODULE TYPE)
616 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
617
618 if(__module_UNPARSED_ARGUMENTS)
619 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
620 endif()
621
622 # Add the module to the module group list, if it is defined
623 if(DEFINED CURRENT_MODULE_GROUP)
624 set_property(GLOBAL APPEND PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST "${MODULE}")
625 endif()
626
627 # Set subsystem. Also take this as an occasion
628 # to error out if someone gave a non existing type
629 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll)
630 OR (${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
631 set(__subsystem native)
632 elseif(${TYPE} STREQUAL win32cui)
633 set(__subsystem console)
634 elseif(${TYPE} STREQUAL win32gui)
635 set(__subsystem windows)
636 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
637 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
638 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
639 endif()
640
641 if(DEFINED __subsystem)
642 set_subsystem(${MODULE} ${__subsystem})
643 endif()
644
645 # Set the PE image version numbers from the NT OS version ReactOS is based on
646 if (MSVC)
647 add_target_link_flags(${MODULE} "/VERSION:5.01")
648 else()
649 add_target_link_flags(${MODULE} "-Wl,--major-image-version,5 -Wl,--minor-image-version,01")
650 add_target_link_flags(${MODULE} "-Wl,--major-os-version,5 -Wl,--minor-os-version,01")
651 endif()
652
653 # Set unicode definitions
654 if(__module_UNICODE)
655 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
656 endif()
657
658 # Set entry point
659 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
660 list(GET __module_ENTRYPOINT 0 __entrypoint)
661 list(LENGTH __module_ENTRYPOINT __length)
662 if(${__length} EQUAL 2)
663 list(GET __module_ENTRYPOINT 1 __entrystack)
664 elseif(NOT ${__length} EQUAL 1)
665 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
666 endif()
667 unset(__length)
668 elseif(${TYPE} STREQUAL nativecui)
669 set(__entrypoint NtProcessStartup)
670 set(__entrystack 4)
671 elseif(${TYPE} STREQUAL win32cui)
672 if(__module_UNICODE)
673 set(__entrypoint wmainCRTStartup)
674 else()
675 set(__entrypoint mainCRTStartup)
676 endif()
677 elseif(${TYPE} STREQUAL win32gui)
678 if(__module_UNICODE)
679 set(__entrypoint wWinMainCRTStartup)
680 else()
681 set(__entrypoint WinMainCRTStartup)
682 endif()
683 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
684 OR (${TYPE} STREQUAL cpl))
685 set(__entrypoint DllMainCRTStartup)
686 set(__entrystack 12)
687 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
688 set(__entrypoint DriverEntry)
689 set(__entrystack 8)
690 elseif(${TYPE} STREQUAL nativedll)
691 set(__entrypoint DllMain)
692 set(__entrystack 12)
693 elseif(${TYPE} STREQUAL module)
694 set(__entrypoint 0)
695 endif()
696
697 if(DEFINED __entrypoint)
698 if(DEFINED __entrystack)
699 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
700 else()
701 set_entrypoint(${MODULE} ${__entrypoint})
702 endif()
703 endif()
704
705 # Set base address
706 if(__module_IMAGEBASE)
707 set_image_base(${MODULE} ${__module_IMAGEBASE})
708 elseif(${TYPE} STREQUAL win32dll)
709 if(DEFINED baseaddress_${MODULE})
710 set_image_base(${MODULE} ${baseaddress_${MODULE}})
711 else()
712 message(STATUS "${MODULE} has no base address")
713 endif()
714 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
715 set_image_base(${MODULE} 0x00010000)
716 endif()
717
718 # Now do some stuff which is specific to each type
719 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver) OR (${TYPE} STREQUAL kerneldll))
720 add_dependencies(${MODULE} bugcodes xdk)
721 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
722 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
723 endif()
724 endif()
725
726 if(${TYPE} STREQUAL win32ocx)
727 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
728 endif()
729
730 if(${TYPE} STREQUAL cpl)
731 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
732 endif()
733
734 # Do compiler specific stuff
735 set_module_type_toolchain(${MODULE} ${TYPE})
736 endfunction()
737
738 function(start_module_group __name)
739 if(DEFINED CURRENT_MODULE_GROUP)
740 message(FATAL_ERROR "CURRENT_MODULE_GROUP is already set ('${CURRENT_MODULE_GROUP}')")
741 endif()
742 set(CURRENT_MODULE_GROUP ${__name} PARENT_SCOPE)
743 endfunction()
744
745 function(end_module_group)
746 get_property(__modulelist GLOBAL PROPERTY ${CURRENT_MODULE_GROUP}_MODULE_LIST)
747 add_custom_target(${CURRENT_MODULE_GROUP})
748 foreach(__module ${__modulelist})
749 add_dependencies(${CURRENT_MODULE_GROUP} ${__module})
750 endforeach()
751 set(CURRENT_MODULE_GROUP PARENT_SCOPE)
752 endfunction()
753
754 function(preprocess_file __in __out)
755 set(__arg ${__in})
756 foreach(__def ${ARGN})
757 list(APPEND __arg -D${__def})
758 endforeach()
759 if(MSVC)
760 add_custom_command(OUTPUT ${_out}
761 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
762 DEPENDS ${__in})
763 else()
764 add_custom_command(OUTPUT ${_out}
765 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}
766 DEPENDS ${__in})
767 endif()
768 endfunction()
769
770 function(get_includes OUTPUT_VAR)
771 get_directory_property(_includes INCLUDE_DIRECTORIES)
772 foreach(arg ${_includes})
773 list(APPEND __tmp_var -I${arg})
774 endforeach()
775 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
776 endfunction()
777
778 function(get_defines OUTPUT_VAR)
779 get_directory_property(_defines COMPILE_DEFINITIONS)
780 foreach(arg ${_defines})
781 list(APPEND __tmp_var -D${arg})
782 endforeach()
783 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
784 endfunction()
785
786 if(NOT MSVC)
787 function(add_object_library _target)
788 add_library(${_target} OBJECT ${ARGN})
789 endfunction()
790 else()
791 function(add_object_library _target)
792 add_library(${_target} ${ARGN})
793 endfunction()
794 endif()
795
796 function(add_registry_inf)
797 # Add to the inf files list
798 foreach(_file ${ARGN})
799 set(_source_file "${CMAKE_CURRENT_SOURCE_DIR}/${_file}")
800 set_property(GLOBAL APPEND PROPERTY REGISTRY_INF_LIST ${_source_file})
801 endforeach()
802 endfunction()
803
804 function(create_registry_hives)
805
806 # Shortcut to the registry.inf file
807 set(_registry_inf "${CMAKE_BINARY_DIR}/boot/bootdata/registry.inf")
808
809 # Get the list of inf files
810 get_property(_inf_files GLOBAL PROPERTY REGISTRY_INF_LIST)
811
812 # Convert files to utf16le
813 foreach(_file ${_inf_files})
814 get_filename_component(_file_name ${_file} NAME_WE)
815 string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} _converted_file "${_file}")
816 string(REPLACE ${_file_name} "${_file_name}_utf16" _converted_file ${_converted_file})
817 add_custom_command(OUTPUT ${_converted_file}
818 COMMAND native-utf16le ${_file} ${_converted_file}
819 DEPENDS native-utf16le ${_file})
820 list(APPEND _converted_files ${_converted_file})
821 endforeach()
822
823 # Concatenate all registry files to registry.inf
824 concatenate_files(${_registry_inf} ${_converted_files})
825
826 # Add registry.inf to bootcd
827 add_custom_target(registry_inf DEPENDS ${_registry_inf})
828 add_cd_file(TARGET registry_inf
829 FILE ${_registry_inf}
830 DESTINATION reactos
831 NO_CAB
832 FOR bootcd regtest)
833
834 # BootCD setup system hive
835 add_custom_command(
836 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV
837 COMMAND native-mkhive -h:SETUPREG -u -d:${CMAKE_BINARY_DIR}/boot/bootdata ${CMAKE_BINARY_DIR}/boot/bootdata/hivesys_utf16.inf ${CMAKE_SOURCE_DIR}/boot/bootdata/setupreg.inf
838 DEPENDS native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata/hivesys_utf16.inf)
839
840 add_custom_target(bootcd_hives
841 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV)
842
843 add_cd_file(
844 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/SETUPREG.HIV
845 TARGET bootcd_hives
846 DESTINATION reactos
847 NO_CAB
848 FOR bootcd regtest)
849
850 # LiveCD hives
851 list(APPEND _livecd_inf_files
852 ${_registry_inf}
853 ${CMAKE_SOURCE_DIR}/boot/bootdata/livecd.inf
854 ${CMAKE_SOURCE_DIR}/boot/bootdata/hiveinst.inf)
855
856 add_custom_command(
857 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/system
858 ${CMAKE_BINARY_DIR}/boot/bootdata/software
859 ${CMAKE_BINARY_DIR}/boot/bootdata/default
860 ${CMAKE_BINARY_DIR}/boot/bootdata/sam
861 ${CMAKE_BINARY_DIR}/boot/bootdata/security
862 COMMAND native-mkhive -h:SYSTEM,SOFTWARE,DEFAULT,SAM,SECURITY -d:${CMAKE_BINARY_DIR}/boot/bootdata ${_livecd_inf_files}
863 DEPENDS native-mkhive ${_livecd_inf_files})
864
865 add_custom_target(livecd_hives
866 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/system
867 ${CMAKE_BINARY_DIR}/boot/bootdata/software
868 ${CMAKE_BINARY_DIR}/boot/bootdata/default
869 ${CMAKE_BINARY_DIR}/boot/bootdata/sam
870 ${CMAKE_BINARY_DIR}/boot/bootdata/security)
871
872 add_cd_file(
873 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/system
874 ${CMAKE_BINARY_DIR}/boot/bootdata/software
875 ${CMAKE_BINARY_DIR}/boot/bootdata/default
876 ${CMAKE_BINARY_DIR}/boot/bootdata/sam
877 ${CMAKE_BINARY_DIR}/boot/bootdata/security
878 TARGET livecd_hives
879 DESTINATION reactos/system32/config
880 FOR livecd)
881
882 # BCD Hive
883 add_custom_command(
884 OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
885 COMMAND native-mkhive -h:BCD -u -d:${CMAKE_BINARY_DIR}/boot/bootdata ${CMAKE_BINARY_DIR}/boot/bootdata/hivebcd_utf16.inf
886 DEPENDS native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata/hivebcd_utf16.inf)
887
888 add_custom_target(bcd_hive
889 DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/BCD)
890
891 add_cd_file(
892 FILE ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
893 TARGET bcd_hive
894 DESTINATION efi/boot
895 NO_CAB
896 FOR bootcd regtest livecd)
897
898 endfunction()
899
900 if(KDBG)
901 set(ROSSYM_LIB "rossym")
902 else()
903 set(ROSSYM_LIB "")
904 endif()
905
906 function(add_rc_deps _target_rc)
907 set_source_files_properties(${_target_rc} PROPERTIES OBJECT_DEPENDS "${ARGN}")
908 endfunction()
909
910 add_custom_target(rostests_install COMMAND ${CMAKE_COMMAND} -DCOMPONENT=rostests -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
911 function(add_rostests_file)
912 cmake_parse_arguments(_ROSTESTS "" "RENAME;SUBDIR;TARGET" "FILE" ${ARGN})
913 if(NOT (_ROSTESTS_TARGET OR _ROSTESTS_FILE))
914 message(FATAL_ERROR "You must provide a target or a file to install!")
915 endif()
916
917 set(_ROSTESTS_NAME_ON_CD "${_ROSTESTS_RENAME}")
918 if(NOT _ROSTESTS_FILE)
919 set(_ROSTESTS_FILE "$<TARGET_FILE:${_ROSTESTS_TARGET}>")
920 if(NOT _ROSTESTS_RENAME)
921 set(_ROSTESTS_NAME_ON_CD "$<TARGET_FILE_NAME:${_ROSTESTS_TARGET}>")
922 endif()
923 else()
924 if(NOT _ROSTESTS_RENAME)
925 get_filename_component(_ROSTESTS_NAME_ON_CD ${_ROSTESTS_FILE} NAME)
926 endif()
927 endif()
928
929 if(_ROSTESTS_SUBDIR)
930 set(_ROSTESTS_SUBDIR "/${_ROSTESTS_SUBDIR}")
931 endif()
932
933 if(_ROSTESTS_TARGET)
934 add_cd_file(TARGET ${_ROSTESTS_TARGET} FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
935 else()
936 add_cd_file(FILE ${_ROSTESTS_FILE} DESTINATION "reactos/bin${_ROSTESTS_SUBDIR}" NAME_ON_CD ${_ROSTESTS_NAME_ON_CD} FOR all)
937 endif()
938
939 if(DEFINED ENV{ROSTESTS_INSTALL})
940 if(_ROSTESTS_RENAME)
941 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests RENAME ${_ROSTESTS_RENAME})
942 else()
943 install(FILES ${_ROSTESTS_FILE} DESTINATION "$ENV{ROSTESTS_INSTALL}${_ROSTESTS_SUBDIR}" COMPONENT rostests)
944 endif()
945 endif()
946 endfunction()