[XDK] Even the DBG_UNREFERENCED_PARAMETER() should use (void)P. Addendum to 46ca069e.
[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 project(REACTOS)
11
12 set(CMAKE_INCLUDE_CURRENT_DIR ON)
13 set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
14 set(CMAKE_SHARED_LIBRARY_PREFIX "")
15 set(CMAKE_SHARED_MODULE_PREFIX "")
16 set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE)
17 set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE)
18 set(CMAKE_COLOR_MAKEFILE OFF)
19 set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
20 set(CMAKE_C_STANDARD 99)
21 set(CMAKE_CXX_STANDARD 11)
22 #set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
23
24 if(NOT ARCH)
25 set(ARCH i386)
26 endif()
27 # Now the ARCH variable will be in lowercase.
28 # It is needed because STREQUAL comparison
29 # is case-sensitive.
30 # See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html
31 # for more information.
32 string(TOLOWER ${ARCH} ARCH)
33
34 # Alternative WinNT-compatible architecture string
35 if(ARCH STREQUAL "i386")
36 set(WINARCH "x86")
37 else()
38 set(WINARCH ${ARCH})
39 endif()
40
41 # Versioning
42 include(sdk/include/reactos/version.cmake)
43
44 # Compile options
45 if(ARCH STREQUAL "i386")
46 include(sdk/cmake/config.cmake)
47 elseif(ARCH STREQUAL "amd64")
48 include(sdk/cmake/config-amd64.cmake)
49 elseif(ARCH STREQUAL "arm")
50 include(sdk/cmake/config-arm.cmake)
51 endif()
52
53 # Compiler flags handling
54 include(sdk/cmake/compilerflags.cmake)
55
56 add_definitions(-D__REACTOS__)
57
58 # There doesn't seem to be a standard for __FILE__ being relative or absolute, so detect it at runtime.
59 file(RELATIVE_PATH _PATH_PREFIX ${REACTOS_BINARY_DIR} ${REACTOS_SOURCE_DIR})
60 if (GCC AND ((CMAKE_C_COMPILER_ID STREQUAL "GNU") AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0")
61 OR ((CMAKE_C_COMPILER_ID STREQUAL "Clang") AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "10.0.0"))))
62 # Thankfully, GCC has this
63 add_compile_options(-ffile-prefix-map=${REACTOS_SOURCE_DIR}=)
64 add_compile_options(-ffile-prefix-map=${_PATH_PREFIX}=)
65 else()
66 string(LENGTH ${_PATH_PREFIX} _PATH_PREFIX_LENGTH)
67 string(LENGTH ${REACTOS_SOURCE_DIR} REACTOS_SOURCE_DIR_LENGTH)
68 math(EXPR REACTOS_SOURCE_DIR_LENGTH "${REACTOS_SOURCE_DIR_LENGTH} + 1")
69 add_compile_definitions("$<$<COMPILE_LANGUAGE:C,CXX>:__RELFILE__=&__FILE__[__FILE__[0] == '.' ? ${_PATH_PREFIX_LENGTH} : ${REACTOS_SOURCE_DIR_LENGTH}]>")
70 endif()
71
72 if(MSVC_IDE)
73 add_compile_options("/MP")
74 endif()
75
76 # Bison and Flex support
77 # include(sdk/cmake/bison-flex.cmake)
78
79 if(NOT CMAKE_CROSSCOMPILING)
80 set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
81 add_definitions(-DTARGET_${ARCH})
82
83 if(MSVC)
84 if(ARCH STREQUAL "i386")
85 add_definitions(/D_X86_ /D__i386__ /DWIN32 /D_WINDOWS)
86 elseif(ARCH STREQUAL "amd64")
87 add_definitions(-D_AMD64_ -D__x86_64__ /DWIN32 -D_WINDOWS)
88 endif()
89 if(MSVC_VERSION GREATER 1699)
90 add_definitions(/D_ALLOW_KEYWORD_MACROS)
91 endif()
92 if(NOT USE_CLANG_CL)
93 # FIXME: Inspect
94 add_definitions(/Dinline=__inline)
95 endif()
96 endif()
97 add_subdirectory(sdk/include/host)
98
99 if(NOT MSVC)
100 add_subdirectory(dll/win32/dbghelp)
101 endif()
102 add_subdirectory(sdk/tools)
103 add_subdirectory(sdk/lib)
104
105 set(NATIVE_TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb)
106 if(NOT MSVC)
107 list(APPEND NATIVE_TARGETS rsym pefixup)
108 endif()
109
110 install(TARGETS ${NATIVE_TARGETS})
111 else()
112 # Add host tools target
113 include(sdk/cmake/host-tools.cmake)
114 setup_host_tools()
115
116 # We don't need CMake importlib handling.
117 unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
118
119 # Print build type
120 message("-- Build Type: ${CMAKE_BUILD_TYPE}")
121
122 # adjust the default behaviour of the FIND_XXX() commands:
123 # search headers and libraries in the target environment, search
124 # programs in the host environment
125 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
126 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
127 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
128
129 # Add our own target properties
130 # General module definitions
131 define_property(TARGET PROPERTY REACTOS_MODULE_TYPE
132 BRIEF_DOCS "The type of this module"
133 FULL_DOCS [[
134 The type of this module.
135 One of "nativecui", "nativedll", "kernelmodedriver", "wdmdriver", "kerneldll", "win32cui", "win32gui", "win32dll", "win32ocx", "cpl" or "module"]])
136
137 # C++
138 define_property(TARGET PROPERTY WITH_CXX_EXCEPTIONS
139 BRIEF_DOCS "Enable C++ exceptions on this target"
140 FULL_DOCS [[
141 Enables C++ exception handling.
142 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).]])
143 define_property(TARGET PROPERTY WITH_CXX_RTTI
144 BRIEF_DOCS "Enable C++ RTTI on this target"
145 FULL_DOCS [[
146 Enables run-time type information.
147 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.]])
148
149
150 if(DBG)
151 add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
152 else()
153 add_definitions(-DDBG=0)
154 endif()
155
156 if(KDBG)
157 add_definitions(-DKDBG)
158 endif()
159
160 if(_WINKD_)
161 add_definitions(-D_WINKD_)
162 endif()
163
164 if(ENABLE_CCACHE)
165 message(WARNING "-- Disabling precompiled headers support (ccache).")
166 option(PCH "Whether to use precompiled headers" OFF)
167 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
168 elseif(GCC)
169 message(WARNING "-- Disabling precompiled headers on GCC by default CORE-17108.")
170 option(PCH "Whether to use precompiled headers" OFF)
171 else()
172 option(PCH "Whether to use precompiled headers" ON)
173 endif()
174
175 # Version Options
176 add_definitions(-DWINVER=0x502
177 -D_WIN32_IE=0x600
178 -D_WIN32_WINNT=0x502
179 -D_WIN32_WINDOWS=0x502
180 -D_SETUPAPI_VER=0x502
181 -DMINGW_HAS_SECURE_API=1)
182
183 # Arch Options
184 if(ARCH STREQUAL "i386")
185 if(NOT USE_CLANG_CL)
186 add_definitions(-D_M_IX86)
187 endif()
188 add_definitions(-D_X86_ -D__i386__ -Di386)
189 if(SARCH STREQUAL "xbox")
190 add_definitions(-DSARCH_XBOX)
191 elseif(SARCH STREQUAL "pc98")
192 add_definitions(-DSARCH_PC98)
193 endif()
194 elseif(ARCH STREQUAL "amd64")
195 add_definitions(-D_M_AMD64 -D_AMD64_ -D__x86_64__ -D_WIN64)
196 elseif(ARCH STREQUAL "arm")
197 # _M_ARM is already defined by toolchain
198 add_definitions(-D_ARM_ -D__arm__ -DWIN32)
199 if(SARCH STREQUAL "omap-zoom2")
200 add_definitions(-D_ZOOM2_)
201 endif()
202 endif()
203
204 # Other
205 add_definitions(-D_NEW_DELETE_OPERATORS_)
206 if(ARCH STREQUAL "i386")
207 add_definitions(-DUSE_COMPILER_EXCEPTIONS -D_USE_32BIT_TIME_T)
208 elseif(ARCH STREQUAL "amd64")
209 add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX)
210 elseif(ARCH STREQUAL "arm")
211 add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX)
212 endif()
213
214 # Activate support for assembly source files
215 enable_language(ASM)
216
217 # Activate language support for resource files
218 enable_language(RC)
219
220 # Localization definitions
221 include(sdk/cmake/localization.cmake)
222 set(I18N_DEFS "")
223 # This will set I18N_DEFS for later use
224 set_i18n_language(${I18N_LANG})
225
226 # Compiler specific definitions and macros
227 if(MSVC)
228 include(sdk/cmake/msvc.cmake)
229 else()
230 include(sdk/cmake/gcc.cmake)
231 endif()
232
233 # Generic macros
234 include(sdk/cmake/CMakeMacros.cmake)
235
236 # IDL macros for widl/midl
237 # We're using widl now for both MSVC and GCC builds
238 include(sdk/cmake/widl-support.cmake)
239
240 include_directories(
241 sdk/include
242 sdk/include/psdk
243 sdk/include/dxsdk
244 ${REACTOS_BINARY_DIR}/sdk/include
245 ${REACTOS_BINARY_DIR}/sdk/include/psdk
246 ${REACTOS_BINARY_DIR}/sdk/include/dxsdk
247 ${REACTOS_BINARY_DIR}/sdk/include/ddk
248 ${REACTOS_BINARY_DIR}/sdk/include/reactos
249 ${REACTOS_BINARY_DIR}/sdk/include/reactos/mc
250 sdk/include/crt
251 sdk/include/ddk
252 sdk/include/ndk
253 sdk/include/reactos
254 sdk/include/reactos/libs)
255
256 if(ARCH STREQUAL "arm")
257 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/arm)
258 endif()
259
260 add_dependency_header()
261
262 add_subdirectory(sdk/include/ndk/tests)
263 add_subdirectory(sdk/include/xdk)
264 add_subdirectory(sdk/include/psdk)
265 add_subdirectory(sdk/include/dxsdk)
266 add_subdirectory(sdk/include/reactos/wine)
267 add_subdirectory(sdk/include/reactos/mc)
268 add_subdirectory(sdk/include/asm)
269
270 if(NO_ROSSYM)
271 include(sdk/cmake/baseaddress_dwarf.cmake)
272 elseif(MSVC)
273 if (ARCH STREQUAL "amd64")
274 include(sdk/cmake/baseaddress_msvc_x64.cmake)
275 else()
276 include(sdk/cmake/baseaddress_msvc.cmake)
277 endif()
278 else()
279 include(sdk/cmake/baseaddress.cmake)
280 endif()
281
282 # For MSVC builds, this puts all debug symbols file in the same directory.
283 if(MSVC)
284 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb")
285 elseif(SEPARATE_DBG)
286 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/symbols")
287 endif()
288
289 #begin with boot so reactos_cab target is defined before all other modules
290 add_subdirectory(boot)
291 add_subdirectory(base)
292 add_subdirectory(dll)
293 add_subdirectory(drivers)
294 add_subdirectory(hal)
295 add_subdirectory(sdk/lib)
296 add_subdirectory(media)
297 add_subdirectory(modules)
298 add_subdirectory(ntoskrnl)
299 add_subdirectory(subsystems)
300 add_subdirectory(sdk/tools/wpp)
301 add_subdirectory(win32ss)
302
303 # Create the registry hives
304 create_registry_hives()
305
306 # Create {bootcd, livecd, bootcdregtest}.lst
307 create_iso_lists()
308
309 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/sdk/include/reactos)
310
311 add_dependency_footer()
312 endif()