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