[CMAKE]
[reactos.git] / gcc.cmake
1
2
3 if(NOT CMAKE_CROSSCOMPILING)
4
5 add_definitions(-fshort-wchar)
6
7
8 else()
9
10 # Linking
11 link_directories("${REACTOS_SOURCE_DIR}/importlibs" ${REACTOS_BINARY_DIR}/lib/3rdparty/mingw)
12 set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
13 set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
14 set(CMAKE_EXE_LINKER_FLAGS "-nodefaultlibs -nostdlib -Wl,--enable-auto-image-base -Wl,--kill-at -Wl,--enable-auto-import")
15 # -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds
16
17 # Compiler Core
18 add_definitions(-pipe -fms-extensions)
19
20 set(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
21
22 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>")
23
24 # Debugging (Note: DWARF-4 on 4.5.1 when we ship)
25 #add_definitions(-gdwarf-2 -g2 -femit-struct-debug-detailed=none -feliminate-unused-debug-types)
26
27 # Tuning
28 add_definitions(-march=pentium -mtune=i686)
29
30 # Warnings
31 add_definitions(-Wall -Wno-char-subscripts -Wpointer-arith -Wno-multichar -Wno-error=uninitialized -Wno-unused-value -Winvalid-pch)
32
33 # Optimizations
34 add_definitions(-Os -fno-strict-aliasing -ftracer -momit-leaf-frame-pointer -mpreferred-stack-boundary=2 -fno-set-stack-executable -fno-optimize-sibling-calls)
35
36 # Macros
37 macro(set_entrypoint MODULE ENTRYPOINT)
38 if(${ENTRYPOINT} STREQUAL "0")
39 set(NEW_LINKER_FLAGS "-Wl,-entry,0")
40 else()
41 set(NEW_LINKER_FLAGS "-Wl,-entry,_${ENTRYPOINT}")
42 endif()
43 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
44 if(LINKER_FLAGS)
45 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
46 endif()
47 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
48 endmacro()
49
50 macro(set_subsystem MODULE SUBSYSTEM)
51 set(NEW_LINKER_FLAGS "-Wl,--subsystem,${SUBSYSTEM}")
52 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
53 if(LINKER_FLAGS)
54 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
55 endif()
56 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
57 endmacro()
58
59 macro(set_image_base MODULE IMAGE_BASE)
60 set(NEW_LINKER_FLAGS "-Wl,--image-base,${IMAGE_BASE}")
61 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
62 if(LINKER_FLAGS)
63 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
64 endif()
65 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
66 endmacro()
67
68 macro(add_importlibs MODULE)
69 foreach(LIB ${ARGN})
70 target_link_libraries(${MODULE} ${LIB}.dll.a)
71 endforeach()
72 endmacro()
73
74 macro(set_module_type MODULE TYPE)
75
76 add_dependencies(${MODULE} psdk buildno_header)
77
78 if(${IS_CPP})
79 target_link_libraries(${MODULE} stlport -lsupc++ -lgcc)
80 endif()
81
82 if(${TYPE} MATCHES nativecui)
83 set_subsystem(${MODULE} native)
84 set_entrypoint(${MODULE} NtProcessStartup@4)
85 endif()
86 if(${TYPE} MATCHES win32gui)
87 set_subsystem(${MODULE} windows)
88 set_entrypoint(${MODULE} WinMainCRTStartup)
89 if(NOT IS_UNICODE)
90 target_link_libraries(${MODULE} mingw_main)
91 else()
92 target_link_libraries(${MODULE} mingw_wmain)
93 endif(NOT IS_UNICODE)
94 target_link_libraries(${MODULE} mingw_common)
95 endif()
96 if(${TYPE} MATCHES win32cui)
97 set_subsystem(${MODULE} console)
98 set_entrypoint(${MODULE} mainCRTStartup)
99 if(NOT IS_UNICODE)
100 target_link_libraries(${MODULE} mingw_main)
101 else()
102 target_link_libraries(${MODULE} mingw_wmain)
103 endif(NOT IS_UNICODE)
104 target_link_libraries(${MODULE} mingw_common)
105 endif()
106 if(${TYPE} MATCHES win32dll)
107 set_entrypoint(${MODULE} DllMain@12)
108 if(DEFINED baseaddress_${MODULE})
109 set_image_base(${MODULE} ${baseaddress_${MODULE}})
110 else()
111 message(STATUS "${MODULE} has no base address")
112 endif()
113 endif()
114 if(${TYPE} MATCHES win32ocx)
115 set_entrypoint(${MODULE} DllMain@12)
116 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
117 endif()
118 if(${TYPE} MATCHES cpl)
119 set_entrypoint(${MODULE} DllMain@12)
120 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
121 endif()
122 if(${TYPE} MATCHES kernelmodedriver)
123 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS "-Wl,--exclude-all-symbols" SUFFIX ".sys")
124 set_entrypoint(${MODULE} DriverEntry@8)
125 set_subsystem(${MODULE} native)
126 set_image_base(${MODULE} 0x00010000)
127 add_dependencies(${MODULE} bugcodes)
128 endif()
129 endmacro()
130
131 macro(set_unicode)
132 add_definitions(-DUNICODE -D_UNICODE)
133 set(IS_UNICODE 1)
134 endmacro()
135
136 # Workaround lack of mingw RC support in cmake
137 macro(set_rc_compiler)
138 get_directory_property(defines COMPILE_DEFINITIONS)
139 get_directory_property(includes INCLUDE_DIRECTORIES)
140
141 foreach(arg ${defines})
142 set(result_defs "${result_defs} -D${arg}")
143 endforeach(arg ${defines})
144
145 foreach(arg ${includes})
146 set(result_incs "-I${arg} ${result_incs}")
147 endforeach(arg ${includes})
148
149 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${result_defs} ${result_incs} -i <SOURCE> -O coff -o <OBJECT>")
150 endmacro()
151
152 #idl files support
153 set(IDL_COMPILER native-widl)
154 set(IDL_FLAGS -m32 --win32)
155 set(IDL_HEADER_ARG -h -H) #.h
156 set(IDL_TYPELIB_ARG -t -T) #.tlb
157 set(IDL_SERVER_ARG -s -S) #.c for server library
158 set(IDL_CLIENT_ARG -c -C) #.c for stub client library
159
160 macro(add_importlib_target _def_file)
161 # empty for now, while import libs are shipped
162 endmacro()
163
164 #pseh lib, needed with mingw
165 set(PSEH_LIB "pseh")
166
167 endif()