blob: 5aeb930a52cc6cde3d73628326b6795cec5d4027 (
plain)
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
|
cmake_minimum_required(VERSION 2.8.12)
project(CoreRT)
# Include cmake functions
include(functions.cmake)
string(FIND ${CMAKE_GENERATOR} "Visual Studio 15 2017" VS2017_POS)
if(VS2017_POS EQUAL 0 AND (CMAKE_VERSION VERSION_LESS 3.6.0))
message(FATAL_ERROR "CMake version 3.6.0 or higher is required to compile targeting VS 2017")
endif()
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_INSTALL_PREFIX $ENV{__CMakeBinDir})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(NOT WIN32)
set(CMAKE_C_FLAGS "-std=c11")
set(CMAKE_CXX_FLAGS "-std=c++11")
endif()
set(CMAKE_SHARED_LIBRARY_PREFIX "")
function(clr_unknown_arch)
if (WIN32)
message(FATAL_ERROR "Only AMD64 and I386 are supported")
else()
message(FATAL_ERROR "Only AMD64, ARM64, ARM, ARMEL and I386 are supported")
endif()
endfunction()
if (CLR_CMAKE_TARGET_ARCH STREQUAL x64 OR CLR_CMAKE_TARGET_ARCH STREQUAL arm64)
set(IS_64BIT_BUILD 1)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
add_definitions(-DBIT32=1)
# Because we don't use CMAKE_C_COMPILER/CMAKE_CXX_COMPILER to use clang
# we have to set the triple by adding a compiler argument
if(TOOLCHAIN STREQUAL arm-linux-gnueabi)
add_compile_options(-target armv7-linux-gnueabi)
add_compile_options(-mfloat-abi=softfp)
else ()
add_compile_options(-target armv7-linux-gnueabihf)
endif ()
add_compile_options(-mthumb)
add_compile_options(-mfpu=vfpv3)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
set(IS_64BIT_BUILD 1)
# Because we don't use CMAKE_C_COMPILER/CMAKE_CXX_COMPILER to use clang
# we have to set the triple by adding a compiler argument
add_compile_options(-target aarch64-linux-gnu)
endif ()
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)
set(CLR_CMAKE_PLATFORM_DARWIN 1)
if(CMAKE_VERSION VERSION_LESS "3.4.0")
set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> -o <OBJECT> -c <SOURCE>")
else()
set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> <INCLUDES> -o <OBJECT> -c <SOURCE>")
endif(CMAKE_VERSION VERSION_LESS "3.4.0")
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CLR_CMAKE_PLATFORM_UNIX 1)
if(CLR_CMAKE_TARGET_ARCH STREQUAL x64)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM 1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armel)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM 1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM64 1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_I386 1)
else()
clr_unknown_arch()
endif()
set(CLR_CMAKE_PLATFORM_LINUX 1)
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)
if(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
set(CLR_CMAKE_PLATFORM_UNIX 1)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
set(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM64 1)
else()
clr_unknown_arch()
endif()
set(CLR_CMAKE_PLATFORM_NETBSD 1)
endif(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
set(CLR_CMAKE_PLATFORM_WASM 1)
endif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
if (CLR_CMAKE_PLATFORM_UNIX OR CLR_CMAKE_PLATFORM_WASM)
include_directories(inc/unix)
add_definitions(-DPLATFORM_UNIX=1)
add_definitions(-DPAL_STDCPP_COMPAT)
# All warnings that are not explicitly disabled are reported as errors
add_compile_options(-Wall)
add_compile_options(-Werror)
add_compile_options(-Wno-invalid-offsetof)
add_compile_options(-Wno-null-arithmetic)
add_compile_options(-Wno-null-conversion)
if (CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 OR CLR_CMAKE_PLATFORM_UNIX_TARGET_I386)
# Allow 16 byte compare-exchange
add_compile_options(-mcx16)
endif()
if (CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)
add_definitions(-DUNIX_AMD64_ABI)
elseif (CLR_CMAKE_PLATFORM_UNIX_TARGET_I386)
add_definitions(-DUNIX_X86_ABI)
endif()
# Disable strict warning on unused functions.
add_compile_options(-Wno-unused-function)
# The -fms-extensions enable the stuff like __if_exists, __declspec(uuid()), etc.
add_compile_options(-fms-extensions)
add_compile_options(-fPIC)
add_compile_options(-fvisibility=hidden)
if(CLR_CMAKE_PLATFORM_DARWIN)
# We cannot enable "stack-protector-strong" on OS X due to a bug in clang compiler (current version 7.0.2)
add_compile_options(-fstack-protector)
else()
add_compile_options(-fstack-protector-strong)
endif(CLR_CMAKE_PLATFORM_DARWIN)
if(CLR_CMAKE_PLATFORM_LINUX)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
endif(CLR_CMAKE_PLATFORM_LINUX)
endif(CLR_CMAKE_PLATFORM_UNIX OR CLR_CMAKE_PLATFORM_WASM)
if(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM)
set(CLR_CMAKE_PLATFORM_ARCH_ARM 1)
elseif(CLR_CMAKE_PLATFORM_UNIX_TARGET_ARM64)
set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1)
elseif(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)
set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1)
elseif(CLR_CMAKE_PLATFORM_UNIX_TARGET_I386)
set(CLR_CMAKE_PLATFORM_ARCH_I386 1)
elseif(CLR_CMAKE_PLATFORM_WASM)
set(CLR_CMAKE_PLATFORM_ARCH_WASM 1)
elseif(WIN32)
if (CLR_CMAKE_TARGET_ARCH STREQUAL x64)
set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1)
set(IS_64BIT_BUILD 1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86)
set(CLR_CMAKE_PLATFORM_ARCH_I386 1)
set(IS_64BIT_BUILD 0)
else()
clr_unknown_arch()
endif()
endif()
if(IS_64BIT_BUILD)
add_definitions(-DBIT64=1)
endif(IS_64BIT_BUILD)
if(WIN32)
enable_language(ASM_MASM)
else()
enable_language(ASM)
endif(WIN32)
# Build a list of compiler definitions by putting -D in front of each define.
function(get_compile_definitions DefinitionName)
# Get the current list of definitions
get_directory_property(COMPILE_DEFINITIONS_LIST COMPILE_DEFINITIONS)
foreach(DEFINITION IN LISTS COMPILE_DEFINITIONS_LIST)
if (${DEFINITION} MATCHES "^\\$<\\$<CONFIG:([^>]+)>:([^>]+)>$")
# The entries that contain generator expressions must have the -D inside of the
# expression. So we transform e.g. $<$<CONFIG:Debug>:_DEBUG> to $<$<CONFIG:Debug>:-D_DEBUG>
set(DEFINITION "$<$<CONFIG:${CMAKE_MATCH_1}>:-D${CMAKE_MATCH_2}>")
else()
set(DEFINITION -D${DEFINITION})
endif()
list(APPEND DEFINITIONS ${DEFINITION})
endforeach()
set(${DefinitionName} ${DEFINITIONS} PARENT_SCOPE)
endfunction(get_compile_definitions)
if(CLR_CMAKE_PLATFORM_ARCH_AMD64)
add_definitions(-D_TARGET_AMD64_=1)
add_definitions(-D_AMD64_)
elseif(CLR_CMAKE_PLATFORM_ARCH_I386)
add_definitions(-D_TARGET_X86_=1)
add_definitions(-D_X86_)
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM)
add_definitions(-D_TARGET_ARM_=1)
add_definitions(-D_ARM_)
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
add_definitions(-D_TARGET_ARM64_=1)
add_definitions(-D_ARM64_)
elseif(CLR_CMAKE_PLATFORM_ARCH_WASM)
add_definitions(-D_TARGET_WASM_=1)
add_definitions(-D_WASM_)
else()
clr_unknown_arch()
endif()
# Set the passed in RetSources variable to the list of sources with added current source directory
# to form absolute paths.
# The parameters after the RetSources are the input files.
function(convert_to_absolute_path RetSources)
set(Sources ${ARGN})
foreach(Source IN LISTS Sources)
list(APPEND AbsolutePathSources ${CMAKE_CURRENT_SOURCE_DIR}/${Source})
endforeach()
set(${RetSources} ${AbsolutePathSources} PARENT_SCOPE)
endfunction(convert_to_absolute_path)
if(WIN32)
add_definitions(-DUNICODE=1)
add_compile_options($<$<CONFIG:Debug>:-DDEBUG>)
add_compile_options($<$<CONFIG:Debug>:/MTd>)
add_compile_options($<$<CONFIG:Release>:/MT>)
add_compile_options(/Zi) # enable debugging information
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG")
if (CLR_CMAKE_PLATFORM_ARCH_I386)
add_compile_options(/Gz)
endif (CLR_CMAKE_PLATFORM_ARCH_I386)
else(WIN32)
string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_CMAKE_BUILD_TYPE)
if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG)
add_compile_options(-g -O0)
add_definitions(-DDEBUG)
add_definitions(-D_DEBUG)
elseif (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE)
add_compile_options (-g -O3)
add_definitions(-DNDEBUG)
else ()
message(FATAL_ERROR "Unknown build type. Set CMAKE_BUILD_TYPE to DEBUG or RELEASE.")
endif ()
if (CLR_CMAKE_PLATFORM_ARCH_I386)
add_compile_options(-m32)
link_libraries(-m32)
endif()
endif (WIN32)
include(configure.cmake)
if(WIN32)
add_subdirectory(gc)
endif()
add_subdirectory(Runtime)
add_subdirectory(Bootstrap)
if(NOT CLR_CMAKE_PLATFORM_WASM)
add_subdirectory(jitinterface)
endif(NOT CLR_CMAKE_PLATFORM_WASM)
# We don't need the PAL on Windows.
if(NOT WIN32)
add_subdirectory(System.Private.CoreLib.Native)
endif(NOT WIN32)
|