llvm-project

Форк
0
/
base-config-ix.cmake 
285 строк · 12.7 Кб
1
# The CompilerRT build system requires CMake version 2.8.8 or higher in order
2
# to use its support for building convenience "libraries" as a collection of
3
# .o files. This is particularly useful in producing larger, more complex
4
# runtime libraries.
5

6
include(BuiltinTests)
7
include(CheckIncludeFile)
8
include(CheckCXXSourceCompiles)
9
include(GNUInstallDirs)
10
include(GetClangResourceDir)
11
include(ExtendPath)
12
include(CompilerRTDarwinUtils)
13

14
check_include_file(unwind.h HAVE_UNWIND_H)
15

16
# Used by sanitizer_common and tests.
17
check_include_file(rpc/xdr.h HAVE_RPC_XDR_H)
18
if (NOT HAVE_RPC_XDR_H)
19
  set(HAVE_RPC_XDR_H 0)
20
endif()
21

22
# Top level target used to build all compiler-rt libraries.
23
add_custom_target(compiler-rt ALL)
24
add_custom_target(install-compiler-rt)
25
add_custom_target(install-compiler-rt-stripped)
26
set_property(TARGET compiler-rt PROPERTY FOLDER "Compiler-RT/Metatargets")
27
set_property(
28
  TARGET
29
    install-compiler-rt
30
    install-compiler-rt-stripped
31
  PROPERTY
32
    FOLDER "Compiler-RT/Installation"
33
)
34

35
# Setting these variables from an LLVM build is sufficient that compiler-rt can
36
# construct the output paths, so it can behave as if it were in-tree here.
37
if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSION)
38
  set(LLVM_TREE_AVAILABLE On)
39
endif()
40

41
if (LLVM_TREE_AVAILABLE)
42
  # Setup the paths where compiler-rt runtimes and headers should be stored.
43
  get_clang_resource_dir(COMPILER_RT_OUTPUT_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/..)
44
  set(COMPILER_RT_EXEC_OUTPUT_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
45
  get_clang_resource_dir(COMPILER_RT_INSTALL_PATH)
46
  option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests."
47
         ${LLVM_INCLUDE_TESTS})
48
  option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered"
49
         ${LLVM_ENABLE_WERROR})
50

51
  # Use just-built Clang to compile/link tests on all platforms.
52
  if (CMAKE_CROSSCOMPILING)
53
    if (CMAKE_HOST_WIN32)
54
      set(_host_executable_suffix ".exe")
55
    else()
56
      set(_host_executable_suffix "")
57
    endif()
58
  else()
59
    set(_host_executable_suffix ${CMAKE_EXECUTABLE_SUFFIX})
60
  endif()
61
  set(COMPILER_RT_TEST_COMPILER
62
    ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${_host_executable_suffix})
63
  set(COMPILER_RT_TEST_CXX_COMPILER
64
    ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++${_host_executable_suffix})
65
else()
66
    # Take output dir and install path from the user.
67
  set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
68
    "Path where built compiler-rt libraries should be stored.")
69
  set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH
70
    "Path where built compiler-rt executables should be stored.")
71
  set(COMPILER_RT_INSTALL_PATH "" CACHE PATH
72
    "Prefix for directories where built compiler-rt artifacts should be installed.")
73
  option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF)
74
  option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF)
75
  # Use a host compiler to compile/link tests.
76
  set(COMPILER_RT_TEST_COMPILER ${CMAKE_C_COMPILER} CACHE PATH "Compiler to use for testing")
77
  set(COMPILER_RT_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE PATH "C++ Compiler to use for testing")
78
endif()
79

80
if("${COMPILER_RT_TEST_COMPILER}" MATCHES "clang[+]*$")
81
  set(COMPILER_RT_TEST_COMPILER_ID Clang)
82
elseif("${COMPILER_RT_TEST_COMPILER}" MATCHES "clang.*.exe$")
83
  set(COMPILER_RT_TEST_COMPILER_ID Clang)
84
else()
85
  set(COMPILER_RT_TEST_COMPILER_ID GNU)
86
endif()
87

88
if(NOT DEFINED COMPILER_RT_OS_DIR)
89
  if(ANDROID)
90
    # The CMAKE_SYSTEM_NAME for Android is Android, but the OS is Linux and the
91
    # driver will search for compiler-rt libraries in the "linux" directory.
92
    set(COMPILER_RT_OS_DIR linux)
93
  else()
94
    string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR)
95
  endif()
96
endif()
97
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
98
  set(COMPILER_RT_OUTPUT_LIBRARY_DIR
99
    ${COMPILER_RT_OUTPUT_DIR}/lib)
100
  extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib)
101
  set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
102
    "Path where built compiler-rt libraries should be installed.")
103
else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
104
  set(COMPILER_RT_OUTPUT_LIBRARY_DIR
105
    ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
106
  extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}")
107
  set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
108
    "Path where built compiler-rt libraries should be installed.")
109
endif()
110
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_BINDIR}")
111
set(COMPILER_RT_INSTALL_BINARY_DIR "${default_install_path}" CACHE PATH
112
  "Path where built compiler-rt executables should be installed.")
113
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_INCLUDEDIR}")
114
set(COMPILER_RT_INSTALL_INCLUDE_DIR "${default_install_path}" CACHE PATH
115
  "Path where compiler-rt headers should be installed.")
116
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_DATADIR}")
117
set(COMPILER_RT_INSTALL_DATA_DIR "${default_install_path}" CACHE PATH
118
  "Path where compiler-rt data files should be installed.")
119

120
if(APPLE)
121
  # On Darwin if /usr/include/c++ doesn't exist, the user probably has Xcode but
122
  # not the command line tools (or is using macOS 10.14 or newer). If this is
123
  # the case, we need to find the OS X sysroot to pass to clang.
124
  if(NOT EXISTS /usr/include/c++)
125
    execute_process(COMMAND xcrun -sdk macosx --show-sdk-path
126
       OUTPUT_VARIABLE OSX_SYSROOT
127
       ERROR_QUIET
128
       OUTPUT_STRIP_TRAILING_WHITESPACE)
129
    if (NOT OSX_SYSROOT OR NOT EXISTS ${OSX_SYSROOT})
130
      message(WARNING "Detected OSX_SYSROOT ${OSX_SYSROOT} does not exist")
131
    else()
132
      message(STATUS "Found OSX_SYSROOT: ${OSX_SYSROOT}")
133
      set(OSX_SYSROOT_FLAG "-isysroot${OSX_SYSROOT}")
134
    endif()
135
  else()
136
    set(OSX_SYSROOT_FLAG "")
137
  endif()
138

139
  try_compile_only(COMPILER_RT_HAS_DARWIN_TARGET_VARIANT_FLAG
140
                   FLAGS
141
                   "-target" "x86_64-apple-macos10.15"
142
                   "-darwin-target-variant" "x86_64-apple-ios13.1-macabi"
143
                   "-Werror")
144
  option(COMPILER_RT_ENABLE_MACCATALYST "Enable building for Mac Catalyst" ${COMPILER_RT_HAS_DARWIN_TARGET_VARIANT_FLAG})
145

146
  # Don't enable COMPILER_RT_ENABLE_IOS if we can't find the sdk dir.
147
  # This can happen when you only have the commandline tools installed
148
  # which doesn't come with the iOS SDK.
149
  find_darwin_sdk_dir(HAS_IOS_SDK "iphoneos")
150
  set(COMPILER_RT_ENABLE_IOS_DEFAULT On)
151
  if("${HAS_IOS_SDK}" STREQUAL "")
152
    message(WARNING "iOS SDK not found! Building compiler-rt without iOS support.")
153
    set(COMPILER_RT_ENABLE_IOS_DEFAULT Off)
154
  endif()
155
  option(COMPILER_RT_ENABLE_IOS "Enable building for iOS" ${COMPILER_RT_ENABLE_IOS_DEFAULT})
156

157
  option(COMPILER_RT_ENABLE_WATCHOS "Enable building for watchOS - Experimental" Off)
158
  option(COMPILER_RT_ENABLE_TVOS "Enable building for tvOS - Experimental" Off)
159
  option(COMPILER_RT_ENABLE_XROS "Enable building for xrOS - Experimental" Off)
160

161
else()
162
  option(COMPILER_RT_DEFAULT_TARGET_ONLY "Build builtins only for the default target" Off)
163
endif()
164

165
if(WIN32 AND NOT MINGW AND NOT CYGWIN)
166
  set(CMAKE_SHARED_LIBRARY_PREFIX_C "")
167
  set(CMAKE_SHARED_LIBRARY_PREFIX_CXX "")
168
  set(CMAKE_STATIC_LIBRARY_PREFIX_C "")
169
  set(CMAKE_STATIC_LIBRARY_PREFIX_CXX "")
170
  set(CMAKE_STATIC_LIBRARY_SUFFIX_C ".lib")
171
  set(CMAKE_STATIC_LIBRARY_SUFFIX_CXX ".lib")
172
endif()
173

174
macro(test_targets)
175
  # Find and run MSVC (not clang-cl) and get its version. This will tell clang-cl
176
  # what version of MSVC to pretend to be so that the STL works.
177
  set(MSVC_VERSION_FLAG "")
178
  if (MSVC)
179
    execute_process(COMMAND "$ENV{VSINSTALLDIR}/VC/bin/cl.exe"
180
      OUTPUT_QUIET
181
      ERROR_VARIABLE MSVC_COMPAT_VERSION
182
      )
183
    string(REGEX REPLACE "^.*Compiler Version ([0-9.]+) for .*$" "\\1"
184
      MSVC_COMPAT_VERSION "${MSVC_COMPAT_VERSION}")
185
    if (MSVC_COMPAT_VERSION MATCHES "^[0-9].+$")
186
      set(MSVC_VERSION_FLAG "-fms-compatibility-version=${MSVC_COMPAT_VERSION}")
187
      # Add this flag into the host build if this is clang-cl.
188
      if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
189
        append("${MSVC_VERSION_FLAG}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
190
      elseif (COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang")
191
        # Add this flag to test compiles to suppress clang's auto-detection
192
        # logic.
193
        append("${MSVC_VERSION_FLAG}" COMPILER_RT_TEST_COMPILER_CFLAGS)
194
      endif()
195
    endif()
196
  endif()
197

198
  # Generate the COMPILER_RT_SUPPORTED_ARCH list.
199
  if(ANDROID)
200
    # Examine compiler output to determine target architecture.
201
    detect_target_arch()
202
    set(COMPILER_RT_OS_SUFFIX "-android")
203
  elseif(NOT APPLE) # Supported archs for Apple platforms are generated later
204
    if(COMPILER_RT_DEFAULT_TARGET_ONLY)
205
      add_default_target_arch(${COMPILER_RT_DEFAULT_TARGET_ARCH})
206
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "i[2-6]86|x86|amd64")
207
      if(NOT MSVC)
208
        test_target_arch(x86_64 "" "-m64")
209
        test_target_arch(i386 __i386__ "-m32")
210
      else()
211
        if (CMAKE_SIZEOF_VOID_P EQUAL 4)
212
          test_target_arch(i386 "" "")
213
        else()
214
          test_target_arch(x86_64 "" "")
215
        endif()
216
      endif()
217
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "loongarch64")
218
      test_target_arch(loongarch64 "" "")
219
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc64le|ppc64le")
220
      test_target_arch(powerpc64le "" "-m64")
221
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc")
222
      test_target_arch(powerpc "" "-m32")
223
      test_target_arch(powerpc64 "" "-m64")
224
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
225
      test_target_arch(s390x "" "")
226
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
227
      test_target_arch(sparc "" "-m32")
228
      test_target_arch(sparcv9 "" "-m64")
229
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips")
230
      CHECK_SYMBOL_EXISTS (_MIPS_ARCH_MIPS32R6 "" COMPILER_RT_MIPS32R6)
231
      CHECK_SYMBOL_EXISTS (_MIPS_ARCH_MIPS64R6 "" COMPILER_RT_MIPS64R6)
232
      CHECK_SYMBOL_EXISTS (__mips64 "" COMPILER_RT_MIPS_64)
233
      CHECK_SYMBOL_EXISTS (__MIPSEL__ "" COMPILER_RT_MIPS_EL)
234
      if ("${COMPILER_RT_MIPS_64}")
235
        set(COMPILER_RT_DEFAULT_TARGET_ARCH "mips64")
236
      else()
237
        set(COMPILER_RT_DEFAULT_TARGET_ARCH "mips")
238
      endif()
239
      if ("${COMPILER_RT_MIPS_EL}")
240
        set(COMPILER_RT_DEFAULT_TARGET_ARCH "${COMPILER_RT_DEFAULT_TARGET_ARCH}el")
241
      endif()
242

243
      # FIXME: Ideally, we would build the N32 library too.
244
      if("${COMPILER_RT_MIPS_EL}" AND ("${COMPILER_RT_MIPS32R6}" OR "${COMPILER_RT_MIPS64R6}"))
245
        test_target_arch(mipsel "" "-mips32r6" "-mabi=32" "-D_LARGEFILE_SOURCE=1" "-D_FILE_OFFSET_BITS=64")
246
        test_target_arch(mips64el "" "-mips64r6" "-mabi=64")
247
      elseif("${COMPILER_RT_MIPS_EL}")
248
        test_target_arch(mipsel "" "-mips32r2" "-mabi=32" "-D_LARGEFILE_SOURCE=1" "-D_FILE_OFFSET_BITS=64")
249
        test_target_arch(mips64el "" "-mips64r2" "-mabi=64")
250
      elseif("${COMPILER_RT_MIPS32R6}" OR "${COMPILER_RT_MIPS64R6}")
251
        test_target_arch(mips "" "-mips32r6" "-mabi=32" "-D_LARGEFILE_SOURCE=1" "-D_FILE_OFFSET_BITS=64")
252
        test_target_arch(mips64 "" "-mips64r6" "-mabi=64")
253
      else()
254
        test_target_arch(mips "" "-mips32r2" "-mabi=32" "-D_LARGEFILE_SOURCE=1" "-D_FILE_OFFSET_BITS=64")
255
        test_target_arch(mips64 "" "-mips64r2" "-mabi=64")
256
      endif()
257
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm")
258
      if(WIN32)
259
        test_target_arch(arm "" "" "")
260
      else()
261
        test_target_arch(armv4t "" "-march=armv4t" "-mfloat-abi=soft")
262
        test_target_arch(armv6m "" "-march=armv6m" "-mfloat-abi=soft")
263
        test_target_arch(arm "" "-march=armv7-a" "-mfloat-abi=soft")
264
        test_target_arch(armhf "" "-march=armv7-a" "-mfloat-abi=hard")
265
      endif()
266
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "avr")
267
      test_target_arch(avr "__AVR__" "--target=avr")
268
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch32")
269
      test_target_arch(aarch32 "" "-march=armv8-a")
270
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch64")
271
      test_target_arch(aarch64 "" "-march=armv8-a")
272
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "riscv32")
273
      test_target_arch(riscv32 "" "")
274
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "riscv64")
275
      test_target_arch(riscv64 "" "")
276
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "wasm32")
277
      test_target_arch(wasm32 "" "--target=wasm32-unknown-unknown")
278
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "wasm64")
279
      test_target_arch(wasm64 "" "--target=wasm64-unknown-unknown")
280
    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "ve")
281
      test_target_arch(ve "__ve__" "--target=ve-unknown-none")
282
    endif()
283
    set(COMPILER_RT_OS_SUFFIX "")
284
  endif()
285
endmacro()
286

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.