[CMAKE]
[reactos.git] / msc.cmake
index 0c0a527..864eea0 100644 (file)
--- a/msc.cmake
+++ b/msc.cmake
@@ -1,36 +1,43 @@
 \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
+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(add_pch _target_name _header_filename _src_list)\r
+endmacro()\r
 \r
 macro(add_linkerflag MODULE _flag)\r
     set(NEW_LINKER_FLAGS ${_flag})\r
@@ -71,7 +78,7 @@ macro(set_module_type MODULE TYPE)
         else()\r
             target_link_libraries(${MODULE} mingw_main)\r
         endif()\r
-               target_link_libraries(${MODULE} mingw_common msvcsup)\r
+        target_link_libraries(${MODULE} mingw_common msvcsup)\r
     endif ()\r
     if (${TYPE} MATCHES win32cui)\r
         set_subsystem(${MODULE} console)\r
@@ -81,17 +88,17 @@ macro(set_module_type MODULE TYPE)
         else()\r
             target_link_libraries(${MODULE} mingw_main)\r
         endif()\r
-               target_link_libraries(${MODULE} mingw_common msvcsup)\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 msvcsup)\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
     if(${TYPE} MATCHES win32ocx)\r
@@ -106,15 +113,15 @@ macro(set_module_type MODULE TYPE)
         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
+    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
-       endif()\r
-\r
+        add_dependencies(${MODULE} bugcodes)\r
+        target_link_libraries(${MODULE} msvcsup)\r
+    endif()\r
 endmacro()\r
 \r
 macro(set_unicode)\r
@@ -129,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)\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-spec2def -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-spec2def -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
@@ -190,27 +192,19 @@ endmacro()
 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-spec2def -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
+    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
-# Optional 3rd parameter: dllname\r
-macro(set_export_spec _module _spec_file)\r
-    get_filename_component(_file ${_spec_file} NAME_WE)\r
-    if (${ARGC} GREATER 2)\r
-        set(_dllname ${ARGV2})\r
-    else()\r
-        set(_dllname ${_file}.dll)\r
-    endif()\r
-    spec2def(${_dllname} ${_spec_file})\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