[FREELDR]: Continue removing code not related to freeldr entry-point from entry.S...
[reactos.git] / reactos / 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_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <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}/lib/cmlib)
30 include_directories(${REACTOS_SOURCE_DIR}/include/reactos/libs)
31 include_directories(${REACTOS_SOURCE_DIR}/include/reactos/elf)
32
33 add_definitions(-D_NTHAL_ -D_BLDR_ -D_NTSYSTEM_)
34
35
36 list(APPEND FREELDR_BOOTLIB_COMMON_SOURCE
37 lib/debug.c
38 lib/peloader.c
39
40 lib/comm/rs232.c
41 ## add KD support
42 lib/fs/ext2.c
43 lib/fs/fat.c
44 lib/fs/fs.c
45 lib/fs/iso.c
46 lib/fs/ntfs.c
47 lib/inifile/ini_init.c
48 lib/inifile/inifile.c
49 lib/inifile/parse.c
50 lib/mm/meminit.c
51 lib/mm/mm.c
52 lib/mm/heap.c
53 )
54
55 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
56 ntldr/conversion.c
57 ntldr/registry.c
58 ntldr/winldr.c
59 ntldr/wlmemory.c
60 ntldr/wlregistry.c
61 )
62
63 list(APPEND FREELDR_ARC_COMMON_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
75 list(APPEND FREELDR_COMMON_SOURCE
76 include/freeldr.h
77 cmdline.c
78 custom.c
79 linuxboot.c
80 miscboot.c
81 options.c
82 oslist.c
83 version.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 video/fade.c
92 video/palette.c
93 video/video.c
94 )
95
96 if(ARCH STREQUAL "i386")
97 list(APPEND FREELDR_COMMON_ASM_SOURCE
98 arch/i386/entry.S
99 arch/i386/int386.S
100 arch/i386/pnpbios.S
101 arch/i386/i386trap.S
102 arch/i386/linux.S
103 arch/i386/mb.S
104 )
105
106 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
107 ntldr/arch/i386/winldr.c
108 ntldr/headless.c
109 )
110
111 ## list(APPEND FREELDR_COMMON_SOURCE
112 list(APPEND FREELDR_ARC_COMMON_SOURCE
113 lib/fs/pxe.c
114
115 arch/i386/halstub.c
116 arch/i386/ntoskrnl.c
117
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/i386disk.c
127 arch/i386/i386idt.c
128 arch/i386/i386rtl.c
129 arch/i386/i386vid.c
130 arch/i386/machpc.c
131 arch/i386/pccons.c
132 arch/i386/pcdisk.c
133 arch/i386/pcmem.c
134 arch/i386/pcrtc.c
135 arch/i386/pcvideo.c
136 arch/i386/machxbox.c
137 arch/i386/xboxcons.c
138 arch/i386/xboxdisk.c
139 arch/i386/xboxfont.c
140 arch/i386/xboxhw.c
141 arch/i386/xboxi2c.c
142 arch/i386/xboxmem.c
143 arch/i386/xboxrtc.c
144 arch/i386/xboxvideo.c
145 disk/scsiport.c)
146 if(NOT MSVC)
147 list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
148 endif()
149 elseif(ARCH STREQUAL "amd64")
150 list(APPEND FREELDR_COMMON_ASM_SOURCE
151 arch/amd64/entry.S
152 arch/amd64/int386.S
153 arch/amd64/pnpbios.S)
154
155 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
156 ntldr/arch/amd64/winldr.c
157 )
158
159 ## list(APPEND FREELDR_COMMON_SOURCE
160 list(APPEND FREELDR_ARC_COMMON_SOURCE
161 lib/fs/pxe.c
162
163 arch/i386/ntoskrnl.c
164
165 arch/i386/drivemap.c
166 arch/i386/hardware.c
167 arch/i386/hwacpi.c
168 arch/i386/hwapm.c
169 arch/i386/hwdisk.c
170 arch/i386/hwpci.c
171 arch/i386/i386bug.c
172 arch/i386/i386rtl.c
173 arch/i386/i386disk.c
174 arch/i386/i386vid.c
175 arch/i386/machpc.c
176 arch/i386/pccons.c
177 arch/i386/pcdisk.c
178 arch/i386/pcmem.c
179 arch/i386/pcrtc.c
180 arch/i386/pcvideo.c)
181 elseif(ARCH STREQUAL "arm")
182 list(APPEND FREELDR_COMMON_ASM_SOURCE
183 arch/arm/boot.S)
184
185 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
186 ntldr/arch/arm/winldr.c
187 )
188
189 ## list(APPEND FREELDR_COMMON_SOURCE
190 list(APPEND FREELDR_ARC_COMMON_SOURCE
191 arch/arm/entry.c
192 arch/arm/macharm.c)
193 else()
194 #TBD
195 endif()
196
197 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
198 add_library(freeldr_common ${FREELDR_BOOTLIB_COMMON_SOURCE} ${FREELDR_ARC_COMMON_SOURCE}
199 ${FREELDR_NTLDR_COMMON_SOURCE}
200 ${FREELDR_COMMON_SOURCE} ${freeldr_common_asm})
201 add_pch(freeldr_common include/freeldr.h FREELDR_COMMON_SOURCE)
202 add_dependencies(freeldr_common bugcodes asm xdk)
203
204 if(ARCH STREQUAL "i386" AND NOT MSVC)
205 list(APPEND FREELDR_BASE_SOURCE arch/i386/multiboot.S)
206 target_link_libraries(freeldr_common mini_hal)
207 endif()
208
209 list(APPEND FREELDR_BASE_SOURCE
210 bootmgr.c # This file is compiled with custom definitions
211 freeldr.c
212 ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
213 ## even if ${FREELDR_NTLDR_COMMON_SOURCE} is not added,
214 ## otherwise we get linking errors with Rtl**Bitmap** APIs.
215 ## Do not happen on MSVC builds however...
216 lib/inffile/inffile.c
217 lib/rtl/libsupp.c)
218
219 if(ARCH STREQUAL "i386")
220 # Must be included together with disk/scsiport.c
221 list(APPEND FREELDR_BASE_SOURCE
222 ${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
223 endif()
224
225 add_executable(freeldr_pe ${FREELDR_BASE_SOURCE})
226 add_executable(freeldr_pe_dbg EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
227
228 if(NOT MSVC AND SEPARATE_DBG)
229 set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
230 set_target_properties(freeldr_pe_dbg PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
231 endif()
232
233 if(MSVC)
234 if(ARCH STREQUAL "arm")
235 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER")
236 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER")
237 else()
238 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")
239 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")
240 endif()
241 else()
242 add_target_link_flags(freeldr_pe "-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
243 add_target_link_flags(freeldr_pe_dbg "-Wl,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
244 endif()
245
246 set_image_base(freeldr_pe 0x10000)
247 set_subsystem(freeldr_pe native)
248 set_entrypoint(freeldr_pe RealEntryPoint)
249
250 set_image_base(freeldr_pe_dbg 0x10000)
251 set_subsystem(freeldr_pe_dbg native)
252 set_entrypoint(freeldr_pe_dbg RealEntryPoint)
253
254 if(ARCH STREQUAL "i386")
255 target_link_libraries(freeldr_pe mini_hal)
256 target_link_libraries(freeldr_pe_dbg mini_hal)
257 endif()
258
259 target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
260 target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
261
262 if(STACK_PROTECTOR)
263 target_link_libraries(freeldr_pe gcc_ssp)
264 target_link_libraries(freeldr_pe_dbg gcc_ssp)
265 elseif(RUNTIME_CHECKS)
266 target_link_libraries(freeldr_pe runtmchk)
267 target_link_libraries(freeldr_pe_dbg runtmchk)
268 add_target_link_flags(freeldr_pe "/MERGE:.rtc=.text")
269 endif()
270
271 add_dependencies(freeldr_pe asm)
272 add_dependencies(freeldr_pe_dbg asm)
273
274 # Retrieve the full path to the generated file of the 'freeldr_pe' target
275 get_target_property(_freeldr_pe_output_file freeldr_pe LOCATION)
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 ${_freeldr_pe_output_file})
282 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
283 else()
284 add_custom_target(freeldr ALL DEPENDS ${_freeldr_pe_output_file})
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 ${_freeldr_pe_output_file})
296 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
297 else()
298 add_custom_target(setupldr ALL DEPENDS ${_freeldr_pe_output_file})
299 endif()
300
301 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)