5 include_directories(${REACTOS_SOURCE_DIR}/include/c++)
9 function(add_dependency_node _node)
10 if(GENERATE_DEPENDENCY_GRAPH)
11 get_target_property(_type ${_node} TYPE)
12 if(_type MATCHES SHARED_LIBRARY OR ${_node} MATCHES ntoskrnl)
13 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <node id=\"${_node}\"/>\n")
18 function(add_dependency_edge _source _target)
19 if(GENERATE_DEPENDENCY_GRAPH)
20 get_target_property(_type ${_source} TYPE)
21 if(_type MATCHES SHARED_LIBRARY)
22 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <edge source=\"${_source}\" target=\"${_target}\"/>\n")
27 function(add_dependency_header)
28 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")
31 function(add_dependency_footer)
32 add_dependency_node(ntdll)
33 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " </graph>\n</graphml>\n")
36 function(add_message_headers _type)
37 if(${_type} STREQUAL UNICODE)
42 foreach(_in_FILE ${ARGN})
43 get_filename_component(FILE ${_in_FILE} NAME_WE)
44 macro_mc(${_flag} ${FILE})
46 OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h
47 COMMAND ${COMMAND_MC} ${MC_FLAGS}
48 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)
49 set_source_files_properties(
50 ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc
51 PROPERTIES GENERATED TRUE)
52 add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc)
57 cmake_parse_arguments(_LINK "MINIMIZE" "NAME;PATH;CMD_LINE_ARGS;ICON;GUID" "" ${ARGN})
58 if(NOT _LINK_NAME OR NOT _LINK_PATH)
59 message(FATAL_ERROR "You must provide name and path")
62 if(_LINK_CMD_LINE_ARGS)
63 set(_LINK_CMD_LINE_ARGS -c ${_LINK_CMD_LINE_ARGS})
67 set(_LINK_ICON -i ${_LINK_ICON})
71 set(_LINK_GUID -g ${_LINK_GUID})
75 set(_LINK_MINIMIZE "-m")
79 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk
80 COMMAND native-mkshelllink -o ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk ${_LINK_CMD_LINE_ARGS} ${_LINK_ICON} ${_LINK_GUID} ${_LINK_MINIMIZE} ${_LINK_PATH}
81 DEPENDS native-mkshelllink)
82 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk PROPERTIES GENERATED TRUE)
85 macro(dir_to_num dir var)
86 if(${dir} STREQUAL reactos/system32)
88 elseif(${dir} STREQUAL reactos/system32/drivers)
90 elseif(${dir} STREQUAL reactos/Fonts)
92 elseif(${dir} STREQUAL reactos)
94 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
96 elseif(${dir} STREQUAL reactos/inf)
98 elseif(${dir} STREQUAL reactos/bin)
100 elseif(${dir} STREQUAL reactos/media)
102 elseif(${dir} STREQUAL reactos/Microsoft.NET)
104 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework)
106 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.0.3705)
108 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.1.4322)
110 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v2.0.50727)
113 message(ERROR "Wrong destination: ${dir}")
117 function(add_cd_file)
118 cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
119 if(NOT (_CD_TARGET OR _CD_FILE))
120 message(FATAL_ERROR "You must provide a target or a file to install!")
123 if(NOT _CD_DESTINATION)
124 message(FATAL_ERROR "You must provide a destination")
125 elseif(${_CD_DESTINATION} STREQUAL root)
126 set(_CD_DESTINATION "")
130 message(FATAL_ERROR "You must provide a cd name (or "all" for all of them) to install the file on!")
133 #get file if we need to
135 get_target_property(_CD_FILE ${_CD_TARGET} LOCATION)
138 #do we add it to all CDs?
139 if(_CD_FOR STREQUAL all)
140 set(_CD_FOR "bootcd;livecd;regtest")
143 #do we add it to bootcd?
144 list(FIND _CD_FOR bootcd __cd)
145 if(NOT __cd EQUAL -1)
146 #whether or not we should put it in reactos.cab or directly on cd
149 foreach(item ${_CD_FILE})
150 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
153 get_filename_component(__file ${_CD_FILE} NAME)
154 #rename it in the cd tree
155 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
159 add_dependencies(bootcd ${_CD_TARGET})
162 #add it in reactos.cab
163 dir_to_num(${_CD_DESTINATION} _num)
164 file(RELATIVE_PATH __relative_file ${REACTOS_SOURCE_DIR} ${_CD_FILE})
165 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${__relative_file}\" ${_num}\n")
166 unset(__relative_file)
169 add_dependencies(reactos_cab ${_CD_TARGET})
174 #do we add it to livecd?
175 list(FIND _CD_FOR livecd __cd)
176 if(NOT __cd EQUAL -1)
179 add_dependencies(livecd ${_CD_TARGET})
181 foreach(item ${_CD_FILE})
182 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
185 get_filename_component(__file ${_CD_FILE} NAME)
186 #rename it in the cd tree
187 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
191 #do we add it to regtest?
192 list(FIND _CD_FOR regtest __cd)
193 if(NOT __cd EQUAL -1)
194 #whether or not we should put it in reactos.cab or directly on cd
197 foreach(item ${_CD_FILE})
198 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
201 get_filename_component(__file ${_CD_FILE} NAME)
202 #rename it in the cd tree
203 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
207 add_dependencies(bootcdregtest ${_CD_TARGET})
210 #add it in reactos.cab
211 #dir_to_num(${_CD_DESTINATION} _num)
212 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
215 # add_dependencies(reactos_cab ${_CD_TARGET})
221 # Create module_clean targets
222 function(add_clean_target _target)
223 set(_clean_working_directory ${CMAKE_CURRENT_BINARY_DIR})
224 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
225 set(_clean_command make clean)
226 elseif(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
227 set(_clean_command nmake /nologo clean)
228 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
229 set(_clean_command ninja -t clean ${_target})
230 set(_clean_working_directory ${REACTOS_BINARY_DIR})
232 add_custom_target(${_target}_clean
233 COMMAND ${_clean_command}
234 WORKING_DIRECTORY ${_clean_working_directory}
235 COMMENT "Cleaning ${_target}")
239 function(add_library name)
240 _add_library(${name} ${ARGN})
241 add_clean_target(${name})
244 function(add_executable name)
245 _add_executable(${name} ${ARGN})
246 add_clean_target(${name})
250 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
251 macro(to_win_path _cmake_path _native_path)
252 string(REPLACE "/" "\\" ${_native_path} "${_cmake_path}")
255 # yeah the parameter mess sucks, but thats what works...
256 function(concatenate_files _file1 _target2 _output)
257 get_target_property(_file2 ${_target2} LOCATION)
258 to_win_path("${_file1}" _real_file1)
259 to_win_path("${_file2}" _real_file2)
260 to_win_path("${_output}" _real_output)
263 COMMAND cmd.exe /C "copy /Y /B ${_real_file1} + ${_real_file2} ${_real_output} > nul"
268 macro(concatenate_files _file1 _target2 _output)
269 get_target_property(_file2 ${_target2} LOCATION)
272 COMMAND cat ${_file1} ${_file2} > ${_output}
278 function(add_importlibs _module)
279 add_dependency_node(${_module})
281 if("${LIB}" MATCHES "msvcrt")
282 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
283 target_link_libraries(${_module} msvcrtex)
285 target_link_libraries(${_module} lib${LIB})
286 add_dependencies(${_module} lib${LIB})
287 add_dependency_edge(${_module} ${LIB})
291 function(set_module_type MODULE TYPE)
292 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
294 if(__module_UNPARSED_ARGUMENTS)
295 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
298 # Set subsystem. Also take this as an occasion
299 # to error out if someone gave a non existing type
300 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll) OR (${TYPE} STREQUAL kernelmodedriver))
301 set(__subsystem native)
302 elseif(${TYPE} STREQUAL win32cui)
303 set(__subsystem console)
304 elseif(${TYPE} STREQUAL win32gui)
305 set(__subsystem windows)
306 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
307 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
308 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
311 if(DEFINED __subsystem)
312 set_subsystem(${MODULE} ${__subsystem})
315 #set unicode definitions
317 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
321 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
322 list(GET __module_ENTRYPOINT 0 __entrypoint)
323 list(LENGTH __module_ENTRYPOINT __length)
324 if(${__length} EQUAL 2)
325 list(GET __module_ENTRYPOINT 1 __entrystack)
326 elseif(NOT ${__length} EQUAL 1)
327 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
330 elseif(${TYPE} STREQUAL nativecui)
331 set(__entrypoint NtProcessStartup)
333 elseif((${TYPE} STREQUAL win32gui) OR (${TYPE} STREQUAL win32cui))
335 set(__entrypoint wWinMainCRTStartup)
337 set(__entrypoint WinMainCRTStartup)
339 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
340 OR (${TYPE} STREQUAL cpl))
341 set(__entrypoint DllMainCRTStartup)
343 elseif(${TYPE} STREQUAL kernelmodedriver)
344 set(__entrypoint DriverEntry)
346 elseif(${TYPE} STREQUAL nativedll)
347 set(__entrypoint DllMain)
349 elseif(${TYPE} STREQUAL module)
353 if(DEFINED __entrypoint)
354 if(DEFINED __entrystack)
355 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
357 set_entrypoint(${MODULE} ${__entrypoint})
362 if(__module_IMAGEBASE)
363 set_image_base(${MODULE} __module_IMAGEBASE)
364 elseif(${TYPE} STREQUAL win32dll)
365 if(DEFINED baseaddress_${MODULE})
366 set_image_base(${MODULE} ${baseaddress_${MODULE}})
368 message(STATUS "${MODULE} has no base address")
370 elseif(${TYPE} STREQUAL kernelmodedriver)
371 set_image_base(${MODULE} 0x00010000)
374 # Now do some stuff which is specific to each type
375 if(${TYPE} STREQUAL kernelmodedriver)
376 add_dependencies(${MODULE} bugcodes)
377 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
380 if(${TYPE} STREQUAL win32ocx)
381 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
384 if(${TYPE} STREQUAL cpl)
385 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
388 # do compiler specific stuff
389 set_module_type_toolchain(${MODULE} ${TYPE})
392 function(preprocess_file __in __out)
394 foreach(__def in ${ARGN})
395 list(APPEND __arg -D${__def})
398 add_custom_command(OUTPUT ${_out}
399 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
402 add_custom_command(OUTPUT ${_out}
403 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}
408 function(get_includes OUTPUT_VAR)
409 get_directory_property(_includes INCLUDE_DIRECTORIES)
410 foreach(arg ${_includes})
411 list(APPEND __tmp_var -I${arg})
413 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
416 function(get_defines OUTPUT_VAR)
417 get_directory_property(_defines COMPILE_DEFINITIONS)
418 foreach(arg ${_defines})
419 list(APPEND __tmp_var -D${arg})
421 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)