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