[CMAKE]
authorAmine Khaldi <amine.khaldi@reactos.org>
Thu, 2 Dec 2010 21:56:40 +0000 (21:56 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Thu, 2 Dec 2010 21:56:40 +0000 (21:56 +0000)
- Group some cross compiling related sections.
- Implement add_importlib_target() for gcc.
- Improve the msvc version.

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

CMakeLists.txt
gcc.cmake
msc.cmake

index 3835afb..308a6aa 100644 (file)
@@ -1,30 +1,10 @@
+
 cmake_minimum_required(VERSION 2.8)
 project(REACTOS)
 
 # Compile options
 include(config.cmake)
 
-# Compiler specific definitions and macros
-if(MSVC)
-include(msc.cmake)
-else()
-include(gcc.cmake)
-endif(MSVC)
-
-# Generic macros
-include(CMakeMacros.cmake)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
-set(CMAKE_SHARED_LIBRARY_PREFIX "")
-
-set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE)
-set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE)
-
-set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
-
-add_definitions(-D__REACTOS__)
-
 if(NOT CMAKE_CROSSCOMPILING)
 
 add_definitions(-DTARGET_i386)
@@ -48,6 +28,40 @@ endif()
 
 else()
 
+if(NOT DEFINED REACTOS_BUILD_TOOLS_DIR)
+    set(REACTOS_BUILD_TOOLS_DIR ${REACTOS_SOURCE_DIR}/build)
+endif()
+
+set(IMPORT_EXECUTABLES "${REACTOS_BUILD_TOOLS_DIR}/ImportExecutables.cmake" CACHE FILEPATH "Host executables")
+include(${IMPORT_EXECUTABLES})
+
+endif(NOT CMAKE_CROSSCOMPILING)
+
+# Compiler specific definitions and macros
+if(MSVC)
+include(msc.cmake)
+else()
+include(gcc.cmake)
+endif(MSVC)
+
+# Generic macros
+include(CMakeMacros.cmake)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
+set(CMAKE_SHARED_LIBRARY_PREFIX "")
+
+set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE)
+set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE)
+
+set(CMAKE_COLOR_MAKEFILE OFF)
+
+set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
+
+add_definitions(-D__REACTOS__)
+
+if(CMAKE_CROSSCOMPILING)
+
 #Some cleanup
 file(REMOVE
     ${REACTOS_BINARY_DIR}/boot/ros_livecd.txt
@@ -67,13 +81,6 @@ enable_language(ASM)
 # Activate language support for resource files
 enable_language(RC)
 
-if(NOT DEFINED REACTOS_BUILD_TOOLS_DIR)
-    set(REACTOS_BUILD_TOOLS_DIR ${REACTOS_SOURCE_DIR}/build)
-endif()
-
-set(IMPORT_EXECUTABLES "${REACTOS_BUILD_TOOLS_DIR}/ImportExecutables.cmake" CACHE FILEPATH "Host executables")
-include(${IMPORT_EXECUTABLES})
-
 add_definitions(-DDBG=${DBG} -DKDBG=${KDBG})
 
 if(DBG)
@@ -189,6 +196,8 @@ add_custom_command(
 
 add_custom_target(gendib_generated ALL DEPENDS ${OUTPUT_FILES})
 
+file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/importlibs)
+
 #bootcd and livecd
 include(ros_cd.cmake)
 
index f02a2ba..158e52f 100644 (file)
--- a/gcc.cmake
+++ b/gcc.cmake
@@ -96,12 +96,6 @@ macro(set_image_base MODULE IMAGE_BASE)
     add_linkerflag(${MODULE} "-Wl,--image-base,${IMAGE_BASE}")
 endmacro()
 
-macro(add_importlibs MODULE)
-  foreach(LIB ${ARGN})
-    target_link_libraries(${MODULE} ${LIB}.dll.a)
-  endforeach()
-endmacro()
-
 macro(set_module_type MODULE TYPE)
 
     add_dependencies(${MODULE} psdk buildno_header)
@@ -193,8 +187,23 @@ set(IDL_CLIENT_ARG -c -C) #.c for stub client library
 set(IDL_PROXY_ARG -p -P)
 set(IDL_DLLDATA_ARG --dlldata-only --dlldata=)
 
-macro(add_importlib_target _def_file)
-  # empty for now, while import libs are shipped
+macro(add_importlibs MODULE)
+    foreach(LIB ${ARGN})
+        target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.a)
+        add_dependencies(${MODULE} lib${LIB})
+    endforeach()
+endmacro()
+
+macro(add_importlib_target _spec_file)
+    get_filename_component(_name ${_spec_file} NAME_WE)
+    add_custom_command(
+        OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
+        COMMAND native-spec2def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} ${CMAKE_CURRENT_BINARY_DIR}/${_name}.def
+        COMMAND ${MINGW_PREFIX}dlltool --def ${CMAKE_CURRENT_BINARY_DIR}/${_name}.def --kill-at --output-lib=${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a
+        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file})
+    add_custom_target(
+        lib${_name}
+        DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a)
 endmacro()
 
 macro(spec2def _dllname _spec_file)
index b08e9af..9d9fdc5 100644 (file)
--- a/msc.cmake
+++ b/msc.cmake
@@ -7,7 +7,6 @@ add_definitions(-Dinline=__inline)
 \r
 if(NOT CMAKE_CROSSCOMPILING)\r
 \r
-\r
 else()\r
 \r
 add_definitions(/GS- /Zl /Zi)\r
@@ -143,15 +142,11 @@ set(IDL_DLLDATA_ARG /dlldata )
 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
+        OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def\r
+        # Generate the asm stub file\r
         COMMAND native-spec2def -l=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}\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
+        # Generate a the export def file\r
         COMMAND native-spec2def -@ -r -d=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}\r
         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file})\r
 \r
@@ -159,8 +154,7 @@ macro(add_importlib_target _spec_file)
     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
+        DEPENDS "${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm")\r
 \r
     # Add neccessary importlibs for redirections\r
     set(_libraries "")\r
@@ -173,14 +167,12 @@ macro(add_importlib_target _spec_file)
     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\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