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