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)
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)
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)
31 # check that the ARCH (target architecture) variable is defined
33 message(FATAL_ERROR "Target architecture (ARCH) is not defined. Please, choose one of: i386, amd64, arm, arm64")
35 # Now the ARCH variable will be in lowercase.
36 # It is needed because STREQUAL comparison
38 # See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html
39 # for more information.
40 string(TOLOWER ${ARCH} ARCH)
42 # set possible values for cmake GUI
43 set_property(CACHE ARCH PROPERTY STRINGS "i386" "amd64" "arm" "arm64")
45 # Alternative WinNT-compatible architecture string
46 if(ARCH STREQUAL "i386")
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")
63 include(sdk/include/reactos/version.cmake)
66 include(sdk/cmake/config.cmake)
68 # Compiler flags handling
69 include(sdk/cmake/compilerflags.cmake)
73 # swprintf without count argument is used in most of the codebase
74 -D_CRT_NON_CONFORMING_SWPRINTFS
77 # There doesn't seem to be a standard for __FILE__ being relative or absolute, so detect it at runtime.
78 file(RELATIVE_PATH _PATH_PREFIX ${REACTOS_BINARY_DIR} ${REACTOS_SOURCE_DIR})
79 if (NOT MSVC AND ((CMAKE_C_COMPILER_ID STREQUAL "GNU") AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0")
80 OR (CMAKE_C_COMPILER_ID STREQUAL "Clang") AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "10.0.0")))
81 # Thankfully, GCC has this
82 add_compile_options(-ffile-prefix-map=${REACTOS_SOURCE_DIR}=)
83 add_compile_options(-ffile-prefix-map=${_PATH_PREFIX}=)
85 string(LENGTH ${_PATH_PREFIX} _PATH_PREFIX_LENGTH)
86 string(LENGTH ${REACTOS_SOURCE_DIR} REACTOS_SOURCE_DIR_LENGTH)
87 math(EXPR REACTOS_SOURCE_DIR_LENGTH "${REACTOS_SOURCE_DIR_LENGTH} + 1")
88 add_compile_definitions("$<$<COMPILE_LANGUAGE:C,CXX>:__RELFILE__=&__FILE__[__FILE__[0] == '.' ? ${_PATH_PREFIX_LENGTH} : ${REACTOS_SOURCE_DIR_LENGTH}]>")
92 add_compile_options("/MP")
95 # Bison and Flex support
96 find_package(BISON REQUIRED)
97 find_package(FLEX REQUIRED)
100 # Bison needs M4 and BISON_PKGDATADIR set at build time,
101 # but visual studio is hardly ever opened from the configure-time environment.
102 # Since cmake does not support setting env variables for a custom command,
103 # we have to write a wrapper that sets the variables and then executes bison.
104 # Idea taken from https://stackoverflow.com/a/35032051/4928207
106 # Store this environment variable for configure re-runs from withing visual studio.
107 SET(ROS_SAVED_M4 "$ENV{M4}" CACHE INTERNAL "")
109 if(DEFINED ENV{BISON_PKGDATADIR})
110 SET(ROS_SAVED_BISON_PKGDATADIR "$ENV{BISON_PKGDATADIR}" CACHE INTERNAL "")
113 # Tell the user about a misconfigured environment
114 if("x${ROS_SAVED_M4}x" STREQUAL "xx" OR "x${ROS_SAVED_BISON_PKGDATADIR}x" STREQUAL "xx")
115 message(FATAL_ERROR "\nM4 or BISON_PKGDATADIR environment variables not set, cannot continue!\n"
116 "See https://reactos.org/wiki/Visual_Studio for more information!")
119 file(WRITE "${CMAKE_BINARY_DIR}/bison_wrapper.cmd"
121 "set M4=${ROS_SAVED_M4}\n"
122 "set BISON_PKGDATADIR=${ROS_SAVED_BISON_PKGDATADIR}\n"
123 "${BISON_EXECUTABLE} %*\n")
124 set(BISON_EXECUTABLE "${CMAKE_BINARY_DIR}/bison_wrapper.cmd")
125 # And the same hacks for FLEX
126 file(WRITE "${CMAKE_BINARY_DIR}/flex_wrapper.cmd"
128 "set M4=${ROS_SAVED_M4}\n"
129 "set BISON_PKGDATADIR=${ROS_SAVED_BISON_PKGDATADIR}\n"
130 "${FLEX_EXECUTABLE} %*\n")
131 set(FLEX_EXECUTABLE "${CMAKE_BINARY_DIR}/flex_wrapper.cmd")
134 if(NOT CMAKE_CROSSCOMPILING)
135 set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
136 add_definitions(-DTARGET_${ARCH})
139 if(ARCH STREQUAL "i386")
140 add_definitions(/D_X86_ /D__i386__ /DWIN32 /D_WINDOWS)
141 elseif(ARCH STREQUAL "amd64")
142 add_definitions(-D_AMD64_ -D__x86_64__ /DWIN32 -D_WINDOWS)
144 if(MSVC_VERSION GREATER 1699)
145 add_definitions(/D_ALLOW_KEYWORD_MACROS)
148 add_subdirectory(sdk/include/host)
150 add_subdirectory(dll/win32/dbghelp)
151 add_subdirectory(sdk/tools)
152 add_subdirectory(sdk/lib)
154 set(NATIVE_TARGETS asmpp bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb)
156 list(APPEND NATIVE_TARGETS rsym pefixup)
159 install(TARGETS ${NATIVE_TARGETS})
161 # Add host tools target
162 include(sdk/cmake/host-tools.cmake)
165 # We don't need CMake importlib handling.
166 unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
168 # Print build type(s)
169 if(CMAKE_CONFIGURATION_TYPES)
170 # Multi-config generators, like Visual Studio (MSBuild).
171 message("-- Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
173 # Single-configuration generators, like Ninja.
174 message("-- Build type: ${CMAKE_BUILD_TYPE}")
177 # Always add /MT in VS CMAKE_GENERATOR and define _SBCS otherwise VS thinks it's a multi-byte or whatever project
179 add_compile_options("/MT")
180 add_compile_definitions(_SBCS)
184 # adjust the default behaviour of the FIND_XXX() commands:
185 # search headers and libraries in the target environment, search
186 # programs in the host environment
187 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
188 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
189 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
191 # Add our own target properties
192 # General module definitions
193 define_property(TARGET PROPERTY REACTOS_MODULE_TYPE
194 BRIEF_DOCS "The type of this module"
196 The type of this module.
197 One of "nativecui", "nativedll", "kernelmodedriver", "wdmdriver", "kerneldll", "win32cui", "win32gui", "win32dll", "win32ocx", "cpl" or "module"]])
200 define_property(TARGET PROPERTY WITH_CXX_EXCEPTIONS
201 BRIEF_DOCS "Enable C++ exceptions on this target"
203 Enables C++ exception handling.
204 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).]])
205 define_property(TARGET PROPERTY WITH_CXX_RTTI
206 BRIEF_DOCS "Enable C++ RTTI on this target"
208 Enables run-time type information.
209 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.]])
213 add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
215 add_definitions(-DDBG=0)
219 message(WARNING "-- Disabling precompiled headers support (ccache).")
220 option(PCH "Whether to use precompiled headers" OFF)
221 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
222 elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
223 message(WARNING "-- Disabling precompiled headers on GCC by default CORE-17108.")
224 option(PCH "Whether to use precompiled headers" OFF)
226 option(PCH "Whether to use precompiled headers" ON)
230 add_definitions(-DWINVER=0x502
233 -D_WIN32_WINDOWS=0x502
234 -D_SETUPAPI_VER=0x502
235 -DMINGW_HAS_SECURE_API=1
236 -DDLL_EXPORT_VERSION=${DLL_EXPORT_VERSION})
239 if(ARCH STREQUAL "i386")
240 # clang-cl defines this one for itself
241 if(NOT (MSVC AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
242 add_definitions(-D_M_IX86)
244 add_definitions(-D_X86_ -D__i386__ -Di386)
245 if(SARCH STREQUAL "xbox")
246 add_definitions(-DSARCH_XBOX)
247 elseif(SARCH STREQUAL "pc98")
248 add_definitions(-DSARCH_PC98)
250 elseif(ARCH STREQUAL "amd64")
251 # clang-cl defines this one for itself
252 if (NOT (MSVC AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
253 add_compile_definitions(_M_AMD64)
255 add_definitions(-D_AMD64_ -D__x86_64__ -D_WIN64)
256 elseif(ARCH STREQUAL "arm")
257 # _M_ARM is already defined by toolchain
258 add_definitions(-D_ARM_ -D__arm__ -DWIN32)
259 if(SARCH STREQUAL "omap3-zoom2")
260 add_definitions(-D_ZOOM2_)
262 elseif(ARCH STREQUAL "arm64")
263 # GNU tools refer to arm64 as aarch64
264 add_definitions(-D_ARM64_ -D__arm64__ -D__aarch64__ -D_WIN64)
268 add_definitions(-D_NEW_DELETE_OPERATORS_)
269 if(ARCH STREQUAL "i386")
270 add_definitions(-DUSE_COMPILER_EXCEPTIONS -D_USE_32BIT_TIME_T)
271 elseif(ARCH STREQUAL "amd64")
272 add_compile_definitions(USE_COMPILER_EXCEPTIONS)
273 elseif(ARCH STREQUAL "arm")
274 add_compile_definitions(USE_COMPILER_EXCEPTIONS)
275 elseif(ARCH STREQUAL "arm64")
276 add_compile_definitions(USE_COMPILER_EXCEPTIONS)
279 # Activate support for assembly source files
281 enable_language(ASM_MASM)
286 # Activate language support for resource files
289 # Localization definitions
290 include(sdk/cmake/localization.cmake)
292 # This will set I18N_DEFS for later use
293 set_i18n_language(${I18N_LANG})
295 # Compiler specific definitions and macros
297 include(sdk/cmake/msvc.cmake)
299 include(sdk/cmake/gcc.cmake)
303 include(sdk/cmake/CMakeMacros.cmake)
305 # IDL macros for widl/midl
306 # We're using widl now for both MSVC and GCC builds
307 include(sdk/cmake/widl-support.cmake)
313 ${REACTOS_BINARY_DIR}/sdk/include
314 ${REACTOS_BINARY_DIR}/sdk/include/psdk
315 ${REACTOS_BINARY_DIR}/sdk/include/dxsdk
316 ${REACTOS_BINARY_DIR}/sdk/include/ddk
317 ${REACTOS_BINARY_DIR}/sdk/include/reactos
318 ${REACTOS_BINARY_DIR}/sdk/include/reactos/mc
323 sdk/include/reactos/libs)
325 if(ARCH STREQUAL "arm")
326 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/arm)
329 add_dependency_header()
331 add_subdirectory(sdk/include/ndk/tests)
332 add_subdirectory(sdk/include/xdk)
333 add_subdirectory(sdk/include/psdk)
334 add_subdirectory(sdk/include/dxsdk)
335 add_subdirectory(sdk/include/reactos/wine)
336 add_subdirectory(sdk/include/reactos/mc)
337 add_subdirectory(sdk/include/asm)
339 if(ARCH MATCHES "64$")
340 include(sdk/cmake/baseaddress64.cmake)
342 include(sdk/cmake/baseaddress_dwarf.cmake)
344 include(sdk/cmake/baseaddress_msvc.cmake)
346 include(sdk/cmake/baseaddress.cmake)
349 # For MSVC builds, this puts all debug symbols file in the same directory.
351 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb")
353 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/symbols")
356 #begin with boot so reactos_cab target is defined before all other modules
357 add_subdirectory(boot)
358 add_subdirectory(base)
359 add_subdirectory(dll)
360 add_subdirectory(drivers)
361 add_subdirectory(hal)
362 add_subdirectory(sdk/lib)
363 add_subdirectory(media)
364 add_subdirectory(modules)
365 add_subdirectory(ntoskrnl)
366 add_subdirectory(subsystems)
367 add_subdirectory(sdk/tools/wpp)
368 add_subdirectory(win32ss)
370 # Create the registry hives
371 create_registry_hives()
373 # Create {bootcd, livecd, bootcdregtest}.lst
376 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/sdk/include/reactos)
378 add_dependency_footer()