5 include_directories(BEFORE ${REACTOS_SOURCE_DIR}/include/c++/stlport)
7 -DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/include/c++
8 -DNATIVE_C_INCLUDE=${REACTOS_SOURCE_DIR}/include/crt)
12 function(add_dependency_node _node)
13 if(GENERATE_DEPENDENCY_GRAPH)
14 get_target_property(_type ${_node} TYPE)
15 if(_type MATCHES SHARED_LIBRARY OR ${_node} MATCHES ntoskrnl)
16 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <node id=\"${_node}\"/>\n")
21 function(add_dependency_edge _source _target)
22 if(GENERATE_DEPENDENCY_GRAPH)
23 get_target_property(_type ${_source} TYPE)
24 if(_type MATCHES SHARED_LIBRARY)
25 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <edge source=\"${_source}\" target=\"${_target}\"/>\n")
30 function(add_dependency_header)
31 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")
34 function(add_dependency_footer)
35 add_dependency_node(ntdll)
36 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " </graph>\n</graphml>\n")
39 function(add_message_headers _type)
40 if(${_type} STREQUAL UNICODE)
45 foreach(_in_FILE ${ARGN})
46 get_filename_component(FILE ${_in_FILE} NAME_WE)
47 macro_mc(${_flag} ${FILE})
49 OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h
50 COMMAND ${COMMAND_MC} ${MC_FLAGS}
51 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)
52 set_source_files_properties(
53 ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc
54 PROPERTIES GENERATED TRUE)
55 add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc)
60 cmake_parse_arguments(_LINK "MINIMIZE" "NAME;PATH;CMD_LINE_ARGS;ICON;GUID" "" ${ARGN})
61 if(NOT _LINK_NAME OR NOT _LINK_PATH)
62 message(FATAL_ERROR "You must provide name and path")
65 if(_LINK_CMD_LINE_ARGS)
66 set(_LINK_CMD_LINE_ARGS -c ${_LINK_CMD_LINE_ARGS})
70 set(_LINK_ICON -i ${_LINK_ICON})
74 set(_LINK_GUID -g ${_LINK_GUID})
78 set(_LINK_MINIMIZE "-m")
82 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk
83 COMMAND native-mkshelllink -o ${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk ${_LINK_CMD_LINE_ARGS} ${_LINK_ICON} ${_LINK_GUID} ${_LINK_MINIMIZE} ${_LINK_PATH}
84 DEPENDS native-mkshelllink)
85 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_LINK_NAME}.lnk PROPERTIES GENERATED TRUE)
88 macro(dir_to_num dir var)
89 if(${dir} STREQUAL reactos/system32)
91 elseif(${dir} STREQUAL reactos/system32/drivers)
93 elseif(${dir} STREQUAL reactos/Fonts)
95 elseif(${dir} STREQUAL reactos)
97 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
99 elseif(${dir} STREQUAL reactos/inf)
101 elseif(${dir} STREQUAL reactos/bin)
103 elseif(${dir} STREQUAL reactos/media)
105 elseif(${dir} STREQUAL reactos/Microsoft.NET)
107 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework)
109 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v1.1.4322)
111 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v2.0.50727)
113 elseif(${dir} STREQUAL reactos/Microsoft.NET/Framework/v4.0.30319)
116 message(ERROR "Wrong destination: ${dir}")
120 function(add_cd_file)
121 cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
122 if(NOT (_CD_TARGET OR _CD_FILE))
123 message(FATAL_ERROR "You must provide a target or a file to install!")
126 if(NOT _CD_DESTINATION)
127 message(FATAL_ERROR "You must provide a destination")
128 elseif(${_CD_DESTINATION} STREQUAL root)
129 set(_CD_DESTINATION "")
133 message(FATAL_ERROR "You must provide a cd name (or "all" for all of them) to install the file on!")
136 #get file if we need to
138 get_target_property(_CD_FILE ${_CD_TARGET} LOCATION)
141 #do we add it to all CDs?
142 if(_CD_FOR STREQUAL all)
143 set(_CD_FOR "bootcd;livecd;regtest")
146 #do we add it to bootcd?
147 list(FIND _CD_FOR bootcd __cd)
148 if(NOT __cd EQUAL -1)
149 #whether or not we should put it in reactos.cab or directly on cd
152 foreach(item ${_CD_FILE})
153 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
156 get_filename_component(__file ${_CD_FILE} NAME)
157 #rename it in the cd tree
158 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
162 add_dependencies(bootcd ${_CD_TARGET})
165 #add it in reactos.cab
166 dir_to_num(${_CD_DESTINATION} _num)
167 file(RELATIVE_PATH __relative_file ${REACTOS_SOURCE_DIR} ${_CD_FILE})
168 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${__relative_file}\" ${_num}\n")
169 unset(__relative_file)
172 add_dependencies(reactos_cab ${_CD_TARGET})
177 #do we add it to livecd?
178 list(FIND _CD_FOR livecd __cd)
179 if(NOT __cd EQUAL -1)
182 add_dependencies(livecd ${_CD_TARGET})
184 foreach(item ${_CD_FILE})
185 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
188 get_filename_component(__file ${_CD_FILE} NAME)
189 #rename it in the cd tree
190 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
194 #do we add it to regtest?
195 list(FIND _CD_FOR regtest __cd)
196 if(NOT __cd EQUAL -1)
197 #whether or not we should put it in reactos.cab or directly on cd
200 foreach(item ${_CD_FILE})
201 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
204 get_filename_component(__file ${_CD_FILE} NAME)
205 #rename it in the cd tree
206 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
210 add_dependencies(bootcdregtest ${_CD_TARGET})
213 #add it in reactos.cab
214 #dir_to_num(${_CD_DESTINATION} _num)
215 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
218 # add_dependencies(reactos_cab ${_CD_TARGET})
224 # Create module_clean targets
225 function(add_clean_target target)
226 if(CMAKE_GENERATOR MATCHES "Unix Makefiles" OR CMAKE_GENERATOR MATCHES "MinGW Makefiles")
227 set(CLEAN_COMMAND make clean)
228 elseif(CMAKE_GENERATOR MATCHES "NMake Makefiles")
229 set(CLEAN_COMMAND nmake /nologo clean)
231 add_custom_target(${target}_clean
232 COMMAND ${CLEAN_COMMAND}
233 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
234 COMMENT "Cleaning ${target}")
238 function(add_library name)
239 _add_library(${name} ${ARGN})
240 add_clean_target(${name})
243 function(add_executable name)
244 _add_executable(${name} ${ARGN})
245 add_clean_target(${name})
249 if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
250 macro(to_win_path _cmake_path _native_path)
251 string(REPLACE "/" "\\" ${_native_path} "${_cmake_path}")
254 # yeah the parameter mess sucks, but thats what works...
255 function(concatenate_files _file1 _target2 _output)
256 get_target_property(_file2 ${_target2} LOCATION)
257 to_win_path("${_file1}" _real_file1)
258 to_win_path("${_file2}" _real_file2)
259 to_win_path("${_output}" _real_output)
262 COMMAND cmd.exe /C "copy /Y /B ${_real_file1} + ${_real_file2} ${_real_output} > nul"
267 macro(concatenate_files _file1 _target2 _output)
268 get_target_property(_file2 ${_target2} LOCATION)
271 COMMAND cat ${_file1} ${_file2} > ${_output}
277 function(add_importlibs _module)
278 add_dependency_node(${_module})
280 if("${LIB}" MATCHES "msvcrt")
281 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
282 target_link_libraries(${_module} msvcrtex)
284 target_link_libraries(${_module} lib${LIB})
285 add_dependencies(${_module} lib${LIB})
286 add_dependency_edge(${_module} ${LIB})
290 function(set_module_type MODULE TYPE)
291 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
293 if(__module_UNPARSED_ARGUMENTS)
294 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
297 # Set subsystem. Also take this as an occasion
298 # to error out if someone gave a non existing type
299 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll) OR (${TYPE} STREQUAL kernelmodedriver))
300 set(__subsystem native)
301 elseif(${TYPE} STREQUAL win32cui)
302 set(__subsystem console)
303 elseif(${TYPE} STREQUAL win32gui)
304 set(__subsystem windows)
305 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
306 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
307 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
310 if(DEFINED __subsystem)
311 set_subsystem(${MODULE} ${__subsystem})
314 #set unicode definitions
316 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
320 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
321 list(GET __module_ENTRYPOINT 0 __entrypoint)
322 list(LENGTH __module_ENTRYPOINT __length)
323 if(${__length} EQUAL 2)
324 list(GET __module_ENTRYPOINT 1 __entrystack)
325 elseif(NOT ${__length} EQUAL 1)
326 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
329 elseif(${TYPE} STREQUAL nativecui)
330 set(__entrypoint NtProcessStartup)
332 elseif((${TYPE} STREQUAL win32gui) OR (${TYPE} STREQUAL win32cui))
334 set(__entrypoint wWinMainCRTStartup)
336 set(__entrypoint WinMainCRTStartup)
338 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
339 OR (${TYPE} STREQUAL cpl))
340 set(__entrypoint DllMainCRTStartup)
342 elseif(${TYPE} STREQUAL kernelmodedriver)
343 set(__entrypoint DriverEntry)
345 elseif(${TYPE} STREQUAL nativedll)
346 set(__entrypoint DllMain)
348 elseif(${TYPE} STREQUAL module)
352 if(DEFINED __entrypoint)
353 if(DEFINED __entrystack)
354 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
356 set_entrypoint(${MODULE} ${__entrypoint})
361 if(__module_IMAGEBASE)
362 set_image_base(${MODULE} __module_IMAGEBASE)
363 elseif(${TYPE} STREQUAL win32dll)
364 if(DEFINED baseaddress_${MODULE})
365 set_image_base(${MODULE} ${baseaddress_${MODULE}})
367 message(STATUS "${MODULE} has no base address")
369 elseif(${TYPE} STREQUAL kernelmodedriver)
370 set_image_base(${MODULE} 0x00010000)
373 # Now do some stuff which is specific to each type
374 if(${TYPE} STREQUAL kernelmodedriver)
375 add_dependencies(${MODULE} bugcodes)
376 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
379 if(${TYPE} STREQUAL win32ocx)
380 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
383 if(${TYPE} STREQUAL cpl)
384 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
387 # do compiler specific stuff
388 set_module_type_toolchain(${MODULE} ${TYPE})
391 function(preprocess_file __in __out)
393 foreach(__def in ${ARGN})
394 list(APPEND __arg -D${__def})
397 add_custom_command(OUTPUT ${_out}
398 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
401 add_custom_command(OUTPUT ${_out}
402 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}
407 function(get_includes OUTPUT_VAR)
408 get_directory_property(_includes INCLUDE_DIRECTORIES)
409 foreach(arg ${_includes})
410 list(APPEND __tmp_var -I${arg})
412 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)
415 function(get_defines OUTPUT_VAR)
416 get_directory_property(_defines COMPILE_DEFINITIONS)
417 foreach(arg ${_defines})
418 list(APPEND __tmp_var -D${arg})
420 set(${OUTPUT_VAR} ${__tmp_var} PARENT_SCOPE)