[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 # Macros
40 macro(set_entrypoint MODULE ENTRYPOINT)
41 if(${ENTRYPOINT} STREQUAL "0")
42 set(NEW_LINKER_FLAGS "-Wl,-entry,0")
43 else()
44 set(NEW_LINKER_FLAGS "-Wl,-entry,_${ENTRYPOINT}")
45 endif()
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_subsystem MODULE SUBSYSTEM)
54 set(NEW_LINKER_FLAGS "-Wl,--subsystem,${SUBSYSTEM}")
55 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
56 if(LINKER_FLAGS)
57 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
58 endif()
59 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
60 endmacro()
61
62 macro(add_importlibs MODULE)
63 foreach(LIB ${ARGN})
64 target_link_libraries(${MODULE} ${LIB}.dll.a)
65 endforeach()
66 endmacro()
67
68 macro(set_module_type MODULE TYPE)
69
70 add_dependencies(${MODULE} psdk buildno_header)
71
72 if(${IS_CPP})
73 target_link_libraries(${MODULE} stlport -lsupc++ -lgcc)
74 endif()
75
76 if(${TYPE} MATCHES nativecui)
77 set_subsystem(${MODULE} native)
78 set_entrypoint(${MODULE} NtProcessStartup@4)
79 endif()
80 if(${TYPE} MATCHES win32gui)
81 set_subsystem(${MODULE} windows)
82 set_entrypoint(${MODULE} WinMainCRTStartup)
83 if(NOT IS_UNICODE)
84 target_link_libraries(${MODULE} mingw_main)
85 else()
86 target_link_libraries(${MODULE} mingw_wmain)
87 endif(NOT IS_UNICODE)
88 target_link_libraries(${MODULE} mingw_common)
89 endif()
90 if(${TYPE} MATCHES win32cui)
91 set_subsystem(${MODULE} console)
92 set_entrypoint(${MODULE} mainCRTStartup)
93 if(NOT IS_UNICODE)
94 target_link_libraries(${MODULE} mingw_main)
95 else()
96 target_link_libraries(${MODULE} mingw_wmain)
97 endif(NOT IS_UNICODE)
98 target_link_libraries(${MODULE} mingw_common)
99 endif()
100 if(${TYPE} MATCHES win32dll)
101 set_entrypoint(${MODULE} DllMain@12)
102 endif()
103 if(${TYPE} MATCHES win32ocx)
104 set_entrypoint(${MODULE} DllMain@12)
105 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
106 endif()
107 if(${TYPE} MATCHES cpl)
108 set_entrypoint(${MODULE} DllMain@12)
109 set_target_properties(${MODULE} PROPERTIES SUFFIX ".cpl")
110 endif()
111 if(${TYPE} MATCHES kernelmodedriver)
112 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS "-Wl,--image-base,0x00010000 -Wl,--exclude-all-symbols" SUFFIX ".sys")
113 set_entrypoint(${MODULE} DriverEntry@8)
114 set_subsystem(${MODULE} native)
115 add_dependencies(${MODULE} bugcodes)
116 endif()
117 endmacro()
118
119 endif()
120
121 macro(set_unicode)
122 add_definitions(-DUNICODE -D_UNICODE)
123 set(IS_UNICODE 1)
124 endmacro()
125
126 macro(set_cpp)
127 set(IS_CPP 1)
128 endmacro()
129
130 # Workaround lack of mingw RC support in cmake
131 macro(set_rc_compiler)
132 get_directory_property(defines COMPILE_DEFINITIONS)
133 get_directory_property(includes INCLUDE_DIRECTORIES)
134
135 foreach(arg ${defines})
136 set(result_defs "${result_defs} -D${arg}")
137 endforeach(arg ${defines})
138
139 foreach(arg ${includes})
140 set(result_incs "-I${arg} ${result_incs}")
141 endforeach(arg ${includes})
142
143 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${result_defs} ${result_incs} -i <SOURCE> -O coff -o <OBJECT>")
144 endmacro()
145
146 #typelib support
147 macro(ADD_TYPELIB TARGET)
148 foreach(SOURCE ${ARGN})
149 get_filename_component(FILE ${SOURCE} NAME_WE)
150 set(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb)
151 add_custom_command(OUTPUT ${OBJECT}
152 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}
153 DEPENDS native-widl)
154 list(APPEND OBJECTS ${OBJECT})
155 endforeach()
156 add_custom_target(${TARGET} ALL DEPENDS ${OBJECTS})
157 endmacro()