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