• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1include(GetLibraryName)
2
3if(LLVM_ENABLE_ZLIB)
4  set(imported_libs ZLIB::ZLIB)
5endif()
6
7if( MSVC OR MINGW )
8  # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
9  # advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
10  set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32)
11elseif( CMAKE_HOST_UNIX )
12  if( HAVE_LIBRT )
13    set(system_libs ${system_libs} rt)
14  endif()
15  if( HAVE_LIBDL )
16    set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
17  endif()
18  if( HAVE_BACKTRACE AND NOT "${Backtrace_LIBRARIES}" STREQUAL "" )
19    # On BSDs, CMake returns a fully qualified path to the backtrace library.
20    # We need to remove the path and the 'lib' prefix, to make it look like a
21    # regular short library name, suitable for appending to a -l link flag.
22    get_filename_component(Backtrace_LIBFILE ${Backtrace_LIBRARIES} NAME_WE)
23    STRING(REGEX REPLACE "^lib" "" Backtrace_LIBFILE ${Backtrace_LIBFILE})
24    set(system_libs ${system_libs} ${Backtrace_LIBFILE})
25  endif()
26  if( LLVM_ENABLE_TERMINFO )
27    set(imported_libs ${imported_libs} "${TERMINFO_LIB}")
28  endif()
29  if( LLVM_ENABLE_THREADS AND (HAVE_LIBATOMIC OR HAVE_CXX_LIBATOMICS64) )
30    set(system_libs ${system_libs} atomic)
31  endif()
32  set(system_libs ${system_libs} ${LLVM_PTHREAD_LIB})
33  if( UNIX AND NOT (BEOS OR HAIKU) )
34    set(system_libs ${system_libs} m)
35  endif()
36  if( FUCHSIA )
37    set(system_libs ${system_libs} zircon)
38  endif()
39endif( MSVC OR MINGW )
40
41# Delay load shell32.dll if possible to speed up process startup.
42set (delayload_flags)
43if (MSVC)
44  set (delayload_flags delayimp -delayload:shell32.dll -delayload:ole32.dll)
45endif()
46
47# Link Z3 if the user wants to build it.
48if(LLVM_WITH_Z3)
49  set(system_libs ${system_libs} ${Z3_LIBRARIES})
50endif()
51
52# Override the C runtime allocator on Windows and embed it into LLVM tools & libraries
53if(LLVM_INTEGRATED_CRT_ALLOC)
54  if (CMAKE_BUILD_TYPE AND NOT ${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$")
55    message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC only works with /MT or /MTd. Use LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE} to set the appropriate option.")
56  endif()
57
58  string(REGEX REPLACE "(/|\\\\)$" "" LLVM_INTEGRATED_CRT_ALLOC "${LLVM_INTEGRATED_CRT_ALLOC}")
59
60  if(NOT EXISTS "${LLVM_INTEGRATED_CRT_ALLOC}")
61    message(FATAL_ERROR "Cannot find the path to `git clone` for the CRT allocator! (${LLVM_INTEGRATED_CRT_ALLOC}). Currently, rpmalloc, snmalloc and mimalloc are supported.")
62  endif()
63
64  if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "rpmalloc$")
65    add_definitions(-DENABLE_OVERRIDE -DENABLE_PRELOAD)
66    set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/rpmalloc/rpmalloc.c")
67  elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$")
68    set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/src/override/malloc.cc" "${LLVM_INTEGRATED_CRT_ALLOC}/src/override/new.cc")
69    set(system_libs ${system_libs} "mincore.lib" "-INCLUDE:malloc")
70  elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "mimalloc$")
71    set(MIMALLOC_LIB "${LLVM_INTEGRATED_CRT_ALLOC}/out/msvc-x64/Release/mimalloc-static.lib")
72    if(NOT EXISTS "${MIMALLOC_LIB}")
73	  message(FATAL_ERROR "Cannot find the mimalloc static library. To build it, first apply the patch from https://github.com/microsoft/mimalloc/issues/268 then build the Release x64 target through ${LLVM_INTEGRATED_CRT_ALLOC}\\ide\\vs2019\\mimalloc.sln")
74    endif()
75    set(system_libs ${system_libs} "${MIMALLOC_LIB}" "-INCLUDE:malloc")
76  endif()
77endif()
78
79add_llvm_component_library(LLVMSupport
80  AArch64TargetParser.cpp
81  ABIBreak.cpp
82  ARMTargetParser.cpp
83  AMDGPUMetadata.cpp
84  APFixedPoint.cpp
85  APFloat.cpp
86  APInt.cpp
87  APSInt.cpp
88  ARMBuildAttrs.cpp
89  ARMAttributeParser.cpp
90  ARMWinEH.cpp
91  Allocator.cpp
92  BinaryStreamError.cpp
93  BinaryStreamReader.cpp
94  BinaryStreamRef.cpp
95  BinaryStreamWriter.cpp
96  BlockFrequency.cpp
97  BranchProbability.cpp
98  BuryPointer.cpp
99  CachePruning.cpp
100  circular_raw_ostream.cpp
101  Chrono.cpp
102  COM.cpp
103  CodeGenCoverage.cpp
104  CommandLine.cpp
105  Compression.cpp
106  CRC.cpp
107  ConvertUTF.cpp
108  ConvertUTFWrapper.cpp
109  CrashRecoveryContext.cpp
110  DataExtractor.cpp
111  Debug.cpp
112  DebugCounter.cpp
113  DeltaAlgorithm.cpp
114  DAGDeltaAlgorithm.cpp
115  DJB.cpp
116  ELFAttributeParser.cpp
117  ELFAttributes.cpp
118  Error.cpp
119  ErrorHandling.cpp
120  ExtensibleRTTI.cpp
121  FileCollector.cpp
122  FileUtilities.cpp
123  FileOutputBuffer.cpp
124  FoldingSet.cpp
125  FormattedStream.cpp
126  FormatVariadic.cpp
127  GlobPattern.cpp
128  GraphWriter.cpp
129  Hashing.cpp
130  InitLLVM.cpp
131  IntEqClasses.cpp
132  IntervalMap.cpp
133  ItaniumManglingCanonicalizer.cpp
134  JSON.cpp
135  KnownBits.cpp
136  LEB128.cpp
137  LineIterator.cpp
138  Locale.cpp
139  LockFileManager.cpp
140  LowLevelType.cpp
141  ManagedStatic.cpp
142  MathExtras.cpp
143  MemAlloc.cpp
144  MemoryBuffer.cpp
145  MemoryBufferRef.cpp
146  MD5.cpp
147  NativeFormatting.cpp
148  OptimizedStructLayout.cpp
149  Optional.cpp
150  Parallel.cpp
151  PluginLoader.cpp
152  PrettyStackTrace.cpp
153  RandomNumberGenerator.cpp
154  Regex.cpp
155  RISCVAttributes.cpp
156  RISCVAttributeParser.cpp
157  ScaledNumber.cpp
158  ScopedPrinter.cpp
159  SHA1.cpp
160  Signposts.cpp
161  SmallPtrSet.cpp
162  SmallVector.cpp
163  SourceMgr.cpp
164  SpecialCaseList.cpp
165  Statistic.cpp
166  StringExtras.cpp
167  StringMap.cpp
168  StringSaver.cpp
169  StringRef.cpp
170  SuffixTree.cpp
171  SymbolRemappingReader.cpp
172  SystemUtils.cpp
173  TarWriter.cpp
174  TargetParser.cpp
175  ThreadPool.cpp
176  TimeProfiler.cpp
177  Timer.cpp
178  ToolOutputFile.cpp
179  TrigramIndex.cpp
180  Triple.cpp
181  Twine.cpp
182  Unicode.cpp
183  UnicodeCaseFold.cpp
184  VersionTuple.cpp
185  VirtualFileSystem.cpp
186  WithColor.cpp
187  X86TargetParser.cpp
188  YAMLParser.cpp
189  YAMLTraits.cpp
190  raw_os_ostream.cpp
191  raw_ostream.cpp
192  regcomp.c
193  regerror.c
194  regexec.c
195  regfree.c
196  regstrlcpy.c
197  xxhash.cpp
198  Z3Solver.cpp
199
200  ${ALLOCATOR_FILES}
201
202# System
203  Atomic.cpp
204  DynamicLibrary.cpp
205  Errno.cpp
206  Host.cpp
207  Memory.cpp
208  Path.cpp
209  Process.cpp
210  Program.cpp
211  RWMutex.cpp
212  Signals.cpp
213  TargetRegistry.cpp
214  ThreadLocal.cpp
215  Threading.cpp
216  Valgrind.cpp
217  Watchdog.cpp
218
219  ADDITIONAL_HEADER_DIRS
220  Unix
221  Windows
222  ${LLVM_MAIN_INCLUDE_DIR}/llvm/ADT
223  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support
224  ${Backtrace_INCLUDE_DIRS}
225
226  LINK_LIBS
227  ${system_libs} ${imported_libs} ${delayload_flags}
228
229  LINK_COMPONENTS
230  Demangle
231  )
232
233set(llvm_system_libs ${system_libs})
234
235# This block is only needed for llvm-config. When we deprecate llvm-config and
236# move to using CMake export, this block can be removed.
237if(LLVM_ENABLE_ZLIB)
238  # CMAKE_BUILD_TYPE is only meaningful to single-configuration generators.
239  if(CMAKE_BUILD_TYPE)
240    string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
241    get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION_${build_type})
242  endif()
243  if(NOT zlib_library)
244    get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION)
245  endif()
246  get_library_name(${zlib_library} zlib_library)
247  set(llvm_system_libs ${llvm_system_libs} "${zlib_library}")
248endif()
249
250if(LLVM_ENABLE_TERMINFO)
251  get_library_name(${TERMINFO_LIB} terminfo_library)
252  set(llvm_system_libs ${llvm_system_libs} "${terminfo_library}")
253endif()
254
255set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")
256
257
258if(LLVM_INTEGRATED_CRT_ALLOC)
259  if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$")
260    set_property(TARGET LLVMSupport PROPERTY CXX_STANDARD 17)
261    add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
262    if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND
263        "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64")
264      set_property(TARGET LLVMSupport PROPERTY COMPILE_FLAGS "-mcx16")
265    endif()
266  endif()
267endif()
268
269if(LLVM_WITH_Z3)
270  target_include_directories(LLVMSupport SYSTEM
271    PRIVATE
272    ${Z3_INCLUDE_DIR}
273    )
274endif()
275