[EXT2] Upgrade to 0.69
[reactos.git] / boot / freeldr / freeldr / CMakeLists.txt
1
2 if(SEPARATE_DBG)
3 # FIXME: http://sourceware.org/bugzilla/show_bug.cgi?id=11822
4 set(CMAKE_LDR_PE_HELPER_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
5 set(CMAKE_LDR_PE_HELPER_STANDARD_LIBRARIES "-lgcc" CACHE STRING "Standard C Libraries")
6 endif()
7
8 if(MSVC)
9 # We don't need it here
10 replace_compile_flags("/hotpatch" " ")
11 endif()
12
13 spec2def(freeldr_pe.exe freeldr.spec)
14
15 if(ARCH STREQUAL "i386")
16 CreateBootSectorTarget(frldr16
17 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/i386.S
18 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
19 F800)
20 elseif(ARCH STREQUAL "amd64")
21 CreateBootSectorTarget(frldr16
22 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/amd64.S
23 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
24 F800)
25 endif()
26
27 include_directories(BEFORE include)
28 include_directories(${REACTOS_SOURCE_DIR}/ntoskrnl/include)
29 include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/cmlib)
30 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs)
31 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/elf)
32
33 add_definitions(-D_NTHAL_ -D_BLDR_ -D_NTSYSTEM_)
34
35
36 list(APPEND FREELDR_BOOTLIB_COMMON_SOURCE
37 lib/debug.c
38 lib/peloader.c
39
40 lib/comm/rs232.c
41 ## add KD support
42 lib/fs/ext2.c
43 lib/fs/fat.c
44 lib/fs/fs.c
45 lib/fs/iso.c
46 lib/fs/ntfs.c
47 lib/inifile/ini_init.c
48 lib/inifile/inifile.c
49 lib/inifile/parse.c
50 lib/mm/meminit.c
51 lib/mm/mm.c
52 lib/mm/heap.c
53 )
54
55 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
56 ntldr/conversion.c
57 ntldr/registry.c
58 ntldr/winldr.c
59 ntldr/wlmemory.c
60 ntldr/wlregistry.c
61 )
62
63 list(APPEND FREELDR_ARC_COMMON_SOURCE
64 arcname.c
65 machine.c
66 arch/archwsup.c
67 cache/blocklist.c
68 cache/cache.c
69 disk/disk.c
70 disk/partition.c
71 disk/ramdisk.c
72 #disk/scsiport.c
73 )
74
75 list(APPEND FREELDR_COMMON_SOURCE
76 include/freeldr.h
77 cmdline.c
78 custom.c
79 linuxboot.c
80 miscboot.c
81 options.c
82 oslist.c
83 version.c
84 ui/directui.c
85 ui/gui.c
86 ui/minitui.c
87 ui/noui.c
88 ui/tui.c
89 ui/tuimenu.c
90 ui/ui.c
91 video/fade.c
92 video/palette.c
93 video/video.c
94 )
95
96 if(ARCH STREQUAL "i386")
97 list(APPEND FREELDR_COMMON_ASM_SOURCE
98 arch/i386/entry.S
99 arch/i386/int386.S
100 arch/i386/pnpbios.S
101 arch/i386/i386trap.S
102 arch/i386/linux.S
103 arch/i386/mb.S
104 )
105
106 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
107 ntldr/arch/i386/winldr.c
108 ntldr/headless.c
109 )
110
111 ## list(APPEND FREELDR_COMMON_SOURCE
112 list(APPEND FREELDR_ARC_COMMON_SOURCE
113 lib/fs/pxe.c
114
115 arch/i386/halstub.c
116 arch/i386/ntoskrnl.c
117
118 arch/i386/archmach.c
119 arch/i386/drivemap.c
120 arch/i386/hardware.c
121 arch/i386/hwacpi.c
122 arch/i386/hwapm.c
123 arch/i386/hwdisk.c
124 arch/i386/hwpci.c
125 arch/i386/i386bug.c
126 arch/i386/i386idt.c
127 arch/i386/i386rtl.c
128 arch/i386/i386vid.c
129 arch/i386/machpc.c
130 arch/i386/pccons.c
131 arch/i386/pcdisk.c
132 arch/i386/pcmem.c
133 arch/i386/pcrtc.c
134 arch/i386/pcvideo.c
135 arch/i386/machxbox.c
136 arch/i386/xboxcons.c
137 arch/i386/xboxdisk.c
138 arch/i386/xboxfont.c
139 arch/i386/xboxi2c.c
140 arch/i386/xboxmem.c
141 arch/i386/xboxrtc.c
142 arch/i386/xboxvideo.c
143 disk/scsiport.c)
144 if(NOT MSVC)
145 list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
146 endif()
147 elseif(ARCH STREQUAL "amd64")
148 list(APPEND FREELDR_COMMON_ASM_SOURCE
149 arch/amd64/entry.S
150 arch/amd64/int386.S
151 arch/amd64/pnpbios.S)
152
153 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
154 ntldr/arch/amd64/winldr.c
155 )
156
157 ## list(APPEND FREELDR_COMMON_SOURCE
158 list(APPEND FREELDR_ARC_COMMON_SOURCE
159 lib/fs/pxe.c
160
161 arch/i386/ntoskrnl.c
162
163 arch/i386/drivemap.c
164 arch/i386/hardware.c
165 arch/i386/hwacpi.c
166 arch/i386/hwapm.c
167 arch/i386/hwdisk.c
168 arch/i386/hwpci.c
169 arch/i386/i386bug.c
170 arch/i386/i386rtl.c
171 arch/i386/i386vid.c
172 arch/i386/machpc.c
173 arch/i386/pccons.c
174 arch/i386/pcdisk.c
175 arch/i386/pcmem.c
176 arch/i386/pcrtc.c
177 arch/i386/pcvideo.c)
178 elseif(ARCH STREQUAL "arm")
179 list(APPEND FREELDR_COMMON_ASM_SOURCE
180 arch/arm/boot.S)
181
182 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
183 ntldr/arch/arm/winldr.c
184 )
185
186 ## list(APPEND FREELDR_COMMON_SOURCE
187 list(APPEND FREELDR_ARC_COMMON_SOURCE
188 arch/arm/entry.c
189 arch/arm/macharm.c)
190 else()
191 #TBD
192 endif()
193
194 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
195 add_library(freeldr_common ${FREELDR_BOOTLIB_COMMON_SOURCE} ${FREELDR_ARC_COMMON_SOURCE}
196 ${FREELDR_NTLDR_COMMON_SOURCE}
197 ${FREELDR_COMMON_SOURCE} ${freeldr_common_asm})
198 add_pch(freeldr_common include/freeldr.h FREELDR_COMMON_SOURCE)
199 add_dependencies(freeldr_common bugcodes asm xdk)
200
201 if(ARCH STREQUAL "i386" AND NOT MSVC)
202 list(APPEND FREELDR_BASE_SOURCE arch/i386/multiboot.S)
203 target_link_libraries(freeldr_common mini_hal)
204 endif()
205
206 list(APPEND FREELDR_BASE_SOURCE
207 bootmgr.c # This file is compiled with custom definitions
208 freeldr.c
209 ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
210 ## even if ${FREELDR_NTLDR_COMMON_SOURCE} is not added,
211 ## otherwise we get linking errors with Rtl**Bitmap** APIs.
212 ## Do not happen on MSVC builds however...
213 lib/inffile/inffile.c
214 lib/rtl/libsupp.c)
215
216 if(ARCH STREQUAL "i386")
217 # Must be included together with disk/scsiport.c
218 list(APPEND FREELDR_BASE_SOURCE
219 ${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
220 endif()
221
222 add_executable(freeldr_pe ${FREELDR_BASE_SOURCE})
223 add_executable(freeldr_pe_dbg EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
224
225 if(NOT MSVC AND SEPARATE_DBG)
226 set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
227 set_target_properties(freeldr_pe_dbg PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
228 endif()
229
230 if(MSVC)
231 if(ARCH STREQUAL "arm")
232 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER")
233 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER")
234 else()
235 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER /FIXED /ALIGN:0x400 /SECTION:.text,ERW /SECTION:.data,RW /MERGE:.text16=.text /MERGE:.data=.text /MERGE:.rdata=.text /MERGE:.bss=.text")
236 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER /FIXED /ALIGN:0x400 /SECTION:.text,ERW /SECTION:.data,RW /MERGE:.text16=.text /MERGE:.data=.text /MERGE:.rdata=.text /MERGE:.bss=.text")
237 endif()
238 else()
239 add_target_link_flags(freeldr_pe "-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
240 add_target_link_flags(freeldr_pe_dbg "-Wl,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
241 endif()
242
243 set_image_base(freeldr_pe 0x10000)
244 set_subsystem(freeldr_pe native)
245 set_entrypoint(freeldr_pe RealEntryPoint)
246
247 set_image_base(freeldr_pe_dbg 0x10000)
248 set_subsystem(freeldr_pe_dbg native)
249 set_entrypoint(freeldr_pe_dbg RealEntryPoint)
250
251 if(ARCH STREQUAL "i386")
252 target_link_libraries(freeldr_pe mini_hal)
253 target_link_libraries(freeldr_pe_dbg mini_hal)
254 endif()
255
256 target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
257 target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
258
259 if(STACK_PROTECTOR)
260 target_link_libraries(freeldr_pe gcc_ssp)
261 target_link_libraries(freeldr_pe_dbg gcc_ssp)
262 elseif(RUNTIME_CHECKS)
263 target_link_libraries(freeldr_pe runtmchk)
264 target_link_libraries(freeldr_pe_dbg runtmchk)
265 add_target_link_flags(freeldr_pe "/MERGE:.rtc=.text")
266 endif()
267
268 add_dependencies(freeldr_pe asm)
269 add_dependencies(freeldr_pe_dbg asm)
270
271 # Retrieve the full path to the generated file of the 'freeldr_pe' target
272 get_target_property(_freeldr_pe_output_file freeldr_pe LOCATION)
273
274 if(NOT ARCH STREQUAL "arm")
275 concatenate_files(
276 ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
277 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
278 ${_freeldr_pe_output_file})
279 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
280 else()
281 add_custom_target(freeldr ALL DEPENDS ${_freeldr_pe_output_file})
282 endif()
283
284 # rename freeldr on livecd to setupldr.sys because isoboot.bin looks for setupldr.sys
285 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
286 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB NOT_IN_HYBRIDCD FOR livecd hybridcd NAME_ON_CD setupldr.sys)
287
288 if(NOT ARCH STREQUAL "arm")
289 concatenate_files(
290 ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
291 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
292 ${_freeldr_pe_output_file})
293 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
294 else()
295 add_custom_target(setupldr ALL DEPENDS ${_freeldr_pe_output_file})
296 endif()
297
298 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)