[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 -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 # Debugging (Note: DWARF-4 on 4.5.1 when we ship)
22 add_definitions(-gdwarf-2 -g2 -femit-struct-debug-detailed=none -feliminate-unused-debug-types)
23
24 # Tuning
25 add_definitions(-march=pentium -mtune=i686)
26
27 # Warnings
28 add_definitions(-Wall -Wno-char-subscripts -Wpointer-arith -Wno-multichar -Wno-error=uninitialized -Wno-unused-value -Winvalid-pch)
29
30 # Optimizations
31 add_definitions(-Os -fno-strict-aliasing -ftracer -momit-leaf-frame-pointer -mpreferred-stack-boundary=2 -fno-set-stack-executable -fno-optimize-sibling-calls)
32
33 # C++ Flags
34 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
35
36 # Macros
37 macro(set_entrypoint MODULE ENTRYPOINT)
38 set(NEW_LINKER_FLAGS "-Wl,-entry,_${ENTRYPOINT}")
39 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
40 if(LINKER_FLAGS)
41 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
42 endif()
43 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
44 endmacro()
45
46 macro(set_subsystem MODULE SUBSYSTEM)
47 set(NEW_LINKER_FLAGS "-Wl,--subsystem,${SUBSYSTEM}")
48 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
49 if(LINKER_FLAGS)
50 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
51 endif()
52 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
53 endmacro()
54
55 macro(add_importlibs MODULE)
56 FOREACH(LIB ${ARGN})
57 target_link_libraries(${MODULE} ${LIB}.a)
58 ENDFOREACH()
59 endmacro()
60
61 macro(set_module_type MODULE TYPE)
62
63 add_dependencies(${MODULE} builno_header psdk)
64
65 if(${TYPE} MATCHES nativecui)
66 set_subsystem(${MODULE} native)
67 set_entrypoint(${MODULE} NtProcessStartup@4)
68 endif()
69 if(${TYPE} MATCHES win32gui)
70 set_subsystem(${MODULE} windows)
71 set_entrypoint(${MODULE} WinMainCRTStartup)
72 endif()
73 if(${TYPE} MATCHES win32cui)
74 set_subsystem(${MODULE} console)
75 set_entrypoint(${MODULE} mainCRTStartup)
76 endif()
77 if(${TYPE} MATCHES win32dll)
78 target_link_libraries(${MODULE} mingw_dllmain mingw_common)
79 set_entrypoint(${MODULE} DllMain@12)
80 endif()
81 endmacro()
82
83 endif()
84
85 macro(set_unicode MODULE STATE)
86 if(${STATE} MATCHES yes)
87 add_definitions(-DUNICODE -D_UNICODE)
88 target_link_libraries(${MODULE} mingw_wmain)
89 else()
90 target_link_libraries(${MODULE} mingw_main)
91 endif()
92
93 target_link_libraries(${MODULE} mingw_common)
94 endmacro()
95
96 # Workaround lack of mingw RC support in cmake
97 macro(set_rc_compiler)
98 get_directory_property(defines COMPILE_DEFINITIONS)
99 get_directory_property(includes INCLUDE_DIRECTORIES)
100
101 foreach(arg ${defines})
102 set(result_defs "${result_defs} -D${arg}")
103 endforeach(arg ${defines})
104
105 foreach(arg ${includes})
106 set(result_incs "-I${arg} ${result_incs}")
107 endforeach(arg ${includes})
108
109 SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${result_defs} ${result_incs} -i <SOURCE> -O coff -o <OBJECT>")
110 endmacro()