[FREELDR]
[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 spec2def(freeldr.sys freeldr.spec)
9
10 if(ARCH STREQUAL "i386")
11 CreateBootSectorTarget(frldr16
12 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/i386.S
13 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
14 F800)
15 elseif(ARCH STREQUAL "amd64")
16 CreateBootSectorTarget(frldr16
17 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/amd64.S
18 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
19 F800)
20 endif()
21
22 include_directories(BEFORE include)
23 include_directories(${REACTOS_SOURCE_DIR}/ntoskrnl/include)
24 include_directories(${REACTOS_SOURCE_DIR}/lib/cmlib)
25 include_directories(${REACTOS_SOURCE_DIR}/include/reactos/libs)
26 include_directories(${REACTOS_SOURCE_DIR}/include/reactos/elf)
27
28 add_definitions(-D_NTHAL_ -D_BLDR_ -D_NTSYSTEM_)
29
30 if((ARCH STREQUAL "arm") AND (SARCH STREQUAL "omap-zoom2"))
31 add_definitions(-D_ZOOM2_)
32 endif()
33
34 list(APPEND FREELDR_COMMON_SOURCE
35 include/freeldr.h
36 arcname.c
37 cmdline.c
38 custom.c
39 debug.c
40 linuxboot.c
41 miscboot.c
42 machine.c
43 options.c
44 oslist.c
45 version.c
46 arch/archwsup.c
47 cache/blocklist.c
48 cache/cache.c
49 comm/rs232.c
50 disk/disk.c
51 disk/partition.c
52 disk/ramdisk.c
53 #disk/scsiport.c
54 fs/ext2.c
55 fs/fat.c
56 fs/fs.c
57 fs/iso.c
58 fs/ntfs.c
59 lib/inifile/ini_init.c
60 lib/inifile/inifile.c
61 lib/inifile/parse.c
62 mm/meminit.c
63 mm/mm.c
64 mm/heap.c
65 ui/directui.c
66 ui/gui.c
67 ui/minitui.c
68 ui/noui.c
69 ui/tui.c
70 ui/tuimenu.c
71 ui/ui.c
72 video/fade.c
73 video/palette.c
74 video/video.c
75 windows/conversion.c
76 windows/peloader.c
77 windows/registry.c
78 windows/winldr.c
79 windows/wlmemory.c
80 windows/wlregistry.c)
81
82 if(ARCH STREQUAL "i386")
83 list(APPEND FREELDR_COMMON_ASM_SOURCE
84 arch/i386/entry.S
85 arch/i386/i386pnp.S
86 arch/i386/i386trap.S
87 arch/i386/linux.S
88 arch/i386/mb.S)
89 list(APPEND FREELDR_COMMON_SOURCE
90 fs/pxe.c
91 arch/i386/archmach.c
92 arch/i386/drivemap.c
93 arch/i386/halstub.c
94 arch/i386/hardware.c
95 arch/i386/hwacpi.c
96 arch/i386/hwapm.c
97 arch/i386/hwdisk.c
98 arch/i386/hwpci.c
99 arch/i386/i386bug.c
100 arch/i386/i386disk.c
101 arch/i386/i386idt.c
102 arch/i386/i386rtl.c
103 arch/i386/i386vid.c
104 arch/i386/machpc.c
105 arch/i386/ntoskrnl.c
106 arch/i386/pccons.c
107 arch/i386/pcdisk.c
108 arch/i386/pcmem.c
109 arch/i386/pcrtc.c
110 arch/i386/pcvideo.c
111 arch/i386/machxbox.c
112 arch/i386/xboxcons.c
113 arch/i386/xboxdisk.c
114 arch/i386/xboxfont.c
115 arch/i386/xboxhw.c
116 arch/i386/xboxi2c.c
117 arch/i386/xboxmem.c
118 arch/i386/xboxrtc.c
119 arch/i386/xboxvideo.c
120 arch/i386/winldr.c
121 windows/headless.c
122 disk/scsiport.c)
123 if(NOT MSVC)
124 list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
125 endif()
126 elseif(ARCH STREQUAL "amd64")
127 list(APPEND FREELDR_COMMON_ASM_SOURCE
128 arch/amd64/entry.S
129 arch/amd64/int386.S
130 arch/amd64/pnpbios.S)
131 list(APPEND FREELDR_COMMON_SOURCE
132 fs/pxe.c
133 arch/i386/drivemap.c
134 arch/i386/hardware.c
135 arch/i386/hwacpi.c
136 arch/i386/hwapm.c
137 arch/i386/hwdisk.c
138 arch/i386/hwpci.c
139 arch/i386/i386bug.c
140 arch/i386/i386rtl.c
141 arch/i386/i386disk.c
142 arch/i386/i386vid.c
143 arch/i386/machpc.c
144 arch/i386/ntoskrnl.c
145 arch/i386/pccons.c
146 arch/i386/pcdisk.c
147 arch/i386/pcmem.c
148 arch/i386/pcrtc.c
149 arch/i386/pcvideo.c
150 arch/amd64/winldr.c)
151 elseif(ARCH STREQUAL "arm")
152 list(APPEND FREELDR_COMMON_ASM_SOURCE
153 arch/arm/boot.S)
154 list(APPEND FREELDR_COMMON_SOURCE
155 arch/arm/macharm.c
156 arch/arm/winldr.c)
157 else()
158 #TBD
159 endif()
160
161 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
162 add_library(freeldr_common ${FREELDR_COMMON_SOURCE} ${freeldr_common_asm})
163 add_pch(freeldr_common include/freeldr.h FREELDR_COMMON_SOURCE)
164 add_dependencies(freeldr_common bugcodes)
165
166 if(ARCH STREQUAL "i386" AND NOT MSVC)
167 list(APPEND FREELDR_BASE_SOURCE arch/i386/multiboot.S)
168 target_link_libraries(freeldr_common mini_hal)
169 endif()
170
171 if(ARCH STREQUAL "i386" OR ARCH STREQUAL "amd64")
172 list(APPEND FREELDR_BASE_SOURCE windows/setupldr.c)
173 endif()
174
175 list(APPEND FREELDR_BASE_SOURCE
176 bootmgr.c # This file is compiled with custom definitions
177 freeldr.c
178 lib/inffile/inffile.c
179 lib/rtl/libsupp.c)
180
181 if(NOT MSVC)
182 list(APPEND FREELDR_BASE_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.def)
183 endif()
184
185 add_library(freeldr_pe SHARED ${FREELDR_BASE_SOURCE})
186 add_library(freeldr_pe_dbg SHARED EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
187
188 if(NOT MSVC AND SEPARATE_DBG)
189 set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
190 set_target_properties(freeldr_pe_dbg PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
191 endif()
192
193 if(MSVC)
194 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 ")
195 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")
196 else()
197 add_target_link_flags(freeldr_pe "-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
198 add_target_link_flags(freeldr_pe_dbg "-Wl,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
199 endif()
200
201 set_image_base(freeldr_pe 0x10000)
202 set_subsystem(freeldr_pe native)
203 set_entrypoint(freeldr_pe RealEntryPoint)
204
205 set_image_base(freeldr_pe_dbg 0x10000)
206 set_subsystem(freeldr_pe_dbg native)
207 set_entrypoint(freeldr_pe_dbg RealEntryPoint)
208
209 if(ARCH STREQUAL "i386")
210 target_link_libraries(freeldr_pe mini_hal)
211 target_link_libraries(freeldr_pe_dbg mini_hal)
212 endif()
213
214 target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
215 target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
216
217 if(STACK_PROTECTOR)
218 target_link_libraries(freeldr_pe gcc_ssp)
219 target_link_libraries(freeldr_pe_dbg gcc_ssp)
220 elseif(RUNTIME_CHECKS)
221 target_link_libraries(freeldr_pe runtmchk)
222 target_link_libraries(freeldr_pe_dbg runtmchk)
223 add_target_link_flags(freeldr_pe "/MERGE:.rtc=.text")
224 endif()
225
226 add_dependencies(freeldr_pe asm)
227 add_dependencies(freeldr_pe_dbg asm)
228
229 # Retrieve the full path to the generated file of the 'freeldr_pe' target
230 get_target_property(_freeldr_pe_output_file freeldr_pe LOCATION)
231
232 concatenate_files(
233 ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
234 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
235 ${_freeldr_pe_output_file})
236
237 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
238
239 # rename freeldr on livecd to setupldr.sys because isoboot.bin looks for setupldr.sys
240 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
241 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)
242
243 concatenate_files(
244 ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
245 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
246 ${_freeldr_pe_output_file})
247
248 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
249 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
250