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