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/bin/data)
102 elseif(${dir} STREQUAL reactos/media)
104 elseif(${dir} STREQUAL reactos/Microsoft.NET)
106 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework)
108 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.0.3705)
110 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.1.4322)
112 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v2.0.50727)
115 message(ERROR "Wrong destination: ${dir}")
119 function(add_cd_file)
120 cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
121 if(NOT (_CD_TARGET OR _CD_FILE))
122 message(FATAL_ERROR "You must provide a target or a file to install!")
125 if(NOT _CD_DESTINATION)
126 message(FATAL_ERROR "You must provide a destination")
127 elseif(${_CD_DESTINATION} STREQUAL root)
128 set(_CD_DESTINATION "")
132 message(FATAL_ERROR "You must provide a cd name (or "all" for all of them) to install the file on!")
135 #get file if we need to
137 get_target_property(_CD_FILE ${_CD_TARGET} LOCATION_${CMAKE_BUILD_TYPE})
140 #do we add it to all CDs?
141 if(_CD_FOR STREQUAL all)
142 set(_CD_FOR "bootcd;livecd;regtest")
145 #do we add it to bootcd?
146 list(FIND _CD_FOR bootcd __cd)
147 if(NOT __cd EQUAL -1)
148 #whether or not we should put it in reactos.cab or directly on cd
151 foreach(item ${_CD_FILE})
152 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
155 get_filename_component(__file ${_CD_FILE} NAME)
156 #rename it in the cd tree
157 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
161 add_dependencies(bootcd ${_CD_TARGET})
164 #add it in reactos.cab
165 dir_to_num(${_CD_DESTINATION} _num)
166 file(RELATIVE_PATH __relative_file ${REACTOS_SOURCE_DIR} ${_CD_FILE})
167 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${__relative_file}\" ${_num}\n")
168 unset(__relative_file)
171 add_dependencies(reactos_cab ${_CD_TARGET})
176 #do we add it to livecd?
177 list(FIND _CD_FOR livecd __cd)
178 if(NOT __cd EQUAL -1)
181 add_dependencies(livecd ${_CD_TARGET})
183 foreach(item ${_CD_FILE})
184 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
187 get_filename_component(__file ${_CD_FILE} NAME)
188 #rename it in the cd tree
189 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
193 #do we add it to regtest?
194 list(FIND _CD_FOR regtest __cd)
195 if(NOT __cd EQUAL -1)
196 #whether or not we should put it in reactos.cab or directly on cd
199 foreach(item ${_CD_FILE})
200 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
203 get_filename_component(__file ${_CD_FILE} NAME)
204 #rename it in the cd tree
205 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
209 add_dependencies(bootcdregtest ${_CD_TARGET})
212 #add it in reactos.cab
213 #dir_to_num(${_CD_DESTINATION} _num)
214 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
217 # add_dependencies(reactos_cab ${_CD_TARGET})
223 # Create module_clean targets
224 function(add_clean_target _target)
225 set(_clean_working_directory ${CMAKE_CURRENT_BINARY_DIR})
226 if(CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
227 set(_clean_command make clean)
228 elseif(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
229 set(_clean_command nmake /nologo clean)
230 elseif(CMAKE_GENERATOR STREQUAL "Ninja")
231 set(_clean_command ninja -t clean ${_target})
232 set(_clean_working_directory ${REACTOS_BINARY_DIR})
234 add_custom_target(${_target}_clean
235 COMMAND ${_clean_command}
236 WORKING_DIRECTORY ${_clean_working_directory}
237 COMMENT "Cleaning ${_target}")
241 function(add_library name)
242 _add_library(${name} ${ARGN})
243 add_clean_target(${name})
246 function(add_executable name)
247 _add_executable(${name} ${ARGN})
248 add_clean_target(${name})
252 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
253 macro(to_win_path _cmake_path _native_path)
254 string(REPLACE "/" "\\" ${_native_path} "${_cmake_path}")
257 # yeah the parameter mess sucks, but thats what works...
258 function(concatenate_files _file1 _target2 _output)
259 get_target_property(_file2 ${_target2} LOCATION)
260 to_win_path("${_file1}" _real_file1)
261 to_win_path("${_file2}" _real_file2)
262 to_win_path("${_output}" _real_output)
265 COMMAND cmd.exe /C "copy /Y /B ${_real_file1} + ${_real_file2} ${_real_output} > nul"
270 macro(concatenate_files _file1 _target2 _output)
271 get_target_property(_file2 ${_target2} LOCATION)
274 COMMAND cat ${_file1} ${_file2} > ${_output}
280 function(add_importlibs _module)
281 add_dependency_node(${_module})
283 if("${LIB}" MATCHES "msvcrt")
284 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
285 target_link_libraries(${_module} msvcrtex)
287 target_link_libraries(${_module} lib${LIB})
288 add_dependencies(${_module} lib${LIB})
289 add_dependency_edge(${_module} ${LIB})
293 function(set_module_type MODULE TYPE)
294 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
296 if(__module_UNPARSED_ARGUMENTS)
297 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
300 # Set subsystem. Also take this as an occasion
301 # to error out if someone gave a non existing type
302 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll) OR (${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
303 set(__subsystem native)
304 elseif(${TYPE} STREQUAL win32cui)
305 set(__subsystem console)
306 elseif(${TYPE} STREQUAL win32gui)
307 set(__subsystem windows)
308 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
309 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
310 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
313 if(DEFINED __subsystem)
314 set_subsystem(${MODULE} ${__subsystem})
317 #set unicode definitions
319 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
323 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
324 list(GET __module_ENTRYPOINT 0 __entrypoint)
325 list(LENGTH __module_ENTRYPOINT __length)
326 if(${__length} EQUAL 2)
327 list(GET __module_ENTRYPOINT 1 __entrystack)
328 elseif(NOT ${__length} EQUAL 1)
329 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
332 elseif(${TYPE} STREQUAL nativecui)
333 set(__entrypoint NtProcessStartup)
335 elseif((${TYPE} STREQUAL win32gui) OR (${TYPE} STREQUAL win32cui))
337 set(__entrypoint wWinMainCRTStartup)
339 set(__entrypoint WinMainCRTStartup)
341 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
342 OR (${TYPE} STREQUAL cpl))
343 set(__entrypoint DllMainCRTStartup)
345 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
346 set(__entrypoint DriverEntry)
348 elseif(${TYPE} STREQUAL nativedll)
349 set(__entrypoint DllMain)
351 elseif(${TYPE} STREQUAL module)
355 if(DEFINED __entrypoint)
356 if(DEFINED __entrystack)
357 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
359 set_entrypoint(${MODULE} ${__entrypoint})
364 if(__module_IMAGEBASE)
365 set_image_base(${MODULE} __module_IMAGEBASE)
366 elseif(${TYPE} STREQUAL win32dll)
367 if(DEFINED baseaddress_${MODULE})
368 set_image_base(${MODULE} ${baseaddress_${MODULE}})
370 message(STATUS "${MODULE} has no base address")
372 elseif((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
373 set_image_base(${MODULE} 0x00010000)
376 # Now do some stuff which is specific to each type
377 if((${TYPE} STREQUAL kernelmodedriver) OR (${TYPE} STREQUAL wdmdriver))
378 add_dependencies(${MODULE} bugcodes)
379 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
382 if(${TYPE} STREQUAL win32ocx)
383 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
386 if(${TYPE} STREQUAL cpl)
387 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
390 # do compiler specific stuff
391 set_module_type_toolchain(${MODULE} ${TYPE})
394 function(preprocess_file __in __out)
396 foreach(__def in ${ARGN})
397 list(APPEND __arg -D${__def})
400 add_custom_command(OUTPUT ${_out}
401 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
404 add_custom_command(OUTPUT ${_out}
405 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}
410 function(get_includes OUTPUT_VAR)
411 get_directory_property(_includes INCLUDE_DIRECTORIES)
412 foreach(arg ${_includes})
413 list(APPEND __tmp_var -I${arg})
415 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
418 function(get_defines OUTPUT_VAR)
419 get_directory_property(_defines COMPILE_DEFINITIONS)
420 foreach(arg ${_defines})
421 list(APPEND __tmp_var -D${arg})
423 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
426 if(NOT MSVC AND (CMAKE_VERSION VERSION_GREATER 2.8.7))
427 function(add_object_library _target)
428 add_library(${_target} OBJECT ${ARGN})
431 function(add_object_library _target)
432 add_library(${_target} ${ARGN})