[CLANG-CL] Initial commit that allows us to compile ReactOS with clang-cl.
[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
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/i386idt.c
127 arch/i386/i386rtl.c
128 arch/i386/i386vid.c
129 arch/i386/machpc.c
130 arch/i386/pccons.c
131 arch/i386/pcdisk.c
132 arch/i386/pcmem.c
133 arch/i386/pcrtc.c
134 arch/i386/pcvideo.c
135 arch/i386/machxbox.c
136 arch/i386/xboxcons.c
137 arch/i386/xboxdisk.c
138 arch/i386/xboxfont.c
139 arch/i386/xboxi2c.c
140 arch/i386/xboxmem.c
141 arch/i386/xboxrtc.c
142 arch/i386/xboxvideo.c
143 disk/scsiport.c)
144 if(NOT MSVC)
145 list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
146 endif()
147 elseif(ARCH STREQUAL "amd64")
148 list(APPEND FREELDR_COMMON_ASM_SOURCE
149 arch/amd64/entry.S
150 arch/amd64/int386.S
151 arch/amd64/pnpbios.S)
152
153 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
154 ntldr/arch/amd64/winldr.c
155 )
156
157 ## list(APPEND FREELDR_COMMON_SOURCE
158 list(APPEND FREELDR_ARC_COMMON_SOURCE
159 lib/fs/pxe.c
160
161 arch/i386/ntoskrnl.c
162
163 arch/i386/drivemap.c
164 arch/i386/hardware.c
165 arch/i386/hwacpi.c
166 arch/i386/hwapm.c
167 arch/i386/hwdisk.c
168 arch/i386/hwpci.c
169 arch/i386/i386bug.c
170 arch/i386/i386rtl.c
171 arch/i386/i386vid.c
172 arch/i386/machpc.c
173 arch/i386/pccons.c
174 arch/i386/pcdisk.c
175 arch/i386/pcmem.c
176 arch/i386/pcrtc.c
177 arch/i386/pcvideo.c)
178 elseif(ARCH STREQUAL "arm")
179 list(APPEND FREELDR_COMMON_ASM_SOURCE
180 arch/arm/boot.S)
181
182 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
183 ntldr/arch/arm/winldr.c
184 )
185
186 ## list(APPEND FREELDR_COMMON_SOURCE
187 list(APPEND FREELDR_ARC_COMMON_SOURCE
188 arch/arm/entry.c
189 arch/arm/macharm.c)
190 else()
191 #TBD
192 endif()
193
194 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
195 add_library(freeldr_common ${FREELDR_BOOTLIB_COMMON_SOURCE} ${FREELDR_ARC_COMMON_SOURCE}
196 ${FREELDR_NTLDR_COMMON_SOURCE}
197 ${FREELDR_COMMON_SOURCE} ${freeldr_common_asm})
198 add_pch(freeldr_common include/freeldr.h FREELDR_COMMON_SOURCE)
199 add_dependencies(freeldr_common bugcodes asm xdk)
200
201 if(USE_CLANG_CL)
202 # We need to reduce the binary size
203 set_property(SOURCE ${FREELDR_BOOTLIB_COMMON_SOURCE} ${FREELDR_ARC_COMMON_SOURCE} APPEND_STRING PROPERTY COMPILE_FLAGS " /Os")
204 endif()
205
206 if(ARCH STREQUAL "i386" AND NOT MSVC)
207 list(APPEND FREELDR_BASE_SOURCE arch/i386/multiboot.S)
208 target_link_libraries(freeldr_common mini_hal)
209 endif()
210
211 list(APPEND FREELDR_BASE_SOURCE
212 bootmgr.c # This file is compiled with custom definitions
213 freeldr.c
214 ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
215 ## even if ${FREELDR_NTLDR_COMMON_SOURCE} is not added,
216 ## otherwise we get linking errors with Rtl**Bitmap** APIs.
217 ## Do not happen on MSVC builds however...
218 lib/inffile/inffile.c
219 lib/rtl/libsupp.c)
220
221 if(ARCH STREQUAL "i386")
222 # Must be included together with disk/scsiport.c
223 list(APPEND FREELDR_BASE_SOURCE
224 ${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
225 endif()
226
227 add_executable(freeldr_pe ${FREELDR_BASE_SOURCE})
228 add_executable(freeldr_pe_dbg EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
229
230 if(NOT MSVC AND SEPARATE_DBG)
231 set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
232 set_target_properties(freeldr_pe_dbg PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
233 endif()
234
235 if(MSVC)
236 if(ARCH STREQUAL "arm")
237 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER")
238 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER")
239 else()
240 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")
241 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")
242 endif()
243 else()
244 add_target_link_flags(freeldr_pe "-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
245 add_target_link_flags(freeldr_pe_dbg "-Wl,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
246 endif()
247
248 set_image_base(freeldr_pe 0x10000)
249 set_subsystem(freeldr_pe native)
250 set_entrypoint(freeldr_pe RealEntryPoint)
251
252 set_image_base(freeldr_pe_dbg 0x10000)
253 set_subsystem(freeldr_pe_dbg native)
254 set_entrypoint(freeldr_pe_dbg RealEntryPoint)
255
256 if(ARCH STREQUAL "i386")
257 target_link_libraries(freeldr_pe mini_hal)
258 target_link_libraries(freeldr_pe_dbg mini_hal)
259 endif()
260
261 target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
262 target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
263
264 if(STACK_PROTECTOR)
265 target_link_libraries(freeldr_pe gcc_ssp)
266 target_link_libraries(freeldr_pe_dbg gcc_ssp)
267 elseif(RUNTIME_CHECKS)
268 target_link_libraries(freeldr_pe runtmchk)
269 target_link_libraries(freeldr_pe_dbg runtmchk)
270 add_target_link_flags(freeldr_pe "/MERGE:.rtc=.text")
271 endif()
272
273 add_dependencies(freeldr_pe asm)
274 add_dependencies(freeldr_pe_dbg asm)
275
276 # Retrieve the full path to the generated file of the 'freeldr_pe' target
277 get_target_property(_freeldr_pe_output_file freeldr_pe LOCATION)
278
279 if(NOT ARCH STREQUAL "arm")
280 concatenate_files(
281 ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
282 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
283 ${_freeldr_pe_output_file})
284 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
285 else()
286 add_custom_target(freeldr ALL DEPENDS ${_freeldr_pe_output_file})
287 endif()
288
289 # rename freeldr on livecd to setupldr.sys because isoboot.bin looks for setupldr.sys
290 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
291 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)
292
293 if(NOT ARCH STREQUAL "arm")
294 concatenate_files(
295 ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
296 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
297 ${_freeldr_pe_output_file})
298 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
299 else()
300 add_custom_target(setupldr ALL DEPENDS ${_freeldr_pe_output_file})
301 endif()
302
303 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)