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