1 2cmake_minimum_required(VERSION 3.2.1) 3cmake_policy(VERSION 3.2.1) 4 5if(NOT CMAKE_VERSION MATCHES "ReactOS") 6 message(WARNING "Building with \"${CMAKE_COMMAND}\", which is not the custom CMake included in RosBE, might cause build issues...") 7endif() 8 9# Don't escape preprocessor definition values added via add_definitions 10cmake_policy(SET CMP0005 OLD) 11 12# Honor CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable. 13cmake_policy(SET CMP0018 OLD) 14 15if(POLICY CMP0058) 16 # Ninja requires custom command byproducts to be explicit 17 cmake_policy(SET CMP0058 OLD) 18endif() 19 20project(REACTOS) 21 22# Versioning 23include(sdk/include/reactos/version.cmake) 24 25set(CMAKE_INCLUDE_CURRENT_DIR ON) 26set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) 27set(CMAKE_SHARED_LIBRARY_PREFIX "") 28set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE) 29set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE) 30set(CMAKE_COLOR_MAKEFILE OFF) 31#set_property(GLOBAL PROPERTY RULE_MESSAGES OFF) 32 33if(NOT DEFINED NEW_STYLE_BUILD) 34 set(NEW_STYLE_BUILD TRUE) 35endif() 36 37if(NOT ARCH) 38 set(ARCH i386) 39endif() 40# Now the ARCH variable will be in lowercase. 41# It is needed because STREQUAL comparison 42# is case-sensitive. 43# See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html 44# for more information. 45string(TOLOWER ${ARCH} ARCH) 46 47# Compile options 48if(ARCH STREQUAL "i386") 49 include(sdk/cmake/config.cmake) 50elseif(ARCH STREQUAL "amd64") 51 include(sdk/cmake/config-amd64.cmake) 52elseif(ARCH STREQUAL "arm") 53 include(sdk/cmake/config-arm.cmake) 54endif() 55 56# Compiler flags handling 57include(sdk/cmake/compilerflags.cmake) 58 59add_definitions(-D__REACTOS__) 60 61# Double escape, since CMake unescapes before putting it on the command-line, where it's unescaped again by GCC/CL. 62add_definitions(-DREACTOS_SOURCE_DIR="\\\"${REACTOS_SOURCE_DIR}\\\"") 63add_definitions(-DREACTOS_BINARY_DIR="\\\"${REACTOS_BINARY_DIR}\\\"") 64 65# There doesn't seem to be a standard for __FILE__ being relative or absolute, so detect it at runtime. 66file(RELATIVE_PATH _PATH_PREFIX ${REACTOS_BINARY_DIR} ${REACTOS_SOURCE_DIR}) 67add_compile_flags(-D__RELFILE__="&__FILE__[__FILE__[0] == '.' ? sizeof \\\"${_PATH_PREFIX}\\\" - 1 : sizeof REACTOS_SOURCE_DIR]") 68 69if(MSVC_IDE) 70 add_compile_flags("/MP") 71endif() 72 73# Bison and Flex support 74# include(sdk/cmake/bison-flex.cmake) 75 76if(NOT CMAKE_CROSSCOMPILING) 77 78 if(NEW_STYLE_BUILD) 79 set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR}) 80 endif() 81 82 add_definitions(-DTARGET_${ARCH}) 83 84 if(MSVC) 85 if(ARCH STREQUAL "i386") 86 add_definitions(/D_X86_ /DWIN32 /D_WINDOWS) 87 endif() 88 if(MSVC_VERSION GREATER 1699) 89 add_definitions(/D_ALLOW_KEYWORD_MACROS) 90 endif() 91 if(NOT USE_CLANG_CL) 92 # FIXME: Inspect 93 add_definitions(/Dinline=__inline) 94 endif() 95 endif() 96 97 include_directories(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 if(NOT NEW_STYLE_BUILD) 106 if(NOT MSVC) 107 export(TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc rsym mkshelllink utf16le xml2sdb FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- ) 108 else() 109 export(TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- ) 110 endif() 111 endif() 112 113else() 114 # We don't need CMake importlib handling. 115 unset(CMAKE_IMPORT_LIBRARY_SUFFIX) 116 117 if(NEW_STYLE_BUILD) 118 include(sdk/cmake/host-tools.cmake) 119 endif() 120 121 # Print build type 122 message("-- Build Type: ${CMAKE_BUILD_TYPE}") 123 124 # adjust the default behaviour of the FIND_XXX() commands: 125 # search headers and libraries in the target environment, search 126 # programs in the host environment 127 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 128 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) 129 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) 130 131 #useful stuff! 132 include(CMakeParseArguments) 133 134 if(NOT NEW_STYLE_BUILD) 135 if(NOT DEFINED REACTOS_BUILD_TOOLS_DIR) 136 set(REACTOS_BUILD_TOOLS_DIR ${REACTOS_SOURCE_DIR}/build) 137 endif() 138 set(IMPORT_EXECUTABLES "${REACTOS_BUILD_TOOLS_DIR}/ImportExecutables.cmake" CACHE FILEPATH "Host executables") 139 include(${IMPORT_EXECUTABLES}) 140 endif() 141 142 if(DBG) 143 add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE) 144 else() 145 add_definitions(-DDBG=0) 146 endif() 147 148 if(KDBG) 149 add_definitions(-DKDBG=1) 150 endif() 151 152 if(_WINKD_) 153 add_definitions(-D_WINKD_=1) 154 endif() 155 156 if(CMAKE_VERSION MATCHES "ReactOS") 157 set(PCH 1 CACHE BOOL "Whether to use precompiled headers") 158 else() 159 set(PCH 0 CACHE BOOL "Whether to use precompiled headers") 160 endif() 161 162 # Version Options 163 add_definitions(-DWINVER=0x502 164 -D_WIN32_IE=0x600 165 -D_WIN32_WINNT=0x502 166 -D_WIN32_WINDOWS=0x502 167 -D_SETUPAPI_VER=0x502) 168 169 # Arch Options 170 if(ARCH STREQUAL "i386") 171 if(NOT USE_CLANG_CL) 172 add_definitions(-D_M_IX86) 173 endif() 174 add_definitions(-D_X86_ -D__i386__ -Di386) 175 elseif(ARCH STREQUAL "amd64") 176 add_definitions(-D_M_AMD64 -D_AMD64_ -D__x86_64__ -D_WIN64) 177 elseif(ARCH STREQUAL "arm") 178 # _M_ARM is already defined by toolchain 179 add_definitions(-D_ARM_ -D__arm__ -DWIN32) 180 if(SARCH STREQUAL "omap-zoom2") 181 add_definitions(-D_ZOOM2_) 182 endif() 183 endif() 184 185 # Other 186 if(ARCH STREQUAL "i386") 187 add_definitions(-DUSE_COMPILER_EXCEPTIONS -D_USE_32BIT_TIME_T) 188 elseif(ARCH STREQUAL "amd64") 189 add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX) 190 elseif(ARCH STREQUAL "arm") 191 add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX) 192 endif() 193 194 # Activate support for assembly source files 195 enable_language(ASM) 196 197 # Activate language support for resource files 198 enable_language(RC) 199 200 # Localization definitions 201 include(sdk/cmake/localization.cmake) 202 set(I18N_DEFS "") 203 # This will set I18N_DEFS for later use 204 set_i18n_language(${I18N_LANG}) 205 206 # Compiler specific definitions and macros 207 if(MSVC) 208 include(sdk/cmake/msvc.cmake) 209 else() 210 include(sdk/cmake/gcc.cmake) 211 endif() 212 213 # Generic macros 214 include(sdk/cmake/CMakeMacros.cmake) 215 216 # IDL macros for widl/midl 217 # We're using widl now for both MSVC and GCC builds 218 include(sdk/cmake/widl-support.cmake) 219 220 include_directories( 221 sdk/include 222 sdk/include/psdk 223 sdk/include/dxsdk 224 ${REACTOS_BINARY_DIR}/sdk/include 225 ${REACTOS_BINARY_DIR}/sdk/include/psdk 226 ${REACTOS_BINARY_DIR}/sdk/include/dxsdk 227 ${REACTOS_BINARY_DIR}/sdk/include/ddk 228 ${REACTOS_BINARY_DIR}/sdk/include/reactos 229 ${REACTOS_BINARY_DIR}/sdk/include/reactos/mc 230 sdk/include/crt 231 sdk/include/ddk 232 sdk/include/ndk 233 sdk/include/reactos 234 sdk/include/reactos/libs) 235 236 if(ARCH STREQUAL "arm") 237 include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/arm) 238 endif() 239 240 add_dependency_header() 241 242 add_subdirectory(sdk/include/ndk/tests) 243 add_subdirectory(sdk/include/xdk) 244 add_subdirectory(sdk/include/psdk) 245 add_subdirectory(sdk/include/dxsdk) 246 add_subdirectory(sdk/include/reactos/wine) 247 add_subdirectory(sdk/include/reactos/mc) 248 add_subdirectory(sdk/include/asm) 249 250 if(NO_ROSSYM) 251 include(sdk/cmake/baseaddress_dwarf.cmake) 252 elseif(MSVC) 253 include(sdk/cmake/baseaddress_msvc.cmake) 254 else() 255 include(sdk/cmake/baseaddress.cmake) 256 endif() 257 258 # For MSVC builds, this puts all debug symbols file in the same directory. 259 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb") 260 261 #begin with boot so reactos_cab target is defined before all other modules 262 add_subdirectory(boot) 263 add_subdirectory(base) 264 add_subdirectory(dll) 265 add_subdirectory(drivers) 266 add_subdirectory(hal) 267 add_subdirectory(sdk/lib) 268 add_subdirectory(media) 269 add_subdirectory(modules) 270 add_subdirectory(ntoskrnl) 271 add_subdirectory(subsystems) 272 add_subdirectory(sdk/tools/wpp) 273 add_subdirectory(win32ss) 274 275 # Create the registry hives 276 create_registry_hives() 277 278 # Create {bootcd, livecd, bootcdregtest}.lst 279 create_iso_lists() 280 281 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/sdk/include/reactos) 282 283 add_dependency_footer() 284endif() 285