53eaca33b743488f41d10c0b7c197fba4e26229f
[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/cache/blocklist.c
44 lib/cache/cache.c
45 lib/comm/rs232.c
46 ## add KD support
47 lib/fs/btrfs.c
48 lib/fs/ext2.c
49 lib/fs/fat.c
50 lib/fs/fs.c
51 lib/fs/iso.c
52 lib/fs/ntfs.c
53 lib/inifile/ini_init.c
54 lib/inifile/inifile.c
55 lib/inifile/parse.c
56 lib/mm/meminit.c
57 lib/mm/mm.c
58 lib/mm/heap.c)
59
60 list(APPEND FREELDR_NTLDR_SOURCE
61 ntldr/conversion.c
62 ntldr/registry.c
63 ntldr/winldr.c
64 ntldr/wlmemory.c
65 ntldr/wlregistry.c)
66
67 list(APPEND FREELDR_ARC_SOURCE
68 arcname.c
69 arch/arcemul.c
70 arch/archwsup.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 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 ui/video.c)
92
93 list(APPEND FREELDR_BASE_ASM_SOURCE)
94
95 if(ARCH STREQUAL "i386")
96 list(APPEND FREELDR_BASE_ASM_SOURCE
97 arch/i386/multiboot.S)
98
99 list(APPEND FREELDR_COMMON_ASM_SOURCE
100 arch/i386/drvmap.S
101 arch/i386/entry.S
102 arch/i386/int386.S
103 arch/i386/pnpbios.S
104 arch/i386/i386trap.S
105 arch/i386/linux.S)
106
107 list(APPEND FREELDR_NTLDR_SOURCE
108 ntldr/arch/i386/winldr.c
109 ntldr/headless.c)
110
111 list(APPEND FREELDR_ARC_SOURCE
112 lib/fs/pxe.c
113 arch/i386/halstub.c
114 arch/i386/ntoskrnl.c
115 arch/i386/archmach.c
116 arch/i386/drivemap.c
117 arch/i386/hardware.c
118 arch/i386/hwacpi.c
119 arch/i386/hwapm.c
120 arch/i386/hwdisk.c
121 arch/i386/hwpci.c
122 arch/i386/i386bug.c
123 arch/i386/i386idt.c
124 arch/i386/i386rtl.c
125 arch/i386/i386vid.c
126 arch/i386/machpc.c
127 arch/i386/pccons.c
128 arch/i386/pcdisk.c
129 arch/i386/pcmem.c
130 arch/i386/pcrtc.c
131 arch/i386/pcvideo.c
132 arch/i386/machxbox.c
133 arch/i386/xboxcons.c
134 arch/i386/xboxdisk.c
135 arch/i386/xboxfont.c
136 arch/i386/xboxi2c.c
137 arch/i386/xboxmem.c
138 arch/i386/xboxrtc.c
139 arch/i386/xboxvideo.c
140 disk/scsiport.c)
141
142 elseif(ARCH STREQUAL "amd64")
143 list(APPEND FREELDR_COMMON_ASM_SOURCE
144 arch/amd64/entry.S
145 arch/amd64/int386.S
146 arch/amd64/pnpbios.S)
147
148 list(APPEND FREELDR_NTLDR_SOURCE
149 ntldr/arch/amd64/winldr.c)
150
151 list(APPEND FREELDR_ARC_SOURCE
152 lib/fs/pxe.c
153 arch/i386/ntoskrnl.c
154 arch/i386/drivemap.c
155 arch/i386/hardware.c
156 arch/i386/hwacpi.c
157 arch/i386/hwapm.c
158 arch/i386/hwdisk.c
159 arch/i386/hwpci.c
160 arch/i386/i386bug.c
161 arch/i386/i386rtl.c
162 arch/i386/i386vid.c
163 arch/i386/machpc.c
164 arch/i386/pccons.c
165 arch/i386/pcdisk.c
166 arch/i386/pcmem.c
167 arch/i386/pcrtc.c
168 arch/i386/pcvideo.c)
169
170 elseif(ARCH STREQUAL "arm")
171 list(APPEND FREELDR_COMMON_ASM_SOURCE
172 arch/arm/boot.S)
173
174 list(APPEND FREELDR_NTLDR_SOURCE
175 ntldr/arch/arm/winldr.c)
176
177 list(APPEND FREELDR_ARC_SOURCE
178 arch/arm/entry.c
179 arch/arm/macharm.c)
180 else()
181 #TBD
182 endif()
183
184 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
185
186 add_library(freeldr_common
187 ${freeldr_common_asm}
188 ${FREELDR_BOOTLIB_SOURCE}
189 ${FREELDR_ARC_SOURCE}
190 ${FREELDR_NTLDR_SOURCE}
191 ${FREELDR_BOOTMGR_SOURCE})
192
193 if(USE_CLANG_CL)
194 # We need to reduce the binary size
195 add_target_compile_flags(freeldr_common "/Os")
196 endif()
197 if(NOT MSVC AND ARCH STREQUAL "i386")
198 # Prevent a warning when doing a memcmp with address 0
199 set_source_files_properties(arch/i386/xboxmem.c PROPERTIES COMPILE_FLAGS "-Wno-nonnull")
200 endif()
201
202 set(PCH_SOURCE
203 ${FREELDR_BOOTLIB_SOURCE}
204 ${FREELDR_ARC_SOURCE}
205 ${FREELDR_NTLDR_SOURCE}
206 ${FREELDR_BOOTMGR_SOURCE})
207
208 add_pch(freeldr_common include/freeldr.h PCH_SOURCE)
209 add_dependencies(freeldr_common bugcodes asm xdk)
210
211 ## GCC builds need this extra thing for some reason...
212 if(ARCH STREQUAL "i386" AND NOT MSVC)
213 target_link_libraries(freeldr_common mini_hal)
214 endif()
215
216 add_asm_files(freeldr_base_asm ${FREELDR_BASE_ASM_SOURCE})
217
218 list(APPEND FREELDR_BASE_SOURCE
219 ${freeldr_base_asm}
220 bootmgr.c # This file is compiled with custom definitions
221 freeldr.c
222 ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
223 ## even if ${FREELDR_NTLDR_SOURCE} is not added,
224 ## otherwise we get linking errors with Rtl**Bitmap** APIs.
225 ## Do not happen on MSVC builds however...
226 ntldr/inffile.c
227 lib/rtl/libsupp.c)
228
229 if(ARCH STREQUAL "i386")
230 # Must be included together with disk/scsiport.c
231 list(APPEND FREELDR_BASE_SOURCE
232 ${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
233 endif()
234
235 add_executable(freeldr_pe ${FREELDR_BASE_SOURCE})
236 add_executable(freeldr_pe_dbg EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
237
238 set_target_properties(freeldr_pe freeldr_pe_dbg
239 PROPERTIES
240 ENABLE_EXPORTS TRUE
241 DEFINE_SYMBOL "")
242
243 if(NOT MSVC AND SEPARATE_DBG)
244 set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
245 set_target_properties(freeldr_pe_dbg PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
246 endif()
247
248 if(MSVC)
249 if(ARCH STREQUAL "arm")
250 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER")
251 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER")
252 else()
253 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER /FIXED /FILEALIGN:0x200 /ALIGN:0x200")
254 add_linker_script(freeldr_pe freeldr_i386.msvc.lds)
255 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER /FIXED /FILEALIGN:0x200 /ALIGN:0x200")
256 add_linker_script(freeldr_pe_dbg freeldr_i386.msvc.lds)
257 endif()
258 else()
259 add_target_link_flags(freeldr_pe "-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x200,--section-alignment,0x200")
260 add_linker_script(freeldr_pe freeldr_i386.lds)
261 add_target_link_flags(freeldr_pe_dbg "-Wl,--exclude-all-symbols,--file-alignment,0x200,--section-alignment,0x200")
262 add_linker_script(freeldr_pe_dbg freeldr_i386.lds)
263 endif()
264
265 set_image_base(freeldr_pe 0x10000)
266 set_subsystem(freeldr_pe native)
267 set_entrypoint(freeldr_pe RealEntryPoint)
268
269 set_image_base(freeldr_pe_dbg 0x10000)
270 set_subsystem(freeldr_pe_dbg native)
271 set_entrypoint(freeldr_pe_dbg RealEntryPoint)
272
273 if(ARCH STREQUAL "i386")
274 target_link_libraries(freeldr_pe mini_hal)
275 target_link_libraries(freeldr_pe_dbg mini_hal)
276 endif()
277
278 target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
279 target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
280
281 if(STACK_PROTECTOR)
282 target_link_libraries(freeldr_pe gcc_ssp)
283 target_link_libraries(freeldr_pe_dbg gcc_ssp)
284 elseif(RUNTIME_CHECKS)
285 target_link_libraries(freeldr_pe runtmchk)
286 target_link_libraries(freeldr_pe_dbg runtmchk)
287 add_target_link_flags(freeldr_pe "/MERGE:.rtc=.text")
288 endif()
289
290 add_dependencies(freeldr_pe asm)
291 add_dependencies(freeldr_pe_dbg asm)
292
293 if(NOT ARCH STREQUAL "arm")
294 concatenate_files(
295 ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
296 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
297 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
298 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
299 else()
300 add_custom_target(freeldr ALL DEPENDS freeldr_pe)
301 endif()
302
303 # Rename freeldr on livecd to setupldr.sys because isoboot.bin looks for setupldr.sys
304 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
305 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)
306
307 if(NOT ARCH STREQUAL "arm")
308 concatenate_files(
309 ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
310 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
311 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
312 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
313 else()
314 add_custom_target(setupldr ALL DEPENDS freeldr_pe)
315 endif()
316
317 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)