[ros-diffs] [tkreuzer] 49524: [CMAKE] - add new macro add_linkerflag to avoid code duplication - add new macro set_pdef_file, replacing the use of pdef2def, which is neccessary to resolve issues with MSVC. cma...

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Mon Nov 8 12:24:34 UTC 2010


Author: tkreuzer
Date: Mon Nov  8 12:24:33 2010
New Revision: 49524

URL: http://svn.reactos.org/svn/reactos?rev=49524&view=rev
Log:
[CMAKE]
- add new macro add_linkerflag to avoid code duplication
- add new macro set_pdef_file, replacing the use of pdef2def, which is neccessary to resolve issues with MSVC. cmake doesn't handle def files as source files very well, when they are not in the current source directory.

Modified:
    branches/cmake-bringup/gcc.cmake
    branches/cmake-bringup/msc.cmake

Modified: branches/cmake-bringup/gcc.cmake
URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/gcc.cmake?rev=49524&r1=49523&r2=49524&view=diff
==============================================================================
--- branches/cmake-bringup/gcc.cmake [iso-8859-1] (original)
+++ branches/cmake-bringup/gcc.cmake [iso-8859-1] Mon Nov  8 12:24:33 2010
@@ -32,12 +32,8 @@
 add_definitions(-Os -fno-strict-aliasing -ftracer -momit-leaf-frame-pointer -mpreferred-stack-boundary=2 -fno-set-stack-executable -fno-optimize-sibling-calls)
 
 # Macros
-macro(set_entrypoint MODULE ENTRYPOINT)
-    if(${ENTRYPOINT} STREQUAL "0")
-        set(NEW_LINKER_FLAGS "-Wl,-entry,0")
-    else()
-        set(NEW_LINKER_FLAGS "-Wl,-entry,_${ENTRYPOINT}")
-    endif()
+macro(add_linkerflag MODULE _flag)
+    set(NEW_LINKER_FLAGS ${_flag})
     get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
     if(LINKER_FLAGS)
         set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
@@ -45,13 +41,16 @@
     set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
 endmacro()
 
+macro(set_entrypoint MODULE ENTRYPOINT)
+    if(${ENTRYPOINT} STREQUAL "0")
+        add_linkerflag(${MODULE} "-Wl,-entry,0")
+    else()
+        add_linkerflag(${MODULE} "-Wl,-entry,_${ENTRYPOINT}")
+    endif()
+endmacro()
+
 macro(set_subsystem MODULE SUBSYSTEM)
-    set(NEW_LINKER_FLAGS "-Wl,--subsystem,${SUBSYSTEM}")
-    get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
-    if(LINKER_FLAGS)
-        set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
-    endif()
-    set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
+    add_linkerflag(${MODULE} "-Wl,--subsystem,${SUBSYSTEM}")
 endmacro()
 
 macro(set_image_base MODULE IMAGE_BASE)
@@ -167,7 +166,16 @@
         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_pdef_file})
     set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_file}.def
         PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE)
+    add_custom_target(
+        ${_file}_def
+        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def)
 endmacro(pdef2def _pdef_file)
+
+macro(set_pdef_file _module _pdef_file)
+    pdef2def(${_pdef_file})
+    get_filename_component(_file ${_pdef_file} NAME_WE)
+    target_link_libraries(${_module} "${CMAKE_CURRENT_BINARY_DIR}/${_file}.def")
+endmacro()
 
 #pseh lib, needed with mingw
 set(PSEH_LIB "pseh")

Modified: branches/cmake-bringup/msc.cmake
URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/msc.cmake?rev=49524&r1=49523&r2=49524&view=diff
==============================================================================
--- branches/cmake-bringup/msc.cmake [iso-8859-1] (original)
+++ branches/cmake-bringup/msc.cmake [iso-8859-1] Mon Nov  8 12:24:33 2010
@@ -23,13 +23,8 @@
 
 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>")
 
-
-macro(set_entrypoint MODULE ENTRYPOINT)
-    if(${ENTRYPOINT} STREQUAL "0")
-        set(NEW_LINKER_FLAGS "/ENTRY:0")
-    else()
-        set(NEW_LINKER_FLAGS "/ENTRY:${ENTRYPOINT}")
-    endif()
+macro(add_linkerflag MODULE _flag)
+    set(NEW_LINKER_FLAGS ${_flag})
     get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
     if(LINKER_FLAGS)
         set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
@@ -37,22 +32,20 @@
     set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
 endmacro()
 
+macro(set_entrypoint MODULE ENTRYPOINT)
+    if(${ENTRYPOINT} STREQUAL "0")
+        add_linkerflag(${MODULE} "/ENTRY:0")
+    else()
+        add_linkerflag(${MODULE} "/ENTRY:${ENTRYPOINT}")
+    endif()
+endmacro()
+
 macro(set_subsystem MODULE SUBSYSTEM)
-    set(NEW_LINKER_FLAGS "/subsystem:${SUBSYSTEM}")
-    get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
-    if(LINKER_FLAGS)
-        set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
-    endif()
-    set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
+    add_linkerflag(${MODULE} "/subsystem:${SUBSYSTEM}")
 endmacro()
 
 macro(set_image_base MODULE IMAGE_BASE)
-    set(NEW_LINKER_FLAGS "/BASE:${IMAGE_BASE}")
-    get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
-    if(LINKER_FLAGS)
-        set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
-    endif()
-    set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
+    add_linkerflag(${MODULE} "/BASE:${IMAGE_BASE}")
 endmacro()
 
 macro(set_module_type MODULE TYPE)
@@ -67,6 +60,7 @@
     if (${TYPE} MATCHES win32cui)
         set_subsystem(${MODULE} console)
         set_entrypoint(${MODULE} mainCRTStartup)
+		target_link_libraries(${MODULE} mingw_common mingw_wmain)
     endif ()
     if(${TYPE} MATCHES win32dll)
         # Need this only because mingw library is broken
@@ -77,6 +71,7 @@
 			message(STATUS "${MODULE} has no base address")
 		endif()
 		target_link_libraries(${MODULE} mingw_common mingw_dllmain)
+		add_importlibs(${MODULE} msvcrt kernel32)
     endif()
 
 endmacro()
@@ -122,7 +117,21 @@
 endmacro()
 
 macro(pdef2def _pdef_file)
-# Dummy for now
+    get_filename_component(_file ${_pdef_file} NAME_WE)
+    add_custom_command(
+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def
+        COMMAND ${CMAKE_C_COMPILER} /EP /c ${CMAKE_CURRENT_SOURCE_DIR}/${_pdef_file} > ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def
+        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_pdef_file})
+    add_custom_target(
+        ${_file}_def
+        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def)
+endmacro(pdef2def _pdef_file)
+
+macro(set_pdef_file _module _pdef_file)
+    pdef2def(${_pdef_file})
+    get_filename_component(_file ${_pdef_file} NAME_WE)
+    add_linkerflag(${_module} "/DEF:${CMAKE_CURRENT_BINARY_DIR}/${_file}.def")
+    add_dependencies(${_module} ${_file}_def)
 endmacro()
 
 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/importlibs)




More information about the Ros-diffs mailing list