[CMAKE]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Wed, 10 Nov 2010 12:33:24 +0000 (12:33 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Wed, 10 Nov 2010 12:33:24 +0000 (12:33 +0000)
- Move spec2def into comppiler specific files, use spec2pdef tool on MSVC builds
- Add a ridiculously complex macro to create the importlibs for MSVC. (It was hard for me to figure this out, so be it for you ;-))

svn path=/branches/cmake-bringup/; revision=49545

CMakeMacros.cmake
gcc.cmake
msc.cmake

index b77ce8f..462fc9b 100644 (file)
@@ -1,4 +1,4 @@
-
+\r
 MACRO(_PCH_GET_COMPILE_FLAGS _target_name _out_compile_flags _header_filename)\r
 \r
     # Add the precompiled header to the build\r
@@ -41,16 +41,6 @@ MACRO(add_pch _target_name _header_filename _src_list)
 \r
 ENDMACRO(add_pch _target_name _header_filename _src_list)\r
 \r
-MACRO(spec2def _dllname _spec_file)
-    get_filename_component(_file ${_spec_file} NAME_WE)\r
-    add_custom_command(\r
-        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def\r
-        COMMAND native-winebuild -o ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def --def -E ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} --filename ${_dllname}\r
-        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file})
-    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_file}.def
-        PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE)\r
-ENDMACRO(spec2def _dllname _spec_file)\r
-\r
 if (NOT MSVC)\r
 MACRO(CreateBootSectorTarget _target_name _asm_file _object_file)\r
 \r
@@ -116,85 +106,85 @@ MACRO(ADD_INTERFACE_DEFINITIONS TARGET)
 ENDMACRO()\r
 \r
 MACRO(add_minicd_target _targetname _dir) # optional parameter: _nameoncd\r
-    if("${ARGN}" STREQUAL "")
-        get_target_property(FILENAME ${_targetname} LOCATION)
-       get_filename_component(_nameoncd ${FILENAME} NAME)
-    else()
-       set(_nameoncd ${ARGN})
-    endif()
-    
+    if("${ARGN}" STREQUAL "")\r
+        get_target_property(FILENAME ${_targetname} LOCATION)\r
+       get_filename_component(_nameoncd ${FILENAME} NAME)\r
+    else()\r
+       set(_nameoncd ${ARGN})\r
+    endif()\r
+    \r
     file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_minicd_target.txt "${_targetname}\t${_dir}\t${_nameoncd}\n")\r
 ENDMACRO(add_minicd_target)\r
 \r
 MACRO(add_minicd FILENAME _dir _nameoncd)\r
     file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_minicd.txt "${FILENAME}\t${_dir}\t${_nameoncd}\n")\r
 ENDMACRO(add_minicd)\r
-
-macro(set_cpp)
-  include_directories(BEFORE ${REACTOS_SOURCE_DIR}/lib/3rdparty/stlport/stlport)
-  set(IS_CPP 1)
-endmacro()
-
+\r
+macro(set_cpp)\r
+  include_directories(BEFORE ${REACTOS_SOURCE_DIR}/lib/3rdparty/stlport/stlport)\r
+  set(IS_CPP 1)\r
+endmacro()\r
+\r
 MACRO(add_livecd_target _targetname _dir )# optional parameter : _nameoncd\r
-    if("${ARGN}" STREQUAL "")
+    if("${ARGN}" STREQUAL "")\r
         get_target_property(FILENAME ${_targetname} LOCATION)\r
        get_filename_component(_nameoncd ${FILENAME} NAME)\r
     else()\r
        set(_nameoncd ${ARGN})\r
-    endif()
-    
+    endif()\r
+    \r
     file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_livecd_target.txt "${_targetname}\t${_dir}\t${_nameoncd}\n")\r
-ENDMACRO(add_livecd_target)
-
-MACRO(add_livecd FILENAME _dir)# optional parameter : _nameoncd
-    if("${ARGN}" STREQUAL "")
-       get_filename_component(_nameoncd ${FILENAME} NAME)
-    else()
-       set(_nameoncd ${ARGN})
-    endif()
-    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_livecd.txt "${FILENAME}\t${_dir}\t${_nameoncd}\n")
-ENDMACRO(add_livecd)
-
-macro(cab_to_dir _dir_num _var_name)
-#   1 = system32
-#   2 = system32\drivers
-#   3 = Fonts
-#   4 =
-#   5 = system32\drivers\etc
-#   6 = inf
-#   7 = bin
-#   8 = media
-    if(${_dir_num} STREQUAL "1")
-        set(${_var_name} "reactos/system32")
-    elseif(${_dir_num} STREQUAL "2")
-        set(${_var_name} "reactos/system32/drivers")
-    elseif(${_dir_num} STREQUAL "3")
-        set(${_var_name} "reactos/fonts")
-    elseif(${_dir_num} STREQUAL "4")
-        set(${_var_name} "reactos")
-    elseif(${_dir_num} STREQUAL "5")
-        set(${_var_name} "reactos/system32/drivers/etc")
-    elseif(${_dir_num} STREQUAL "6")
-        set(${_var_name} "reactos/inf")
-    elseif(${_dir_num} STREQUAL "7")
-        set(${_var_name} "reactos/bin")
-    elseif(${_dir_num} STREQUAL "8")
-        set(${_var_name} "reactos/system32/drivers")
-    else()
-        message(FATAL_ERROR "Wrong directory ${_dir_num}")
-    endif()
-endmacro()
-
-MACRO(add_cab_target _targetname _num )
-    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab_target.txt "${_targetname}\t${_num}\n")
-    cab_to_dir(${_num} _dir)
-    add_livecd_target(${_targetname} ${_dir})
-ENDMACRO(add_cab_target)
-
-MACRO(add_cab FILENAME _num)
-    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab.txt "${FILENAME}\t${_num}\n")
-    cab_to_dir(${_num} _dir)
-    add_livecd(${FILENAME} ${_dir})
+ENDMACRO(add_livecd_target)\r
+\r
+MACRO(add_livecd FILENAME _dir)# optional parameter : _nameoncd\r
+    if("${ARGN}" STREQUAL "")\r
+       get_filename_component(_nameoncd ${FILENAME} NAME)\r
+    else()\r
+       set(_nameoncd ${ARGN})\r
+    endif()\r
+    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_livecd.txt "${FILENAME}\t${_dir}\t${_nameoncd}\n")\r
+ENDMACRO(add_livecd)\r
+\r
+macro(cab_to_dir _dir_num _var_name)\r
+#   1 = system32\r
+#   2 = system32\drivers\r
+#   3 = Fonts\r
+#   4 =\r
+#   5 = system32\drivers\etc\r
+#   6 = inf\r
+#   7 = bin\r
+#   8 = media\r
+    if(${_dir_num} STREQUAL "1")\r
+        set(${_var_name} "reactos/system32")\r
+    elseif(${_dir_num} STREQUAL "2")\r
+        set(${_var_name} "reactos/system32/drivers")\r
+    elseif(${_dir_num} STREQUAL "3")\r
+        set(${_var_name} "reactos/fonts")\r
+    elseif(${_dir_num} STREQUAL "4")\r
+        set(${_var_name} "reactos")\r
+    elseif(${_dir_num} STREQUAL "5")\r
+        set(${_var_name} "reactos/system32/drivers/etc")\r
+    elseif(${_dir_num} STREQUAL "6")\r
+        set(${_var_name} "reactos/inf")\r
+    elseif(${_dir_num} STREQUAL "7")\r
+        set(${_var_name} "reactos/bin")\r
+    elseif(${_dir_num} STREQUAL "8")\r
+        set(${_var_name} "reactos/system32/drivers")\r
+    else()\r
+        message(FATAL_ERROR "Wrong directory ${_dir_num}")\r
+    endif()\r
+endmacro()\r
+\r
+MACRO(add_cab_target _targetname _num )\r
+    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab_target.txt "${_targetname}\t${_num}\n")\r
+    cab_to_dir(${_num} _dir)\r
+    add_livecd_target(${_targetname} ${_dir})\r
+ENDMACRO(add_cab_target)\r
+\r
+MACRO(add_cab FILENAME _num)\r
+    file(APPEND ${REACTOS_BINARY_DIR}/boot/ros_cab.txt "${FILENAME}\t${_num}\n")\r
+    cab_to_dir(${_num} _dir)\r
+    add_livecd(${FILENAME} ${_dir})\r
 ENDMACRO(add_cab)    \r
 \r
 macro(custom_incdefs)\r
@@ -251,8 +241,8 @@ macro (MACRO_IDL_FILES)
         get_filename_component(FILE ${_in_FILE} NAME_WE)\r
         add_custom_command(\r
             OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c\r
-            COMMAND ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${IDL_SERVER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl
-            DEPENDS ${_in_file})
+            COMMAND ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${IDL_SERVER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl\r
+            DEPENDS ${_in_file})\r
         set_source_files_properties(\r
             ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_s.c\r
             PROPERTIES GENERATED TRUE)\r
@@ -261,8 +251,8 @@ macro (MACRO_IDL_FILES)
     \r
         add_custom_command(\r
             OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c\r
-            COMMAND ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${IDL_CLIENT_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl
-            DEPENDS ${_in_file})
+            COMMAND ${IDL_COMPILER} ${result_incs} ${result_defs} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${IDL_CLIENT_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.idl\r
+            DEPENDS ${_in_file})\r
         set_source_files_properties(\r
             ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.h ${CMAKE_CURRENT_BINARY_DIR}/${FILE}_c.c\r
             PROPERTIES GENERATED TRUE)\r
@@ -271,16 +261,16 @@ macro (MACRO_IDL_FILES)
     endforeach(_in_FILE ${ARGN})\r
 \r
 endmacro (MACRO_IDL_FILES)\r
-
-macro(ADD_TYPELIB TARGET)
-  custom_incdefs()
-  foreach(SOURCE ${ARGN})
-    get_filename_component(FILE ${SOURCE} NAME_WE)
-    set(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb)
-    add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb
-                       COMMAND ${IDL_COMPILER} ${result_incs} ${IDL_FLAGS} ${IDL_TYPELIB_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}
-                       DEPENDS ${SOURCE})
-    list(APPEND OBJECTS ${OBJECT})
-  endforeach()
-  add_custom_target(${TARGET} ALL DEPENDS ${OBJECTS})
-endmacro()
+\r
+macro(ADD_TYPELIB TARGET)\r
+  custom_incdefs()\r
+  foreach(SOURCE ${ARGN})\r
+    get_filename_component(FILE ${SOURCE} NAME_WE)\r
+    set(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb)\r
+    add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb\r
+                       COMMAND ${IDL_COMPILER} ${result_incs} ${IDL_FLAGS} ${IDL_TYPELIB_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}\r
+                       DEPENDS ${SOURCE})\r
+    list(APPEND OBJECTS ${OBJECT})\r
+  endforeach()\r
+  add_custom_target(${TARGET} ALL DEPENDS ${OBJECTS})\r
+endmacro()\r
index 679cc21..e1250e5 100644 (file)
--- a/gcc.cmake
+++ b/gcc.cmake
@@ -158,6 +158,16 @@ macro(add_importlib_target _def_file)
   # empty for now, while import libs are shipped
 endmacro()
 
+MACRO(spec2def _dllname _spec_file)
+    get_filename_component(_file ${_spec_file} NAME_WE)
+    add_custom_command(
+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def
+        COMMAND native-winebuild -o ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def --def -E ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} --filename ${_dllname}
+        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file})
+    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_file}.def
+        PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE)
+ENDMACRO(spec2def _dllname _spec_file)
+
 macro(pdef2def _pdef_file)
     get_filename_component(_file ${_pdef_file} NAME_WE)
     add_custom_command(
index 506a7f5..e74ca7d 100644 (file)
--- a/msc.cmake
+++ b/msc.cmake
@@ -56,6 +56,8 @@ macro(set_module_type MODULE TYPE)
     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
     endif ()\r
     if (${TYPE} MATCHES win32cui)\r
         set_subsystem(${MODULE} console)\r
@@ -72,6 +74,7 @@ macro(set_module_type MODULE TYPE)
                endif()\r
                target_link_libraries(${MODULE} mingw_common mingw_dllmain)\r
                add_importlibs(${MODULE} msvcrt kernel32)\r
+        add_linkerflag(${MODULE} "/DLL")\r
     endif()\r
 \r
 endmacro()\r
@@ -89,20 +92,48 @@ endmacro()
 \r
 #idl files support\r
 set(IDL_COMPILER midl)\r
-set(IDL_FLAGS /win32)\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
+\r
+    # Generate a 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
+\r
+    # Assemble the file\r
+    add_custom_command(\r
+        OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj\r
+        COMMAND ${CMAKE_ASM_COMPILER} /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
+\r
+    # Add neccessary importlibs for redirections\r
+    foreach(_lib ${ARGN})\r
+        list(APPEND _libraries "${CMAKE_BINARY_DIR}/importlibs/${_lib}.lib")\r
+    endforeach()\r
 \r
-macro(add_importlib_target _def_file)\r
-    get_filename_component(_name ${_def_file} NAME_WE)\r
+    # Build the importlib\r
     add_custom_command(\r
         OUTPUT {CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib\r
-        COMMAND LINK /LIB /MACHINE:X86 /DEF:${_def_file} /OUT:${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib\r
-        DEPENDS ${_def_file}\r
+        COMMAND LINK /LIB /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
+\r
+    # Add the importlib target\r
     add_custom_target(\r
         lib${_name}\r
         DEPENDS {CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib\r
@@ -116,6 +147,16 @@ macro(add_importlibs MODULE)
     endforeach()\r
 endmacro()\r
 \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
+        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
+\r
 macro(pdef2def _pdef_file)\r
     get_filename_component(_file ${_pdef_file} NAME_WE)\r
     add_custom_command(\r