* Sync the recent cmake branch changes.
[reactos.git] / CMakeMacros.cmake
1
2 if (NOT MSVC)
3
4 macro(CreateBootSectorTarget _target_name _asm_file _object_file)
5 get_filename_component(OBJECT_PATH ${_object_file} PATH)
6 get_filename_component(OBJECT_NAME ${_object_file} NAME)
7 file(MAKE_DIRECTORY ${OBJECT_PATH})
8 get_directory_property(defines COMPILE_DEFINITIONS)
9 get_directory_property(includes INCLUDE_DIRECTORIES)
10
11 foreach(arg ${defines})
12 set(result_defs ${result_defs} -D${arg})
13 endforeach()
14
15 foreach(arg ${includes})
16 set(result_incs -I${arg} ${result_incs})
17 endforeach()
18
19 add_custom_command(
20 OUTPUT ${_object_file}
21 COMMAND nasm -o ${_object_file} ${result_incs} ${result_defs} -f bin ${_asm_file}
22 DEPENDS ${_asm_file})
23 set_source_files_properties(${_object_file} PROPERTIES GENERATED TRUE)
24 add_custom_target(${_target_name} ALL DEPENDS ${_object_file})
25 endmacro()
26
27 else()
28
29 macro(CreateBootSectorTarget _target_name _asm_file _object_file)
30 endmacro()
31
32 endif()
33
34 macro(set_cpp)
35 include_directories(BEFORE ${REACTOS_SOURCE_DIR}/include/c++/stlport)
36 set(IS_CPP 1)
37 add_definitions(
38 -DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/include/c++
39 -DNATIVE_C_INCLUDE=${REACTOS_SOURCE_DIR}/include/crt)
40 endmacro()
41
42 macro(add_dependency_node _node)
43 if(GENERATE_DEPENDENCY_GRAPH)
44 get_target_property(_type ${_node} TYPE)
45 if(_type MATCHES SHARED_LIBRARY)
46 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <node id=\"${_node}\"/>\n")
47 endif()
48 endif()
49 endmacro()
50
51 macro(add_dependency_edge _source _target)
52 if(GENERATE_DEPENDENCY_GRAPH)
53 get_target_property(_type ${_source} TYPE)
54 if(_type MATCHES SHARED_LIBRARY)
55 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <edge source=\"${_source}\" target=\"${_target}\"/>\n")
56 endif()
57 endif()
58 endmacro()
59
60 macro(add_dependency_header)
61 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")
62 add_dependency_node(ntdll)
63 endmacro()
64
65 macro(add_dependency_footer)
66 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " </graph>\n</graphml>\n")
67 endmacro()
68
69 macro(add_message_headers)
70 foreach(_in_FILE ${ARGN})
71 get_filename_component(FILE ${_in_FILE} NAME_WE)
72 macro_mc(${FILE})
73 add_custom_command(
74 OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h
75 COMMAND ${COMMAND_MC}
76 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)
77 set_source_files_properties(
78 ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc
79 PROPERTIES GENERATED TRUE)
80 add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc)
81 endforeach()
82 endmacro()
83
84 macro(dir_to_num dir var)
85 if(${dir} STREQUAL reactos/system32)
86 set(${var} 1)
87 elseif(${dir} STREQUAL reactos/system32/drivers)
88 set(${var} 2)
89 elseif(${dir} STREQUAL reactos/Fonts)
90 set(${var} 3)
91 elseif(${dir} STREQUAL reactos)
92 set(${var} 4)
93 elseif(${dir} STREQUAL reactos/system32/drivers/etc)
94 set(${var} 5)
95 elseif(${dir} STREQUAL reactos/inf)
96 set(${var} 6)
97 elseif(${dir} STREQUAL reactos/bin)
98 set(${var} 7)
99 elseif(${dir} STREQUAL reactos/media)
100 set(${var} 8)
101 else()
102 message(ERROR "Wrong destination: ${dir}")
103 endif()
104 endmacro()
105
106 function(add_cd_file)
107 cmake_parse_arguments(_CD "NO_CAB" "DESTINATION;NAME_ON_CD;TARGET" "FILE;FOR" ${ARGN})
108 if(NOT (_CD_TARGET OR _CD_FILE))
109 message(FATAL_ERROR "You must provide a target or a file to install!")
110 endif()
111
112 if(NOT _CD_DESTINATION)
113 message(FATAL_ERROR "You must provide a destination")
114 elseif(${_CD_DESTINATION} STREQUAL root)
115 set(_CD_DESTINATION "")
116 endif()
117
118 if(NOT _CD_FOR)
119 message(FATAL_ERROR "You must provide a cd name (or "all" for all of them) to install the file on!")
120 endif()
121
122 #get file if we need to
123 if(NOT _CD_FILE)
124 get_target_property(_CD_FILE ${_CD_TARGET} LOCATION)
125 endif()
126
127 #do we add it to all CDs?
128 if(_CD_FOR STREQUAL all)
129 set(_CD_FOR "bootcd;livecd;regtest")
130 endif()
131
132 #do we add it to bootcd?
133 list(FIND _CD_FOR bootcd __cd)
134 if(NOT __cd EQUAL -1)
135 #whether or not we should put it in reactos.cab or directly on cd
136 if(_CD_NO_CAB)
137 #directly on cd
138 foreach(item ${_CD_FILE})
139 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
140 endforeach()
141 if(_CD_NAME_ON_CD)
142 get_filename_component(__file ${_CD_FILE} NAME)
143 #rename it in the cd tree
144 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
145 endif()
146 if(_CD_TARGET)
147 #manage dependency
148 add_dependencies(bootcd ${_CD_TARGET})
149 endif()
150 else()
151 #add it in reactos.cab
152 dir_to_num(${_CD_DESTINATION} _num)
153 if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
154 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${_CD_FILE} ${_num}\n")
155 else()
156 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "\"${_CD_FILE}\" ${_num}\n")
157 endif()
158 if(_CD_TARGET)
159 #manage dependency
160 add_dependencies(reactos_cab ${_CD_TARGET})
161 endif()
162 endif()
163 endif() #end bootcd
164
165 #do we add it to livecd?
166 list(FIND _CD_FOR livecd __cd)
167 if(NOT __cd EQUAL -1)
168 #manage dependency
169 if(_CD_TARGET)
170 add_dependencies(livecd ${_CD_TARGET})
171 endif()
172 foreach(item ${_CD_FILE})
173 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
174 endforeach()
175 if(_CD_NAME_ON_CD)
176 get_filename_component(__file ${_CD_FILE} NAME)
177 #rename it in the cd tree
178 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
179 endif()
180 endif() #end livecd
181
182 endfunction()