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 hotpatching
10 replace_compile_flags("/hotpatch" " ")
12 # Explicitly use string pooling
13 add_compile_flags("/GF")
16 spec2def(freeldr_pe.exe freeldr.spec)
18 if(ARCH STREQUAL "i386")
19 CreateBootSectorTarget(frldr16
20 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/i386.S
21 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
23 elseif(ARCH STREQUAL "amd64")
24 CreateBootSectorTarget(frldr16
25 ${CMAKE_CURRENT_SOURCE_DIR}/arch/realmode/amd64.S
26 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
30 include_directories(BEFORE include)
31 include_directories(${REACTOS_SOURCE_DIR}/ntoskrnl/include)
32 include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/cmlib)
33 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs)
34 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/elf)
36 add_definitions(-D_NTHAL_ -D_BLDR_ -D_NTSYSTEM_)
38 list(APPEND FREELDR_BOOTLIB_SOURCE
49 lib/inifile/ini_init.c
56 list(APPEND FREELDR_NTLDR_SOURCE
63 list(APPEND FREELDR_ARC_SOURCE
74 list(APPEND FREELDR_BOOTMGR_SOURCE
94 if(ARCH STREQUAL "i386")
95 list(APPEND FREELDR_COMMON_ASM_SOURCE
103 list(APPEND FREELDR_NTLDR_SOURCE
104 ntldr/arch/i386/winldr.c
107 list(APPEND FREELDR_ARC_SOURCE
135 arch/i386/xboxvideo.c
138 list(APPEND FREELDR_COMMON_ASM_SOURCE arch/i386/drvmap.S)
141 elseif(ARCH STREQUAL "amd64")
142 list(APPEND FREELDR_COMMON_ASM_SOURCE
145 arch/amd64/pnpbios.S)
147 list(APPEND FREELDR_NTLDR_SOURCE
148 ntldr/arch/amd64/winldr.c)
150 list(APPEND FREELDR_ARC_SOURCE
169 elseif(ARCH STREQUAL "arm")
170 list(APPEND FREELDR_COMMON_ASM_SOURCE
173 list(APPEND FREELDR_NTLDR_SOURCE
174 ntldr/arch/arm/winldr.c)
176 list(APPEND FREELDR_ARC_SOURCE
183 add_asm_files(freeldr_common_asm ${FREELDR_COMMON_ASM_SOURCE})
185 add_library(freeldr_common
186 ${freeldr_common_asm}
187 ${FREELDR_BOOTLIB_SOURCE}
188 ${FREELDR_ARC_SOURCE}
189 ${FREELDR_NTLDR_SOURCE}
190 ${FREELDR_BOOTMGR_SOURCE})
193 # We need to reduce the binary size
194 add_target_compile_flags(freeldr_common "/Os")
198 ${FREELDR_BOOTLIB_SOURCE}
199 ${FREELDR_ARC_SOURCE}
200 ${FREELDR_NTLDR_SOURCE}
201 ${FREELDR_BOOTMGR_SOURCE})
203 add_pch(freeldr_common include/freeldr.h PCH_SOURCE)
204 add_dependencies(freeldr_common bugcodes asm xdk)
206 if(ARCH STREQUAL "i386" AND NOT MSVC)
207 list(APPEND FREELDR_BASE_SOURCE arch/i386/multiboot.S)
208 ## GCC builds need this extra thing for some reason...
209 target_link_libraries(freeldr_common mini_hal)
212 list(APPEND FREELDR_BASE_SOURCE
213 bootmgr.c # This file is compiled with custom definitions
215 ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
216 ## even if ${FREELDR_NTLDR_SOURCE} is not added,
217 ## otherwise we get linking errors with Rtl**Bitmap** APIs.
218 ## Do not happen on MSVC builds however...
219 lib/inffile/inffile.c
222 if(ARCH STREQUAL "i386")
223 # Must be included together with disk/scsiport.c
224 list(APPEND FREELDR_BASE_SOURCE
225 ${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
228 add_executable(freeldr_pe ${FREELDR_BASE_SOURCE})
229 add_executable(freeldr_pe_dbg EXCLUDE_FROM_ALL ${FREELDR_BASE_SOURCE})
231 if(NOT MSVC AND SEPARATE_DBG)
232 set_target_properties(freeldr_pe PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
233 set_target_properties(freeldr_pe_dbg PROPERTIES LINKER_LANGUAGE LDR_PE_HELPER)
237 if(ARCH STREQUAL "arm")
238 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER")
239 add_target_link_flags(freeldr_pe_dbg "/ignore:4078 /ignore:4254 /DRIVER")
241 add_target_link_flags(freeldr_pe "/ignore:4078 /ignore:4254 /DRIVER /FIXED /ALIGN:0x400 /SECTION:.text,ERW /SECTION:.data,RW /MERGE:.text16=.text /MERGE:INIT=.text /MERGE:.data=.text /MERGE:.rdata=.text /MERGE:.bss=.text")
242 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:INIT=.text /MERGE:.data=.text /MERGE:.rdata=.text /MERGE:.bss=.text")
245 add_target_link_flags(freeldr_pe "-Wl,--strip-all,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
246 add_target_link_flags(freeldr_pe_dbg "-Wl,--exclude-all-symbols,--file-alignment,0x1000,-T,${CMAKE_CURRENT_SOURCE_DIR}/freeldr_i386.lds")
249 set_image_base(freeldr_pe 0x10000)
250 set_subsystem(freeldr_pe native)
251 set_entrypoint(freeldr_pe RealEntryPoint)
253 set_image_base(freeldr_pe_dbg 0x10000)
254 set_subsystem(freeldr_pe_dbg native)
255 set_entrypoint(freeldr_pe_dbg RealEntryPoint)
257 if(ARCH STREQUAL "i386")
258 target_link_libraries(freeldr_pe mini_hal)
259 target_link_libraries(freeldr_pe_dbg mini_hal)
262 target_link_libraries(freeldr_pe freeldr_common cportlib cmlib rtl libcntpr)
263 target_link_libraries(freeldr_pe_dbg freeldr_common cportlib cmlib rtl libcntpr)
266 target_link_libraries(freeldr_pe gcc_ssp)
267 target_link_libraries(freeldr_pe_dbg gcc_ssp)
268 elseif(RUNTIME_CHECKS)
269 target_link_libraries(freeldr_pe runtmchk)
270 target_link_libraries(freeldr_pe_dbg runtmchk)
271 add_target_link_flags(freeldr_pe "/MERGE:.rtc=.text")
274 add_dependencies(freeldr_pe asm)
275 add_dependencies(freeldr_pe_dbg asm)
277 if(NOT ARCH STREQUAL "arm")
279 ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys
280 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
281 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
282 add_custom_target(freeldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys)
284 add_custom_target(freeldr ALL DEPENDS freeldr_pe)
287 # Rename freeldr on livecd to setupldr.sys because isoboot.bin looks for setupldr.sys
288 add_cd_file(TARGET freeldr FILE ${CMAKE_CURRENT_BINARY_DIR}/freeldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)
289 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)
291 if(NOT ARCH STREQUAL "arm")
293 ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys
294 ${CMAKE_CURRENT_BINARY_DIR}/frldr16.bin
295 ${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:freeldr_pe>)
296 add_custom_target(setupldr ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys)
298 add_custom_target(setupldr ALL DEPENDS freeldr_pe)
301 add_cd_file(TARGET setupldr FILE ${CMAKE_CURRENT_BINARY_DIR}/setupldr.sys DESTINATION loader NO_CAB FOR bootcd regtest)