506a7f55ab5b6cc2f6e23e26de12a8fdef3db277
[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 macro(add_linkerflag MODULE _flag)
27 set(NEW_LINKER_FLAGS ${_flag})
28 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
29 if(LINKER_FLAGS)
30 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
31 endif()
32 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
33 endmacro()
34
35 macro(set_entrypoint MODULE ENTRYPOINT)
36 if(${ENTRYPOINT} STREQUAL "0")
37 add_linkerflag(${MODULE} "/ENTRY:0")
38 else()
39 add_linkerflag(${MODULE} "/ENTRY:${ENTRYPOINT}")
40 endif()
41 endmacro()
42
43 macro(set_subsystem MODULE SUBSYSTEM)
44 add_linkerflag(${MODULE} "/subsystem:${SUBSYSTEM}")
45 endmacro()
46
47 macro(set_image_base MODULE IMAGE_BASE)
48 add_linkerflag(${MODULE} "/BASE:${IMAGE_BASE}")
49 endmacro()
50
51 macro(set_module_type MODULE TYPE)
52 add_dependencies(${MODULE} psdk buildno_header)
53 if(${TYPE} MATCHES nativecui)
54 set_subsystem(${MODULE} native)
55 add_importlibs(${MODULE} ntdll)
56 endif()
57 if (${TYPE} MATCHES win32gui)
58 set_subsystem(${MODULE} windows)
59 endif ()
60 if (${TYPE} MATCHES win32cui)
61 set_subsystem(${MODULE} console)
62 set_entrypoint(${MODULE} mainCRTStartup)
63 target_link_libraries(${MODULE} mingw_common mingw_wmain)
64 endif ()
65 if(${TYPE} MATCHES win32dll)
66 # Need this only because mingw library is broken
67 set_entrypoint(${MODULE} DllMainCRTStartup@12)
68 if(DEFINED baseaddress_${MODULE})
69 set_image_base(${MODULE} ${baseaddress_${MODULE}})
70 else()
71 message(STATUS "${MODULE} has no base address")
72 endif()
73 target_link_libraries(${MODULE} mingw_common mingw_dllmain)
74 add_importlibs(${MODULE} msvcrt kernel32)
75 endif()
76
77 endmacro()
78
79 macro(set_unicode)
80 add_definitions(-DUNICODE -D_UNICODE)
81 endmacro()
82
83 set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od")
84 set(CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od")
85
86 macro(set_rc_compiler)
87 # dummy, this workaround is only needed in mingw due to lack of RC support in cmake
88 endmacro()
89
90 #idl files support
91 set(IDL_COMPILER midl)
92 set(IDL_FLAGS /win32)
93 set(IDL_HEADER_ARG /h) #.h
94 set(IDL_TYPELIB_ARG /tlb) #.tlb
95 set(IDL_SERVER_ARG /sstub) #.c for stub server library
96 set(IDL_CLIENT_ARG /cstub) #.c for stub client library
97
98
99 macro(add_importlib_target _def_file)
100 get_filename_component(_name ${_def_file} NAME_WE)
101 add_custom_command(
102 OUTPUT {CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
103 COMMAND LINK /LIB /MACHINE:X86 /DEF:${_def_file} /OUT:${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
104 DEPENDS ${_def_file}
105 )
106 add_custom_target(
107 lib${_name}
108 DEPENDS {CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
109 )
110 endmacro()
111
112 macro(add_importlibs MODULE)
113 foreach(LIB ${ARGN})
114 target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.lib)
115 add_dependencies(${MODULE} lib${LIB})
116 endforeach()
117 endmacro()
118
119 macro(pdef2def _pdef_file)
120 get_filename_component(_file ${_pdef_file} NAME_WE)
121 add_custom_command(
122 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def
123 COMMAND ${CMAKE_C_COMPILER} /EP /c ${CMAKE_CURRENT_SOURCE_DIR}/${_pdef_file} > ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def
124 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_pdef_file})
125 add_custom_target(
126 ${_file}_def
127 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def)
128 endmacro(pdef2def _pdef_file)
129
130 macro(set_pdef_file _module _pdef_file)
131 pdef2def(${_pdef_file})
132 get_filename_component(_file ${_pdef_file} NAME_WE)
133 add_linkerflag(${_module} "/DEF:${CMAKE_CURRENT_BINARY_DIR}/${_file}.def")
134 add_dependencies(${_module} ${_file}_def)
135 endmacro()
136
137 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/importlibs)
138
139 #pseh workaround
140 set(PSEH_LIB "")
141
142 endif()