[CMAKE] winetests/: Move '/wd4334' to 3 sub-modules only
[reactos.git] / CMakeLists.txt
1
2 cmake_minimum_required(VERSION 3.17.0)
3
4 if(NOT CMAKE_VERSION MATCHES "ReactOS")
5 message(WARNING "Building with \"${CMAKE_COMMAND}\", which is not the custom CMake included in RosBE, might cause build issues...")
6 endif()
7
8 include(CMakeDependentOption)
9
10 # CMAKE_CROSSCOMPILING and MSVC_IDE are not set until project() is called, so let's test this instead
11 if ((DEFINED CMAKE_TOOLCHAIN_FILE) AND (CMAKE_GENERATOR MATCHES "Visual Studio.*"))
12 # Do not use MSVC_RUNTIME_LIBRARY target property. We use our own flags instead
13 message(WARNING "Setting policy CMP0091 to OLD behaviour")
14 cmake_policy(SET CMP0091 OLD)
15 endif()
16
17 project(REACTOS)
18
19 set(CMAKE_INCLUDE_CURRENT_DIR ON)
20 set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
21 set(CMAKE_SHARED_LIBRARY_PREFIX "")
22 set(CMAKE_SHARED_MODULE_PREFIX "")
23 set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE)
24 set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE)
25 set(CMAKE_COLOR_MAKEFILE OFF)
26 set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
27 set(CMAKE_C_STANDARD 99)
28 set(CMAKE_CXX_STANDARD 11)
29 #set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
30
31 # check that the ARCH (target architecture) variable is defined
32 if(NOT ARCH)
33 message(FATAL_ERROR "Target architecture (ARCH) is not defined. Please, choose one of: i386, amd64, arm")
34 endif()
35 # Now the ARCH variable will be in lowercase.
36 # It is needed because STREQUAL comparison
37 # is case-sensitive.
38 # See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html
39 # for more information.
40 string(TOLOWER ${ARCH} ARCH)
41
42 # set possible values for cmake GUI
43 set_property(CACHE ARCH PROPERTY STRINGS "i386" "amd64" "arm")
44
45 # Alternative WinNT-compatible architecture string
46 if(ARCH STREQUAL "i386")
47 set(WINARCH "x86")
48 else()
49 set(WINARCH ${ARCH})
50 endif()
51
52 # set CMAKE_BUILD_TYPE if not set
53 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
54 message(STATUS "Setting build type to Debug as none was specified.")
55 set(CMAKE_BUILD_TYPE "Debug" CACHE
56 STRING "Choose the type of build." FORCE)
57 # Set the possible values of build type for cmake-gui
58 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
59 "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
60 endif()
61
62 # Versioning
63 include(sdk/include/reactos/version.cmake)
64
65 # Compile options
66 include(sdk/cmake/config.cmake)
67
68 # Compiler flags handling
69 include(sdk/cmake/compilerflags.cmake)
70
71 add_definitions(-D__REACTOS__)
72
73 # There doesn't seem to be a standard for __FILE__ being relative or absolute, so detect it at runtime.
74 file(RELATIVE_PATH _PATH_PREFIX ${REACTOS_BINARY_DIR} ${REACTOS_SOURCE_DIR})
75 if (GCC AND ((CMAKE_C_COMPILER_ID STREQUAL "GNU") AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0")
76 OR ((CMAKE_C_COMPILER_ID STREQUAL "Clang") AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "10.0.0"))))
77 # Thankfully, GCC has this
78 add_compile_options(-ffile-prefix-map=${REACTOS_SOURCE_DIR}=)
79 add_compile_options(-ffile-prefix-map=${_PATH_PREFIX}=)
80 else()
81 string(LENGTH ${_PATH_PREFIX} _PATH_PREFIX_LENGTH)
82 string(LENGTH ${REACTOS_SOURCE_DIR} REACTOS_SOURCE_DIR_LENGTH)
83 math(EXPR REACTOS_SOURCE_DIR_LENGTH "${REACTOS_SOURCE_DIR_LENGTH} + 1")
84 add_compile_definitions("$<$<COMPILE_LANGUAGE:C,CXX>:__RELFILE__=&__FILE__[__FILE__[0] == '.' ? ${_PATH_PREFIX_LENGTH} : ${REACTOS_SOURCE_DIR_LENGTH}]>")
85 endif()
86
87 if(MSVC_IDE)
88 add_compile_options("/MP")
89 endif()
90
91 # Bison and Flex support
92 find_package(BISON REQUIRED)
93 find_package(FLEX REQUIRED)
94
95 if(NOT CMAKE_CROSSCOMPILING)
96 set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
97 add_definitions(-DTARGET_${ARCH})
98
99 if(MSVC)
100 if(ARCH STREQUAL "i386")
101 add_definitions(/D_X86_ /D__i386__ /DWIN32 /D_WINDOWS)
102 elseif(ARCH STREQUAL "amd64")
103 add_definitions(-D_AMD64_ -D__x86_64__ /DWIN32 -D_WINDOWS)
104 endif()
105 if(MSVC_VERSION GREATER 1699)
106 add_definitions(/D_ALLOW_KEYWORD_MACROS)
107 endif()
108 if(NOT USE_CLANG_CL)
109 # FIXME: Inspect
110 add_definitions(/Dinline=__inline)
111 endif()
112 endif()
113 add_subdirectory(sdk/include/host)
114
115 if(NOT MSVC)
116 add_subdirectory(dll/win32/dbghelp)
117 endif()
118 add_subdirectory(sdk/tools)
119 add_subdirectory(sdk/lib)
120
121 set(NATIVE_TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb)
122 if(NOT MSVC)
123 list(APPEND NATIVE_TARGETS rsym pefixup)
124 endif()
125
126 install(TARGETS ${NATIVE_TARGETS})
127 else()
128 # Add host tools target
129 include(sdk/cmake/host-tools.cmake)
130 setup_host_tools()
131
132 # We don't need CMake importlib handling.
133 unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
134
135 # Print build type(s)
136 if(CMAKE_CONFIGURATION_TYPES)
137 # Multi-config generators, like Visual Studio (MSBuild).
138 message("-- Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
139 else()
140 # Single-configuration generators, like Ninja.
141 message("-- Build type: ${CMAKE_BUILD_TYPE}")
142 endif()
143
144 # Always add /MT in VS CMAKE_GENERATOR and define _SBCS otherwise VS thinks it's a multi-byte or whatever project
145 if (MSVC_IDE)
146 add_compile_options("/MT")
147 add_compile_definitions(_SBCS)
148 endif()
149
150
151 # adjust the default behaviour of the FIND_XXX() commands:
152 # search headers and libraries in the target environment, search
153 # programs in the host environment
154 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
155 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
156 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
157
158 # Add our own target properties
159 # General module definitions
160 define_property(TARGET PROPERTY REACTOS_MODULE_TYPE
161 BRIEF_DOCS "The type of this module"
162 FULL_DOCS [[
163 The type of this module.
164 One of "nativecui", "nativedll", "kernelmodedriver", "wdmdriver", "kerneldll", "win32cui", "win32gui", "win32dll", "win32ocx", "cpl" or "module"]])
165
166 # C++
167 define_property(TARGET PROPERTY WITH_CXX_EXCEPTIONS
168 BRIEF_DOCS "Enable C++ exceptions on this target"
169 FULL_DOCS [[
170 Enables C++ exception handling.
171 Enable this if the module uses try/catch or throw. You might also need this if you use a standard operator new (the one without nothrow).]])
172 define_property(TARGET PROPERTY WITH_CXX_RTTI
173 BRIEF_DOCS "Enable C++ RTTI on this target"
174 FULL_DOCS [[
175 Enables run-time type information.
176 Enable this if the module uses typeid or dynamic_cast. You will probably need to link yith cpprt as well, if you are not already using STL.]])
177
178
179 if(DBG)
180 add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
181 else()
182 add_definitions(-DDBG=0)
183 endif()
184
185 if(KDBG)
186 add_definitions(-DKDBG)
187 endif()
188
189 if(_WINKD_)
190 add_definitions(-D_WINKD_)
191 endif()
192
193 if(ENABLE_CCACHE)
194 message(WARNING "-- Disabling precompiled headers support (ccache).")
195 option(PCH "Whether to use precompiled headers" OFF)
196 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
197 elseif(GCC)
198 message(WARNING "-- Disabling precompiled headers on GCC by default CORE-17108.")
199 option(PCH "Whether to use precompiled headers" OFF)
200 else()
201 option(PCH "Whether to use precompiled headers" ON)
202 endif()
203
204 # Version Options
205 add_definitions(-DWINVER=0x502
206 -D_WIN32_IE=0x600
207 -D_WIN32_WINNT=0x502
208 -D_WIN32_WINDOWS=0x502
209 -D_SETUPAPI_VER=0x502
210 -DMINGW_HAS_SECURE_API=1)
211
212 # Arch Options
213 if(ARCH STREQUAL "i386")
214 if(NOT USE_CLANG_CL)
215 add_definitions(-D_M_IX86)
216 endif()
217 add_definitions(-D_X86_ -D__i386__ -Di386)
218 if(SARCH STREQUAL "xbox")
219 add_definitions(-DSARCH_XBOX)
220 elseif(SARCH STREQUAL "pc98")
221 add_definitions(-DSARCH_PC98)
222 endif()
223 elseif(ARCH STREQUAL "amd64")
224 # clang-cl defines this one for itself
225 if (NOT (MSVC AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
226 add_compile_definitions(_M_AMD64)
227 endif()
228 add_definitions(-D_AMD64_ -D__x86_64__ -D_WIN64)
229 elseif(ARCH STREQUAL "arm")
230 # _M_ARM is already defined by toolchain
231 add_definitions(-D_ARM_ -D__arm__ -DWIN32)
232 if(SARCH STREQUAL "omap-zoom2")
233 add_definitions(-D_ZOOM2_)
234 endif()
235 endif()
236
237 # Other
238 add_definitions(-D_NEW_DELETE_OPERATORS_)
239 if(ARCH STREQUAL "i386")
240 add_definitions(-DUSE_COMPILER_EXCEPTIONS -D_USE_32BIT_TIME_T)
241 elseif(ARCH STREQUAL "amd64")
242 add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX)
243 elseif(ARCH STREQUAL "arm")
244 add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX)
245 endif()
246
247 # Activate support for assembly source files
248 if (MSVC)
249 enable_language(ASM_MASM)
250 else()
251 enable_language(ASM)
252 endif()
253
254 # Activate language support for resource files
255 enable_language(RC)
256
257 # Localization definitions
258 include(sdk/cmake/localization.cmake)
259 set(I18N_DEFS "")
260 # This will set I18N_DEFS for later use
261 set_i18n_language(${I18N_LANG})
262
263 # Compiler specific definitions and macros
264 if(MSVC)
265 include(sdk/cmake/msvc.cmake)
266 else()
267 include(sdk/cmake/gcc.cmake)
268 endif()
269
270 # Generic macros
271 include(sdk/cmake/CMakeMacros.cmake)
272
273 # IDL macros for widl/midl
274 # We're using widl now for both MSVC and GCC builds
275 include(sdk/cmake/widl-support.cmake)
276
277 include_directories(
278 sdk/include
279 sdk/include/psdk
280 sdk/include/dxsdk
281 ${REACTOS_BINARY_DIR}/sdk/include
282 ${REACTOS_BINARY_DIR}/sdk/include/psdk
283 ${REACTOS_BINARY_DIR}/sdk/include/dxsdk
284 ${REACTOS_BINARY_DIR}/sdk/include/ddk
285 ${REACTOS_BINARY_DIR}/sdk/include/reactos
286 ${REACTOS_BINARY_DIR}/sdk/include/reactos/mc
287 sdk/include/crt
288 sdk/include/ddk
289 sdk/include/ndk
290 sdk/include/reactos
291 sdk/include/reactos/libs)
292
293 if(ARCH STREQUAL "arm")
294 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/arm)
295 endif()
296
297 add_dependency_header()
298
299 add_subdirectory(sdk/include/ndk/tests)
300 add_subdirectory(sdk/include/xdk)
301 add_subdirectory(sdk/include/psdk)
302 add_subdirectory(sdk/include/dxsdk)
303 add_subdirectory(sdk/include/reactos/wine)
304 add_subdirectory(sdk/include/reactos/mc)
305 add_subdirectory(sdk/include/asm)
306
307 if(NO_ROSSYM)
308 include(sdk/cmake/baseaddress_dwarf.cmake)
309 elseif(MSVC)
310 if (ARCH STREQUAL "amd64")
311 include(sdk/cmake/baseaddress_msvc_x64.cmake)
312 else()
313 include(sdk/cmake/baseaddress_msvc.cmake)
314 endif()
315 else()
316 include(sdk/cmake/baseaddress.cmake)
317 endif()
318
319 # For MSVC builds, this puts all debug symbols file in the same directory.
320 if(MSVC)
321 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb")
322 elseif(SEPARATE_DBG)
323 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/symbols")
324 endif()
325
326 #begin with boot so reactos_cab target is defined before all other modules
327 add_subdirectory(boot)
328 add_subdirectory(base)
329 add_subdirectory(dll)
330 add_subdirectory(drivers)
331 add_subdirectory(hal)
332 add_subdirectory(sdk/lib)
333 add_subdirectory(media)
334 add_subdirectory(modules)
335 add_subdirectory(ntoskrnl)
336 add_subdirectory(subsystems)
337 add_subdirectory(sdk/tools/wpp)
338 add_subdirectory(win32ss)
339
340 # Create the registry hives
341 create_registry_hives()
342
343 # Create {bootcd, livecd, bootcdregtest}.lst
344 create_iso_lists()
345
346 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/sdk/include/reactos)
347
348 add_dependency_footer()
349 endif()