f22723bbbef773b3fe78f349834d5fc285bdf5b7
[reactos.git] / reactos / 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}/include/c++)
74 include_directories(${REACTOS_SOURCE_DIR}/include/c++/stlport)
75 endif()
76 endif()
77
78 set(IS_CPP 1)
79 endmacro()
80
81 function(add_dependency_node _node)
82 if(GENERATE_DEPENDENCY_GRAPH)
83 get_target_property(_type ${_node} TYPE)
84 if(_type MATCHES SHARED_LIBRARY OR ${_node} MATCHES ntoskrnl)
85 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <node id=\"${_node}\"/>\n")
86 endif()
87 endif()
88 endfunction()
89
90 function(add_dependency_edge _source _target)
91 if(GENERATE_DEPENDENCY_GRAPH)
92 get_target_property(_type ${_source} TYPE)
93 if(_type MATCHES SHARED_LIBRARY)
94 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <edge source=\"${_source}\" target=\"${_target}\"/>\n")
95 endif()
96 endif()
97 endfunction()
98
99 function(add_dependency_header)
100 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")
101 endfunction()
102
103 function(add_dependency_footer)
104 add_dependency_node(ntdll)
105 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " </graph>\n</graphml>\n")
106 endfunction()
107
108 function(add_message_headers _type)
109 if(${_type} STREQUAL UNICODE)
110 set(_flag "-U")
111 else()
112 set(_flag "-A")
113 endif()
114 foreach(_in_FILE ${ARGN})
115 get_filename_component(FILE ${_in_FILE} NAME_WE)
116 macro_mc(${_flag} ${FILE})
117 add_custom_command(
118 OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h
119 COMMAND ${COMMAND_MC} ${MC_FLAGS}
120 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)
121 set_source_files_properties(
122 ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc
123 PROPERTIES GENERATED TRUE)
124 add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc)
125 endforeach()
126 endfunction()
127
128 function(add_link)
129 cmake_parse_arguments(_LINK "MINIMIZE" "NAME;PATH;CMD_LINE_ARGS;ICON;GUID" "" ${ARGN})
130 if(NOT _LINK_NAME OR NOT _LINK_PATH)
131 message(FATAL_ERROR "You must provide name and path")
132 endif()
133
134 if(_LINK_CMD_LINE_ARGS)
135 set(_LINK_CMD_LINE_ARGS -c ${_LINK_CMD_LINE_ARGS})
136 endif()
137
138 if(_LINK_ICON)
139 set(_LINK_ICON -i ${_LINK_ICON})
140 endif()
141
142 if(_LINK_GUID)
143 set(_LINK_GUID -g ${_LINK_GUID})
144 endif()
145
146 if(_LINK_MINIMIZE)
147 set(_LINK_MINIMIZE "-m")
148 endif()
149
150 add_custom_command(
151 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk
152 COMMAND native-mkshelllink -o ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk ${_LINK_CMD_LINE_ARGS} ${_LINK_ICON} ${_LINK_GUID} ${_LINK_MINIMIZE} ${_LINK_PATH}
153 DEPENDS native-mkshelllink)
154 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk PROPERTIES GENERATED TRUE)
155 endfunction()
156
157 macro(dir_to_num dir var)
158 if(${dir} STREQUAL reactos/system32)
159 set(${var} 1)
160 elseif(${dir} STREQUAL reactos/system32/drivers)
161 set(${var} 2)
162 elseif(${dir} STREQUAL reactos/Fonts)
163 set(${var} 3)
164 elseif(${dir} STREQUAL reactos)
165 set(${var} 4)
166 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
167 set(${var} 5)
168 elseif(${dir} STREQUAL reactos/inf)
169 set(${var} 6)
170 elseif(${dir} STREQUAL reactos/bin)
171 set(${var} 7)
172 elseif(${dir} STREQUAL reactos/bin/data)
173 set(${var} 8)
174 elseif(${dir} STREQUAL reactos/media)
175 set(${var} 9)
176 elseif(${dir} STREQUAL reactos/Microsoft.NET)
177 set(${var} 10)
178 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework)
179 set(${var} 11)
180 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.0.3705)
181 set(${var} 12)
182 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.1.4322)
183 set(${var} 13)
184 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v2.0.50727)
185 set(${var} 14)
186 elseif(${dir} STREQUAL reactos/Resources)
187 set(${var} 15)
188 elseif(${dir} STREQUAL reactos/Resources/Themes)
189 set(${var} 16)
190 elseif(${dir} STREQUAL reactos/system32/wbem)
191 set(${var} 17)
192 elseif(${dir} STREQUAL reactos/Resources/Themes/Lautus)
193 set(${var} 18)
194 else()
195 message(FATAL_ERROR "Wrong destination: ${dir}")
196 endif()
197 endmacro()
198
199 function(add_cd_file)
200 cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
201 if(NOT (_CD_TARGET OR _CD_FILE))
202 message(FATAL_ERROR "You must provide a target or a file to install!")
203 endif()
204
205 if(NOT _CD_DESTINATION)
206 message(FATAL_ERROR "You must provide a destination")
207 elseif(${_CD_DESTINATION} STREQUAL root)
208 set(_CD_DESTINATION "")
209 endif()
210
211 if(NOT _CD_FOR)
212 message(FATAL_ERROR "You must provide a cd name (or \"all\" for all of them) to install the file on!")
213 endif()
214
215 #get file if we need to
216 if(NOT _CD_FILE)
217 get_target_property(_CD_FILE ${_CD_TARGET} LOCATION_${CMAKE_BUILD_TYPE})
218 endif()
219
220 #do we add it to all CDs?
221 if(_CD_FOR STREQUAL all)
222 set(_CD_FOR "bootcd;livecd;regtest")
223 endif()
224
225 #do we add it to bootcd?
226 list(FIND _CD_FOR bootcd __cd)
227 if(NOT __cd EQUAL -1)
228 #whether or not we should put it in reactos.cab or directly on cd
229 if(_CD_NO_CAB)
230 #directly on cd
231 foreach(item ${_CD_FILE})
232 if(_CD_NAME_ON_CD)
233 #rename it in the cd tree
234 set(__file ${_CD_NAME_ON_CD})
235 else()
236 get_filename_component(__file ${item} NAME)
237 endif()
238 set_property(GLOBAL APPEND PROPERTY BOOTCD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
239 endforeach()
240 if(_CD_TARGET)
241 #manage dependency
242 add_dependencies(bootcd ${_CD_TARGET})
243 endif()
244 else()
245 #add it in reactos.cab
246 dir_to_num(${_CD_DESTINATION} _num)
247 file(RELATIVE_PATH __relative_file ${REACTOS_SOURCE_DIR} ${_CD_FILE})
248 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${__relative_file}\" ${_num}\n")
249 unset(__relative_file)
250 if(_CD_TARGET)
251 #manage dependency
252 add_dependencies(reactos_cab ${_CD_TARGET})
253 endif()
254 endif()
255 endif() #end bootcd
256
257 #do we add it to livecd?
258 list(FIND _CD_FOR livecd __cd)
259 if(NOT __cd EQUAL -1)
260 #manage dependency
261 if(_CD_TARGET)
262 add_dependencies(livecd ${_CD_TARGET})
263 endif()
264 foreach(item ${_CD_FILE})
265 if(_CD_NAME_ON_CD)
266 #rename it in the cd tree
267 set(__file ${_CD_NAME_ON_CD})
268 else()
269 get_filename_component(__file ${item} NAME)
270 endif()
271 set_property(GLOBAL APPEND PROPERTY LIVECD_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
272 endforeach()
273 endif() #end livecd
274
275 #do we add it to regtest?
276 list(FIND _CD_FOR regtest __cd)
277 if(NOT __cd EQUAL -1)
278 #whether or not we should put it in reactos.cab or directly on cd
279 if(_CD_NO_CAB)
280 #directly on cd
281 foreach(item ${_CD_FILE})
282 if(_CD_NAME_ON_CD)
283 #rename it in the cd tree
284 set(__file ${_CD_NAME_ON_CD})
285 else()
286 get_filename_component(__file ${item} NAME)
287 endif()
288 set_property(GLOBAL APPEND PROPERTY BOOTCDREGTEST_FILE_LIST "${_CD_DESTINATION}/${__file}=${item}")
289 endforeach()
290 if(_CD_TARGET)
291 #manage dependency
292 add_dependencies(bootcdregtest ${_CD_TARGET})
293 endif()
294 else()
295 #add it in reactos.cab
296 #dir_to_num(${_CD_DESTINATION} _num)
297 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
298 #if(_CD_TARGET)
299 # #manage dependency
300 # add_dependencies(reactos_cab ${_CD_TARGET})
301 #endif()
302 endif()
303 endif() #end bootcd
304 endfunction()
305
306 function(create_iso_lists)
307 get_property(_filelist GLOBAL PROPERTY BOOTCD_FILE_LIST)
308 string(REPLACE ";" "\n" _filelist "${_filelist}")
309 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.lst "${_filelist}")
310 unset(_filelist)
311
312 get_property(_filelist GLOBAL PROPERTY LIVECD_FILE_LIST)
313 string(REPLACE ";" "\n" _filelist "${_filelist}")
314 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.lst "${_filelist}")
315 unset(_filelist)
316
317 get_property(_filelist GLOBAL PROPERTY BOOTCDREGTEST_FILE_LIST)
318 string(REPLACE ";" "\n" _filelist "${_filelist}")
319 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.lst "${_filelist}")
320 unset(_filelist)
321 endfunction()
322
323 # Create module_clean targets
324 function(add_clean_target _target)
325 set(_clean_working_directory ${CMAKE_CURRENT_BINARY_DIR})
326 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
327 set(_clean_command make clean)
328 elseif(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
329 set(_clean_command nmake /nologo clean)
330 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
331 set(_clean_command ninja -t clean ${_target})
332 set(_clean_working_directory ${REACTOS_BINARY_DIR})
333 endif()
334 add_custom_target(${_target}_clean
335 COMMAND ${_clean_command}
336 WORKING_DIRECTORY ${_clean_working_directory}
337 COMMENT "Cleaning ${_target}")
338 endfunction()
339
340 if(NOT MSVC_IDE)
341 function(add_library name)
342 _add_library(${name} ${ARGN})
343 add_clean_target(${name})
344 endfunction()
345
346 function(add_executable name)
347 _add_executable(${name} ${ARGN})
348 add_clean_target(${name})
349 endfunction()
350 elseif(USE_FOLDER_STRUCTURE)
351 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
352 string(LENGTH ${CMAKE_SOURCE_DIR} CMAKE_SOURCE_DIR_LENGTH)
353
354 function(add_custom_target name)
355 _add_custom_target(${name} ${ARGN})
356 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
357 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
358 endfunction()
359
360 function(add_library name)
361 _add_library(${name} ${ARGN})
362 get_target_property(_target_excluded ${name} EXCLUDE_FROM_ALL)
363 if(_target_excluded AND ${name} MATCHES "^lib.*")
364 set_property(TARGET "${name}" PROPERTY FOLDER "Importlibs")
365 else()
366 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
367 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
368 endif()
369 endfunction()
370
371 function(add_executable name)
372 _add_executable(${name} ${ARGN})
373 string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR_LENGTH} -1 CMAKE_CURRENT_SOURCE_DIR_RELATIVE)
374 set_property(TARGET "${name}" PROPERTY FOLDER "${CMAKE_CURRENT_SOURCE_DIR_RELATIVE}")
375 endfunction()
376 endif()
377
378 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
379 macro(to_win_path _cmake_path _native_path)
380 string(REPLACE "/" "\\" ${_native_path} "${_cmake_path}")
381 endmacro()
382
383 # yeah the parameter mess sucks, but thats what works...
384 function(concatenate_files _file1 _target2 _output)
385 get_target_property(_file2 ${_target2} LOCATION)
386 to_win_path("${_file1}" _real_file1)
387 to_win_path("${_file2}" _real_file2)
388 to_win_path("${_output}" _real_output)
389 add_custom_command(
390 OUTPUT ${_output}
391 COMMAND cmd.exe /C "copy /Y /B ${_real_file1} + ${_real_file2} ${_real_output} > nul"
392 DEPENDS ${_file1}
393 DEPENDS ${_target2})
394 endfunction()
395 else()
396 macro(concatenate_files _file1 _target2 _output)
397 get_target_property(_file2 ${_target2} LOCATION)
398 add_custom_command(
399 OUTPUT ${_output}
400 COMMAND cat ${_file1} ${_file2} > ${_output}
401 DEPENDS ${_file1}
402 DEPENDS ${_target2})
403 endmacro()
404 endif()
405
406 function(add_importlibs _module)
407 add_dependency_node(${_module})
408 foreach(LIB ${ARGN})
409 if("${LIB}" MATCHES "msvcrt")
410 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
411 target_link_libraries(${_module} msvcrtex)
412 endif()
413 target_link_libraries(${_module} lib${LIB})
414 add_dependencies(${_module} lib${LIB})
415 add_dependency_edge(${_module} ${LIB})
416 endforeach()
417 endfunction()
418
419 function(set_module_type MODULE TYPE)
420 cmake_parse_arguments(__module "UNICODE;HOTPATCHABLE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
421
422 if(__module_UNPARSED_ARGUMENTS)
423 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
424 endif()
425
426 # Set subsystem. Also take this as an occasion
427 # to error out if someone gave a non existing type
428 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll) OR (${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
429 set(__subsystem native)
430 elseif(${TYPE} STREQUAL win32cui)
431 set(__subsystem console)
432 elseif(${TYPE} STREQUAL win32gui)
433 set(__subsystem windows)
434 elseif(${TYPE} STREQUAL kbdlayout)
435 set_entrypoint(${MODULE} 0)
436 set_image_base(${MODULE} 0x5FFF0000)
437 set_subsystem(${MODULE} native)
438 if (MSVC)
439 # Merge the .text and .rdata section into the .data section
440 add_target_link_flags(${MODULE} "/ignore:4254 /SECTION:.data,ER /MERGE:.text=.data /MERGE:.rdata=.data /MERGE:.bss=.data /MERGE:.edata=.data")
441 else()
442 # Use a custom linker script
443 add_target_link_flags(${MODULE} "-Wl,-T,${CMAKE_SOURCE_DIR}/kbdlayout.lds")
444 add_dependencies(${MODULE} "${CMAKE_SOURCE_DIR}/kbdlayout.lds")
445 endif()
446 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
447 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
448 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
449 endif()
450
451 if(DEFINED __subsystem)
452 set_subsystem(${MODULE} ${__subsystem})
453 endif()
454
455 #set unicode definitions
456 if(__module_UNICODE)
457 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
458 endif()
459
460 # Handle hotpatchable images.
461 # GCC has this as a function attribute so we're handling it using DECLSPEC_HOTPATCH
462 if(__module_HOTPATCHABLE AND MSVC)
463 set_property(TARGET ${MODULE} APPEND_STRING PROPERTY COMPILE_FLAGS " /hotpatch")
464 if(ARCH STREQUAL "i386")
465 set_property(TARGET ${MODULE} APPEND_STRING PROPERTY LINK_FLAGS " /FUNCTIONPADMIN:5")
466 elseif(ARCH STREQUAL "amd64")
467 set_property(TARGET ${MODULE} APPEND_STRING PROPERTY LINK_FLAGS " /FUNCTIONPADMIN:6")
468 endif()
469 endif()
470
471 # set entry point
472 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
473 list(GET __module_ENTRYPOINT 0 __entrypoint)
474 list(LENGTH __module_ENTRYPOINT __length)
475 if(${__length} EQUAL 2)
476 list(GET __module_ENTRYPOINT 1 __entrystack)
477 elseif(NOT ${__length} EQUAL 1)
478 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
479 endif()
480 unset(__length)
481 elseif(${TYPE} STREQUAL nativecui)
482 set(__entrypoint NtProcessStartup)
483 set(__entrystack 4)
484 elseif(${TYPE} STREQUAL win32cui)
485 if(__module_UNICODE)
486 set(__entrypoint wmainCRTStartup)
487 else()
488 set(__entrypoint mainCRTStartup)
489 endif()
490 elseif(${TYPE} STREQUAL win32gui)
491 if(__module_UNICODE)
492 set(__entrypoint wWinMainCRTStartup)
493 else()
494 set(__entrypoint WinMainCRTStartup)
495 endif()
496 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
497 OR (${TYPE} STREQUAL cpl))
498 set(__entrypoint DllMainCRTStartup)
499 set(__entrystack 12)
500 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
501 set(__entrypoint DriverEntry)
502 set(__entrystack 8)
503 elseif(${TYPE} STREQUAL nativedll)
504 set(__entrypoint DllMain)
505 set(__entrystack 12)
506 elseif(${TYPE} STREQUAL module)
507 set(__entrypoint 0)
508 endif()
509
510 if(DEFINED __entrypoint)
511 if(DEFINED __entrystack)
512 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
513 else()
514 set_entrypoint(${MODULE} ${__entrypoint})
515 endif()
516 endif()
517
518 #set base address
519 if(__module_IMAGEBASE)
520 set_image_base(${MODULE} __module_IMAGEBASE)
521 elseif(${TYPE} STREQUAL win32dll)
522 if(DEFINED baseaddress_${MODULE})
523 set_image_base(${MODULE} ${baseaddress_${MODULE}})
524 else()
525 message(STATUS "${MODULE} has no base address")
526 endif()
527 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
528 set_image_base(${MODULE} 0x00010000)
529 endif()
530
531 # Now do some stuff which is specific to each type
532 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
533 add_dependencies(${MODULE} bugcodes)
534 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
535 endif()
536
537 if(${TYPE} STREQUAL win32ocx)
538 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
539 endif()
540
541 if(${TYPE} STREQUAL cpl)
542 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
543 endif()
544
545 # do compiler specific stuff
546 set_module_type_toolchain(${MODULE} ${TYPE})
547 endfunction()
548
549 function(preprocess_file __in __out)
550 set(__arg ${__in})
551 foreach(__def in ${ARGN})
552 list(APPEND __arg -D${__def})
553 endforeach()
554 if(MSVC)
555 add_custom_command(OUTPUT ${_out}
556 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
557 DEPENDS ${__in})
558 else()
559 add_custom_command(OUTPUT ${_out}
560 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}
561 DEPENDS ${__in})
562 endif()
563 endfunction()
564
565 function(get_includes OUTPUT_VAR)
566 get_directory_property(_includes INCLUDE_DIRECTORIES)
567 foreach(arg ${_includes})
568 list(APPEND __tmp_var -I${arg})
569 endforeach()
570 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
571 endfunction()
572
573 function(get_defines OUTPUT_VAR)
574 get_directory_property(_defines COMPILE_DEFINITIONS)
575 foreach(arg ${_defines})
576 list(APPEND __tmp_var -D${arg})
577 endforeach()
578 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
579 endfunction()
580
581 if(NOT MSVC)
582 function(add_object_library _target)
583 add_library(${_target} OBJECT ${ARGN})
584 endfunction()
585 else()
586 function(add_object_library _target)
587 add_library(${_target} ${ARGN})
588 endfunction()
589 endif()
590
591 if(KDBG)
592 set(ROSSYM_LIB "rossym")
593 else()
594 set(ROSSYM_LIB "")
595 endif()