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