[LOG2LINES] Optimize malloc() calls.
[reactos.git] / CMakeLists.txt
1
2 cmake_minimum_required(VERSION 3.2.1)
3 cmake_policy(VERSION 3.2.1)
4
5 if(NOT CMAKE_VERSION MATCHES "ReactOS")
6 message(WARNING "Building with \"${CMAKE_COMMAND}\", which is not the custom CMake included in RosBE, might cause build issues...")
7 endif()
8
9 # Don't escape preprocessor definition values added via add_definitions
10 cmake_policy(SET CMP0005 OLD)
11
12 # Honor CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.
13 cmake_policy(SET CMP0018 OLD)
14
15 if(POLICY CMP0058)
16 # Ninja requires custom command byproducts to be explicit
17 cmake_policy(SET CMP0058 OLD)
18 endif()
19
20 project(REACTOS)
21
22 # Versioning
23 include(sdk/include/reactos/version.cmake)
24
25 set(CMAKE_INCLUDE_CURRENT_DIR ON)
26 set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
27 set(CMAKE_SHARED_LIBRARY_PREFIX "")
28 set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE)
29 set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE)
30 set(CMAKE_COLOR_MAKEFILE OFF)
31 #set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
32
33 if(NOT DEFINED NEW_STYLE_BUILD)
34 set(NEW_STYLE_BUILD TRUE)
35 endif()
36
37 if(NOT ARCH)
38 set(ARCH i386)
39 endif()
40 # Now the ARCH variable will be in lowercase.
41 # It is needed because STREQUAL comparison
42 # is case-sensitive.
43 # See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html
44 # for more information.
45 string(TOLOWER ${ARCH} ARCH)
46
47 # Compile options
48 if(ARCH STREQUAL "i386")
49 include(sdk/cmake/config.cmake)
50 elseif(ARCH STREQUAL "amd64")
51 include(sdk/cmake/config-amd64.cmake)
52 elseif(ARCH STREQUAL "arm")
53 include(sdk/cmake/config-arm.cmake)
54 endif()
55
56 # Compiler flags handling
57 include(sdk/cmake/compilerflags.cmake)
58
59 add_definitions(-D__REACTOS__)
60
61 if(MSVC_IDE)
62 add_compile_flags("/MP")
63 endif()
64
65 # Bison and Flex support
66 # include(sdk/cmake/bison-flex.cmake)
67
68 if(NOT CMAKE_CROSSCOMPILING)
69
70 if(NEW_STYLE_BUILD)
71 set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
72 endif()
73
74 add_definitions(-DTARGET_${ARCH})
75
76 if(MSVC)
77 if(ARCH STREQUAL "i386")
78 add_definitions(/D_X86_ /DWIN32 /D_WINDOWS)
79 endif()
80 if(MSVC_VERSION GREATER 1699)
81 add_definitions(/D_ALLOW_KEYWORD_MACROS)
82 endif()
83 if(NOT USE_CLANG_CL)
84 # FIXME: Inspect
85 add_definitions(/Dinline=__inline)
86 endif()
87 endif()
88
89 include_directories(sdk/include/host)
90
91 if(NOT MSVC)
92 add_subdirectory(dll/win32/dbghelp)
93 endif()
94 add_subdirectory(sdk/tools)
95 add_subdirectory(sdk/lib)
96
97 if(NOT NEW_STYLE_BUILD)
98 if(NOT MSVC)
99 export(TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc rsym mkshelllink utf16le xml2sdb FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
100 else()
101 export(TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
102 endif()
103 endif()
104
105 else()
106 # We don't need CMake importlib handling.
107 unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
108
109 if(NEW_STYLE_BUILD)
110 include(sdk/cmake/host-tools.cmake)
111 endif()
112
113 # Print build type
114 message("-- Build Type: ${CMAKE_BUILD_TYPE}")
115
116 # adjust the default behaviour of the FIND_XXX() commands:
117 # search headers and libraries in the target environment, search
118 # programs in the host environment
119 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
120 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
121 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
122
123 #useful stuff!
124 include(CMakeParseArguments)
125
126 if(NOT NEW_STYLE_BUILD)
127 if(NOT DEFINED REACTOS_BUILD_TOOLS_DIR)
128 set(REACTOS_BUILD_TOOLS_DIR ${REACTOS_SOURCE_DIR}/build)
129 endif()
130 set(IMPORT_EXECUTABLES "${REACTOS_BUILD_TOOLS_DIR}/ImportExecutables.cmake" CACHE FILEPATH "Host executables")
131 include(${IMPORT_EXECUTABLES})
132 endif()
133
134 if(DBG)
135 add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
136 else()
137 add_definitions(-DDBG=0)
138 endif()
139
140 if(KDBG)
141 add_definitions(-DKDBG=1)
142 endif()
143
144 if(_WINKD_)
145 add_definitions(-D_WINKD_=1)
146 endif()
147
148 if(CMAKE_VERSION MATCHES "ReactOS")
149 set(PCH 1 CACHE BOOL "Whether to use precompiled headers")
150 else()
151 set(PCH 0 CACHE BOOL "Whether to use precompiled headers")
152 endif()
153
154 # Version Options
155 add_definitions(-DWINVER=0x502
156 -D_WIN32_IE=0x600
157 -D_WIN32_WINNT=0x502
158 -D_WIN32_WINDOWS=0x502
159 -D_SETUPAPI_VER=0x502)
160
161 # Arch Options
162 if(ARCH STREQUAL "i386")
163 if(NOT USE_CLANG_CL)
164 add_definitions(-D_M_IX86)
165 endif()
166 add_definitions(-D_X86_ -D__i386__ -Di386)
167 elseif(ARCH STREQUAL "amd64")
168 add_definitions(-D_M_AMD64 -D_AMD64_ -D__x86_64__ -D_WIN64)
169 elseif(ARCH STREQUAL "arm")
170 # _M_ARM is already defined by toolchain
171 add_definitions(-D_ARM_ -D__arm__ -DWIN32)
172 if(SARCH STREQUAL "omap-zoom2")
173 add_definitions(-D_ZOOM2_)
174 endif()
175 endif()
176
177 # Other
178 if(ARCH STREQUAL "i386")
179 add_definitions(-DUSE_COMPILER_EXCEPTIONS -D_USE_32BIT_TIME_T)
180 elseif(ARCH STREQUAL "amd64")
181 add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX)
182 elseif(ARCH STREQUAL "arm")
183 add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX)
184 endif()
185
186 # Activate support for assembly source files
187 enable_language(ASM)
188
189 # Activate language support for resource files
190 enable_language(RC)
191
192 # Localization definitions
193 include(sdk/cmake/localization.cmake)
194 set(I18N_DEFS "")
195 # This will set I18N_DEFS for later use
196 set_i18n_language(${I18N_LANG})
197
198 # Compiler specific definitions and macros
199 if(MSVC)
200 include(sdk/cmake/msvc.cmake)
201 else()
202 include(sdk/cmake/gcc.cmake)
203 endif()
204
205 # Generic macros
206 include(sdk/cmake/CMakeMacros.cmake)
207
208 # IDL macros for widl/midl
209 # We're using widl now for both MSVC and GCC builds
210 include(sdk/cmake/widl-support.cmake)
211
212 include_directories(
213 sdk/include
214 sdk/include/psdk
215 sdk/include/dxsdk
216 ${REACTOS_BINARY_DIR}/sdk/include
217 ${REACTOS_BINARY_DIR}/sdk/include/psdk
218 ${REACTOS_BINARY_DIR}/sdk/include/dxsdk
219 ${REACTOS_BINARY_DIR}/sdk/include/ddk
220 ${REACTOS_BINARY_DIR}/sdk/include/reactos
221 ${REACTOS_BINARY_DIR}/sdk/include/reactos/mc
222 sdk/include/crt
223 sdk/include/ddk
224 sdk/include/ndk
225 sdk/include/reactos
226 sdk/include/reactos/libs)
227
228 if(ARCH STREQUAL "arm")
229 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/arm)
230 endif()
231
232 add_dependency_header()
233
234 add_subdirectory(sdk/include/ndk/tests)
235 add_subdirectory(sdk/include/xdk)
236 add_subdirectory(sdk/include/psdk)
237 add_subdirectory(sdk/include/dxsdk)
238 add_subdirectory(sdk/include/reactos/wine)
239 add_subdirectory(sdk/include/reactos/mc)
240 add_subdirectory(sdk/include/asm)
241
242 if(NO_ROSSYM)
243 include(sdk/cmake/baseaddress_dwarf.cmake)
244 elseif(MSVC)
245 include(sdk/cmake/baseaddress_msvc.cmake)
246 else()
247 include(sdk/cmake/baseaddress.cmake)
248 endif()
249
250 # For MSVC builds, this puts all debug symbols file in the same directory.
251 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb")
252
253 #begin with boot so reactos_cab target is defined before all other modules
254 add_subdirectory(boot)
255 add_subdirectory(base)
256 add_subdirectory(dll)
257 add_subdirectory(drivers)
258 add_subdirectory(hal)
259 add_subdirectory(sdk/lib)
260 add_subdirectory(media)
261 add_subdirectory(modules)
262 add_subdirectory(ntoskrnl)
263 add_subdirectory(subsystems)
264 add_subdirectory(sdk/tools/wpp)
265 add_subdirectory(win32ss)
266
267 # Create the registry hives
268 create_registry_hives()
269
270 # Create {bootcd, livecd, bootcdregtest}.lst
271 create_iso_lists()
272
273 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/sdk/include/reactos)
274
275 add_dependency_footer()
276 endif()