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