63d985e920f1dac4570d70b425cfa0b43e95702b
[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/ext2.c
41 lib/fs/fat.c
42 lib/fs/fs.c
43 lib/fs/iso.c
44 lib/fs/ntfs.c
45 lib/inifile/ini_init.c
46 lib/inifile/inifile.c
47 lib/inifile/parse.c
48 lib/mm/meminit.c
49 lib/mm/mm.c
50 lib/mm/heap.c)
51
52 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
53 ntldr/conversion.c
54 ntldr/registry.c
55 ntldr/winldr.c
56 ntldr/wlmemory.c
57 ntldr/wlregistry.c)
58
59 list(APPEND FREELDR_ARC_COMMON_SOURCE
60 arcname.c
61 machine.c
62 arch/archwsup.c
63 cache/blocklist.c
64 cache/cache.c
65 disk/disk.c
66 disk/partition.c
67 disk/ramdisk.c)
68 #disk/scsiport.c
69
70 list(APPEND FREELDR_COMMON_SOURCE
71 include/freeldr.h
72 cmdline.c
73 custom.c
74 linuxboot.c
75 miscboot.c
76 options.c
77 oslist.c
78 version.c
79 ui/directui.c
80 ui/gui.c
81 ui/minitui.c
82 ui/noui.c
83 ui/tui.c
84 ui/tuimenu.c
85 ui/ui.c
86 video/fade.c
87 video/palette.c
88 video/video.c)
89
90 if(ARCH STREQUAL "i386")
91 list(APPEND FREELDR_COMMON_ASM_SOURCE
92 arch/i386/entry.S
93 arch/i386/int386.S
94 arch/i386/pnpbios.S
95 arch/i386/i386trap.S
96 arch/i386/linux.S
97 arch/i386/mb.S)
98
99 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
100 ntldr/arch/i386/winldr.c
101 ntldr/headless.c)
102
103 list(APPEND FREELDR_ARC_COMMON_SOURCE
104 lib/fs/pxe.c
105 arch/i386/halstub.c
106 arch/i386/ntoskrnl.c
107 arch/i386/archmach.c
108 arch/i386/drivemap.c
109 arch/i386/hardware.c
110 arch/i386/hwacpi.c
111 arch/i386/hwapm.c
112 arch/i386/hwdisk.c
113 arch/i386/hwpci.c
114 arch/i386/i386bug.c
115 arch/i386/i386idt.c
116 arch/i386/i386rtl.c
117 arch/i386/i386vid.c
118 arch/i386/machpc.c
119 arch/i386/pccons.c
120 arch/i386/pcdisk.c
121 arch/i386/pcmem.c
122 arch/i386/pcrtc.c
123 arch/i386/pcvideo.c
124 arch/i386/machxbox.c
125 arch/i386/xboxcons.c
126 arch/i386/xboxdisk.c
127 arch/i386/xboxfont.c
128 arch/i386/xboxi2c.c
129 arch/i386/xboxmem.c
130 arch/i386/xboxrtc.c
131 arch/i386/xboxvideo.c
132 disk/scsiport.c)
133 if(NOT MSVC)
134 list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
135 endif()
136 elseif(ARCH STREQUAL "amd64")
137 list(APPEND FREELDR_COMMON_ASM_SOURCE
138 arch/amd64/entry.S
139 arch/amd64/int386.S
140 arch/amd64/pnpbios.S)
141
142 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
143 ntldr/arch/amd64/winldr.c)
144
145 list(APPEND FREELDR_ARC_COMMON_SOURCE
146 lib/fs/pxe.c
147 arch/i386/ntoskrnl.c
148 arch/i386/drivemap.c
149 arch/i386/hardware.c
150 arch/i386/hwacpi.c
151 arch/i386/hwapm.c
152 arch/i386/hwdisk.c
153 arch/i386/hwpci.c
154 arch/i386/i386bug.c
155 arch/i386/i386rtl.c
156 arch/i386/i386vid.c
157 arch/i386/machpc.c
158 arch/i386/pccons.c
159 arch/i386/pcdisk.c
160 arch/i386/pcmem.c
161 arch/i386/pcrtc.c
162 arch/i386/pcvideo.c)
163 elseif(ARCH STREQUAL "arm")
164 list(APPEND FREELDR_COMMON_ASM_SOURCE
165 arch/arm/boot.S)
166
167 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
168 ntldr/arch/arm/winldr.c)
169
170 list(APPEND FREELDR_ARC_COMMON_SOURCE
171 arch/arm/entry.c
172 arch/arm/macharm.c)
173 else()
174 #TBD
175 endif()
176
177 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
178
179 add_library(freeldr_common
180 ${FREELDR_BOOTLIB_COMMON_SOURCE}
181 ${FREELDR_ARC_COMMON_SOURCE}
182 ${FREELDR_NTLDR_COMMON_SOURCE}
183 ${FREELDR_COMMON_SOURCE}
184 ${freeldr_common_asm}
185 linuxboot.c)
186
187 if(USE_CLANG_CL)
188 # We need to reduce the binary size
189 add_target_compile_flags(freeldr_common "/Os")
190 endif()
191
192 set(PCH_SOURCE
193 ${FREELDR_BOOTLIB_COMMON_SOURCE}
194 ${FREELDR_ARC_COMMON_SOURCE}
195 ${FREELDR_NTLDR_COMMON_SOURCE}
196 ${FREELDR_COMMON_SOURCE})
197
198 add_pch(freeldr_common include/freeldr.h PCH_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 if(NOT ARCH STREQUAL "arm")
272 concatenate_files(
273 ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
274 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
275 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
276 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
277 else()
278 add_custom_target(freeldr ALL DEPENDS freeldr_pe)
279 endif()
280
281 # rename freeldr on livecd to setupldr.sys because isoboot.bin looks for setupldr.sys
282 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
283 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)
284
285 if(NOT ARCH STREQUAL "arm")
286 concatenate_files(
287 ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
288 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
289 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
290 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
291 else()
292 add_custom_target(setupldr ALL DEPENDS freeldr_pe)
293 endif()
294
295 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)