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