Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CMakeLists.txt « Native « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1a3622a0de44d821887b9bc21181f704075697b0 (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
cmake_minimum_required(VERSION 2.8.12)
project(CoreRT)

# Include cmake functions
include(functions.cmake)

if(CMAKE_SYSTEM_NAME STREQUAL Windows)
    # CMake version 3.8.0 or higher is required to compile targeting VS 2017
    cmake_minimum_required(VERSION 3.8.0)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
    # CMake version 3.4.0 or higher has bug fixes required to compile targeting Darwin
    cmake_minimum_required(VERSION 3.4.0)
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)
    message(FATAL_ERROR "Only AMD64, ARM64, ARM, ARMEL, I386 and WASM are supported")
endfunction()

if(CLR_CMAKE_TARGET_ARCH STREQUAL x64)
    set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1)
    add_definitions(-D_TARGET_AMD64_=1)
    add_definitions(-D_AMD64_)
    add_definitions(-DBIT64=1)
elseif(CLR_CMAKE_TARGET_ARCH MATCHES "^(arm|armel)$")
    set(CLR_CMAKE_PLATFORM_ARCH_ARM 1)
    add_definitions(-D_TARGET_ARM_=1)
    add_definitions(-D_ARM_)
    add_definitions(-DBIT32=1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64)
    set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1)
    add_definitions(-D_TARGET_ARM64_=1)
    add_definitions(-D_ARM64_)
    add_definitions(-DBIT64=1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86)
    set(CLR_CMAKE_PLATFORM_ARCH_I386 1)
    add_definitions(-D_TARGET_X86_=1)
    add_definitions(-D_X86_)
    add_definitions(-DBIT32=1)
elseif(CLR_CMAKE_TARGET_ARCH STREQUAL wasm)
    set(CLR_CMAKE_PLATFORM_ARCH_WASM 1)
    add_definitions(-D_TARGET_WASM_=1)
    add_definitions(-D_WASM_)
    add_definitions(-DBIT32=1)
else()
    clr_unknown_arch()
endif()

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
    set(CLR_CMAKE_PLATFORM_UNIX 1)
    set(CLR_CMAKE_PLATFORM_DARWIN 1)
    set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> <INCLUDES> -o <OBJECT> -c <SOURCE>")
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
    set(CLR_CMAKE_PLATFORM_UNIX 1)
    set(CLR_CMAKE_PLATFORM_LINUX 1)
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)

if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
    set(CLR_CMAKE_PLATFORM_UNIX 1)
    set(CLR_CMAKE_PLATFORM_FREEBSD 1)
endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)

if(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
    set(CLR_CMAKE_PLATFORM_UNIX 1)
    set(CLR_CMAKE_PLATFORM_NETBSD 1)
endif(CMAKE_SYSTEM_NAME STREQUAL NetBSD)

if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
    set(CLR_CMAKE_PLATFORM_UNIX 1)
    set(CLR_CMAKE_PLATFORM_WASM 1)
endif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)

if (CLR_CMAKE_PLATFORM_UNIX)
    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)

    # Since 6 version, clang generates pragma-pack warnings, so disable it because we use pshpack[1..8].h/poppack.h
    add_compile_options(-Wno-pragmas)

    if(CLR_CMAKE_PLATFORM_ARCH_AMD64 OR CLR_CMAKE_PLATFORM_ARCH_I386)
        # Allow 16 byte compare-exchange
        add_compile_options(-mcx16)
    endif()

    if(CLR_CMAKE_PLATFORM_ARCH_ARM)
        add_compile_options(-march=armv7-a)
        if(TOOLCHAIN STREQUAL arm-linux-gnueabi)
            add_compile_options(-mfloat-abi=softfp)
        endif()
        add_compile_options(-mthumb)
        add_compile_options(-mfpu=vfpv3)
    endif()
    
    if(CLR_CMAKE_PLATFORM_ARCH_AMD64)
        add_definitions(-DUNIX_AMD64_ABI)
    elseif(CLR_CMAKE_PLATFORM_ARCH_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)

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)

# 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(/source-charset:utf-8) # Force MSVC to compile source as UTF-8.
    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)

if(NOT CLR_CMAKE_PLATFORM_WASM)
    add_subdirectory(System.Private.TypeLoader.Native)
endif(NOT CLR_CMAKE_PLATFORM_WASM)

if(OBJWRITER_BUILD)
    add_subdirectory(ObjWriter/llvmCap)
endif()