[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")
15 # -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds
16
17 # Compiler Core
18 add_definitions(-pipe -fms-extensions)
19
20 # stlport includes
21 set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> -I${REACTOS_SOURCE_DIR}/lib/3rdparty/stlport/stlport <FLAGS> -o <OBJECT> -c <SOURCE>")
22
23 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>")
24
25 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>")
26
27 # Debugging (Note: DWARF-4 on 4.5.1 when we ship)
28 #add_definitions(-gdwarf-2 -g2 -femit-struct-debug-detailed=none -feliminate-unused-debug-types)
29
30 # Tuning
31 add_definitions(-march=pentium -mtune=i686)
32
33 # Warnings
34 add_definitions(-Wall -Wno-char-subscripts -Wpointer-arith -Wno-multichar -Wno-error=uninitialized -Wno-unused-value -Winvalid-pch)
35
36 # Optimizations
37 add_definitions(-Os -fno-strict-aliasing -ftracer -momit-leaf-frame-pointer -mpreferred-stack-boundary=2 -fno-set-stack-executable -fno-optimize-sibling-calls)
38
39 #linkage hell...
40 add_library(gcc STATIC IMPORTED)
41 set_target_properties(gcc PROPERTIES IMPORTED_LOCATION ${REACTOS_SOURCE_DIR}/importlibs/libgcc.a
42 IMPORTED_LINK_INTERFACE_LIBRARIES "mingw_common -lkernel32")
43 add_library(supc++ STATIC IMPORTED)
44 set_target_properties(supc++ PROPERTIES IMPORTED_LOCATION ${REACTOS_SOURCE_DIR}/importlibs/libsupc++.a
45 IMPORTED_LINK_INTERFACE_LIBRARIES "gcc -lmsvcrt")
46
47 # Macros
48 macro(set_entrypoint MODULE ENTRYPOINT)
49 if(${ENTRYPOINT} STREQUAL "0")
50 set(NEW_LINKER_FLAGS "-Wl,-entry,0")
51 else()
52 set(NEW_LINKER_FLAGS "-Wl,-entry,_${ENTRYPOINT}")
53 endif()
54 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
55 if(LINKER_FLAGS)
56 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
57 endif()
58 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
59 endmacro()
60
61 macro(set_subsystem MODULE SUBSYSTEM)
62 set(NEW_LINKER_FLAGS "-Wl,--subsystem,${SUBSYSTEM}")
63 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
64 if(LINKER_FLAGS)
65 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
66 endif()
67 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
68 endmacro()
69
70 macro(add_importlibs MODULE)
71 foreach(LIB ${ARGN})
72 target_link_libraries(${MODULE} ${LIB}.dll.a)
73 endforeach()
74 endmacro()
75
76 macro(set_module_type MODULE TYPE)
77
78 add_dependencies(${MODULE} psdk buildno_header)
79
80 if(${TYPE} MATCHES nativecui)
81 set_subsystem(${MODULE} native)
82 set_entrypoint(${MODULE} NtProcessStartup@4)
83 endif()
84 if(${TYPE} MATCHES win32gui)
85 set_subsystem(${MODULE} windows)
86 set_entrypoint(${MODULE} WinMainCRTStartup)
87 if(NOT IS_UNICODE)
88 target_link_libraries(${MODULE} mingw_main)
89 else()
90 target_link_libraries(${MODULE} mingw_wmain)
91 endif(NOT IS_UNICODE)
92 target_link_libraries(${MODULE} mingw_common gcc)
93 endif()
94 if(${TYPE} MATCHES win32cui)
95 set_subsystem(${MODULE} console)
96 set_entrypoint(${MODULE} mainCRTStartup)
97 if(NOT IS_UNICODE)
98 target_link_libraries(${MODULE} mingw_main)
99 else()
100 target_link_libraries(${MODULE} mingw_wmain)
101 endif(NOT IS_UNICODE)
102 target_link_libraries(${MODULE} mingw_common gcc)
103 endif()
104 if(${TYPE} MATCHES win32dll)
105 set_entrypoint(${MODULE} DllMain@12)
106 endif()
107 if(${TYPE} MATCHES win32ocx)
108 set_entrypoint(${MODULE} DllMain@12)
109 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
110 endif()
111 endmacro()
112
113 endif()
114
115 macro(set_unicode)
116 add_definitions(-DUNICODE -D_UNICODE)
117 set(IS_UNICODE 1)
118 endmacro()
119
120 # Workaround lack of mingw RC support in cmake
121 macro(set_rc_compiler)
122 get_directory_property(defines COMPILE_DEFINITIONS)
123 get_directory_property(includes INCLUDE_DIRECTORIES)
124
125 foreach(arg ${defines})
126 set(result_defs "${result_defs} -D${arg}")
127 endforeach(arg ${defines})
128
129 foreach(arg ${includes})
130 set(result_incs "-I${arg} ${result_incs}")
131 endforeach(arg ${includes})
132
133 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${result_defs} ${result_incs} -i <SOURCE> -O coff -o <OBJECT>")
134 endmacro()
135
136 #typelib support
137 macro(ADD_TYPELIB TARGET)
138 foreach(SOURCE ${ARGN})
139 get_filename_component(FILE ${SOURCE} NAME_WE)
140 set(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb)
141 add_custom_command(OUTPUT ${OBJECT}
142 COMMAND native-widl -I${REACTOS_SOURCE_DIR}/include/dxsdk -I. -I${REACTOS_SOURCE_DIR}/include -I${REACTOS_SOURCE_DIR}/include/psdk -m32 --win32 -t -T ${OBJECT} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}
143 DEPENDS native-widl)
144 list(APPEND OBJECTS ${OBJECT})
145 endforeach()
146 add_custom_target(${TARGET} ALL DEPENDS ${OBJECTS})
147 endmacro()