[CMAKE]
[reactos.git] / msc.cmake
1
2 if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86")
3 add_definitions(-D__i386__)
4 endif()
5
6 add_definitions(-Dinline=__inline)
7
8 if(NOT CMAKE_CROSSCOMPILING)
9
10
11 else()
12
13 add_definitions(/GS- /Zl /Zi)
14 add_definitions(-Dinline=__inline -D__STDC__=1)
15
16 IF(${_MACHINE_ARCH_FLAG} MATCHES X86)
17 SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
18 SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
19 SET (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
20 ENDIF()
21
22 link_directories("${REACTOS_BINARY_DIR}/importlibs" ${REACTOS_BINARY_DIR}/lib/3rdparty/mingw)
23
24 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>")
25
26
27 macro(set_entrypoint MODULE ENTRYPOINT)
28 if(${ENTRYPOINT} STREQUAL "0")
29 set(NEW_LINKER_FLAGS "/ENTRY:0")
30 else()
31 set(NEW_LINKER_FLAGS "/ENTRY:${ENTRYPOINT}")
32 endif()
33 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
34 if(LINKER_FLAGS)
35 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
36 endif()
37 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
38 endmacro()
39
40 macro(set_subsystem MODULE SUBSYSTEM)
41 set(NEW_LINKER_FLAGS "/subsystem:${SUBSYSTEM}")
42 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
43 if(LINKER_FLAGS)
44 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
45 endif()
46 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
47 endmacro()
48
49 macro(set_image_base MODULE IMAGE_BASE)
50 set(NEW_LINKER_FLAGS "/BASE:${IMAGE_BASE}")
51 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
52 if(LINKER_FLAGS)
53 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
54 endif()
55 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
56 endmacro()
57
58 macro(set_module_type MODULE TYPE)
59 add_dependencies(${MODULE} psdk buildno_header)
60 if(${TYPE} MATCHES nativecui)
61 set_subsystem(${MODULE} native)
62 add_importlibs(${MODULE} ntdll)
63 endif()
64 if (${TYPE} MATCHES win32gui)
65 set_subsystem(${MODULE} windows)
66 endif ()
67 if (${TYPE} MATCHES win32cui)
68 set_subsystem(${MODULE} console)
69 set_entrypoint(${MODULE} mainCRTStartup)
70 endif ()
71 if(${TYPE} MATCHES win32dll)
72 # Need this only because mingw library is broken
73 set_entrypoint(${MODULE} DllMainCRTStartup@12)
74 if(DEFINED baseaddress_${MODULE})
75 set_image_base(${MODULE} ${baseaddress_${MODULE}})
76 else()
77 message(STATUS "${MODULE} has no base address")
78 endif()
79 target_link_libraries(${MODULE} mingw_common mingw_dllmain)
80 endif()
81
82 endmacro()
83
84 macro(set_unicode)
85 add_definitions(-DUNICODE -D_UNICODE)
86 endmacro()
87
88 set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od")
89 set(CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od")
90
91 macro(set_rc_compiler)
92 # dummy, this workaround is only needed in mingw due to lack of RC support in cmake
93 endmacro()
94
95 #idl files support
96 set(IDL_COMPILER midl)
97 set(IDL_FLAGS /win32)
98 set(IDL_HEADER_ARG /h) #.h
99 set(IDL_TYPELIB_ARG /tlb) #.tlb
100 set(IDL_SERVER_ARG /sstub) #.c for stub server library
101 set(IDL_CLIENT_ARG /cstub) #.c for stub client library
102
103
104 macro(add_importlib_target _def_file)
105 get_filename_component(_name ${_def_file} NAME_WE)
106 add_custom_command(
107 OUTPUT {CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
108 COMMAND LINK /LIB /MACHINE:X86 /DEF:${_def_file} /OUT:${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
109 DEPENDS ${_def_file}
110 )
111 add_custom_target(
112 lib${_name}
113 DEPENDS {CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
114 )
115 endmacro()
116
117 macro(add_importlibs MODULE)
118 foreach(LIB ${ARGN})
119 target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.lib)
120 add_dependencies(${MODULE} lib${LIB})
121 endforeach()
122 endmacro()
123
124 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/importlibs)
125
126 #pseh workaround
127 set(PSEH_LIB "")
128
129 endif()