d4263050ad4187aa16dc2256f454a370f312ddc0
[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_INIT "")
6 set(CMAKE_LDR_PE_HELPER_STANDARD_LIBRARIES "-lgcc" CACHE STRING "Standard C Libraries")
7 endif()
8
9 if(MSVC)
10 # We don't need hotpatching
11 replace_compile_flags("/hotpatch" " ")
12
13 # Explicitly use string pooling
14 add_compile_flags("/GF")
15 endif()
16
17 spec2def(freeldr_pe.exe freeldr.spec)
18
19 if(ARCH STREQUAL "i386")
20 CreateBootSectorTarget(frldr16
21 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/i386.S
22 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
23 F800)
24 elseif(ARCH STREQUAL "amd64")
25 CreateBootSectorTarget(frldr16
26 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/amd64.S
27 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
28 F800)
29 endif()
30
31 include_directories(BEFORE include)
32 include_directories(${REACTOS_SOURCE_DIR}/ntoskrnl/include)
33 include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/cmlib)
34 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs)
35 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/elf)
36
37 add_definitions(-D_NTHAL_ -D_BLDR_ -D_NTSYSTEM_)
38
39 list(APPEND FREELDR_BOOTLIB_SOURCE
40 lib/arcsupp.c
41 lib/debug.c
42 lib/peloader.c
43 lib/comm/rs232.c
44 ## add KD support
45 lib/fs/btrfs.c
46 lib/fs/ext2.c
47 lib/fs/fat.c
48 lib/fs/fs.c
49 lib/fs/iso.c
50 lib/fs/ntfs.c
51 lib/inifile/ini_init.c
52 lib/inifile/inifile.c
53 lib/inifile/parse.c
54 lib/mm/meminit.c
55 lib/mm/mm.c
56 lib/mm/heap.c)
57
58 list(APPEND FREELDR_NTLDR_SOURCE
59 ntldr/conversion.c
60 ntldr/registry.c
61 ntldr/winldr.c
62 ntldr/wlmemory.c
63 ntldr/wlregistry.c)
64
65 list(APPEND FREELDR_ARC_SOURCE
66 arcname.c
67 machine.c
68 arch/archwsup.c
69 cache/blocklist.c
70 cache/cache.c
71 disk/disk.c
72 disk/partition.c
73 disk/ramdisk.c)
74 #disk/scsiport.c
75
76 list(APPEND FREELDR_BOOTMGR_SOURCE
77 include/freeldr.h
78 cmdline.c
79 custom.c
80 linuxboot.c
81 miscboot.c
82 options.c
83 oslist.c
84 version.c
85 ui/directui.c
86 ui/gui.c
87 ui/minitui.c
88 ui/noui.c
89 ui/tui.c
90 ui/tuimenu.c
91 ui/ui.c
92 video/fade.c
93 video/palette.c
94 video/video.c)
95
96 list(APPEND FREELDR_BASE_ASM_SOURCE)
97
98 if(ARCH STREQUAL "i386")
99 list(APPEND FREELDR_BASE_ASM_SOURCE
100 arch/i386/multiboot.S)
101
102 list(APPEND FREELDR_COMMON_ASM_SOURCE
103 arch/i386/drvmap.S
104 arch/i386/entry.S
105 arch/i386/int386.S
106 arch/i386/pnpbios.S
107 arch/i386/i386trap.S
108 arch/i386/linux.S)
109
110 list(APPEND FREELDR_NTLDR_SOURCE
111 ntldr/arch/i386/winldr.c
112 ntldr/headless.c)
113
114 list(APPEND FREELDR_ARC_SOURCE
115 lib/fs/pxe.c
116 arch/i386/halstub.c
117 arch/i386/ntoskrnl.c
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
145 elseif(ARCH STREQUAL "amd64")
146 list(APPEND FREELDR_COMMON_ASM_SOURCE
147 arch/amd64/entry.S
148 arch/amd64/int386.S
149 arch/amd64/pnpbios.S)
150
151 list(APPEND FREELDR_NTLDR_SOURCE
152 ntldr/arch/amd64/winldr.c)
153
154 list(APPEND FREELDR_ARC_SOURCE
155 lib/fs/pxe.c
156 arch/i386/ntoskrnl.c
157 arch/i386/drivemap.c
158 arch/i386/hardware.c
159 arch/i386/hwacpi.c
160 arch/i386/hwapm.c
161 arch/i386/hwdisk.c
162 arch/i386/hwpci.c
163 arch/i386/i386bug.c
164 arch/i386/i386rtl.c
165 arch/i386/i386vid.c
166 arch/i386/machpc.c
167 arch/i386/pccons.c
168 arch/i386/pcdisk.c
169 arch/i386/pcmem.c
170 arch/i386/pcrtc.c
171 arch/i386/pcvideo.c)
172
173 elseif(ARCH STREQUAL "arm")
174 list(APPEND FREELDR_COMMON_ASM_SOURCE
175 arch/arm/boot.S)
176
177 list(APPEND FREELDR_NTLDR_SOURCE
178 ntldr/arch/arm/winldr.c)
179
180 list(APPEND FREELDR_ARC_SOURCE
181 arch/arm/entry.c
182 arch/arm/macharm.c)
183 else()
184 #TBD
185 endif()
186
187 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
188
189 add_library(freeldr_common
190 ${freeldr_common_asm}
191 ${FREELDR_BOOTLIB_SOURCE}
192 ${FREELDR_ARC_SOURCE}
193 ${FREELDR_NTLDR_SOURCE}
194 ${FREELDR_BOOTMGR_SOURCE})
195
196 if(USE_CLANG_CL)
197 # We need to reduce the binary size
198 add_target_compile_flags(freeldr_common "/Os")
199 endif()
200 if(NOT MSVC AND ARCH STREQUAL "i386")
201 # Prevent a warning when doing a memcmp with address 0
202 set_source_files_properties(arch/i386/xboxmem.c PROPERTIES COMPILE_FLAGS "-Wno-nonnull")
203 endif()
204
205 set(PCH_SOURCE
206 ${FREELDR_BOOTLIB_SOURCE}
207 ${FREELDR_ARC_SOURCE}
208 ${FREELDR_NTLDR_SOURCE}
209 ${FREELDR_BOOTMGR_SOURCE})
210
211 add_pch(freeldr_common include/freeldr.h PCH_SOURCE)
212 add_dependencies(freeldr_common bugcodes asm xdk)
213
214 ## GCC builds need this extra thing for some reason...
215 if(ARCH STREQUAL "i386" AND NOT MSVC)
216 target_link_libraries(freeldr_common mini_hal)
217 endif()
218
219 add_asm_files(freeldr_base_asm ${FREELDR_BASE_ASM_SOURCE})
220
221 list(APPEND FREELDR_BASE_SOURCE
222 ${freeldr_base_asm}
223 bootmgr.c # This file is compiled with custom definitions
224 freeldr.c
225 ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
226 ## even if ${FREELDR_NTLDR_SOURCE} is not added,
227 ## otherwise we get linking errors with Rtl**Bitmap** APIs.
228 ## Do not happen on MSVC builds however...
229 lib/inffile/inffile.c
230 lib/rtl/libsupp.c)
231
232 if(ARCH STREQUAL "i386")
233 # Must be included together with disk/scsiport.c
234 list(APPEND FREELDR_BASE_SOURCE
235 ${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
236 endif()
237
238 add_executable(freeldr_pe ${FREELDR_BASE_SOURCE})
239 add_executable(freeldr_pe_dbg EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
240
241 set_target_properties(freeldr_pe freeldr_pe_dbg
242 PROPERTIES
243 ENABLE_EXPORTS TRUE
244 DEFINE_SYMBOL "")
245
246 if(NOT MSVC AND SEPARATE_DBG)
247 set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
248 set_target_properties(freeldr_pe_dbg PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
249 endif()
250
251 if(MSVC)
252 if(ARCH STREQUAL "arm")
253 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER")
254 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER")
255 else()
256 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER /FIXED /FILEALIGN:0x200 /ALIGN:0x200")
257 add_linker_script(freeldr_pe freeldr_i386.msvc.lds)
258 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER /FIXED /FILEALIGN:0x200 /ALIGN:0x200")
259 add_linker_script(freeldr_pe_dbg freeldr_i386.msvc.lds)
260 endif()
261 else()
262 add_target_link_flags(freeldr_pe "-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x200,--section-alignment,0x200")
263 add_linker_script(freeldr_pe freeldr_i386.lds)
264 add_target_link_flags(freeldr_pe_dbg "-Wl,--exclude-all-symbols,--file-alignment,0x200,--section-alignment,0x200")
265 add_linker_script(freeldr_pe_dbg freeldr_i386.lds)
266 endif()
267
268 set_image_base(freeldr_pe 0x10000)
269 set_subsystem(freeldr_pe native)
270 set_entrypoint(freeldr_pe RealEntryPoint)
271
272 set_image_base(freeldr_pe_dbg 0x10000)
273 set_subsystem(freeldr_pe_dbg native)
274 set_entrypoint(freeldr_pe_dbg RealEntryPoint)
275
276 if(ARCH STREQUAL "i386")
277 target_link_libraries(freeldr_pe mini_hal)
278 target_link_libraries(freeldr_pe_dbg mini_hal)
279 endif()
280
281 target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
282 target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
283
284 if(STACK_PROTECTOR)
285 target_link_libraries(freeldr_pe gcc_ssp)
286 target_link_libraries(freeldr_pe_dbg gcc_ssp)
287 elseif(RUNTIME_CHECKS)
288 target_link_libraries(freeldr_pe runtmchk)
289 target_link_libraries(freeldr_pe_dbg runtmchk)
290 add_target_link_flags(freeldr_pe "/MERGE:.rtc=.text")
291 endif()
292
293 add_dependencies(freeldr_pe asm)
294 add_dependencies(freeldr_pe_dbg asm)
295
296 if(NOT ARCH STREQUAL "arm")
297 concatenate_files(
298 ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
299 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
300 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
301 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
302 else()
303 add_custom_target(freeldr ALL DEPENDS freeldr_pe)
304 endif()
305
306 # Rename freeldr on livecd to setupldr.sys because isoboot.bin looks for setupldr.sys
307 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
308 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)
309
310 if(NOT ARCH STREQUAL "arm")
311 concatenate_files(
312 ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
313 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
314 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
315 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
316 else()
317 add_custom_target(setupldr ALL DEPENDS freeldr_pe)
318 endif()
319
320 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)