-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
305 lines (270 loc) · 11.3 KB
/
Copy pathCMakeLists.txt
File metadata and controls
305 lines (270 loc) · 11.3 KB
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
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
# Verify minimum required version
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0042 NEW) # MACOSX_RPATH is enabled by default.
if(POLICY CMP0177)
cmake_policy(SET CMP0177 NEW) # install() paths are normalized
endif(POLICY CMP0177)
project(dncdbg LANGUAGES C CXX OBJCXX)
# Require Clang compiler on non-Windows platforms
if(NOT WIN32)
if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang|AppleClang")
message(FATAL_ERROR "Clang compiler is required. Current C compiler: ${CMAKE_C_COMPILER_ID}")
endif()
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
message(FATAL_ERROR "Clang C++ compiler is required. Current C++ compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
endif()
set(DOTNET_DIR "" CACHE FILEPATH "Path to .NET SDK directory")
set(DOTNET_CHANNEL "10.0" CACHE STRING ".NET SDK channel")
if(WIN32)
# For Windows it is expected that CLR_CMAKE_HOST_ARCH parameter is passed
# to CMAKE to determine build arch. If it is not passed, detect arch here.
if(NOT CLR_CMAKE_HOST_ARCH)
if(MSVC_CXX_ARCHITECTURE_ID)
string(TOLOWER "${MSVC_CXX_ARCHITECTURE_ID}" LOWERCASE_ARCH_ID)
else()
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" LOWERCASE_ARCH_ID)
endif()
if(LOWERCASE_ARCH_ID MATCHES "^arm64|^aarch64")
set(CLR_CMAKE_HOST_ARCH arm64)
message(STATUS "Architecture not specified: using host architecture ARM64")
elseif(LOWERCASE_ARCH_ID MATCHES "amd64|x64" OR CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CLR_CMAKE_HOST_ARCH x64)
message(STATUS "Architecture not specified: using host architecture x64")
else()
set(CLR_CMAKE_HOST_ARCH x86)
message(STATUS "Architecture not specified: using host architecture x86")
endif()
endif()
endif()
if(APPLE AND NOT CMAKE_OSX_ARCHITECTURES)
# For macOS it is expected that CMAKE_OSX_ARCHITECTURES parameter is passed
# to CMAKE to determine build arch. If it is not passed, detect arch here.
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64")
message(STATUS "Architecture not specified: using host architecture ARM64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
set(CMAKE_OSX_ARCHITECTURES "x86_64")
message(STATUS "Architecture not specified: using host architecture x86_64")
endif()
endif()
include(cmake/fetchdeps.cmake)
# Basic checks for valid path
if(NOT DOTNET_DIR OR NOT IS_DIRECTORY "${DOTNET_DIR}/shared/Microsoft.NETCore.App")
message(FATAL_ERROR "Invalid or missing .NET SDK directory: '${DOTNET_DIR}'")
endif()
# Debug symbols stripping from libdbgshim and dncdbg for Release build only
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CLR_CMAKE_KEEP_NATIVE_SYMBOLS 0)
else()
set(CLR_CMAKE_KEEP_NATIVE_SYMBOLS 1)
endif()
# Get references to VCS revision for DNCDbg itself and CoreCLR
# (this used in src/debug/dncdbg/CMakeLists.txt)
include(cmake/vcsinfo.cmake)
VCSInfo(DNCDBG_VCS_INFO)
# AddressSanitize
if(ASAN)
set(CLR_CMAKE_ENABLE_SANITIZERS "address")
#TODO UBSanitizer for Debug build
#set(ENV{DEBUG_SANITIZERS} "ubsan")
endif()
include(cmake/configurepaths.cmake)
# diagnostics doesn't have related code, no reason to depend on `liblttng-ust-dev`
set(FEATURE_EVENT_TRACE 0)
### diagnostic's CMakeList.txt part
#
# Note, we don't use separate cmake parts, just re-use diagnostics cmake parts with changes:
#
# - copy main part of `third_party/diagnostics/CMakeLists.cmake` to this file below,
# remove header, `project`, `cmake_minimum_required`, etc. and add `add_subdirectory(third_party/diagnostics)`
# - copy and correct `third_party/diagnostics/eng/native/configurepaths.cmake` file to `cmake` folder
# - correct `third_party/diagnostics/src/CMakeLists.cmake`, remove lines with `SOS` and `tests`
# change CMAKE_C_STANDARD and CMAKE_CXX_STANDARD to 17
# - correct `third_party/diagnostics/eng/native/functions.cmake`, change line
# `add_executable(${ARGV} ${VERSION_FILE_PATH})` to `add_executable(${ARGV})`
# - correct `third_party/diagnostics/src/shared/clrdefinitions.cmake`, comment line `add_custom_target(eventing_headers)`
# since we disable `FEATURE_EVENT_TRACE` and diagnostics don't have `eventing_headers` project in sources
# - add external terminal related code to `third_party/diagnostics/src/dbgshim/dbgshim.cpp`:
# #ifdef _WIN32
# wchar_t flagBuffer[2] = { 0 };
# DWORD copied = GetEnvironmentVariableW(L"DNCDBG_CREATE_NEW_CONSOLE", flagBuffer, 2);
# if (copied == 1 && flagBuffer[0] == L'1')
# {
# dwCreationFlags |= CREATE_NEW_CONSOLE;
# }
# #endif // _WIN32
# - correct `third_party/diagnostics/eng/native/configurecompiler.cmake` change CMAKE_OSX_DEPLOYMENT_TARGET to "13.3"
#
###
# include shared compiler configs
include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake)
if(CLR_CMAKE_HOST_UNIX)
# The -fms-extensions enable the stuff like __if_exists, __declspec(uuid()), etc.
add_compile_options(-fms-extensions)
#-fms-compatibility Enable full Microsoft Visual C++ compatibility
#-fms-extensions Accept some non-standard constructs supported by the Microsoft compiler
add_compile_options(-fvisibility=default)
endif(CLR_CMAKE_HOST_UNIX)
if (CMAKE_VERSION VERSION_LESS "3.16")
# Provide a no-op polyfill for precompiled headers on old CMake versions
function(target_precompile_headers)
endfunction()
endif()
# Register the default component
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME diagnostics)
add_component(diagnostics)
if(CLR_CMAKE_HOST_WIN32)
message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}")
message(STATUS "VS_PLATFORM_NAME is ${CMAKE_VS_PLATFORM_NAME}")
endif(CLR_CMAKE_HOST_WIN32)
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if(CLR_CMAKE_HOST_UNIX)
# Drop the static scope for SOS, so it's available outside the
# compilation unit for external linkage; see extern declaration
# in SOS sources.
file(READ "${VERSION_FILE_PATH}" VERSION_FILE_CONTENTS)
string(REPLACE "static char" "char" VERSION_LINE_WITHOUT_STATIC "${VERSION_FILE_CONTENTS}")
file(WRITE "${VERSION_FILE_PATH}" "${VERSION_LINE_WITHOUT_STATIC}")
endif(CLR_CMAKE_HOST_UNIX)
# Where _version.h for Windows is generated
if(CLR_CMAKE_HOST_WIN32)
include_directories(${CLR_ARTIFACTS_OBJ_DIR})
endif(CLR_CMAKE_HOST_WIN32)
set(CORECLR_SET_RPATH ON)
if(CORECLR_SET_RPATH)
# Enable @rpath support for shared libraries.
set(MACOSX_RPATH ON)
endif(CORECLR_SET_RPATH)
OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)
OPTION(CLR_CMAKE_WARNINGS_ARE_ERRORS "Warnings are errors" ON)
#----------------------------------------------------
# Cross target Component build specific configuration
#----------------------------------------------------
if(CLR_CROSS_COMPONENTS_BUILD)
add_definitions(-DCROSS_COMPILE)
if(CLR_CMAKE_HOST_ARCH_AMD64 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_I386))
set(FEATURE_CROSSBITNESS 1)
endif(CLR_CMAKE_HOST_ARCH_AMD64 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_I386))
endif(CLR_CROSS_COMPONENTS_BUILD)
#------------------------------------
# Definitions (for platform)
#-----------------------------------
if (CLR_CMAKE_HOST_ARCH_AMD64)
add_definitions(-D_AMD64_)
add_definitions(-D_WIN64)
add_definitions(-DAMD64)
add_definitions(-DBIT64=1)
elseif (CLR_CMAKE_HOST_ARCH_I386)
add_definitions(-D_X86_)
elseif (CLR_CMAKE_HOST_ARCH_ARM)
add_definitions(-D_ARM_)
add_definitions(-DARM)
elseif (CLR_CMAKE_HOST_ARCH_ARM64)
add_definitions(-D_ARM64_)
add_definitions(-DARM64)
add_definitions(-D_WIN64)
add_definitions(-DBIT64=1)
elseif (CLR_CMAKE_HOST_ARCH_MIPS64)
add_definitions(-D_MIPS64_)
add_definitions(-DMIPS64)
add_definitions(-D_WIN64)
add_definitions(-DBIT64=1)
elseif (CLR_CMAKE_HOST_ARCH_RISCV64)
add_definitions(-D_RISCV64_)
add_definitions(-DRISCV64)
add_definitions(-D_WIN64)
add_definitions(-DBIT64=1)
elseif (CLR_CMAKE_HOST_ARCH_LOONGARCH64)
add_definitions(-D_LOONGARCH64_)
add_definitions(-DLOONGARCH64)
add_definitions(-D_WIN64)
add_definitions(-DBIT64=1)
else ()
clr_unknown_arch()
endif ()
if (CLR_CMAKE_TARGET_ARCH_AMD64)
if (CLR_CMAKE_HOST_UNIX)
add_definitions(-DDBG_TARGET_AMD64_UNIX)
endif()
add_definitions(-D_TARGET_64BIT_=1)
add_definitions(-D_TARGET_AMD64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_AMD64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
elseif (CLR_CMAKE_TARGET_ARCH_ARM64)
if (CLR_CMAKE_HOST_UNIX)
add_definitions(-DDBG_TARGET_ARM64_UNIX)
endif()
add_definitions(-D_TARGET_ARM64_=1)
add_definitions(-D_TARGET_64BIT_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_ARM64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
add_definitions(-DFEATURE_MULTIREG_RETURN)
elseif (CLR_CMAKE_TARGET_ARCH_ARM)
if (CLR_CMAKE_HOST_UNIX)
add_definitions(-DDBG_TARGET_ARM_UNIX)
elseif (WIN32 AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
# Set this to ensure we can use Arm SDK for Desktop binary linkage when doing native (Arm32) build
add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1)
add_definitions(-D_ARM_WORKAROUND_)
endif (CLR_CMAKE_HOST_UNIX)
add_definitions(-D_TARGET_ARM_=1)
add_definitions(-DDBG_TARGET_32BIT=1)
add_definitions(-DDBG_TARGET_ARM=1)
elseif (CLR_CMAKE_TARGET_ARCH_I386)
add_definitions(-D_TARGET_X86_=1)
add_definitions(-DDBG_TARGET_32BIT=1)
add_definitions(-DDBG_TARGET_X86=1)
elseif (CLR_CMAKE_TARGET_ARCH_MIPS64)
add_definitions(-DDBG_TARGET_MIPS64_UNIX)
add_definitions(-D_TARGET_MIPS64_=1)
add_definitions(-D_TARGET_64BIT_=1)
add_definitions(-DDBG_TARGET_MIPS64=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_WIN64=1)
add_definitions(-DFEATURE_MULTIREG_RETURN)
elseif (CLR_CMAKE_TARGET_ARCH_RISCV64)
add_definitions(-DDBG_TARGET_RISCV64_UNIX)
add_definitions(-D_TARGET_RISCV64_=1)
add_definitions(-D_TARGET_64BIT_=1)
add_definitions(-DDBG_TARGET_RISCV64=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_WIN64=1)
add_definitions(-DFEATURE_MULTIREG_RETURN)
elseif (CLR_CMAKE_TARGET_ARCH_LOONGARCH64)
add_definitions(-DDBG_TARGET_LOONGARCH64_UNIX)
add_definitions(-D_TARGET_LOONGARCH64_=1)
add_definitions(-D_TARGET_64BIT_=1)
add_definitions(-DDBG_TARGET_LOONGARCH64=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_WIN64=1)
add_definitions(-DFEATURE_MULTIREG_RETURN)
else ()
clr_unknown_arch()
endif (CLR_CMAKE_TARGET_ARCH_AMD64)
if(CLR_CMAKE_HOST_WIN32)
add_definitions(-DWIN32)
add_definitions(-D_WIN32)
add_definitions(-DWINVER=0x0602)
add_definitions(-D_WIN32_WINNT=0x0602)
add_definitions(-DWIN32_LEAN_AND_MEAN=1)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif(CLR_CMAKE_HOST_WIN32)
#--------------------------------------
# FEATURE Defines
#--------------------------------------
if(CLR_CMAKE_HOST_UNIX)
add_definitions(-DFEATURE_PAL)
endif(CLR_CMAKE_HOST_UNIX)
#-----------------------------------------
# Native Projects
#-----------------------------------------
add_subdirectory(third_party/diagnostics)
add_subdirectory(third_party/dnmd)
add_subdirectory(third_party/tree-sitter)
add_subdirectory(third_party/tree-sitter-c-sharp)
add_subdirectory(src)