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