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