1 2PROJECT(NTOS) 3 4include(ntos.cmake) 5 6set(NTOSKRNL_SOURCE ${SOURCE}) 7set(NTOSKRNL_ASM_SOURCE ${ASM_SOURCE}) 8 9set(NTKRNLMP_SOURCE ${SOURCE}) 10set(NTKRNLMP_ASM_SOURCE ${ASM_SOURCE}) 11 12spec2def(ntoskrnl.exe ntoskrnl.spec ADD_IMPORTLIB) 13 14# Embed RTC libs 15if (STACK_PROTECTOR) 16 target_sources(libntoskrnl PRIVATE $<TARGET_OBJECTS:gcc_ssp_nt>) 17endif() 18 19add_asm_files(ntoskrnl_asm ${NTOSKRNL_ASM_SOURCE}) 20 21if (GCC AND CLANG) 22 # Clang optimises strcmp calls to memcmp. 23 target_sources(libntoskrnl PRIVATE $<TARGET_OBJECTS:memcmp>) 24endif() 25 26list(APPEND PCH_SKIP_SOURCE 27 guid.c) 28 29add_executable(ntoskrnl 30 ${ntoskrnl_asm} 31 ${NTOSKRNL_SOURCE} 32 ${PCH_SKIP_SOURCE} 33 ntoskrnl.rc 34 ${CMAKE_CURRENT_BINARY_DIR}/ntoskrnl.def) 35set_property(TARGET ntoskrnl PROPERTY ENABLE_EXPORTS TRUE) 36set_target_properties(ntoskrnl PROPERTIES DEFINE_SYMBOL "") 37 38source_group(TREE ${REACTOS_SOURCE_DIR}/ntoskrnl PREFIX "Source Files" FILES ${NTOSKRNL_SOURCE}) 39 40if(ARCH STREQUAL "i386") 41 set_entrypoint(ntoskrnl KiSystemStartup 4) 42else() 43 set_entrypoint(ntoskrnl KiSystemStartup) 44endif() 45set_subsystem(ntoskrnl native) 46 47if(MSVC) 48 set_image_base(ntoskrnl 0x00400000) 49 add_target_link_flags(ntoskrnl "/SECTION:.rsrc,!DP") #Accessed from bugcheck code 50 add_target_link_flags(ntoskrnl "/SECTION:INIT,ERWD") 51else() 52 if(GDB AND NOT CLANG) 53 # Completely disable optimizations when debugging the kernel 54 # Not for CLang, which fails as following in _SEH2_EXCEPT macro: 55 # error: inline assembly requires more registers than available 56 target_compile_options(ntoskrnl PRIVATE -O0) 57 set_image_base(ntoskrnl 0x00800000) 58 else() 59 set_image_base(ntoskrnl 0x80800000) 60 endif() 61 add_linker_script(ntoskrnl ${REACTOS_SOURCE_DIR}/sdk/cmake/init-section.lds) 62endif() 63 64target_link_libraries(ntoskrnl cportlib csq ${PSEH_LIB} arbiter cmlib ntlsalib rtl ${ROSSYM_LIB} libcntpr wdmguid ioevent) 65 66if(STACK_PROTECTOR) 67 target_sources(ntoskrnl PRIVATE $<TARGET_OBJECTS:gcc_ssp_nt>) 68elseif(RUNTIME_CHECKS) 69 target_link_libraries(ntoskrnl runtmchk) 70endif() 71 72add_importlibs(ntoskrnl hal kdcom bootvid) 73add_pch(ntoskrnl ${REACTOS_SOURCE_DIR}/ntoskrnl/include/ntoskrnl.h "${PCH_SKIP_SOURCE}") 74add_dependencies(ntoskrnl psdk bugcodes asm) 75add_cd_file(TARGET ntoskrnl DESTINATION reactos/system32 NO_CAB FOR all) 76 77if(BUILD_MP) 78 add_subdirectory(ntkrnlmp) 79endif() 80 81add_asm_files(ntdllsys_asm ntdll.S) 82add_library(ntdllsys ${ntdllsys_asm}) 83set_target_properties(ntdllsys PROPERTIES LINKER_LANGUAGE "C") 84add_dependencies(ntdllsys asm) 85