3 include_directories(BEFORE ${REACTOS_SOURCE_DIR}/include/c++/stlport)
6 -DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/include/c++
7 -DNATIVE_C_INCLUDE=${REACTOS_SOURCE_DIR}/include/crt)
10 function(add_dependency_node _node)
11 if(GENERATE_DEPENDENCY_GRAPH)
12 get_target_property(_type ${_node} TYPE)
13 if(_type MATCHES SHARED_LIBRARY OR ${_node} MATCHES ntoskrnl)
14 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <node id=\"${_node}\"/>\n")
19 function(add_dependency_edge _source _target)
20 if(GENERATE_DEPENDENCY_GRAPH)
21 get_target_property(_type ${_source} TYPE)
22 if(_type MATCHES SHARED_LIBRARY)
23 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <edge source=\"${_source}\" target=\"${_target}\"/>\n")
28 function(add_dependency_header)
29 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")
32 function(add_dependency_footer)
33 add_dependency_node(ntdll)
34 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " </graph>\n</graphml>\n")
37 function(add_message_headers)
38 foreach(_in_FILE ${ARGN})
39 get_filename_component(FILE ${_in_FILE} NAME_WE)
42 OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h
44 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)
45 set_source_files_properties(
46 ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc
47 PROPERTIES GENERATED TRUE)
48 add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc)
52 macro(dir_to_num dir var)
53 if(${dir} STREQUAL reactos/system32)
55 elseif(${dir} STREQUAL reactos/system32/drivers)
57 elseif(${dir} STREQUAL reactos/Fonts)
59 elseif(${dir} STREQUAL reactos)
61 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
63 elseif(${dir} STREQUAL reactos/inf)
65 elseif(${dir} STREQUAL reactos/bin)
67 elseif(${dir} STREQUAL reactos/media)
70 message(ERROR "Wrong destination: ${dir}")
75 cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
76 if(NOT (_CD_TARGET OR _CD_FILE))
77 message(FATAL_ERROR "You must provide a target or a file to install!")
80 if(NOT _CD_DESTINATION)
81 message(FATAL_ERROR "You must provide a destination")
82 elseif(${_CD_DESTINATION} STREQUAL root)
83 set(_CD_DESTINATION "")
87 message(FATAL_ERROR "You must provide a cd name (or "all" for all of them) to install the file on!")
90 #get file if we need to
92 get_target_property(_CD_FILE ${_CD_TARGET} LOCATION)
95 #do we add it to all CDs?
96 if(_CD_FOR STREQUAL all)
97 set(_CD_FOR "bootcd;livecd;regtest")
100 #do we add it to bootcd?
101 list(FIND _CD_FOR bootcd __cd)
102 if(NOT __cd EQUAL -1)
103 #whether or not we should put it in reactos.cab or directly on cd
106 foreach(item ${_CD_FILE})
107 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
110 get_filename_component(__file ${_CD_FILE} NAME)
111 #rename it in the cd tree
112 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
116 add_dependencies(bootcd ${_CD_TARGET})
119 #add it in reactos.cab
120 dir_to_num(${_CD_DESTINATION} _num)
121 if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
122 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
124 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${_CD_FILE}\" ${_num}\n")
128 add_dependencies(reactos_cab ${_CD_TARGET})
133 #do we add it to livecd?
134 list(FIND _CD_FOR livecd __cd)
135 if(NOT __cd EQUAL -1)
138 add_dependencies(livecd ${_CD_TARGET})
140 foreach(item ${_CD_FILE})
141 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
144 get_filename_component(__file ${_CD_FILE} NAME)
145 #rename it in the cd tree
146 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
150 #do we add it to regtest?
151 list(FIND _CD_FOR regtest __cd)
152 if(NOT __cd EQUAL -1)
153 #whether or not we should put it in reactos.cab or directly on cd
156 foreach(item ${_CD_FILE})
157 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
160 get_filename_component(__file ${_CD_FILE} NAME)
161 #rename it in the cd tree
162 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcdregtest.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
166 add_dependencies(bootcdregtest ${_CD_TARGET})
169 #add it in reactos.cab
170 #dir_to_num(${_CD_DESTINATION} _num)
171 #file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
174 # add_dependencies(reactos_cab ${_CD_TARGET})
180 # Create module_clean targets
181 function(add_clean_target target)
182 if(CMAKE_GENERATOR MATCHES "Unix Makefiles" OR CMAKE_GENERATOR MATCHES "MinGW Makefiles")
183 set(CLEAN_COMMAND make clean)
184 elseif(CMAKE_GENERATOR MATCHES "NMake Makefiles")
185 set(CLEAN_COMMAND nmake /nologo clean)
187 add_custom_target(${target}_clean
188 COMMAND ${CLEAN_COMMAND}
189 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
190 COMMENT "Cleaning ${target}")
194 function(add_library name)
195 _add_library(${name} ${ARGN})
196 add_clean_target(${name})
199 function(add_executable name)
200 _add_executable(${name} ${ARGN})
201 add_clean_target(${name})
205 if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
206 macro(to_win_path _cmake_path _native_path)
207 string(REPLACE "/" "\\" ${_native_path} "${_cmake_path}")
210 function(concatenate_files _file1 _file2 _output)
211 to_win_path("${_file1}" _real_file1)
212 to_win_path("${_file2}" _real_file2)
213 to_win_path("${_output}" _real_output)
216 COMMAND cmd.exe /C "copy /Y /B ${_real_file1} + ${_real_file2} ${_real_output} > nul"
221 macro(concatenate_files _file1 _file2 _output)
224 COMMAND cat ${_file1} ${_file2} > ${_output}
230 function(add_importlibs _module)
231 add_dependency_node(${_module})
233 if ("${LIB}" MATCHES "msvcrt")
234 add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
235 target_link_libraries(${_module} msvcrtex)
237 target_link_libraries(${_module} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}${CMAKE_STATIC_LIBRARY_SUFFIX})
238 add_dependencies(${_module} lib${LIB})
239 add_dependency_edge(${_module} ${LIB})
243 function(set_module_type MODULE TYPE)
244 cmake_parse_arguments(__module "UNICODE" "IMAGEBASE" "ENTRYPOINT" ${ARGN})
246 if(__module_UNPARSED_ARGUMENTS)
247 message(STATUS "set_module_type : unparsed arguments ${__module_UNPARSED_ARGUMENTS}, module : ${MODULE}")
250 # Set subsystem. Also take this as an occasion
251 # to error out if someone gave a non existing type
252 if((${TYPE} STREQUAL nativecui) OR (${TYPE} STREQUAL nativedll) OR (${TYPE} STREQUAL kernelmodedriver))
253 set(__subsystem native)
254 elseif(${TYPE} STREQUAL win32cui)
255 set(__subsystem console)
256 elseif(${TYPE} STREQUAL win32gui)
257 set(__subsystem windows)
258 elseif(NOT ((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx) OR (${TYPE} STREQUAL cpl)))
259 message(FATAL_ERROR "Unknown type ${TYPE} for module ${MODULE}")
262 if(DEFINED __subsystem)
263 set_subsystem(${MODULE} ${__subsystem})
266 #set unicode definitions
268 add_target_compile_definitions(${MODULE} UNICODE _UNICODE)
272 if(__module_ENTRYPOINT OR (__module_ENTRYPOINT STREQUAL "0"))
273 list(GET __module_ENTRYPOINT 0 __entrypoint)
274 list(LENGTH __module_ENTRYPOINT __length)
275 if(${__length} EQUAL 2)
276 list(GET __module_ENTRYPOINT 1 __entrystack)
277 elseif(NOT ${__length} EQUAL 1)
278 message(FATAL_ERROR "Wrong arguments for ENTRYPOINT parameter of set_module_type : ${__module_ENTRYPOINT}")
281 elseif(${TYPE} STREQUAL nativecui)
282 set(__entrypoint NtProcessStartup)
284 elseif((${TYPE} STREQUAL win32gui) OR (${TYPE} STREQUAL win32cui))
286 set(__entrypoint wWinMainCRTStartup)
288 set(__entrypoint WinMainCRTStartup)
290 elseif((${TYPE} STREQUAL win32dll) OR (${TYPE} STREQUAL win32ocx)
291 OR (${TYPE} STREQUAL cpl))
292 set(__entrypoint DllMainCRTStartup)
294 elseif(${TYPE} STREQUAL kernelmodedriver)
295 set(__entrypoint DriverEntry)
297 elseif(${TYPE} STREQUAL nativedll)
298 set(__entrypoint DllMain)
302 if(DEFINED __entrypoint)
303 if(DEFINED __entrystack)
304 set_entrypoint(${MODULE} ${__entrypoint} ${__entrystack})
306 set_entrypoint(${MODULE} ${__entrypoint})
311 if(__module_IMAGEBASE)
312 set_image_base(${MODULE} __module_IMAGEBASE)
313 elseif(${TYPE} STREQUAL win32dll)
314 if(DEFINED baseaddress_${MODULE})
315 set_image_base(${MODULE} ${baseaddress_${MODULE}})
317 message(STATUS "${MODULE} has no base address")
319 elseif(${TYPE} STREQUAL kernelmodedriver)
320 set_image_base(${MODULE} 0x00010000)
323 # Now do some stuff which is specific to each type
324 if(${TYPE} STREQUAL kernelmodedriver)
325 add_dependencies(${MODULE} bugcodes)
326 set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")
329 if(${TYPE} STREQUAL win32ocx)
330 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
333 if(${TYPE} STREQUAL cpl)
334 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
337 # do compiler specific stuff
338 set_module_type_toolchain(${MODULE} ${TYPE})