2 cmake_minimum_required(VERSION 3.17.0)
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...")
8 include(CMakeDependentOption)
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)
27 # Now the ARCH variable will be in lowercase.
28 # It is needed because STREQUAL comparison
30 # See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html
31 # for more information.
32 string(TOLOWER ${ARCH} ARCH)
34 # Alternative WinNT-compatible architecture string
35 if(ARCH STREQUAL "i386")
42 include(sdk/include/reactos/version.cmake)
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)
53 # Compiler flags handling
54 include(sdk/cmake/compilerflags.cmake)
56 add_definitions(-D__REACTOS__)
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}=)
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}]>")
73 add_compile_options("/MP")
76 # Bison and Flex support
77 # include(sdk/cmake/bison-flex.cmake)
79 if(NOT CMAKE_CROSSCOMPILING)
80 set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
81 add_definitions(-DTARGET_${ARCH})
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)
89 if(MSVC_VERSION GREATER 1699)
90 add_definitions(/D_ALLOW_KEYWORD_MACROS)
94 add_definitions(/Dinline=__inline)
97 add_subdirectory(sdk/include/host)
100 add_subdirectory(dll/win32/dbghelp)
102 add_subdirectory(sdk/tools)
103 add_subdirectory(sdk/lib)
105 set(NATIVE_TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb)
107 list(APPEND NATIVE_TARGETS rsym pefixup)
110 install(TARGETS ${NATIVE_TARGETS})
112 # Add host tools target
113 include(sdk/cmake/host-tools.cmake)
116 # We don't need CMake importlib handling.
117 unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
120 message("-- Build Type: ${CMAKE_BUILD_TYPE}")
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)
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"
134 The type of this module.
135 One of "nativecui", "nativedll", "kernelmodedriver", "wdmdriver", "kerneldll", "win32cui", "win32gui", "win32dll", "win32ocx", "cpl" or "module"]])
138 define_property(TARGET PROPERTY WITH_CXX_EXCEPTIONS
139 BRIEF_DOCS "Enable C++ exceptions on this target"
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"
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.]])
151 add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
153 add_definitions(-DDBG=0)
157 add_definitions(-DKDBG)
161 add_definitions(-D_WINKD_)
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)
169 message(WARNING "-- Disabling precompiled headers on GCC by default CORE-17108.")
170 option(PCH "Whether to use precompiled headers" OFF)
172 option(PCH "Whether to use precompiled headers" ON)
176 add_definitions(-DWINVER=0x502
179 -D_WIN32_WINDOWS=0x502
180 -D_SETUPAPI_VER=0x502
181 -DMINGW_HAS_SECURE_API=1)
184 if(ARCH STREQUAL "i386")
186 add_definitions(-D_M_IX86)
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)
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_)
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)
214 # Activate support for assembly source files
217 # Activate language support for resource files
220 # Localization definitions
221 include(sdk/cmake/localization.cmake)
223 # This will set I18N_DEFS for later use
224 set_i18n_language(${I18N_LANG})
226 # Compiler specific definitions and macros
228 include(sdk/cmake/msvc.cmake)
230 include(sdk/cmake/gcc.cmake)
234 include(sdk/cmake/CMakeMacros.cmake)
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)
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
254 sdk/include/reactos/libs)
256 if(ARCH STREQUAL "arm")
257 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/arm)
260 add_dependency_header()
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)
271 include(sdk/cmake/baseaddress_dwarf.cmake)
273 if (ARCH STREQUAL "amd64")
274 include(sdk/cmake/baseaddress_msvc_x64.cmake)
276 include(sdk/cmake/baseaddress_msvc.cmake)
279 include(sdk/cmake/baseaddress.cmake)
282 # For MSVC builds, this puts all debug symbols file in the same directory.
284 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb")
286 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/symbols")
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)
303 # Create the registry hives
304 create_registry_hives()
306 # Create {bootcd, livecd, bootcdregtest}.lst
309 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/sdk/include/reactos)
311 add_dependency_footer()