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