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
46 lib/inifile/ini_init.c
53 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
60 list(APPEND FREELDR_ARC_COMMON_SOURCE
71 list(APPEND FREELDR_COMMON_SOURCE
91 if(ARCH STREQUAL "i386")
92 list(APPEND FREELDR_COMMON_ASM_SOURCE
100 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
101 ntldr/arch/i386/winldr.c
104 list(APPEND FREELDR_ARC_COMMON_SOURCE
132 arch/i386/xboxvideo.c
135 list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
137 elseif(ARCH STREQUAL "amd64")
138 list(APPEND FREELDR_COMMON_ASM_SOURCE
141 arch/amd64/pnpbios.S)
143 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
144 ntldr/arch/amd64/winldr.c)
146 list(APPEND FREELDR_ARC_COMMON_SOURCE
164 elseif(ARCH STREQUAL "arm")
165 list(APPEND FREELDR_COMMON_ASM_SOURCE
168 list(APPEND FREELDR_NTLDR_COMMON_SOURCE
169 ntldr/arch/arm/winldr.c)
171 list(APPEND FREELDR_ARC_COMMON_SOURCE
178 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
180 add_library(freeldr_common
181 ${FREELDR_BOOTLIB_COMMON_SOURCE}
182 ${FREELDR_ARC_COMMON_SOURCE}
183 ${FREELDR_NTLDR_COMMON_SOURCE}
184 ${FREELDR_COMMON_SOURCE}
185 ${freeldr_common_asm}
189 # We need to reduce the binary size
190 add_target_compile_flags(freeldr_common "/Os")
194 ${FREELDR_BOOTLIB_COMMON_SOURCE}
195 ${FREELDR_ARC_COMMON_SOURCE}
196 ${FREELDR_NTLDR_COMMON_SOURCE}
197 ${FREELDR_COMMON_SOURCE})
199 add_pch(freeldr_common include/freeldr.h PCH_SOURCE)
200 add_dependencies(freeldr_common bugcodes asm xdk)
202 if(ARCH STREQUAL "i386" AND NOT MSVC)
203 list(APPEND FREELDR_BASE_SOURCE arch/i386/multiboot.S)
204 target_link_libraries(freeldr_common mini_hal)
207 list(APPEND FREELDR_BASE_SOURCE
208 bootmgr.c # This file is compiled with custom definitions
210 ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
211 ## even if ${FREELDR_NTLDR_COMMON_SOURCE} is not added,
212 ## otherwise we get linking errors with Rtl**Bitmap** APIs.
213 ## Do not happen on MSVC builds however...
214 lib/inffile/inffile.c
217 if(ARCH STREQUAL "i386")
218 # Must be included together with disk/scsiport.c
219 list(APPEND FREELDR_BASE_SOURCE
220 ${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
223 add_executable(freeldr_pe ${FREELDR_BASE_SOURCE})
224 add_executable(freeldr_pe_dbg EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
226 if(NOT MSVC AND SEPARATE_DBG)
227 set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
228 set_target_properties(freeldr_pe_dbg PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
232 if(ARCH STREQUAL "arm")
233 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER")
234 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER")
236 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")
237 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")
240 add_target_link_flags(freeldr_pe "-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
241 add_target_link_flags(freeldr_pe_dbg "-Wl,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
244 set_image_base(freeldr_pe 0x10000)
245 set_subsystem(freeldr_pe native)
246 set_entrypoint(freeldr_pe RealEntryPoint)
248 set_image_base(freeldr_pe_dbg 0x10000)
249 set_subsystem(freeldr_pe_dbg native)
250 set_entrypoint(freeldr_pe_dbg RealEntryPoint)
252 if(ARCH STREQUAL "i386")
253 target_link_libraries(freeldr_pe mini_hal)
254 target_link_libraries(freeldr_pe_dbg mini_hal)
257 target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
258 target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
261 target_link_libraries(freeldr_pe gcc_ssp)
262 target_link_libraries(freeldr_pe_dbg gcc_ssp)
263 elseif(RUNTIME_CHECKS)
264 target_link_libraries(freeldr_pe runtmchk)
265 target_link_libraries(freeldr_pe_dbg runtmchk)
266 add_target_link_flags(freeldr_pe "/MERGE:.rtc=.text")
269 add_dependencies(freeldr_pe asm)
270 add_dependencies(freeldr_pe_dbg asm)
272 if(NOT ARCH STREQUAL "arm")
274 ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
275 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
276 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
277 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
279 add_custom_target(freeldr ALL DEPENDS freeldr_pe)
282 # rename freeldr on livecd to setupldr.sys because isoboot.bin looks for setupldr.sys
283 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
284 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)
286 if(NOT ARCH STREQUAL "arm")
288 ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
289 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
290 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
291 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
293 add_custom_target(setupldr ALL DEPENDS freeldr_pe)
296 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)