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