[CMAKE]
authorAmine Khaldi <amine.khaldi@reactos.org>
Sun, 19 Sep 2010 00:27:24 +0000 (00:27 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 19 Sep 2010 00:27:24 +0000 (00:27 +0000)
- Introduce MSVC toolchain support. Just use -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake for the toolchain.
- Sync setjmp.h from trunk.
- Improve mingw targets (mingw_common, mingw_wmain, oldnames... etc) a bit to make them compile and link with msvc.
- Dedicated to Timo ;)

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

include/crt/setjmp.h
lib/3rdparty/mingw/CMakeLists.txt
toolchain-msvc.cmake [new file with mode: 0644]

index ecfeb82..2a64a9b 100644 (file)
@@ -136,29 +136,18 @@ extern "C" {
 #define _JMP_BUF_DEFINED
 #endif
 
 #define _JMP_BUF_DEFINED
 #endif
 
-static inline __attribute__((always_inline)) void * mingw_getsp(void)
-{
-    void *value;
-#if defined(__x86_64)
 #ifdef _MSC_VER
 #ifdef _MSC_VER
-    __asm {mov value, rsp}
-#else
-    __asm__ __volatile__("movq %%rsp, %[value]" : [value] "=r" (value) );
-#endif
-#elif defined(_X86_)
-#ifdef _MSC_VER
-    __asm {mov value, esp}
-#else
-    __asm__ __volatile__("movql %%esp, %[value]" : [value] "=r" (value) );
-#endif
+int __cdecl __MINGW_NOTHROW setjmp(jmp_buf _Buf);
 #else
 #else
-    #error mingw_getsp unimplemented
-#endif
-    return value;
-}
-
 #ifdef USE_MINGW_SETJMP_TWO_ARGS
 #ifndef _INC_SETJMPEX
 #ifdef USE_MINGW_SETJMP_TWO_ARGS
 #ifndef _INC_SETJMPEX
+#if defined(__x86_64)
+# define mingw_getsp() \
+  ({ void* value; __asm__ __volatile__("movq %%rsp, %[value]" : [value] "=r" (value)); value; })
+#elif defined(_X86_)
+# define mingw_getsp() \
+  ({ void* value; __asm__ __volatile__("movl %%esp, %[value]" : [value] "=r" (value)); value; })
+#endif
 #define setjmp(BUF) _setjmp((BUF),mingw_getsp())
   int __cdecl __MINGW_NOTHROW _setjmp(jmp_buf _Buf,void *_Ctx);
 #else
 #define setjmp(BUF) _setjmp((BUF),mingw_getsp())
   int __cdecl __MINGW_NOTHROW _setjmp(jmp_buf _Buf,void *_Ctx);
 #else
@@ -172,6 +161,7 @@ static inline __attribute__((always_inline)) void * mingw_getsp(void)
 #define setjmp _setjmp
 #endif
   int __cdecl __MINGW_NOTHROW setjmp(jmp_buf _Buf);
 #define setjmp _setjmp
 #endif
   int __cdecl __MINGW_NOTHROW setjmp(jmp_buf _Buf);
+#endif
 #endif
 
   __declspec(noreturn) __MINGW_NOTHROW void __cdecl ms_longjmp(jmp_buf _Buf,int _Value)/* throw(...)*/;
 #endif
 
   __declspec(noreturn) __MINGW_NOTHROW void __cdecl ms_longjmp(jmp_buf _Buf,int _Value)/* throw(...)*/;
index 22e78c3..21b18bc 100644 (file)
@@ -1,7 +1,11 @@
 
 include_directories(${REACTOS_SOURCE_DIR}/include/reactos/mingw-w64)
 
 
 include_directories(${REACTOS_SOURCE_DIR}/include/reactos/mingw-w64)
 
-add_definitions(-D_CRTBLD -Wno-main)
+add_definitions(-D_CRTBLD)
+
+if(NOT MSVC)
+add_definitions(-Wno-main)
+endif(NOT MSVC)
 
 set(MINGW_COMMON_SOURCE
   _newmode.c
 
 set(MINGW_COMMON_SOURCE
   _newmode.c
@@ -31,11 +35,14 @@ set(MINGW_COMMON_SOURCE
   xthdloc.c
   xtxtmode.c
   ofmt_stub.c
   xthdloc.c
   xtxtmode.c
   ofmt_stub.c
-  cxa_pure_virtual.c
-)
+  cxa_pure_virtual.c)
 
 add_library(mingw_common ${MINGW_COMMON_SOURCE})
 
 add_library(mingw_common ${MINGW_COMMON_SOURCE})
+
+if(NOT MSVC)
 target_link_libraries(mingw_common oldnames -lkernel32 -lntdll)
 target_link_libraries(mingw_common oldnames -lkernel32 -lntdll)
+endif(NOT MSVC)
+
 set_target_properties(mingw_common PROPERTIES COMPILE_DEFINITIONS _M_CEE_PURE)
 add_dependencies(mingw_common psdk)
 
 set_target_properties(mingw_common PROPERTIES COMPILE_DEFINITIONS _M_CEE_PURE)
 add_dependencies(mingw_common psdk)
 
@@ -53,8 +60,7 @@ add_dependencies(mingw_dllmain psdk)
 add_custom_command(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a
   COMMAND ${MINGW_PREFIX}dlltool --def ${CMAKE_CURRENT_SOURCE_DIR}/moldname-msvcrt.def --kill-at --output-lib ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a
 add_custom_command(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a
   COMMAND ${MINGW_PREFIX}dlltool --def ${CMAKE_CURRENT_SOURCE_DIR}/moldname-msvcrt.def --kill-at --output-lib ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a
-  COMMAND ${MINGW_PREFIX}ar -rc ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a
-)
+  COMMAND ${MINGW_PREFIX}ar -rc ${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a)
 
 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a PROPERTIES GENERATED TRUE)
 
 
 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/liboldnames.a PROPERTIES GENERATED TRUE)
 
diff --git a/toolchain-msvc.cmake b/toolchain-msvc.cmake
new file mode 100644 (file)
index 0000000..2ac1651
--- /dev/null
@@ -0,0 +1,18 @@
+\r
+if(NOT ARCH)\r
+set(ARCH i386)\r
+endif(NOT ARCH)\r
+\r
+# the name of the target operating system\r
+set(CMAKE_SYSTEM_NAME Windows)\r
+set(CMAKE_SYSTEM_PROCESSOR i686)\r
+\r
+# which compilers to use for C and C++\r
+set(CMAKE_C_COMPILER cl)\r
+set(CMAKE_CXX_COMPILER cl)\r
+\r
+set(CMAKE_C_FLAGS_INIT "/DWIN32 /D_WINDOWS /W1 /Zm1000")\r
+\r
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\r
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\r
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\r