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