[CMAKE]
[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;NO_LIVECD" "DESTINATION;NAME_ON_CD;TARGET" "FILE" ${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_FILE)
119 get_target_property(__file ${_CD_TARGET} LOCATION)
120 else()
121 if(NOT _CD_NO_CAB)
122 add_dependencies(reactos_cab ${_CD_FILE})
123 endif()
124 set(__file ${_CD_FILE})
125 endif()
126 #whether or not we should put it in reactos.cab or directly on cd
127 if(_CD_NO_CAB)
128 foreach(item ${__file})
129 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(COPY \"${item}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
130 endforeach()
131 if(_CD_NAME_ON_CD)
132 get_filename_component(__file ${__file} NAME)
133 #rename it in the cd tree
134 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootcd.cmake "file(RENAME \${CD_DIR}/${_CD_DESTINATION}/${__file} \${CD_DIR}/${_CD_DESTINATION}/${_CD_NAME_ON_CD})\n")
135 endif()
136 #add right dependency
137 if(_CD_TARGET)
138 add_dependencies(bootcd ${_CD_TARGET})
139 else()
140 add_dependencies(bootcd ${_CD_FILE})
141 endif()
142 if(NOT _CD_NO_LIVECD)
143 file(APPEND ${REACTOS_BINARY_DIR}/boot/livecd.cmake "file(COPY \"${__file}\" DESTINATION \"\${CD_DIR}/${_CD_DESTINATION}\")\n")
144 endif()
145 else()
146 #add right dependency
147 if(_CD_TARGET)
148 add_dependencies(reactos_cab ${_CD_TARGET})
149 else()
150 add_dependencies(reactos_cab ${_CD_FILE})
151 endif()
152 dir_to_num(${_CD_DESTINATION} _num)
153 file(APPEND ${REACTOS_BINARY_DIR}/boot/bootdata/packages/reactos.dff.dyn "${__file} ${_num}\n")
154 endif()
155 endfunction()