a559af789482a191c81d6530e523b51ffb7ed6c0
[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> -lstdc++ -lsupc++ -lgcc -lmingwex -lmingw32 <LINK_LIBRARIES>")
14 set(CMAKE_EXE_LINKER_FLAGS "-nodefaultlibs -nostdlib -Wl,--enable-auto-image-base -Wl,--kill-at -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds")
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
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(set_entrypoint MODULE ENTRYPOINT)
37 if(${ENTRYPOINT} STREQUAL "0")
38 set(NEW_LINKER_FLAGS "-Wl,-entry,0")
39 else()
40 set(NEW_LINKER_FLAGS "-Wl,-entry,_${ENTRYPOINT}")
41 endif()
42 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
43 if(LINKER_FLAGS)
44 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
45 endif()
46 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
47 endmacro()
48
49 macro(set_subsystem MODULE SUBSYSTEM)
50 set(NEW_LINKER_FLAGS "-Wl,--subsystem,${SUBSYSTEM}")
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(add_importlibs MODULE)
59 foreach(LIB ${ARGN})
60 target_link_libraries(${MODULE} ${LIB}.a)
61 endforeach()
62 endmacro()
63
64 macro(set_module_type MODULE TYPE)
65
66 add_dependencies(${MODULE} psdk buildno_header)
67
68 if(${TYPE} MATCHES nativecui)
69 set_subsystem(${MODULE} native)
70 set_entrypoint(${MODULE} NtProcessStartup@4)
71 endif()
72 if(${TYPE} MATCHES win32gui)
73 set_subsystem(${MODULE} windows)
74 set_entrypoint(${MODULE} WinMainCRTStartup)
75 if(NOT IS_UNICODE)
76 target_link_libraries(${MODULE} mingw_main)
77 else()
78 target_link_libraries(${MODULE} mingw_wmain)
79 endif(NOT IS_UNICODE)
80 target_link_libraries(${MODULE} mingw_common)
81 endif()
82 if(${TYPE} MATCHES win32cui)
83 set_subsystem(${MODULE} console)
84 set_entrypoint(${MODULE} mainCRTStartup)
85 if(NOT IS_UNICODE)
86 target_link_libraries(${MODULE} mingw_main)
87 else()
88 target_link_libraries(${MODULE} mingw_wmain)
89 endif(NOT IS_UNICODE)
90 target_link_libraries(${MODULE} mingw_common)
91 endif()
92 if(${TYPE} MATCHES win32dll)
93 set_entrypoint(${MODULE} DllMain@12)
94 endif()
95 endmacro()
96
97 endif()
98
99 macro(set_unicode)
100 add_definitions(-DUNICODE -D_UNICODE)
101 set(IS_UNICODE 1)
102 endmacro()
103
104 # Workaround lack of mingw RC support in cmake
105 macro(set_rc_compiler)
106 get_directory_property(defines COMPILE_DEFINITIONS)
107 get_directory_property(includes INCLUDE_DIRECTORIES)
108
109 foreach(arg ${defines})
110 set(result_defs "${result_defs} -D${arg}")
111 endforeach(arg ${defines})
112
113 foreach(arg ${includes})
114 set(result_incs "-I${arg} ${result_incs}")
115 endforeach(arg ${includes})
116
117 set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${result_defs} ${result_incs} -i <SOURCE> -O coff -o <OBJECT>")
118 endmacro()
119
120 #typelib support
121 macro(ADD_TYPELIB TARGET)
122 foreach(SOURCE ${ARGN})
123 get_filename_component(FILE ${SOURCE} NAME_WE)
124 set(OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.tlb)
125 add_custom_command(OUTPUT ${OBJECT}
126 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}
127 DEPENDS native-widl)
128 list(APPEND OBJECTS ${OBJECT})
129 endforeach()
130 add_custom_target(${TARGET} ALL DEPENDS ${OBJECTS})
131 endmacro()