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