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