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/v2.0.50727)
112 message(ERROR "Wrong destination: ${dir}")
116 function(add_cd_file)
117 cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
118 if(NOT (_CD_TARGET OR _CD_FILE))
119 message(FATAL_ERROR "You must provide a target or a file to install!")
122 if(NOT _CD_DESTINATION)
123 message(FATAL_ERROR "You must provide a destination")
124 elseif(${_CD_DESTINATION} STREQUAL root)
125 set(_CD_DESTINATION "")
129 message(FATAL_ERROR "You must provide a cd name (or "all" for all of them) to install the file on!")
132 #get file if we need to
134 get_target_property(_CD_FILE ${_CD_TARGET} LOCATION)
137 #do we add it to all CDs?
138 if(_CD_FOR STREQUAL all)
139 set(_CD_FOR "bootcd;livecd;regtest")
142 #do we add it to bootcd?
143 list(FIND _CD_FOR bootcd __cd)
144 if(NOT __cd EQUAL -1)
145 #whether or not we should put it in reactos.cab or directly on cd
148 foreach(item ${_CD_FILE})
149 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
152 get_filename_component(__file ${_CD_FILE} NAME)
153 #rename it in the cd tree
154 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
158 add_dependencies(bootcd ${_CD_TARGET})
161 #add it in reactos.cab
162 dir_to_num(${_CD_DESTINATION} _num)
163 file(RELATIVE_PATH __relative_file ${REACTOS_SOURCE_DIR} ${_CD_FILE})
164 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${__relative_file}\" ${_num}\n")
165 unset(__relative_file)
168 add_dependencies(reactos_cab ${_CD_TARGET})
173 #do we add it to livecd?
174 list(FIND _CD_FOR livecd __cd)
175 if(NOT __cd EQUAL -1)
178 add_dependencies(livecd ${_CD_TARGET})
180 foreach(item ${_CD_FILE})
181 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
184 get_filename_component(__file ${_CD_FILE} NAME)
185 #rename it in the cd tree
186 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
190 #do we add it to regtest?
191 list(FIND _CD_FOR regtest __cd)
192 if(NOT __cd EQUAL -1)
193 #whether or not we should put it in reactos.cab or directly on cd
196 foreach(item ${_CD_FILE})
197 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
200 get_filename_component(__file ${_CD_FILE} NAME)
201 #rename it in the cd tree
202 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
206 add_dependencies(bootcdregtest ${_CD_TARGET})
209 #add it in reactos.cab
210 #dir_to_num(${_CD_DESTINATION} _num)
211 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
214 # add_dependencies(reactos_cab ${_CD_TARGET})
220 # Create module_clean targets
221 function(add_clean_target target)
222 if(CMAKE_GENERATOR MATCHES "Unix Makefiles" OR CMAKE_GENERATOR MATCHES "MinGW Makefiles")
223 set(CLEAN_COMMAND make clean)
224 elseif(CMAKE_GENERATOR MATCHES "NMake Makefiles")
225 set(CLEAN_COMMAND nmake /nologo clean)
227 add_custom_target(${target}_clean
228 COMMAND ${CLEAN_COMMAND}
229 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
230 COMMENT "Cleaning ${target}")
234 function(add_library name)
235 _add_library(${name} ${ARGN})
236 add_clean_target(${name})
239 function(add_executable name)
240 _add_executable(${name} ${ARGN})
241 add_clean_target(${name})
245 if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
246 macro(to_win_path _cmake_path _native_path)
247 string(REPLACE "/" "\\" ${_native_path} "${_cmake_path}")
250 # yeah the parameter mess sucks, but thats what works...
251 function(concatenate_files _file1 _target2 _output)
252 get_target_property(_file2 ${_target2} LOCATION)
253 to_win_path("${_file1}" _real_file1)
254 to_win_path("${_file2}" _real_file2)
255 to_win_path("${_output}" _real_output)
258 COMMAND cmd.exe /C "copy /Y /B ${_real_file1} + ${_real_file2} ${_real_output} > nul"
263 macro(concatenate_files _file1 _target2 _output)
264 get_target_property(_file2 ${_target2} LOCATION)
267 COMMAND cat ${_file1} ${_file2} > ${_output}
273 function(add_importlibs _module)
274 add_dependency_node(${_module})
276 if("${LIB}" MATCHES "msvcrt")
277 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
278 target_link_libraries(${_module} msvcrtex)
280 target_link_libraries(${_module} lib${LIB})
281 add_dependencies(${_module} lib${LIB})
282 add_dependency_edge(${_module} ${LIB})
286 function(set_module_type MODULE TYPE)
287 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
289 if(__module_UNPARSED_ARGUMENTS)
290 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
293 # Set subsystem. Also take this as an occasion
294 # to error out if someone gave a non existing type
295 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll) OR (${TYPE} STREQUAL kernelmodedriver))
296 set(__subsystem native)
297 elseif(${TYPE} STREQUAL win32cui)
298 set(__subsystem console)
299 elseif(${TYPE} STREQUAL win32gui)
300 set(__subsystem windows)
301 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
302 OR (${TYPE} STREQUAL cpl) OR (${TYPE} STREQUAL module)))
303 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
306 if(DEFINED __subsystem)
307 set_subsystem(${MODULE} ${__subsystem})
310 #set unicode definitions
312 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
316 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
317 list(GET __module_ENTRYPOINT 0 __entrypoint)
318 list(LENGTH __module_ENTRYPOINT __length)
319 if(${__length} EQUAL 2)
320 list(GET __module_ENTRYPOINT 1 __entrystack)
321 elseif(NOT ${__length} EQUAL 1)
322 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
325 elseif(${TYPE} STREQUAL nativecui)
326 set(__entrypoint NtProcessStartup)
328 elseif((${TYPE} STREQUAL win32gui) OR (${TYPE} STREQUAL win32cui))
330 set(__entrypoint wWinMainCRTStartup)
332 set(__entrypoint WinMainCRTStartup)
334 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
335 OR (${TYPE} STREQUAL cpl))
336 set(__entrypoint DllMainCRTStartup)
338 elseif(${TYPE} STREQUAL kernelmodedriver)
339 set(__entrypoint DriverEntry)
341 elseif(${TYPE} STREQUAL nativedll)
342 set(__entrypoint DllMain)
344 elseif(${TYPE} STREQUAL module)
348 if(DEFINED __entrypoint)
349 if(DEFINED __entrystack)
350 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
352 set_entrypoint(${MODULE} ${__entrypoint})
357 if(__module_IMAGEBASE)
358 set_image_base(${MODULE} __module_IMAGEBASE)
359 elseif(${TYPE} STREQUAL win32dll)
360 if(DEFINED baseaddress_${MODULE})
361 set_image_base(${MODULE} ${baseaddress_${MODULE}})
363 message(STATUS "${MODULE} has no base address")
365 elseif(${TYPE} STREQUAL kernelmodedriver)
366 set_image_base(${MODULE} 0x00010000)
369 # Now do some stuff which is specific to each type
370 if(${TYPE} STREQUAL kernelmodedriver)
371 add_dependencies(${MODULE} bugcodes)
372 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
375 if(${TYPE} STREQUAL win32ocx)
376 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
379 if(${TYPE} STREQUAL cpl)
380 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
383 # do compiler specific stuff
384 set_module_type_toolchain(${MODULE} ${TYPE})
387 function(preprocess_file __in __out)
389 foreach(__def in ${ARGN})
390 list(APPEND __arg -D${__def})
393 add_custom_command(OUTPUT ${_out}
394 COMMAND ${CMAKE_C_COMPILER} /EP ${__arg}
397 add_custom_command(OUTPUT ${_out}
398 COMMAND ${CMAKE_C_COMPILER} -E ${__arg}