[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
12 else()
13
14 add_definitions(/GS- /Zl /Zi)
15 add_definitions(-Dinline=__inline -D__STDC__=1)
16
17 link_directories("${REACTOS_BINARY_DIR}/importlibs" ${REACTOS_BINARY_DIR}/lib/3rdparty/mingw)
18
19 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>")
20
21
22 macro(set_entrypoint MODULE ENTRYPOINT)
23 if(${ENTRYPOINT} STREQUAL "0")
24 set(NEW_LINKER_FLAGS "/ENTRY:0")
25 else()
26 set(NEW_LINKER_FLAGS "/ENTRY:${ENTRYPOINT}")
27 endif()
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_subsystem MODULE SUBSYSTEM)
36 set(NEW_LINKER_FLAGS "/subsystem:${SUBSYSTEM}")
37 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
38 if(LINKER_FLAGS)
39 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
40 endif()
41 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
42 endmacro()
43
44 macro(set_image_base MODULE IMAGE_BASE)
45 set(NEW_LINKER_FLAGS "/BASE:${IMAGE_BASE}")
46 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
47 if(LINKER_FLAGS)
48 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
49 endif()
50 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
51 endmacro()
52
53 macro(set_module_type MODULE TYPE)
54 add_dependencies(${MODULE} psdk buildno_header)
55 if(${TYPE} MATCHES nativecui)
56 set_subsystem(${MODULE} native)
57 add_importlibs(${MODULE} ntdll)
58 endif()
59 if (${TYPE} MATCHES win32gui)
60 set_subsystem(${MODULE} windows)
61 endif ()
62 if (${TYPE} MATCHES win32cui)
63 set_subsystem(${MODULE} console)
64 set_entrypoint(${MODULE} mainCRTStartup)
65 endif ()
66 if(${TYPE} MATCHES win32dll)
67 set_entrypoint(${MODULE} __DllMainCRTStartup)
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 endif()
75
76 endmacro()
77
78 macro(set_unicode)
79 add_definitions(-DUNICODE -D_UNICODE)
80 endmacro()
81
82 set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od")
83 set(CMAKE_CXX_FLAGS_DEBUG_INIT "/D_DEBUG /MDd /Zi /Ob0 /Od")
84
85 macro(set_rc_compiler)
86 # dummy, this workaround is only needed in mingw due to lack of RC support in cmake
87 endmacro()
88
89 #idl files support
90 set(IDL_COMPILER midl)
91 set(IDL_FLAGS /win32)
92 set(IDL_HEADER_ARG /h) #.h
93 set(IDL_TYPELIB_ARG /tlb) #.tlb
94 set(IDL_SERVER_ARG /sstub) #.c for stub server library
95 set(IDL_CLIENT_ARG /cstub) #.c for stub client library
96
97
98 macro(add_importlib_target _def_file)
99 get_filename_component(_name ${_def_file} NAME_WE)
100 add_custom_target(
101 lib${_name}
102 COMMAND LINK /LIB /MACHINE:X86 /DEF:${CMAKE_CURRENT_BINARY_DIR}/${_file}.def /OUT:${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib
103 DEPENDS ${_def_file}
104 )
105 endmacro()
106
107 macro(add_importlibs MODULE)
108 foreach(LIB ${ARGN})
109 target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/importlibs/lib${LIB}.lib)
110 #add_dependencies(${MODULE} lib${LIB})
111 endforeach()
112 endmacro()
113
114 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/importlibs)
115
116 #pseh workaround
117 set(PSEH_LIB "")
118
119 endif()
120