[CMAKE] Fix setting CMake build type so we can use other types too (like Release).
[reactos.git] / reactos / CMakeLists.txt
1
2 cmake_minimum_required(VERSION 2.8.12)
3
4 if(POLICY CMP0017)
5 # Shadow cmake provided modules
6 cmake_policy(SET CMP0017 OLD)
7 endif()
8
9 if(POLICY CMP0026)
10 # Allow use of the LOCATION property
11 cmake_policy(SET CMP0026 OLD)
12 endif()
13
14 project(REACTOS)
15
16 # Versioning
17 include(include/reactos/version.cmake)
18
19 # Don't escape preprocessor definition values added via add_definitions
20 cmake_policy(SET CMP0005 OLD)
21 cmake_policy(SET CMP0002 NEW)
22 if(POLICY CMP0018)
23 cmake_policy(SET CMP0018 OLD)
24 endif()
25
26 set(CMAKE_INCLUDE_CURRENT_DIR ON)
27 set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
28 set(CMAKE_SHARED_LIBRARY_PREFIX "")
29 set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE)
30 set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE)
31 set(CMAKE_COLOR_MAKEFILE OFF)
32 #set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
33 set(CMAKE_SKIP_INSTALL_RULES ON)
34
35 if(NOT CMAKE_VERSION STREQUAL "2.8.12.1-ReactOS")
36 set(CMAKE_DISABLE_NINJA_DEPSLOG TRUE)
37 endif()
38
39 if(NOT ARCH)
40 set(ARCH i386)
41 endif()
42 # Now the ARCH variable will be in lowercase.
43 # It is needed because STREQUAL comparison
44 # is case-sensitive.
45 # See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html
46 # for more information.
47 string(TOLOWER ${ARCH} ARCH)
48
49 # Default to Debug for the build type
50 if(NOT CMAKE_BUILD_TYPE)
51 set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
52 "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
53 endif()
54
55 # Compile options
56 if(ARCH STREQUAL "i386")
57 include(cmake/config.cmake)
58 elseif(ARCH STREQUAL "amd64")
59 include(cmake/config-amd64.cmake)
60 elseif(ARCH STREQUAL "arm")
61 include(cmake/config-arm.cmake)
62 endif()
63
64 # Compiler flags handling
65 include(cmake/compilerflags.cmake)
66
67 add_definitions(-D__REACTOS__)
68
69 if(MSVC_IDE)
70 add_compile_flags("/MP")
71 endif()
72
73 # We don't need CMake importlib handling.
74 # FIXME: Remove the MSVC_IDE condition when the upcoming RosBE lands.
75 if(NOT MSVC_IDE)
76 unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
77 endif()
78
79 if(NOT CMAKE_CROSSCOMPILING)
80
81 add_definitions(-DTARGET_${ARCH})
82
83 if(MSVC)
84 if(ARCH STREQUAL "i386")
85 add_definitions(/D_X86_ /DWIN32 /D_WINDOWS)
86 endif()
87 if(MSVC_VERSION GREATER 1699)
88 add_definitions(/D_ALLOW_KEYWORD_MACROS)
89 endif()
90 add_definitions(/Dinline=__inline)
91 else()
92 add_compile_flags("-fshort-wchar -Wno-multichar")
93 endif()
94
95 include_directories(include/host)
96
97 if(NOT MSVC)
98 add_subdirectory(dll/win32/dbghelp)
99 endif()
100 add_subdirectory(tools)
101 add_subdirectory(lib)
102
103 if(NOT MSVC)
104 export(TARGETS bin2c widl gendib cabman cdmake mkhive obj2bin spec2def geninc rsym mkshelllink utf16le FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
105 else()
106 export(TARGETS bin2c widl gendib cabman cdmake mkhive obj2bin spec2def geninc mkshelllink utf16le FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake NAMESPACE native- )
107 endif()
108
109 else()
110
111 # adjust the default behaviour of the FIND_XXX() commands:
112 # search headers and libraries in the target environment, search
113 # programs in the host environment
114 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
115 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
116 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
117
118 #useful stuff!
119 include(CMakeParseArguments)
120
121 # Do some cleanup
122 file(REMOVE
123 ${REACTOS_BINARY_DIR}/dependencies.graphml
124 ${REACTOS_BINARY_DIR}/boot/ros_livecd.txt
125 ${REACTOS_BINARY_DIR}/boot/ros_livecd_target.txt
126 ${REACTOS_BINARY_DIR}/boot/ros_minicd.txt
127 ${REACTOS_BINARY_DIR}/boot/ros_minicd_target.txt
128 ${REACTOS_BINARY_DIR}/boot/ros_cab.txt
129 ${REACTOS_BINARY_DIR}/boot/ros_cab_target.txt)
130
131 if(NOT DEFINED REACTOS_BUILD_TOOLS_DIR)
132 set(REACTOS_BUILD_TOOLS_DIR ${REACTOS_SOURCE_DIR}/build)
133 endif()
134
135 set(IMPORT_EXECUTABLES "${REACTOS_BUILD_TOOLS_DIR}/ImportExecutables.cmake" CACHE FILEPATH "Host executables")
136 include(${IMPORT_EXECUTABLES})
137
138 if(DBG)
139 add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
140 else()
141 add_definitions(-DDBG=0)
142 endif()
143
144 if(KDBG)
145 add_definitions(-DKDBG=1)
146 endif()
147
148 if(_WINKD_)
149 add_definitions(-D_WINKD_=1)
150 endif()
151
152 if(CMAKE_VERSION MATCHES "ReactOS" AND MSVC_VERSION LESS 1900)
153 set(PCH 1 CACHE BOOL "Whether to use precompiled headers")
154 else()
155 set(PCH 0 CACHE BOOL "Whether to use precompiled headers")
156 endif()
157
158 # Version Options
159 add_definitions(-DWINVER=0x502
160 -D_WIN32_IE=0x600
161 -D_WIN32_WINNT=0x502
162 -D_WIN32_WINDOWS=0x502
163 -D_SETUPAPI_VER=0x502)
164
165 # Arch Options
166 if(ARCH STREQUAL "i386")
167 add_definitions(-D_M_IX86 -D_X86_ -D__i386__ -Di386)
168 elseif(ARCH STREQUAL "amd64")
169 add_definitions(-D_M_AMD64 -D_AMD64_ -D__x86_64__ -D_WIN64)
170 elseif(ARCH STREQUAL "arm")
171 # _M_ARM is already defined by toolchain
172 add_definitions(-D_ARM_ -D__arm__ -DWIN32)
173 if(SARCH STREQUAL "omap-zoom2")
174 add_definitions(-D_ZOOM2_)
175 endif()
176 endif()
177
178 # Other
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(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(cmake/msvc.cmake)
202 else()
203 include(cmake/gcc.cmake)
204 endif()
205
206 # Generic macros
207 include(cmake/CMakeMacros.cmake)
208
209 # IDL macros for widl/midl
210 # We're using widl now for both MSVC and GCC builds
211 include(cmake/widl-support.cmake)
212
213 include_directories(
214 include
215 include/psdk
216 include/dxsdk
217 ${REACTOS_BINARY_DIR}/include
218 ${REACTOS_BINARY_DIR}/include/psdk
219 ${REACTOS_BINARY_DIR}/include/dxsdk
220 ${REACTOS_BINARY_DIR}/include/reactos
221 include/crt
222 include/ddk
223 include/ndk
224 include/reactos
225 include/reactos/libs)
226
227 if(ARCH STREQUAL "arm")
228 include_directories(${REACTOS_SOURCE_DIR}/include/reactos/arm)
229 endif()
230
231 add_dependency_header()
232
233 add_subdirectory(include/psdk)
234 add_subdirectory(include/dxsdk)
235 add_subdirectory(include/reactos/wine)
236 add_subdirectory(include/reactos/mc)
237 add_subdirectory(include/asm)
238
239 if(NO_ROSSYM)
240 include(cmake/baseaddress_dwarf.cmake)
241 else()
242 include(cmake/baseaddress.cmake)
243 endif()
244
245 # For MSVC builds, this puts all debug symbols file in the same directory.
246 set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb")
247
248 #begin with boot so reactos_cab target is defined before all other modules
249 add_subdirectory(boot)
250 add_subdirectory(base)
251 add_subdirectory(dll)
252 add_subdirectory(drivers)
253 add_subdirectory(hal)
254 add_subdirectory(lib)
255 add_subdirectory(media)
256 add_subdirectory(modules)
257 add_subdirectory(ntoskrnl)
258 add_subdirectory(subsystems)
259 add_subdirectory(tools/wpp)
260 add_subdirectory(win32ss)
261
262 # Create the registry hives
263 create_registry_hives()
264
265 # Create {bootcd, livecd, bootcdregtest}.lst
266 create_iso_lists()
267
268 file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/include/reactos)
269
270 add_dependency_footer()
271 endif()