[CMAKE]
[reactos.git] / msc.cmake
index bf3b397..864eea0 100644 (file)
--- a/msc.cmake
+++ b/msc.cmake
@@ -1,28 +1,44 @@
 \r
-if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86")\r
-    add_definitions(-D__i386__)\r
+if(0) # Fixme redefinition warning\r
+if(OPTIMIZE STREQUAL "1")\r
+    add_definitions(/O1)\r
+elseif(OPTIMIZE STREQUAL "2")\r
+    add_definitions(/O2)\r
+elseif(OPTIMIZE STREQUAL "3")\r
+    add_definitions(/Ot /Ox /GS-)\r
+elseif(OPTIMIZE STREQUAL "4")\r
+    add_definitions(/Os /Ox /GS-)\r
+elseif(OPTIMIZE STREQUAL "5")\r
+    add_definitions(/GF /Gy /Ob2 /Os /Ox /GS-)\r
+endif()\r
 endif()\r
 \r
-add_definitions(-Dinline=__inline)\r
-\r
-if(NOT CMAKE_CROSSCOMPILING)\r
-\r
-\r
-else()\r
-\r
-add_definitions(/GS- /Zl /Zi)\r
+add_definitions(/X /GS- /Zl /Zi)\r
 add_definitions(-Dinline=__inline -D__STDC__=1)\r
 \r
-IF(${_MACHINE_ARCH_FLAG} MATCHES X86)\r
-  SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")\r
-  SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")\r
-  SET (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")\r
-ENDIF()\r
+if(${_MACHINE_ARCH_FLAG} MATCHES X86)\r
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")\r
+  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")\r
+  set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")\r
+endif()\r
+\r
+if(${ARCH} MATCHES amd64)\r
+    add_definitions(-D__x86_64)\r
+endif()\r
 \r
 link_directories("${REACTOS_BINARY_DIR}/importlibs" ${REACTOS_BINARY_DIR}/lib/3rdparty/mingw)\r
 \r
 set(CMAKE_RC_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")\r
 \r
+macro(add_pch _target_name _header_filename _src_list)\r
+    get_filename_component(FILE ${_header_filename} NAME)\r
+    set(_gch_filename "${_target_name}_${FILE}.gch")\r
+    add_custom_command(\r
+        OUTPUT ${_gch_filename}\r
+        COMMAND echo Ignoring precompiled header\r
+        DEPENDS ${_header_filename})\r
+endmacro()\r
+\r
 macro(add_linkerflag MODULE _flag)\r
     set(NEW_LINKER_FLAGS ${_flag})\r
     get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)\r
@@ -34,7 +50,7 @@ endmacro()
 \r
 macro(set_entrypoint MODULE ENTRYPOINT)\r
     if(${ENTRYPOINT} STREQUAL "0")\r
-        add_linkerflag(${MODULE} "/ENTRY:0")\r
+        add_linkerflag(${MODULE} "/NOENTRY")\r
     else()\r
         add_linkerflag(${MODULE} "/ENTRY:${ENTRYPOINT}")\r
     endif()\r
@@ -52,35 +68,65 @@ macro(set_module_type MODULE TYPE)
     add_dependencies(${MODULE} psdk buildno_header)\r
     if(${TYPE} MATCHES nativecui)\r
         set_subsystem(${MODULE} native)\r
-        add_importlibs(${MODULE} ntdll)\r
+        set_entrypoint(${MODULE} NtProcessStartup@4)\r
     endif()\r
     if (${TYPE} MATCHES win32gui)\r
         set_subsystem(${MODULE} windows)\r
         set_entrypoint(${MODULE} WinMainCRTStartup)\r
-               target_link_libraries(${MODULE} mingw_common mingw_wmain)\r
+        if(IS_UNICODE)\r
+            target_link_libraries(${MODULE} mingw_wmain)\r
+        else()\r
+            target_link_libraries(${MODULE} mingw_main)\r
+        endif()\r
+        target_link_libraries(${MODULE} mingw_common msvcsup)\r
     endif ()\r
     if (${TYPE} MATCHES win32cui)\r
         set_subsystem(${MODULE} console)\r
         set_entrypoint(${MODULE} mainCRTStartup)\r
-               target_link_libraries(${MODULE} mingw_common mingw_wmain)\r
+        if(IS_UNICODE)\r
+            target_link_libraries(${MODULE} mingw_wmain)\r
+        else()\r
+            target_link_libraries(${MODULE} mingw_main)\r
+        endif()\r
+        target_link_libraries(${MODULE} mingw_common msvcsup)\r
     endif ()\r
     if(${TYPE} MATCHES win32dll)\r
         # Need this only because mingw library is broken\r
         set_entrypoint(${MODULE} DllMainCRTStartup@12)\r
-               if(DEFINED baseaddress_${MODULE})\r
-                       set_image_base(${MODULE} ${baseaddress_${MODULE}})\r
-               else()\r
-                       message(STATUS "${MODULE} has no base address")\r
-               endif()\r
-               target_link_libraries(${MODULE} mingw_common mingw_dllmain)\r
-               add_importlibs(${MODULE} msvcrt kernel32)\r
+        if(DEFINED baseaddress_${MODULE})\r
+            set_image_base(${MODULE} ${baseaddress_${MODULE}})\r
+        else()\r
+            message(STATUS "${MODULE} has no base address")\r
+        endif()\r
+        target_link_libraries(${MODULE} mingw_common mingw_dllmain msvcsup)\r
         add_linkerflag(${MODULE} "/DLL")\r
     endif()\r
-\r
+    if(${TYPE} MATCHES win32ocx)\r
+        set_entrypoint(${MODULE} DllMainCRTStartup@12)\r
+        set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")\r
+        target_link_libraries(${MODULE} mingw_common mingw_dllmain msvcsup)\r
+        add_linkerflag(${MODULE} "/DLL")\r
+    endif()\r
+    if(${TYPE} MATCHES cpl)\r
+        set_entrypoint(${MODULE} DllMainCRTStartup@12)\r
+        set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")\r
+        target_link_libraries(${MODULE} mingw_common mingw_dllmain msvcsup)\r
+        add_linkerflag(${MODULE} "/DLL")\r
+    endif()\r
+    if(${TYPE} MATCHES kernelmodedriver)\r
+        set_target_properties(${MODULE} PROPERTIES SUFFIX ".sys")\r
+        set_entrypoint(${MODULE} DriverEntry@8)\r
+        set_subsystem(${MODULE} native)\r
+        set_image_base(${MODULE} 0x00010000)\r
+        add_linkerflag(${MODULE} "/DRIVER")\r
+        add_dependencies(${MODULE} bugcodes)\r
+        target_link_libraries(${MODULE} msvcsup)\r
+    endif()\r
 endmacro()\r
 \r
 macro(set_unicode)\r
-    add_definitions(-DUNICODE -D_UNICODE)\r
+   add_definitions(-DUNICODE -D_UNICODE)\r
+   set(IS_UNICODE 1)\r
 endmacro()\r
 \r
 set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi  /Ob0 /Od")\r
@@ -90,55 +136,50 @@ macro(set_rc_compiler)
 # dummy, this workaround is only needed in mingw due to lack of RC support in cmake\r
 endmacro()\r
 \r
-#idl files support\r
-set(IDL_COMPILER midl)\r
-set(IDL_FLAGS /win32 /Dstrict_context_handle=)\r
-set(IDL_HEADER_ARG /h) #.h\r
-set(IDL_TYPELIB_ARG /tlb) #.tlb\r
-set(IDL_SERVER_ARG /sstub) #.c for stub server library\r
-set(IDL_CLIENT_ARG /cstub) #.c for stub client library\r
-\r
 # Thanks MS for creating a stupid linker\r
-macro(add_importlib_target _spec_file)\r
-    get_filename_component(_name ${_spec_file} NAME_WE)\r
-\r
-    # Generate the asm stub file\r
-    add_custom_command(\r
-        OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm\r
-        COMMAND native-spec2pdef -s ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm\r
-        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file})\r
+macro(add_importlib_target _exports_file)\r
+    get_filename_component(_name ${_exports_file} NAME_WE)\r
+    get_target_property(_suffix ${_name} SUFFIX)\r
+    if(${_suffix} STREQUAL "_suffix-NOTFOUND")\r
+        get_target_property(_type ${_name} TYPE)\r
+        if(${_type} MATCHES EXECUTABLE)\r
+            set(_suffix ".exe")\r
+        else()\r
+            set(_suffix ".dll")\r
+        endif()\r
+    endif()\r
 \r
-    # Generate a the export def file\r
+    # Generate the asm stub file and the export def file\r
     add_custom_command(\r
-        OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def\r
-        COMMAND native-spec2pdef -n -r ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def\r
-        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file})\r
+        OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def\r
+        COMMAND native-spec2def --ms --kill-at -r -n=${_name}${_suffix} -d=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def -l=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}\r
+        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file})\r
 \r
-    # Assemble the file\r
+    # Assemble the stub file\r
     add_custom_command(\r
         OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj\r
-        COMMAND ${CMAKE_ASM_COMPILER} /NOLOGO /Fo${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj /c /Ta ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm\r
-        DEPENDS "${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm"\r
-    )\r
+        COMMAND ${CMAKE_ASM_COMPILER} /nologo /Cp /Fo${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj /c /Ta ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm\r
+        DEPENDS "${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm")\r
 \r
     # Add neccessary importlibs for redirections\r
     set(_libraries "")\r
     foreach(_lib ${ARGN})\r
         list(APPEND _libraries "${CMAKE_BINARY_DIR}/importlibs/${_lib}.lib")\r
+        list(APPEND _dependencies ${_lib})\r
     endforeach()\r
 \r
     # Build the importlib\r
     add_custom_command(\r
         OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib\r
         COMMAND LINK /LIB /NOLOGO /MACHINE:X86 /DEF:${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def /OUT:${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${_libraries}\r
-        DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def ${_libraries}\r
-    )\r
+        DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def)\r
 \r
     # Add the importlib target\r
     add_custom_target(\r
         lib${_name}\r
-        DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib\r
-    )\r
+        DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib)\r
+\r
+    add_dependencies(lib${_name} asm ${_dependencies})\r
 endmacro()\r
 \r
 macro(add_importlibs MODULE)\r
@@ -148,37 +189,22 @@ macro(add_importlibs MODULE)
     endforeach()\r
 endmacro()\r
 \r
-MACRO(spec2def _dllname _spec_file)\r
+macro(spec2def _dllname _spec_file)\r
     get_filename_component(_file ${_spec_file} NAME_WE)\r
     add_custom_command(\r
-        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def\r
-        COMMAND native-spec2pdef -n  --dll ${_dllname} ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def\r
+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c\r
+        COMMAND native-spec2def --ms --kill-at -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}\r
         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file})\r
-    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_file}.def\r
-        PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE)\r
-ENDMACRO(spec2def _dllname _spec_file)\r
+    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c\r
+        PROPERTIES GENERATED TRUE)\r
+endmacro()\r
 \r
-macro(pdef2def _pdef_file)\r
-    get_filename_component(_file ${_pdef_file} NAME_WE)\r
-    add_custom_command(\r
-        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def\r
-        COMMAND ${CMAKE_C_COMPILER} /EP /c ${CMAKE_CURRENT_SOURCE_DIR}/${_pdef_file} > ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def\r
-        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_pdef_file})\r
-    add_custom_target(\r
-        ${_file}_def\r
-        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def)\r
-endmacro(pdef2def _pdef_file)\r
-\r
-macro(set_pdef_file _module _pdef_file)\r
-    pdef2def(${_pdef_file})\r
-    get_filename_component(_file ${_pdef_file} NAME_WE)\r
-    add_linkerflag(${_module} "/DEF:${CMAKE_CURRENT_BINARY_DIR}/${_file}.def")\r
-    add_dependencies(${_module} ${_file}_def)\r
+macro(macro_mc FILE)\r
+    set(COMMAND_MC mc -r ${REACTOS_BINARY_DIR}/include/reactos -h ${REACTOS_BINARY_DIR}/include/reactos ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.mc)\r
 endmacro()\r
 \r
 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/importlibs)\r
 \r
 #pseh workaround\r
-set(PSEH_LIB "")\r
+set(PSEH_LIB "pseh")\r
 \r
-endif()\r