-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
324 lines (268 loc) · 9.79 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
cmake_minimum_required(VERSION 3.17.0)
project(pff)
include(CMakeDependentOption)
add_definitions(-D__PFF__)
set(PFF TRUE)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_MODULE_PREFIX "")
set(CMAKE_SKIP_PREPROCESSED_SOURCE_RULES TRUE)
set(CMAKE_SKIP_ASSEMBLY_SOURCE_RULES TRUE)
set(CMAKE_COLOR_MAKEFILE OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
## PFF SPECIFIC CODE ------------------------
option(ENABLE_TESTS "Enable pff tests" ON)
set(REACTOS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(REACTOS_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(HOST_OUT_PATH "${REACTOS_BINARY_DIR}/bin-tools")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/bin")
# fake modules
include(sdk/cmake/fake_ros.cmake)
if (NOT DEFINED DLL_EXPORT_VERSION)
if (SYS_IS_XP)
set(DLL_EXPORT_VERSION "0x501" CACHE STRING "" FORCE)
else()
set(DLL_EXPORT_VERSION "0x601" CACHE STRING "" FORCE)
endif()
endif()
# check that the ARCH (target architecture) variable is defined
if(NOT ARCH)
# imagine unironically using ARM64/ARM (bro I'm poor)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH "amd64" CACHE STRING "" FORCE)
else()
set(ARCH "x86" CACHE STRING "" FORCE)
endif()
endif()
## END OF PFF SPECIFIC CODE -----------------------------
# Now the ARCH variable will be in lowercase.
# It is needed because STREQUAL comparison
# is case-sensitive.
# See http://cmake.3232098.n2.nabble.com/Case-insensitive-string-compare-td7580269.html
# for more information.
string(TOLOWER ${ARCH} ARCH)
# set possible values for cmake GUI
set_property(CACHE ARCH PROPERTY STRINGS "i386" "amd64" "arm" "arm64")
# Alternative WinNT-compatible architecture string
if(ARCH STREQUAL "i386")
set(WINARCH "x86")
else()
set(WINARCH ${ARCH})
endif()
# set CMAKE_BUILD_TYPE if not set
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to Debug as none was specified.")
set(CMAKE_BUILD_TYPE "Debug" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Versioning
include(sdk/include/reactos/version.cmake)
# Compile options
include(sdk/cmake/config.cmake)
# Compiler flags handling
include(sdk/cmake/compilerflags.cmake)
add_definitions(
-D__REACTOS__
# swprintf without count argument is used in most of the codebase
-D_CRT_NON_CONFORMING_SWPRINTFS
)
# There doesn't seem to be a standard for __FILE__ being relative or absolute, so detect it at runtime.
file(RELATIVE_PATH _PATH_PREFIX ${REACTOS_BINARY_DIR} ${REACTOS_SOURCE_DIR})
if (NOT MSVC AND ((CMAKE_C_COMPILER_ID STREQUAL "GNU") AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0")
OR (CMAKE_C_COMPILER_ID STREQUAL "Clang") AND (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "10.0.0")))
# Thankfully, GCC has this
add_compile_options(-ffile-prefix-map=${REACTOS_SOURCE_DIR}=)
add_compile_options(-ffile-prefix-map=${_PATH_PREFIX}=)
else()
string(LENGTH ${_PATH_PREFIX} _PATH_PREFIX_LENGTH)
string(LENGTH ${REACTOS_SOURCE_DIR} REACTOS_SOURCE_DIR_LENGTH)
math(EXPR REACTOS_SOURCE_DIR_LENGTH "${REACTOS_SOURCE_DIR_LENGTH} + 1")
add_compile_definitions("$<$<COMPILE_LANGUAGE:C,CXX>:__RELFILE__=&__FILE__[__FILE__[0] == '.' ? ${_PATH_PREFIX_LENGTH} : ${REACTOS_SOURCE_DIR_LENGTH}]>")
endif()
if(MSVC_IDE)
add_compile_options("/MP")
endif()
## pff does not crosscompile!
set(TOOLS_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
add_definitions(-DTARGET_${ARCH})
if(MSVC)
if(ARCH STREQUAL "i386")
add_definitions(/D_X86_ /D__i386__ /DWIN32 /D_WINDOWS)
elseif(ARCH STREQUAL "amd64")
add_definitions(-D_AMD64_ -D__x86_64__ /DWIN32 -D_WINDOWS)
endif()
if(MSVC_VERSION GREATER 1699)
add_definitions(/D_ALLOW_KEYWORD_MACROS)
endif()
endif()
add_subdirectory(sdk/include/host)
# bootstrap reactos-like env (damn this build system...)
# We don't need CMake importlib handling.
unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
# Print build type(s)
if(CMAKE_CONFIGURATION_TYPES)
# Multi-config generators, like Visual Studio (MSBuild).
message("-- Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
else()
# Single-configuration generators, like Ninja.
message("-- Build type: ${CMAKE_BUILD_TYPE}")
endif()
# Always add /MT in VS CMAKE_GENERATOR and define _SBCS otherwise VS thinks it's a multi-byte or whatever project
if (MSVC_IDE)
add_compile_options("/MT")
add_compile_definitions(_SBCS)
endif()
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
# Add our own target properties
# General module definitions
define_property(TARGET PROPERTY REACTOS_MODULE_TYPE
BRIEF_DOCS "The type of this module"
FULL_DOCS [[
The type of this module.
One of "nativecui", "nativedll", "kernelmodedriver", "wdmdriver", "kerneldll", "win32cui", "win32gui", "win32dll", "win32ocx", "cpl" or "module"]])
# C++
define_property(TARGET PROPERTY WITH_CXX_EXCEPTIONS
BRIEF_DOCS "Enable C++ exceptions on this target"
FULL_DOCS [[
Enables C++ exception handling.
Enable 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).]])
define_property(TARGET PROPERTY WITH_CXX_RTTI
BRIEF_DOCS "Enable C++ RTTI on this target"
FULL_DOCS [[
Enables run-time type information.
Enable 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.]])
if(DBG)
add_definitions(-DDBG=1 -D_SEH_ENABLE_TRACE)
else()
add_definitions(-DDBG=0)
endif()
# Version Options
add_definitions(-DWINVER=0x502
-D_WIN32_IE=0x600
-D_WIN32_WINNT=0x502
-D_WIN32_WINDOWS=0x502
-D_SETUPAPI_VER=0x502
-DMINGW_HAS_SECURE_API=1
-DDLL_EXPORT_VERSION=${DLL_EXPORT_VERSION})
if(ARCH STREQUAL "i386")
# clang-cl defines this one for itself
if(NOT (MSVC AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
add_definitions(-D_M_IX86)
endif()
add_definitions(-D_X86_ -D__i386__ -Di386)
if(SARCH STREQUAL "xbox")
add_definitions(-DSARCH_XBOX)
elseif(SARCH STREQUAL "pc98")
add_definitions(-DSARCH_PC98)
endif()
elseif(ARCH STREQUAL "amd64")
# clang-cl defines this one for itself
if (NOT (MSVC AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
add_compile_definitions(_M_AMD64)
endif()
add_definitions(-D_AMD64_ -D__x86_64__ -D_WIN64)
elseif(ARCH STREQUAL "arm")
# _M_ARM is already defined by toolchain
add_definitions(-D_ARM_ -D__arm__ -DWIN32)
if(SARCH STREQUAL "omap3-zoom2")
add_definitions(-D_ZOOM2_)
endif()
elseif(ARCH STREQUAL "arm64")
# GNU tools refer to arm64 as aarch64
add_definitions(-D_ARM64_ -D__arm64__ -D__aarch64__ -D_WIN64)
endif()
# Other
add_definitions(-D_NEW_DELETE_OPERATORS_)
if(ARCH STREQUAL "i386")
add_definitions(-DUSE_COMPILER_EXCEPTIONS -D_USE_32BIT_TIME_T)
elseif(ARCH STREQUAL "amd64")
add_compile_definitions(USE_COMPILER_EXCEPTIONS)
elseif(ARCH STREQUAL "arm")
add_compile_definitions(USE_COMPILER_EXCEPTIONS)
elseif(ARCH STREQUAL "arm64")
add_compile_definitions(USE_COMPILER_EXCEPTIONS)
endif()
# Activate support for assembly source files
if (MSVC)
enable_language(ASM_MASM)
else()
enable_language(ASM)
endif()
# Activate language support for resource files
enable_language(RC)
# Localization definitions
include(sdk/cmake/localization.cmake)
set(I18N_DEFS "")
# This will set I18N_DEFS for later use
set_i18n_language(${I18N_LANG})
# Compiler specific definitions and macros
if(MSVC)
include(sdk/cmake/msvc.cmake)
else()
include(sdk/cmake/gcc.cmake)
endif()
# Generic macros
include(sdk/cmake/CMakeMacros.cmake)
# IDL macros for widl/midl
if (MSVC)
include(sdk/cmake/midl-support.cmake)
else()
include(sdk/cmake/widl-support.cmake)
endif()
include_directories(
sdk/include
${REACTOS_BINARY_DIR}/sdk/include
${REACTOS_BINARY_DIR}/sdk/include/reactos
${REACTOS_BINARY_DIR}/sdk/include/reactos/mc
sdk/include/reactos
sdk/include/reactos/libs)
if(ARCH STREQUAL "arm")
include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/arm)
endif()
## pff specific code
# get all host includes for host tools
get_host_includes()
# now we have ${HOST_CRT_INC} and ${HOST_CRT_LIBDIR}
# really bootstrap sdk/tools in a way that's not cancer
add_subdirectory(sdk/tools)
add_fake_targets()
## end of pff specific code
add_dependency_header()
include_directories(${SYS_PSDK_INC} ${SYS_MSVC_CRT_INC})
link_directories(${SYS_PSDK_LIBDIR} ${SYS_MSVC_CRT_LIBDIR})
#add_subdirectory(sdk/include/reactos/wine) # manually import wine!
add_subdirectory(sdk/include/reactos/mc)
if(ARCH MATCHES "64$")
include(sdk/cmake/baseaddress64.cmake)
elseif(NO_ROSSYM)
include(sdk/cmake/baseaddress_dwarf.cmake)
elseif(MSVC)
include(sdk/cmake/baseaddress_msvc.cmake)
else()
include(sdk/cmake/baseaddress.cmake)
endif()
# For MSVC builds, this puts all debug symbols file in the same directory.
if(MSVC)
set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/msvc_pdb")
elseif(SEPARATE_DBG)
set(CMAKE_PDB_OUTPUT_DIRECTORY "${REACTOS_BINARY_DIR}/symbols")
endif()
add_subdirectory(sdk/include/dxsdk)
add_subdirectory(sdk/lib)
add_subdirectory(dll)
add_subdirectory(base)
if (ENABLE_TESTS)
add_subdirectory(tests)
endif()