[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 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 #linkage hell...
37 add_library(gcc STATIC IMPORTED)
38 set_target_properties(gcc PROPERTIES IMPORTED_LOCATION ${REACTOS_SOURCE_DIR}/importlibs/libgcc.a
39 IMPORTED_LINK_INTERFACE_LIBRARIES "mingw_common -lkernel32")
40 add_library(supc++ STATIC IMPORTED)
41 set_target_properties(supc++ PROPERTIES IMPORTED_LOCATION ${REACTOS_SOURCE_DIR}/importlibs/libsupc++.a
42 IMPORTED_LINK_INTERFACE_LIBRARIES "gcc -lmsvcrt")
43
44 # Macros
45 macro(set_entrypoint MODULE ENTRYPOINT)
46 if(${ENTRYPOINT} STREQUAL "0")
47 set(NEW_LINKER_FLAGS "-Wl,-entry,0")
48 else()
49 set(NEW_LINKER_FLAGS "-Wl,-entry,_${ENTRYPOINT}")
50 endif()
51 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
52 if(LINKER_FLAGS)
53 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
54 endif()
55 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
56 endmacro()
57
58 macro(set_subsystem MODULE SUBSYSTEM)
59 set(NEW_LINKER_FLAGS "-Wl,--subsystem,${SUBSYSTEM}")
60 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
61 if(LINKER_FLAGS)
62 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
63 endif()
64 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
65 endmacro()
66
67 macro(add_importlibs MODULE)
68 foreach(LIB ${ARGN})
69 target_link_libraries(${MODULE} ${LIB}.dll.a)
70 endforeach()
71 endmacro()
72
73 macro(set_module_type MODULE TYPE)
74
75 add_dependencies(${MODULE} psdk buildno_header)
76
77 if(${TYPE} MATCHES nativecui)
78 set_subsystem(${MODULE} native)
79 set_entrypoint(${MODULE} NtProcessStartup@4)
80 endif()
81 if(${TYPE} MATCHES win32gui)
82 set_subsystem(${MODULE} windows)
83 set_entrypoint(${MODULE} WinMainCRTStartup)
84 if(NOT IS_UNICODE)
85 target_link_libraries(${MODULE} mingw_main)
86 else()
87 target_link_libraries(${MODULE} mingw_wmain)
88 endif(NOT IS_UNICODE)
89 target_link_libraries(${MODULE} mingw_common gcc)
90 endif()
91 if(${TYPE} MATCHES win32cui)
92 set_subsystem(${MODULE} console)
93 set_entrypoint(${MODULE} mainCRTStartup)
94 if(NOT IS_UNICODE)
95 target_link_libraries(${MODULE} mingw_main)
96 else()
97 target_link_libraries(${MODULE} mingw_wmain)
98 endif(NOT IS_UNICODE)
99 target_link_libraries(${MODULE} mingw_common gcc)
100 endif()
101 if(${TYPE} MATCHES win32dll)
102 set_entrypoint(${MODULE} DllMain@12)
103 endif()
104 if(${TYPE} MATCHES win32ocx)
105 set_entrypoint(${MODULE} DllMain@12)
106 set_target_properties(${MODULE} PROPERTIES SUFFIX ".ocx")
107 endif()
108 endmacro()
109
110 endif()
111
112 macro(set_unicode)
113 add_definitions(-DUNICODE -D_UNICODE)
114 set(IS_UNICODE 1)
115 endmacro()
116
117 # Workaround lack of mingw RC support in cmake
118 macro(set_rc_compiler)
119 get_directory_property(defines COMPILE_DEFINITIONS)
120 get_directory_property(includes INCLUDE_DIRECTORIES)
121
122 foreach(arg ${defines})
123 set(result_defs "${result_defs} -D${arg}")
124 endforeach(arg ${defines})
125
126 foreach(arg ${includes})
127 set(result_incs "-I${arg} ${result_incs}")
128 endforeach(arg ${includes})
129
130 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${result_defs} ${result_incs} -i <SOURCE> -O coff -o <OBJECT>")
131 endmacro()
132
133 #typelib support
134 macro(ADD_TYPELIB TARGET)
135 foreach(SOURCE ${ARGN})
136 get_filename_component(FILE ${SOURCE} NAME_WE)
137 set(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb)
138 add_custom_command(OUTPUT ${OBJECT}
139 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}
140 DEPENDS native-widl)
141 list(APPEND OBJECTS ${OBJECT})
142 endforeach()
143 add_custom_target(${TARGET} ALL DEPENDS ${OBJECTS})
144 endmacro()