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")
9 # We don't need it here
10 replace_compile_flags("/hotpatch" " ")
13 spec2def(freeldr_pe.exe freeldr.spec)
15 if(ARCH STREQUAL "i386")
16 CreateBootSectorTarget(frldr16
17 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/i386.S
18 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
20 elseif(ARCH STREQUAL "amd64")
21 CreateBootSectorTarget(frldr16
22 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/amd64.S
23 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
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)
33 add_definitions(-D_NTHAL_ -D_BLDR_ -D_NTSYSTEM_)
35 list(APPEND FREELDR_BOOTLIB_COMMON_SOURCE
45 lib/inifile/ini_init.c
52 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
59 list(APPEND FREELDR_ARC_COMMON_SOURCE
70 list(APPEND FREELDR_COMMON_SOURCE
90 if(ARCH STREQUAL "i386")
91 list(APPEND FREELDR_COMMON_ASM_SOURCE
99 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
100 ntldr/arch/i386/winldr.c
103 list(APPEND FREELDR_ARC_COMMON_SOURCE
131 arch/i386/xboxvideo.c
134 list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
136 elseif(ARCH STREQUAL "amd64")
137 list(APPEND FREELDR_COMMON_ASM_SOURCE
140 arch/amd64/pnpbios.S)
142 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
143 ntldr/arch/amd64/winldr.c)
145 list(APPEND FREELDR_ARC_COMMON_SOURCE
163 elseif(ARCH STREQUAL "arm")
164 list(APPEND FREELDR_COMMON_ASM_SOURCE
167 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
168 ntldr/arch/arm/winldr.c)
170 list(APPEND FREELDR_ARC_COMMON_SOURCE
177 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
179 add_library(freeldr_common
180 ${FREELDR_BOOTLIB_COMMON_SOURCE}
181 ${FREELDR_ARC_COMMON_SOURCE}
182 ${FREELDR_NTLDR_COMMON_SOURCE}
183 ${FREELDR_COMMON_SOURCE}
184 ${freeldr_common_asm}
188 # We need to reduce the binary size
189 add_target_compile_flags(freeldr_common "/Os")
193 ${FREELDR_BOOTLIB_COMMON_SOURCE}
194 ${FREELDR_ARC_COMMON_SOURCE}
195 ${FREELDR_NTLDR_COMMON_SOURCE}
196 ${FREELDR_COMMON_SOURCE})
198 add_pch(freeldr_common include/freeldr.h PCH_SOURCE)
199 add_dependencies(freeldr_common bugcodes asm xdk)
201 if(ARCH STREQUAL "i386" AND NOT MSVC)
202 list(APPEND FREELDR_BASE_SOURCE arch/i386/multiboot.S)
203 target_link_libraries(freeldr_common mini_hal)
206 list(APPEND FREELDR_BASE_SOURCE
207 bootmgr.c # This file is compiled with custom definitions
209 ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
210 ## even if ${FREELDR_NTLDR_COMMON_SOURCE} is not added,
211 ## otherwise we get linking errors with Rtl**Bitmap** APIs.
212 ## Do not happen on MSVC builds however...
213 lib/inffile/inffile.c
216 if(ARCH STREQUAL "i386")
217 # Must be included together with disk/scsiport.c
218 list(APPEND FREELDR_BASE_SOURCE
219 ${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
222 add_executable(freeldr_pe ${FREELDR_BASE_SOURCE})
223 add_executable(freeldr_pe_dbg EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
225 if(NOT MSVC AND SEPARATE_DBG)
226 set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
227 set_target_properties(freeldr_pe_dbg PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
231 if(ARCH STREQUAL "arm")
232 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER")
233 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER")
235 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")
236 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")
239 add_target_link_flags(freeldr_pe "-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
240 add_target_link_flags(freeldr_pe_dbg "-Wl,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
243 set_image_base(freeldr_pe 0x10000)
244 set_subsystem(freeldr_pe native)
245 set_entrypoint(freeldr_pe RealEntryPoint)
247 set_image_base(freeldr_pe_dbg 0x10000)
248 set_subsystem(freeldr_pe_dbg native)
249 set_entrypoint(freeldr_pe_dbg RealEntryPoint)
251 if(ARCH STREQUAL "i386")
252 target_link_libraries(freeldr_pe mini_hal)
253 target_link_libraries(freeldr_pe_dbg mini_hal)
256 target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
257 target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
260 target_link_libraries(freeldr_pe gcc_ssp)
261 target_link_libraries(freeldr_pe_dbg gcc_ssp)
262 elseif(RUNTIME_CHECKS)
263 target_link_libraries(freeldr_pe runtmchk)
264 target_link_libraries(freeldr_pe_dbg runtmchk)
265 add_target_link_flags(freeldr_pe "/MERGE:.rtc=.text")
268 add_dependencies(freeldr_pe asm)
269 add_dependencies(freeldr_pe_dbg asm)
271 if(NOT ARCH STREQUAL "arm")
273 ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
274 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
275 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
276 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
278 add_custom_target(freeldr ALL DEPENDS freeldr_pe)
281 # rename freeldr on livecd to setupldr.sys because isoboot.bin looks for setupldr.sys
282 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
283 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)
285 if(NOT ARCH STREQUAL "arm")
287 ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
288 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
289 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
290 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
292 add_custom_target(setupldr ALL DEPENDS freeldr_pe)
295 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)