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