xref: /reactos/CMakeLists.txt (revision 40462c92)
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
8include(CMakeDependentOption)
9
10project(REACTOS)
11
12# Versioning
13include(sdk/include/reactos/version.cmake)
14
15set(CMAKE_INCLUDE_CURRENT_DIR ON)
16set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
17set(CMAKE_SHARED_LIBRARY_PREFIX "")
18set(CMAKE_SHARED_MODULE_PREFIX "")
19set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE)
20set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE)
21set(CMAKE_COLOR_MAKEFILE OFF)
22set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
23#set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
24
25if(NOT ARCH)
26    set(ARCH i386)
27endif()
28# Now the ARCH variable will be in lowercase.
29# It is needed because STREQUAL comparison
30# is case-sensitive.
31# See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html
32# for more information.
33string(TOLOWER ${ARCH} ARCH)
34
35# Compile options
36if(ARCH STREQUAL "i386")
37    include(sdk/cmake/config.cmake)
38elseif(ARCH STREQUAL "amd64")
39    include(sdk/cmake/config-amd64.cmake)
40elseif(ARCH STREQUAL "arm")
41    include(sdk/cmake/config-arm.cmake)
42endif()
43
44# Compiler flags handling
45include(sdk/cmake/compilerflags.cmake)
46
47add_definitions(-D__REACTOS__)
48
49# There doesn't seem to be a standard for __FILE__ being relative or absolute, so detect it at runtime.
50file(RELATIVE_PATH _PATH_PREFIX ${REACTOS_BINARY_DIR} ${REACTOS_SOURCE_DIR})
51if (GCC AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0"))
52    # Thankfully, GCC has this
53    add_compile_options(-ffile-prefix-map=${REACTOS_SOURCE_DIR}=)
54    add_compile_options(-ffile-prefix-map=${_PATH_PREFIX}=)
55else()
56    string(LENGTH ${_PATH_PREFIX} _PATH_PREFIX_LENGTH)
57    string(LENGTH ${REACTOS_SOURCE_DIR} REACTOS_SOURCE_DIR_LENGTH)
58    math(EXPR REACTOS_SOURCE_DIR_LENGTH "${REACTOS_SOURCE_DIR_LENGTH} + 1")
59    add_compile_definitions("__RELFILE__=&__FILE__[__FILE__[0] == '.' ? ${_PATH_PREFIX_LENGTH} : ${REACTOS_SOURCE_DIR_LENGTH}]")
60endif()
61
62if(MSVC_IDE)
63    add_compile_options("/MP")
64endif()
65
66# Bison and Flex support
67# include(sdk/cmake/bison-flex.cmake)
68
69if(NOT CMAKE_CROSSCOMPILING)
70    set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
71    add_definitions(-DTARGET_${ARCH})
72
73    if(MSVC)
74        if(ARCH STREQUAL "i386")
75            add_definitions(/D_X86_ /D__i386__ /DWIN32 /D_WINDOWS)
76        elseif(ARCH STREQUAL "amd64")
77            add_definitions(-D_AMD64_ -D__x86_64__ /DWIN32 -D_WINDOWS)
78        endif()
79        if(MSVC_VERSION GREATER 1699)
80            add_definitions(/D_ALLOW_KEYWORD_MACROS)
81        endif()
82        if(NOT USE_CLANG_CL)
83            # FIXME: Inspect
84            add_definitions(/Dinline=__inline)
85        endif()
86    endif()
87    add_subdirectory(sdk/include/host)
88
89    if(NOT MSVC)
90        add_subdirectory(dll/win32/dbghelp)
91    endif()
92    add_subdirectory(sdk/tools)
93    add_subdirectory(sdk/lib)
94
95    set(NATIVE_TARGETS bin2c widl gendib cabman fatten hpp isohybrid mkhive mkisofs obj2bin spec2def geninc mkshelllink utf16le xml2sdb)
96    if(NOT MSVC)
97        list(APPEND NATIVE_TARGETS rsym pefixup)
98    endif()
99
100    install(TARGETS ${NATIVE_TARGETS})
101else()
102    # Add host tools target
103    include(sdk/cmake/host-tools.cmake)
104    setup_host_tools()
105
106    # We don't need CMake importlib handling.
107    unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
108
109    # Print build type
110    message("-- Build Type: ${CMAKE_BUILD_TYPE}")
111
112    # adjust the default behaviour of the FIND_XXX() commands:
113    # search headers and libraries in the target environment, search
114    # programs in the host environment
115    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
116    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
117    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
118
119    # Add our own target properties
120    # General module definitions
121    define_property(TARGET PROPERTY REACTOS_MODULE_TYPE
122        BRIEF_DOCS "The type of this module"
123        FULL_DOCS [[
124The type of this module.
125One of "nativecui", "nativedll", "kernelmodedriver", "wdmdriver", "kerneldll", "win32cui", "win32gui", "win32dll", "win32ocx", "cpl" or "module"]])
126
127    # C++
128    define_property(TARGET PROPERTY WITH_CXX_EXCEPTIONS
129        BRIEF_DOCS "Enable C++ exceptions on this target"
130        FULL_DOCS [[
131Enables C++ exception handling.
132Enable this if the module uses try/catch or throw. You might also need this if you use a standard operator new (the one without nothrow).]])
133    define_property(TARGET PROPERTY WITH_CXX_RTTI
134        BRIEF_DOCS "Enable C++ RTTI on this target"
135        FULL_DOCS [[
136Enables run-time type information.
137Enable this if the module uses typeid or dynamic_cast. You will probably need to link yith cpprt as well, if you are not already using STL.]])
138
139
140    if(DBG)
141        add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
142    else()
143        add_definitions(-DDBG=0)
144    endif()
145
146    if(KDBG)
147        add_definitions(-DKDBG)
148    endif()
149
150    if(_WINKD_)
151        add_definitions(-D_WINKD_)
152    endif()
153
154    if(ENABLE_CCACHE)
155        message(WARNING "-- Disabling precompiled headers support (ccache).")
156        option(PCH "Whether to use precompiled headers" OFF)
157    elseif(GCC)
158        message(WARNING "-- Disabling precompiled headers on GCC by default CORE-17108.")
159        option(PCH "Whether to use precompiled headers" OFF)
160    else()
161        option(PCH "Whether to use precompiled headers" ON)
162    endif()
163
164    # Version Options
165    add_definitions(-DWINVER=0x502
166                    -D_WIN32_IE=0x600
167                    -D_WIN32_WINNT=0x502
168                    -D_WIN32_WINDOWS=0x502
169                    -D_SETUPAPI_VER=0x502
170                    -DMINGW_HAS_SECURE_API=1)
171
172    # Arch Options
173    if(ARCH STREQUAL "i386")
174        if(NOT USE_CLANG_CL)
175            add_definitions(-D_M_IX86)
176        endif()
177        add_definitions(-D_X86_ -D__i386__ -Di386)
178        if(SARCH STREQUAL "xbox")
179            add_definitions(-DSARCH_XBOX)
180        elseif(SARCH STREQUAL "pc98")
181            add_definitions(-DSARCH_PC98)
182        endif()
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    add_definitions(-D_NEW_DELETE_OPERATORS_)
195    if(ARCH STREQUAL "i386")
196        add_definitions(-DUSE_COMPILER_EXCEPTIONS -D_USE_32BIT_TIME_T)
197    elseif(ARCH STREQUAL "amd64")
198        add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX)
199    elseif(ARCH STREQUAL "arm")
200        add_definitions(-DUSE_COMPILER_EXCEPTIONS -DNO_UNDERSCORE_PREFIX)
201    endif()
202
203    # Activate support for assembly source files
204    enable_language(ASM)
205
206    # Activate language support for resource files
207    enable_language(RC)
208
209    # Localization definitions
210    include(sdk/cmake/localization.cmake)
211    set(I18N_DEFS "")
212    # This will set I18N_DEFS for later use
213    set_i18n_language(${I18N_LANG})
214
215    # Compiler specific definitions and macros
216    if(MSVC)
217        include(sdk/cmake/msvc.cmake)
218    else()
219        include(sdk/cmake/gcc.cmake)
220    endif()
221
222    # Generic macros
223    include(sdk/cmake/CMakeMacros.cmake)
224
225    # IDL macros for widl/midl
226    # We're using widl now for both MSVC and GCC builds
227    include(sdk/cmake/widl-support.cmake)
228
229    include_directories(
230        sdk/include
231        sdk/include/psdk
232        sdk/include/dxsdk
233        ${REACTOS_BINARY_DIR}/sdk/include
234        ${REACTOS_BINARY_DIR}/sdk/include/psdk
235        ${REACTOS_BINARY_DIR}/sdk/include/dxsdk
236        ${REACTOS_BINARY_DIR}/sdk/include/ddk
237        ${REACTOS_BINARY_DIR}/sdk/include/reactos
238        ${REACTOS_BINARY_DIR}/sdk/include/reactos/mc
239        sdk/include/crt
240        sdk/include/ddk
241        sdk/include/ndk
242        sdk/include/reactos
243        sdk/include/reactos/libs)
244
245    if(ARCH STREQUAL "arm")
246        include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/arm)
247    endif()
248
249    add_dependency_header()
250
251    add_subdirectory(sdk/include/ndk/tests)
252    add_subdirectory(sdk/include/xdk)
253    add_subdirectory(sdk/include/psdk)
254    add_subdirectory(sdk/include/dxsdk)
255    add_subdirectory(sdk/include/reactos/wine)
256    add_subdirectory(sdk/include/reactos/mc)
257    add_subdirectory(sdk/include/asm)
258
259    if(NO_ROSSYM)
260        include(sdk/cmake/baseaddress_dwarf.cmake)
261    elseif(MSVC)
262        if (ARCH STREQUAL "amd64")
263            include(sdk/cmake/baseaddress_msvc_x64.cmake)
264        else()
265            include(sdk/cmake/baseaddress_msvc.cmake)
266        endif()
267    else()
268        include(sdk/cmake/baseaddress.cmake)
269    endif()
270
271    # For MSVC builds, this puts all debug symbols file in the same directory.
272    if(MSVC)
273        set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb")
274    elseif(SEPARATE_DBG)
275        set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/symbols")
276    endif()
277
278    #begin with boot so reactos_cab target is defined before all other modules
279    add_subdirectory(boot)
280    add_subdirectory(base)
281    add_subdirectory(dll)
282    add_subdirectory(drivers)
283    add_subdirectory(hal)
284    add_subdirectory(sdk/lib)
285    add_subdirectory(media)
286    add_subdirectory(modules)
287    add_subdirectory(ntoskrnl)
288    add_subdirectory(subsystems)
289    add_subdirectory(sdk/tools/wpp)
290    add_subdirectory(win32ss)
291
292    # Create the registry hives
293    create_registry_hives()
294
295    # Create {bootcd, livecd, bootcdregtest}.lst
296    create_iso_lists()
297
298    file(MAKE_DIRECTORY ${REACTOS_BINARY_DIR}/sdk/include/reactos)
299
300    add_dependency_footer()
301endif()
302