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()
39  if ( HAIKU )
40    add_definitions(-D_BSD_SOURCE)
41    set(system_libs ${system_libs} bsd)
42  endif()
43endif( MSVC OR MINGW )
44
45# Delay load shell32.dll if possible to speed up process startup.
46set (delayload_flags)
47if (MSVC)
48  set (delayload_flags delayimp -delayload:shell32.dll -delayload:ole32.dll)
49endif()
50
51# Link Z3 if the user wants to build it.
52if(LLVM_WITH_Z3)
53  set(system_libs ${system_libs} ${Z3_LIBRARIES})
54endif()
55
56# Override the C runtime allocator on Windows and embed it into LLVM tools & libraries
57if(LLVM_INTEGRATED_CRT_ALLOC)
58  if (CMAKE_BUILD_TYPE AND NOT ${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$")
59    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.")
60  endif()
61
62  string(REGEX REPLACE "(/|\\\\)$" "" LLVM_INTEGRATED_CRT_ALLOC "${LLVM_INTEGRATED_CRT_ALLOC}")
63
64  if(NOT EXISTS "${LLVM_INTEGRATED_CRT_ALLOC}")
65    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.")
66  endif()
67
68  if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "rpmalloc$")
69    add_definitions(-DENABLE_OVERRIDE -DENABLE_PRELOAD)
70    set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/rpmalloc/rpmalloc.c")
71  elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$")
72    set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/src/override/malloc.cc" "${LLVM_INTEGRATED_CRT_ALLOC}/src/override/new.cc")
73    set(system_libs ${system_libs} "mincore.lib" "-INCLUDE:malloc")
74  elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "mimalloc$")
75    set(MIMALLOC_LIB "${LLVM_INTEGRATED_CRT_ALLOC}/out/msvc-x64/Release/mimalloc-static.lib")
76    if(NOT EXISTS "${MIMALLOC_LIB}")
77	  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")
78    endif()
79    set(system_libs ${system_libs} "${MIMALLOC_LIB}" "-INCLUDE:malloc")
80  endif()
81endif()
82
83add_llvm_component_library(LLVMSupport
84  AArch64TargetParser.cpp
85  ABIBreak.cpp
86  ARMTargetParser.cpp
87  AMDGPUMetadata.cpp
88  APFixedPoint.cpp
89  APFloat.cpp
90  APInt.cpp
91  APSInt.cpp
92  ARMBuildAttrs.cpp
93  ARMAttributeParser.cpp
94  ARMWinEH.cpp
95  Allocator.cpp
96  AutoConvert.cpp
97  BinaryStreamError.cpp
98  BinaryStreamReader.cpp
99  BinaryStreamRef.cpp
100  BinaryStreamWriter.cpp
101  BlockFrequency.cpp
102  BranchProbability.cpp
103  BuryPointer.cpp
104  CachePruning.cpp
105  circular_raw_ostream.cpp
106  Chrono.cpp
107  COM.cpp
108  CodeGenCoverage.cpp
109  CommandLine.cpp
110  Compression.cpp
111  CRC.cpp
112  ConvertUTF.cpp
113  ConvertUTFWrapper.cpp
114  CrashRecoveryContext.cpp
115  DataExtractor.cpp
116  Debug.cpp
117  DebugCounter.cpp
118  DeltaAlgorithm.cpp
119  DAGDeltaAlgorithm.cpp
120  DJB.cpp
121  ELFAttributeParser.cpp
122  ELFAttributes.cpp
123  Error.cpp
124  ErrorHandling.cpp
125  ExtensibleRTTI.cpp
126  FileCollector.cpp
127  FileUtilities.cpp
128  FileOutputBuffer.cpp
129  FoldingSet.cpp
130  FormattedStream.cpp
131  FormatVariadic.cpp
132  GlobPattern.cpp
133  GraphWriter.cpp
134  Hashing.cpp
135  InitLLVM.cpp
136  InstructionCost.cpp
137  IntEqClasses.cpp
138  IntervalMap.cpp
139  ItaniumManglingCanonicalizer.cpp
140  JSON.cpp
141  KnownBits.cpp
142  LEB128.cpp
143  LineIterator.cpp
144  Locale.cpp
145  LockFileManager.cpp
146  LowLevelType.cpp
147  ManagedStatic.cpp
148  MathExtras.cpp
149  MemAlloc.cpp
150  MemoryBuffer.cpp
151  MemoryBufferRef.cpp
152  MD5.cpp
153  NativeFormatting.cpp
154  OptimizedStructLayout.cpp
155  Optional.cpp
156  Parallel.cpp
157  PluginLoader.cpp
158  PrettyStackTrace.cpp
159  RandomNumberGenerator.cpp
160  Regex.cpp
161  RISCVAttributes.cpp
162  RISCVAttributeParser.cpp
163  ScaledNumber.cpp
164  ScopedPrinter.cpp
165  SHA1.cpp
166  SHA256.cpp
167  Signposts.cpp
168  SmallPtrSet.cpp
169  SmallVector.cpp
170  SourceMgr.cpp
171  SpecialCaseList.cpp
172  Statistic.cpp
173  StringExtras.cpp
174  StringMap.cpp
175  StringSaver.cpp
176  StringRef.cpp
177  SuffixTree.cpp
178  SymbolRemappingReader.cpp
179  SystemUtils.cpp
180  TarWriter.cpp
181  TargetParser.cpp
182  ThreadPool.cpp
183  TimeProfiler.cpp
184  Timer.cpp
185  ToolOutputFile.cpp
186  TrigramIndex.cpp
187  Triple.cpp
188  Twine.cpp
189  TypeSize.cpp
190  Unicode.cpp
191  UnicodeCaseFold.cpp
192  VersionTuple.cpp
193  VirtualFileSystem.cpp
194  WithColor.cpp
195  X86TargetParser.cpp
196  YAMLParser.cpp
197  YAMLTraits.cpp
198  raw_os_ostream.cpp
199  raw_ostream.cpp
200  regcomp.c
201  regerror.c
202  regexec.c
203  regfree.c
204  regstrlcpy.c
205  xxhash.cpp
206  Z3Solver.cpp
207
208  ${ALLOCATOR_FILES}
209
210# System
211  Atomic.cpp
212  DynamicLibrary.cpp
213  Errno.cpp
214  Host.cpp
215  Memory.cpp
216  Path.cpp
217  Process.cpp
218  Program.cpp
219  RWMutex.cpp
220  Signals.cpp
221  TargetRegistry.cpp
222  ThreadLocal.cpp
223  Threading.cpp
224  Valgrind.cpp
225  Watchdog.cpp
226
227  ADDITIONAL_HEADER_DIRS
228  Unix
229  Windows
230  ${LLVM_MAIN_INCLUDE_DIR}/llvm/ADT
231  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support
232  ${Backtrace_INCLUDE_DIRS}
233
234  LINK_LIBS
235  ${system_libs} ${imported_libs} ${delayload_flags}
236
237  LINK_COMPONENTS
238  Demangle
239  )
240
241set(llvm_system_libs ${system_libs})
242
243# This block is only needed for llvm-config. When we deprecate llvm-config and
244# move to using CMake export, this block can be removed.
245if(LLVM_ENABLE_ZLIB)
246  # CMAKE_BUILD_TYPE is only meaningful to single-configuration generators.
247  if(CMAKE_BUILD_TYPE)
248    string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
249    get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION_${build_type})
250  endif()
251  if(NOT zlib_library)
252    get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION)
253  endif()
254  get_library_name(${zlib_library} zlib_library)
255  set(llvm_system_libs ${llvm_system_libs} "${zlib_library}")
256endif()
257
258if(LLVM_ENABLE_TERMINFO)
259  get_library_name(${TERMINFO_LIB} terminfo_library)
260  set(llvm_system_libs ${llvm_system_libs} "${terminfo_library}")
261endif()
262
263set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")
264
265
266if(LLVM_INTEGRATED_CRT_ALLOC)
267  if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$")
268    set_property(TARGET LLVMSupport PROPERTY CXX_STANDARD 17)
269    add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
270    if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND
271        "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64")
272      set_property(TARGET LLVMSupport PROPERTY COMPILE_FLAGS "-mcx16")
273    endif()
274  endif()
275endif()
276
277if(LLVM_WITH_Z3)
278  target_include_directories(LLVMSupport SYSTEM
279    PRIVATE
280    ${Z3_INCLUDE_DIR}
281    )
282endif()
283