|CMAKE] Use ExternalProject for host-tools build
[reactos.git] / CMakeLists.txt
1
2 cmake_minimum_required(VERSION 3.17.0)
3
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...")
6 endif()
7
8 project(REACTOS)
9
10 # Versioning
11 include(sdk/include/reactos/version.cmake)
12
13 set(CMAKE_INCLUDE_CURRENT_DIR ON)
14 set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
15 set(CMAKE_SHARED_LIBRARY_PREFIX "")
16 set(CMAKE_SHARED_MODULE_PREFIX "")
17 set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE)
18 set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE)
19 set(CMAKE_COLOR_MAKEFILE OFF)
20 set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
21 #set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
22
23 if(NOT ARCH)
24 set(ARCH i386)
25 endif()
26 # Now the ARCH variable will be in lowercase.
27 # It is needed because STREQUAL comparison
28 # is case-sensitive.
29 # See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html
30 # for more information.
31 string(TOLOWER ${ARCH} ARCH)
32
33 # Compile options
34 if(ARCH STREQUAL "i386")
35 include(sdk/cmake/config.cmake)
36 elseif(ARCH STREQUAL "amd64")
37 include(sdk/cmake/config-amd64.cmake)
38 elseif(ARCH STREQUAL "arm")
39 include(sdk/cmake/config-arm.cmake)
40 endif()
41
42 # Compiler flags handling
43 include(sdk/cmake/compilerflags.cmake)
44
45 add_definitions(-D__REACTOS__)
46
47 # There doesn't seem to be a standard for __FILE__ being relative or absolute, so detect it at runtime.
48 file(RELATIVE_PATH _PATH_PREFIX ${REACTOS_BINARY_DIR} ${REACTOS_SOURCE_DIR})
49 if (GCC AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0"))
50 # Thankfully, GCC has this
51 add_compile_options(-ffile-prefix-map=${REACTOS_SOURCE_DIR}=)
52 add_compile_options(-ffile-prefix-map=${_PATH_PREFIX}=)
53 else()
54 string(LENGTH ${_PATH_PREFIX} _PATH_PREFIX_LENGTH)
55 string(LENGTH ${REACTOS_SOURCE_DIR} REACTOS_SOURCE_DIR_LENGTH)
56 math(EXPR REACTOS_SOURCE_DIR_LENGTH "${REACTOS_SOURCE_DIR_LENGTH} + 1")
57 add_compile_definitions("__RELFILE__=&__FILE__[__FILE__[0] == '.' ? ${_PATH_PREFIX_LENGTH} : ${REACTOS_SOURCE_DIR_LENGTH}]")
58 endif()
59
60 if(MSVC_IDE)
61 add_compile_options("/MP")
62 endif()
63
64 # Bison and Flex support
65 # include(sdk/cmake/bison-flex.cmake)
66
67 if(NOT CMAKE_CROSSCOMPILING)
68 set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
69 add_definitions(-DTARGET_${ARCH})
70
71 if(MSVC)
72 if(ARCH STREQUAL "i386")
73 add_definitions(/D_X86_ /D__i386__ /DWIN32 /D_WINDOWS)
74 elseif(ARCH STREQUAL "amd64")
75 add_definitions(-D_AMD64_ -D__x86_64__ /DWIN32 -D_WINDOWS)
76 endif()
77 if(MSVC_VERSION GREATER 1699)
78 add_definitions(/D_ALLOW_KEYWORD_MACROS)
79 endif()
80 if(NOT USE_CLANG_CL)
81 # FIXME: Inspect
82 add_definitions(/Dinline=__inline)
83 endif()
84 endif()
85 add_subdirectory(sdk/include/host)
86
87 if(NOT MSVC)
88 add_subdirectory(dll/win32/dbghelp)
89 endif()
90 add_subdirectory(sdk/tools)
91 add_subdirectory(sdk/lib)
92
93 set(NATIVE_TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb)
94 if(NOT MSVC)
95 list(APPEND NATIVE_TARGETS rsym pefixup)
96 endif()
97
98 install(TARGETS ${NATIVE_TARGETS})
99 else()
100 # Add host tools target
101 include(sdk/cmake/host-tools.cmake)
102 setup_host_tools()
103
104 # We don't need CMake importlib handling.
105 unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
106
107 # Print build type
108 message("-- Build Type: ${CMAKE_BUILD_TYPE}")
109
110 # adjust the default behaviour of the FIND_XXX() commands:
111 # search headers and libraries in the target environment, search
112 # programs in the host environment
113 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
114 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
115 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
116
117 # Add our own target properties
118 # C++
119 define_property(TARGET PROPERTY WITH_CXX_EXCEPTIONS
120 BRIEF_DOCS "Enable C++ exceptions on this target"
121 FULL_DOCS [[
122 Enables C++ exception handling.
123 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).]])
124 define_property(TARGET PROPERTY WITH_CXX_RTTI
125 BRIEF_DOCS "Enable C++ RTTI on this target"
126 FULL_DOCS [[
127 Enables run-time type information.
128 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.]])
129
130
131 if(DBG)
132 add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
133 else()
134 add_definitions(-DDBG=0)
135 endif()
136
137 if(KDBG)
138 add_definitions(-DKDBG)
139 endif()
140
141 if(_WINKD_)
142 add_definitions(-D_WINKD_)
143 endif()
144
145 if(ENABLE_CCACHE)
146 message(WARNING "-- Disabling precompiled headers support (ccache).")
147 option(PCH "Whether to use precompiled headers" OFF)
148 elseif(GCC)
149 message(WARNING "-- Disabling precompiled headers on GCC by default CORE-17108.")
150 option(PCH "Whether to use precompiled headers" OFF)
151 else()
152 option(PCH "Whether to use precompiled headers" ON)
153 endif()
154
155 # Version Options
156 add_definitions(-DWINVER=0x502
157 -D_WIN32_IE=0x600
158 -D_WIN32_WINNT=0x502
159 -D_WIN32_WINDOWS=0x502
160 -D_SETUPAPI_VER=0x502
161 -DMINGW_HAS_SECURE_API=1)
162
163 # Arch Options
164 if(ARCH STREQUAL "i386")
165 if(NOT USE_CLANG_CL)
166 add_definitions(-D_M_IX86)
167 endif()
168 add_definitions(-D_X86_ -D__i386__ -Di386)
169 if(SARCH STREQUAL "xbox")
170 add_definitions(-DSARCH_XBOX)
171 elseif(SARCH STREQUAL "pc98")
172 add_definitions(-DSARCH_PC98)
173 endif()
174 elseif(ARCH STREQUAL "amd64")
175 add_definitions(-D_M_AMD64 -D_AMD64_ -D__x86_64__ -D_WIN64)
176 elseif(ARCH STREQUAL "arm")
177 # _M_ARM is already defined by toolchain
178 add_definitions(-D_ARM_ -D__arm__ -DWIN32)
179 if(SARCH STREQUAL "omap-zoom2")
180 add_definitions(-D_ZOOM2_)
181 endif()
182 endif()
183
184 # Other
185 add_definitions(-D_NEW_DELETE_OPERATORS_)
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 if (ARCH STREQUAL "amd64")
254 include(sdk/cmake/baseaddress_msvc_x64.cmake)
255 else()
256 include(sdk/cmake/baseaddress_msvc.cmake)
257 endif()
258 else()
259 include(sdk/cmake/baseaddress.cmake)
260 endif()
261
262 # For MSVC builds, this puts all debug symbols file in the same directory.
263 if(MSVC)
264 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb")
265 elseif(SEPARATE_DBG)
266 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/symbols")
267 endif()
268
269 #begin with boot so reactos_cab target is defined before all other modules
270 add_subdirectory(boot)
271 add_subdirectory(base)
272 add_subdirectory(dll)
273 add_subdirectory(drivers)
274 add_subdirectory(hal)
275 add_subdirectory(sdk/lib)
276 add_subdirectory(media)
277 add_subdirectory(modules)
278 add_subdirectory(ntoskrnl)
279 add_subdirectory(subsystems)
280 add_subdirectory(sdk/tools/wpp)
281 add_subdirectory(win32ss)
282
283 # Create the registry hives
284 create_registry_hives()
285
286 # Create {bootcd, livecd, bootcdregtest}.lst
287 create_iso_lists()
288
289 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/sdk/include/reactos)
290
291 add_dependency_footer()
292 endif()