Synchronize with trunk.
[reactos.git] / ntoskrnl / CMakeLists.txt
index 43046bb..391868a 100644 (file)
@@ -1,5 +1,7 @@
 
-spec2def(ntoskrnl.exe ntoskrnl.spec)
+PROJECT(NTOS)
+
+spec2def(ntoskrnl.exe ntoskrnl.spec ADD_IMPORTLIB)
 
 include_directories(
     ${REACTOS_SOURCE_DIR}
@@ -16,9 +18,9 @@ add_definitions(
     -D_IN_KERNEL_
     -DNTDDI_VERSION=0x05020400)
 
-set_rc_compiler()
-
-set(NEWCC FALSE)
+if(NOT DEFINED NEWCC)
+    set(NEWCC FALSE)
+endif()
 
 if(NEWCC)
     add_definitions(-DNEWCC)
@@ -29,12 +31,7 @@ if(NEWCC)
         cache/lazyrite.c
         cache/logsup.c
         cache/mdlsup.c
-        cache/pinsup.c
-        cache/section/data.c
-        cache/section/fault.c
-        cache/section/reqtools.c
-        cache/section/sptab.c
-        cache/section/swapout.c)
+        cache/pinsup.c)
 else()
     list(APPEND SOURCE
         cc/cacheman.c
@@ -47,6 +44,11 @@ endif()
 
 list(APPEND SOURCE
     cache/section/io.c
+    cache/section/data.c
+    cache/section/fault.c
+    cache/section/reqtools.c
+    cache/section/sptab.c
+    cache/section/swapout.c
     config/cmalloc.c
     config/cmapi.c
     config/cmboot.c
@@ -83,12 +85,12 @@ list(APPEND SOURCE
     ex/event.c
     ex/evtpair.c
     ex/exintrin.c
-    ex/fastinterlck.c
     ex/fmutex.c
     ex/handle.c
     ex/harderr.c
     ex/hdlsterm.c
     ex/init.c
+    ex/interlocked.c
     ex/keyedevt.c
     ex/locale.c
     ex/lookas.c
@@ -107,7 +109,6 @@ list(APPEND SOURCE
     ex/work.c
     ex/xipdisp.c
     ex/zone.c
-    ex/zw.S
     fsrtl/dbcsname.c
     fsrtl/fastio.c
     fsrtl/faulttol.c
@@ -117,6 +118,7 @@ list(APPEND SOURCE
     fsrtl/fsfilter.c
     fsrtl/fsrtlpc.c
     fsrtl/largemcb.c
+    fsrtl/mcb.c
     fsrtl/name.c
     fsrtl/notify.c
     fsrtl/oplock.c
@@ -127,7 +129,7 @@ list(APPEND SOURCE
     fstub/disksup.c
     fstub/fstubex.c
     fstub/halstub.c
-       fstub/translate.c
+    fstub/translate.c
     inbv/inbv.c
     inbv/inbvport.c
     io/iomgr/adapter.c
@@ -214,19 +216,18 @@ list(APPEND SOURCE
     mm/ARM3/pool.c
     mm/ARM3/procsup.c
     mm/ARM3/section.c
+    mm/ARM3/special.c
     mm/ARM3/sysldr.c
     mm/ARM3/syspte.c
     mm/ARM3/vadnode.c
     mm/ARM3/virtual.c
     mm/ARM3/zeropage.c
-    mm/anonmem.c
     mm/balance.c
     mm/freelist.c
     mm/marea.c
     mm/mmfault.c
     mm/mminit.c
     mm/pagefile.c
-    mm/pageop.c
     mm/region.c
     mm/rmap.c
     mm/section.c
@@ -270,20 +271,23 @@ list(APPEND SOURCE
     se/token.c
     vf/driver.c
     wmi/wmi.c
-    ntoskrnl.rc
-    ${CMAKE_CURRENT_BINARY_DIR}/ntoskrnl.def)
+    ntoskrnl.rc)
 
-if(ARCH MATCHES i386)
-    list(APPEND SOURCE
-        config/i386/cmhardwr.c
-        ex/i386/interlck_asm.S
+list(APPEND ASM_SOURCE ex/zw.S)
+
+if(ARCH STREQUAL "i386")
+    list(APPEND ASM_SOURCE
         ex/i386/fastinterlck_asm.S
         ex/i386/ioport.S
-        ke/freeldr.c
+        ke/i386/ctxswitch.S
+        ke/i386/trap.s
+        ke/i386/usercall_asm.S
+        rtl/i386/stack.S)
+    list(APPEND SOURCE
+        config/i386/cmhardwr.c
         ke/i386/abios.c
         ke/i386/cpu.c
         ke/i386/context.c
-        ke/i386/ctxswitch.S
         ke/i386/exp.c
         ke/i386/irqobj.c
         ke/i386/kiinit.c
@@ -291,58 +295,59 @@ if(ARCH MATCHES i386)
         ke/i386/mtrr.c
         ke/i386/patpge.c
         ke/i386/thrdini.c
-        ke/i386/trap.s
         ke/i386/traphdlr.c
-        ke/i386/usercall_asm.S
         ke/i386/usercall.c
         ke/i386/v86vdm.c
         mm/i386/page.c
         mm/ARM3/i386/init.c
         ps/i386/psctx.c
         ps/i386/psldt.c
-        rtl/i386/stack.S
         vdm/vdmmain.c
         vdm/vdmexec.c)
-elseif(ARCH MATCHES amd64)
+elseif(ARCH STREQUAL "amd64")
+    list(APPEND ASM_SOURCE
+        ke/amd64/boot.S
+        ke/amd64/ctxswitch.S
+        ke/amd64/trap.S)
     list(APPEND SOURCE
         config/i386/cmhardwr.c
-        ex/amd64/fastinterlck.c
-        ke/amd64/boot.S
         ke/amd64/context.c
         ke/amd64/cpu.c
-        ke/amd64/ctxswitch.S
         ke/amd64/except.c
         ke/amd64/interrupt.c
         ke/amd64/irql.c
         ke/amd64/kiinit.c
+        ke/amd64/krnlinit.c
         ke/amd64/spinlock.c
         ke/amd64/stubs.c
         ke/amd64/thrdini.c
-        ke/amd64/trap.S
         mm/amd64/init.c
         mm/amd64/page.c
         ps/amd64/psctx.c)
-elseif(ARCH MATCHES arm)
+elseif(ARCH STREQUAL "arm")
+    list(APPEND ASM_SOURCE
+        ke/arm/boot.s
+        ke/arm/ctxswtch.s
+        ke/arm/stubs_asm.s
+        ke/arm/trap.s)
     list(APPEND SOURCE
         config/arm/cmhardwr.c
-        ke/arm/boot.s
         ke/arm/cpu.c
-        ke/arm/ctxswtch.s
         ke/arm/exp.c
         ke/arm/kiinit.c
-        ke/arm/stubs_asm.s
         ke/arm/thrdini.c
-        ke/arm/trap.s
         ke/arm/trapc.c
         ke/arm/usercall.c
         mm/arm/page.c
         mm/ARM3/arm/init.c
         ps/arm/psctx.c
         rtl/arm/rtlexcpt.c)
-elseif(ARCH MATCHES powerpc)
+elseif(ARCH STREQUAL "powerpc")
+    list(APPEND ASM_SOURCE
+        ke/powerpc/main_asm.S
+        ke/powerpc/ctxhelp.S)
     list(APPEND SOURCE
         config/powerpc/cmhardwr.c
-        ke/powerpc/main_asm.S
         ke/powerpc/cpu.c
         ke/powerpc/exp.c
         ke/powerpc/kiinit.c
@@ -351,32 +356,34 @@ elseif(ARCH MATCHES powerpc)
         ke/powerpc/systimer.c
         ke/powerpc/thrdini.c
         ke/powerpc/ctxswitch.c
-        ke/powerpc/ctxhelp.S
         mm/powerpc/pfault.c
         mm/powerpc/page.c)
 endif()
 
 if(NOT _WINKD_)
-    if(ARCH MATCHES i386)
+    if(ARCH STREQUAL "i386")
         list(APPEND SOURCE
+            kd/i386/kdbg.c
             kd/i386/kdmemsup.c
             kd/wrappers/gdbstub.c)
         if(KDBG)
-            list(APPEND SOURCE
-                kdbg/i386/i386-dis.c
-                kdbg/i386/kdb_help.S)
+            list(APPEND ASM_SOURCE kdbg/i386/kdb_help.S)
+            list(APPEND SOURCE kdbg/i386/i386-dis.c)
         endif()
-    elseif(ARCH MATCHES amd64)
+    elseif(ARCH STREQUAL "amd64")
         list(APPEND SOURCE
             kd/amd64/kd.c
+            kd/i386/kdbg.c  # Use the x86 file
             kd/amd64/kdmemsup.c)
         if(KDBG)
+            list(APPEND ASM_SOURCE kdbg/amd64/kdb_help.S)
             list(APPEND SOURCE
                 kdbg/amd64/i386-dis.c
-                kdbg/amd64/kdb_help.S
                 kdbg/amd64/kdb.c)
         endif()
-    elseif(ARCH MATCHES powerpc)
+    elseif(ARCH STREQUAL "arm")
+        list(APPEND SOURCE kd/arm/kdbg.c)
+    elseif(ARCH STREQUAL "powerpc")
         list(APPEND SOURCE kd/wrappers/gdbstub_powerpc.c)
     endif()
 
@@ -390,6 +397,7 @@ if(NOT _WINKD_)
     endif()
 
     if(DBG OR KDBG)
+        #list(APPEND SOURCE kdbg/kdb_symbols.cmake.c)
         list(APPEND SOURCE kdbg/kdb_symbols.c)
     endif()
 
@@ -411,19 +419,28 @@ else() # _WINKD_
         kd64/kdprint.c
         kd64/kdtrap.c)
 
-    if(ARCH MATCHES i386)
+    if(ARCH STREQUAL "i386")
         list(APPEND SOURCE kd64/i386/kdx86.c)
-    elseif(ARCH MATCHES amd64)
+    elseif(ARCH STREQUAL "amd64")
         list(APPEND SOURCE kd64/amd64/kdx64.c)
-    elseif(ARCH MATCHES arm)
+    elseif(ARCH STREQUAL "arm")
         list(APPEND SOURCE kd64/arm/kdarm.c)
     endif()
 
 endif()
 
-add_executable(ntoskrnl ${CMAKE_CURRENT_BINARY_DIR}/ntoskrnl_ntoskrnl.h.gch ${SOURCE})
+add_asm_files(ntoskrnl_asm ${ASM_SOURCE})
+
+add_executable(ntoskrnl
+    ${ntoskrnl_asm}
+    ${SOURCE}
+    ${CMAKE_CURRENT_BINARY_DIR}/ntoskrnl.def)
 
-set_entrypoint(ntoskrnl KiSystemStartup@4)
+if(ARCH STREQUAL "i386")
+    set_entrypoint(ntoskrnl KiSystemStartup 4)
+else()
+    set_entrypoint(ntoskrnl KiSystemStartup)
+endif()
 set_subsystem(ntoskrnl native)
 
 if(MSVC)
@@ -432,6 +449,11 @@ else()
     set_image_base(ntoskrnl 0x80800000)
 endif()
 
+# Linker bug
+if(NOT MSVC AND LTCG)
+    add_target_link_flags(ntoskrnl "-shared")
+endif()
+
 target_link_libraries(ntoskrnl
     cportlib
     csq
@@ -444,12 +466,50 @@ target_link_libraries(ntoskrnl
     ioevent)
 
 add_importlibs(ntoskrnl hal kdcom bootvid)
-
-add_pch(ntoskrnl ${CMAKE_CURRENT_SOURCE_DIR}/include/ntoskrnl.h ${SOURCE})
+add_pch(ntoskrnl include/ntoskrnl.h)
 add_dependencies(ntoskrnl psdk bugcodes asm)
+add_cd_file(TARGET ntoskrnl DESTINATION reactos/system32 NO_CAB FOR all)
+
+if(BUILD_MP)
+    spec2def(ntkrnlmp.exe ntoskrnl.spec)
 
-add_cd_file(TARGET ntoskrnl DESTINATION reactos/system32 NO_CAB)
-add_importlib_target(ntoskrnl.spec)
+    if(MSVC_IDE AND (CMAKE_VERSION MATCHES "ReactOS"))
+        set_source_files_properties(${ASM_SOURCE} PROPERTIES COMPILE_DEFINITIONS "CONFIG_SMP")
+    endif()
+
+    add_asm_files(ntkrnlmp_asm ${ASM_SOURCE})
+
+    add_executable(ntkrnlmp
+        ${ntkrnlmp_asm}
+        ${SOURCE}
+        ${CMAKE_CURRENT_BINARY_DIR}/ntkrnlmp.def)
+
+    add_target_compile_definitions(ntkrnlmp CONFIG_SMP)
+
+    if(ARCH STREQUAL "i386")
+        set_entrypoint(ntkrnlmp KiSystemStartup 4)
+    else()
+        set_entrypoint(ntkrnlmp KiSystemStartup)
+    endif()
+    set_subsystem(ntkrnlmp native)
+
+    if(MSVC)
+        set_image_base(ntkrnlmp 0x00400000)
+    else()
+        set_image_base(ntkrnlmp 0x80800000)
+    endif()
+
+    # Linker bug
+    if(NOT MSVC AND LTCG)
+        add_target_link_flags(ntkrnlmp "-shared")
+    endif()
+
+    target_link_libraries(ntkrnlmp cportlib csq ${PSEH_LIB} cmlib rtl rossym libcntpr wdmguid ioevent)
+    add_importlibs(ntkrnlmp hal kdcom bootvid)
+    add_dependencies(ntkrnlmp psdk bugcodes asm)
+    add_cd_file(TARGET ntkrnlmp DESTINATION reactos/system32 NO_CAB FOR all)
+endif()
 
-add_library(ntdllsys ntdll.S)
-set_target_properties(ntdllsys PROPERTIES LINKER_LANGUAGE C)
+add_asm_files(ntdllsys_asm ntdll.S)
+add_library(ntdllsys ${ntdllsys_asm})
+set_target_properties(ntdllsys PROPERTIES LINKER_LANGUAGE "C")