1e7510893c463bfcae7c351ffda3ab72f71b86c3
[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 add_minicd(${_object_file} loader ${OBJECT_NAME})
26 endmacro()
27
28 else()
29
30 macro(CreateBootSectorTarget _target_name _asm_file _object_file)
31 endmacro()
32
33 endif()
34
35 macro(add_minicd_target _targetname _dir) # optional parameter: _nameoncd
36 if("${ARGN}" STREQUAL "")
37 get_target_property(FILENAME ${_targetname} LOCATION)
38 get_filename_component(_nameoncd ${FILENAME} NAME)
39 else()
40 set(_nameoncd ${ARGN})
41 endif()
42
43 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_minicd_target.txt "${_targetname}\t${_dir}\t${_nameoncd}\n")
44 endmacro()
45
46 macro(add_minicd FILENAME _dir _nameoncd)
47 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_minicd.txt "${FILENAME}\t${_dir}\t${_nameoncd}\n")
48 endmacro()
49
50 macro(set_cpp)
51 include_directories(BEFORE ${REACTOS_SOURCE_DIR}/include/c++/stlport)
52 set(IS_CPP 1)
53 add_definitions(
54 -DNATIVE_CPP_INCLUDE=${REACTOS_SOURCE_DIR}/include/c++
55 -DNATIVE_C_INCLUDE=${REACTOS_SOURCE_DIR}/include/crt)
56 endmacro()
57
58 macro(add_livecd_target _targetname _dir )# optional parameter : _nameoncd
59 if("${ARGN}" STREQUAL "")
60 get_target_property(FILENAME ${_targetname} LOCATION)
61 get_filename_component(_nameoncd ${FILENAME} NAME)
62 else()
63 set(_nameoncd ${ARGN})
64 endif()
65
66 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_livecd_target.txt "${_targetname}\t${_dir}\t${_nameoncd}\n")
67 endmacro()
68
69 macro(add_livecd FILENAME _dir)# optional parameter : _nameoncd
70 if("${ARGN}" STREQUAL "")
71 get_filename_component(_nameoncd ${FILENAME} NAME)
72 else()
73 set(_nameoncd ${ARGN})
74 endif()
75 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_livecd.txt "${FILENAME}\t${_dir}\t${_nameoncd}\n")
76 endmacro()
77
78 macro(cab_to_dir _dir_num _var_name)
79 # 1 = system32
80 # 2 = system32\drivers
81 # 3 = Fonts
82 # 4 =
83 # 5 = system32\drivers\etc
84 # 6 = inf
85 # 7 = bin
86 # 8 = media
87 if(${_dir_num} STREQUAL "1")
88 set(${_var_name} "reactos/system32")
89 elseif(${_dir_num} STREQUAL "2")
90 set(${_var_name} "reactos/system32/drivers")
91 elseif(${_dir_num} STREQUAL "3")
92 set(${_var_name} "reactos/fonts")
93 elseif(${_dir_num} STREQUAL "4")
94 set(${_var_name} "reactos")
95 elseif(${_dir_num} STREQUAL "5")
96 set(${_var_name} "reactos/system32/drivers/etc")
97 elseif(${_dir_num} STREQUAL "6")
98 set(${_var_name} "reactos/inf")
99 elseif(${_dir_num} STREQUAL "7")
100 set(${_var_name} "reactos/bin")
101 elseif(${_dir_num} STREQUAL "8")
102 set(${_var_name} "reactos/system32/drivers")
103 else()
104 message(FATAL_ERROR "Wrong directory ${_dir_num}")
105 endif()
106 endmacro()
107
108 macro(add_cab_target _targetname _num )
109 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab_target.txt "${_targetname}\t${_num}\n")
110 cab_to_dir(${_num} _dir)
111 add_livecd_target(${_targetname} ${_dir})
112 endmacro()
113
114 macro(add_cab FILENAME _num)
115 file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab.txt "${FILENAME}\t${_num}\n")
116 cab_to_dir(${_num} _dir)
117 add_livecd(${FILENAME} ${_dir})
118 endmacro()
119
120 macro(add_dependency_node _node)
121 if(GENERATE_DEPENDENCY_GRAPH)
122 get_target_property(_type ${_node} TYPE)
123 if(_type MATCHES SHARED_LIBRARY)
124 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <node id=\"${_node}\"/>\n")
125 endif()
126 endif()
127 endmacro()
128
129 macro(add_dependency_edge _source _target)
130 if(GENERATE_DEPENDENCY_GRAPH)
131 get_target_property(_type ${_source} TYPE)
132 if(_type MATCHES SHARED_LIBRARY)
133 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " <edge source=\"${_source}\" target=\"${_target}\"/>\n")
134 endif()
135 endif()
136 endmacro()
137
138 macro(add_dependency_header)
139 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<graphml>\n <graph id=\"ReactOS dependencies\" edgedefault=\"directed\">\n")
140 add_dependency_node(ntdll)
141 endmacro()
142
143 macro(add_dependency_footer)
144 file(APPEND ${REACTOS_BINARY_DIR}/dependencies.graphml " </graph>\n</graphml>\n")
145 endmacro()
146
147 macro(add_message_headers)
148 foreach(_in_FILE ${ARGN})
149 get_filename_component(FILE ${_in_FILE} NAME_WE)
150 macro_mc(${FILE})
151 add_custom_command(
152 OUTPUT ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h
153 COMMAND ${COMMAND_MC}
154 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)
155 set_source_files_properties(
156 ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc
157 PROPERTIES GENERATED TRUE)
158 add_custom_target(${FILE} ALL DEPENDS ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.h ${REACTOS_BINARY_DIR}/include/reactos/${FILE}.rc)
159 endforeach()
160 endmacro()
161