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 list(APPEND imported_libs ZLIB::ZLIB) 26endif() 27 28if(LLVM_ENABLE_ZSTD) 29 if(TARGET zstd::libzstd_shared AND NOT LLVM_USE_STATIC_ZSTD) 30 set(zstd_target zstd::libzstd_shared) 31 else() 32 set(zstd_target zstd::libzstd_static) 33 endif() 34endif() 35 36if(LLVM_ENABLE_ZSTD) 37 list(APPEND imported_libs ${zstd_target}) 38endif() 39 40if( MSVC OR MINGW ) 41 # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc. 42 # advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc. 43 set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32) 44elseif( CMAKE_HOST_UNIX ) 45 if( HAVE_LIBRT ) 46 set(system_libs ${system_libs} rt) 47 endif() 48 if( HAVE_LIBDL ) 49 set(system_libs ${system_libs} ${CMAKE_DL_LIBS}) 50 endif() 51 if( HAVE_BACKTRACE AND NOT "${Backtrace_LIBRARIES}" STREQUAL "" ) 52 # On BSDs, CMake returns a fully qualified path to the backtrace library. 53 # We need to remove the path and the 'lib' prefix, to make it look like a 54 # regular short library name, suitable for appending to a -l link flag. 55 get_filename_component(Backtrace_LIBFILE ${Backtrace_LIBRARIES} NAME_WE) 56 STRING(REGEX REPLACE "^lib" "" Backtrace_LIBFILE ${Backtrace_LIBFILE}) 57 set(system_libs ${system_libs} ${Backtrace_LIBFILE}) 58 endif() 59 if( LLVM_ENABLE_TERMINFO ) 60 set(imported_libs ${imported_libs} Terminfo::terminfo) 61 endif() 62 set(system_libs ${system_libs} ${LLVM_ATOMIC_LIB}) 63 set(system_libs ${system_libs} ${LLVM_PTHREAD_LIB}) 64 if( UNIX AND NOT (BEOS OR HAIKU) ) 65 set(system_libs ${system_libs} m) 66 endif() 67 if( UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS" ) 68 set(system_libs ${system_libs} kstat) 69 endif() 70 if( FUCHSIA ) 71 set(system_libs ${system_libs} zircon) 72 endif() 73 if ( HAIKU ) 74 add_compile_definitions(_BSD_SOURCE) 75 set(system_libs ${system_libs} bsd) 76 endif() 77endif( MSVC OR MINGW ) 78 79# Delay load shell32.dll if possible to speed up process startup. 80set (delayload_flags) 81if (MSVC) 82 set (delayload_flags delayimp -delayload:shell32.dll -delayload:ole32.dll) 83endif() 84 85# Link Z3 if the user wants to build it. 86if(LLVM_WITH_Z3) 87 set(system_libs ${system_libs} ${Z3_LIBRARIES}) 88endif() 89 90# Override the C runtime allocator on Windows and embed it into LLVM tools & libraries 91if(LLVM_INTEGRATED_CRT_ALLOC) 92 if (CMAKE_BUILD_TYPE AND NOT ${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$") 93 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.") 94 endif() 95 96 string(REGEX REPLACE "(/|\\\\)$" "" LLVM_INTEGRATED_CRT_ALLOC "${LLVM_INTEGRATED_CRT_ALLOC}") 97 98 if(NOT EXISTS "${LLVM_INTEGRATED_CRT_ALLOC}") 99 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.") 100 endif() 101 102 if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "rpmalloc$") 103 add_compile_definitions(ENABLE_OVERRIDE ENABLE_PRELOAD) 104 set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/rpmalloc/rpmalloc.c") 105 elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$") 106 set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/src/snmalloc/override/new.cc") 107 set(system_libs ${system_libs} "mincore.lib" "-INCLUDE:malloc") 108 elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "mimalloc$") 109 set(MIMALLOC_LIB "${LLVM_INTEGRATED_CRT_ALLOC}/out/msvc-x64/Release/mimalloc-static.lib") 110 if(NOT EXISTS "${MIMALLOC_LIB}") 111 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") 112 endif() 113 set(system_libs ${system_libs} "${MIMALLOC_LIB}" "-INCLUDE:malloc") 114 endif() 115endif() 116 117add_subdirectory(BLAKE3) 118 119add_llvm_component_library(LLVMSupport 120 AddressRanges.cpp 121 ABIBreak.cpp 122 AMDGPUMetadata.cpp 123 APFixedPoint.cpp 124 APFloat.cpp 125 APInt.cpp 126 APSInt.cpp 127 ARMBuildAttrs.cpp 128 ARMAttributeParser.cpp 129 ARMWinEH.cpp 130 Allocator.cpp 131 AutoConvert.cpp 132 Base64.cpp 133 BinaryStreamError.cpp 134 BinaryStreamReader.cpp 135 BinaryStreamRef.cpp 136 BinaryStreamWriter.cpp 137 BlockFrequency.cpp 138 BranchProbability.cpp 139 BuryPointer.cpp 140 CachePruning.cpp 141 Caching.cpp 142 circular_raw_ostream.cpp 143 Chrono.cpp 144 COM.cpp 145 CodeGenCoverage.cpp 146 CommandLine.cpp 147 Compression.cpp 148 CRC.cpp 149 ConvertUTF.cpp 150 ConvertUTFWrapper.cpp 151 CrashRecoveryContext.cpp 152 CSKYAttributes.cpp 153 CSKYAttributeParser.cpp 154 DataExtractor.cpp 155 Debug.cpp 156 DebugCounter.cpp 157 DeltaAlgorithm.cpp 158 DivisionByConstantInfo.cpp 159 DAGDeltaAlgorithm.cpp 160 DJB.cpp 161 ELFAttributeParser.cpp 162 ELFAttributes.cpp 163 Error.cpp 164 ErrorHandling.cpp 165 ExtensibleRTTI.cpp 166 FileCollector.cpp 167 FileUtilities.cpp 168 FileOutputBuffer.cpp 169 FoldingSet.cpp 170 FormattedStream.cpp 171 FormatVariadic.cpp 172 GlobPattern.cpp 173 GraphWriter.cpp 174 Hashing.cpp 175 InitLLVM.cpp 176 InstructionCost.cpp 177 IntEqClasses.cpp 178 IntervalMap.cpp 179 ItaniumManglingCanonicalizer.cpp 180 JSON.cpp 181 KnownBits.cpp 182 LEB128.cpp 183 LineIterator.cpp 184 Locale.cpp 185 LockFileManager.cpp 186 LowLevelType.cpp 187 ManagedStatic.cpp 188 MathExtras.cpp 189 MemAlloc.cpp 190 MemoryBuffer.cpp 191 MemoryBufferRef.cpp 192 MD5.cpp 193 MSP430Attributes.cpp 194 MSP430AttributeParser.cpp 195 NativeFormatting.cpp 196 OptimizedStructLayout.cpp 197 Optional.cpp 198 Parallel.cpp 199 PluginLoader.cpp 200 PrettyStackTrace.cpp 201 RandomNumberGenerator.cpp 202 Regex.cpp 203 RISCVAttributes.cpp 204 RISCVAttributeParser.cpp 205 RISCVISAInfo.cpp 206 ScaledNumber.cpp 207 ScopedPrinter.cpp 208 SHA1.cpp 209 SHA256.cpp 210 Signposts.cpp 211 SmallPtrSet.cpp 212 SmallVector.cpp 213 SourceMgr.cpp 214 SpecialCaseList.cpp 215 Statistic.cpp 216 StringExtras.cpp 217 StringMap.cpp 218 StringSaver.cpp 219 StringRef.cpp 220 SuffixTree.cpp 221 SymbolRemappingReader.cpp 222 SystemUtils.cpp 223 TarWriter.cpp 224 ThreadPool.cpp 225 TimeProfiler.cpp 226 Timer.cpp 227 ToolOutputFile.cpp 228 TrigramIndex.cpp 229 Twine.cpp 230 TypeSize.cpp 231 Unicode.cpp 232 UnicodeCaseFold.cpp 233 UnicodeNameToCodepoint.cpp 234 UnicodeNameToCodepointGenerated.cpp 235 VersionTuple.cpp 236 VirtualFileSystem.cpp 237 WithColor.cpp 238 YAMLParser.cpp 239 YAMLTraits.cpp 240 raw_os_ostream.cpp 241 raw_ostream.cpp 242 regcomp.c 243 regerror.c 244 regexec.c 245 regfree.c 246 regstrlcpy.c 247 xxhash.cpp 248 Z3Solver.cpp 249 250 ${ALLOCATOR_FILES} 251 $<TARGET_OBJECTS:LLVMSupportBlake3> 252 253# System 254 Atomic.cpp 255 DynamicLibrary.cpp 256 Errno.cpp 257 Memory.cpp 258 Path.cpp 259 Process.cpp 260 Program.cpp 261 RWMutex.cpp 262 Signals.cpp 263 Threading.cpp 264 Valgrind.cpp 265 Watchdog.cpp 266 267 ADDITIONAL_HEADER_DIRS 268 Unix 269 Windows 270 ${LLVM_MAIN_INCLUDE_DIR}/llvm/ADT 271 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support 272 ${Backtrace_INCLUDE_DIRS} 273 274 LINK_LIBS 275 ${system_libs} ${imported_libs} ${delayload_flags} 276 277 LINK_COMPONENTS 278 Demangle 279 ) 280 281set(llvm_system_libs ${system_libs}) 282 283# This block is only needed for llvm-config. When we deprecate llvm-config and 284# move to using CMake export, this block can be removed. 285if(LLVM_ENABLE_ZLIB) 286 # CMAKE_BUILD_TYPE is only meaningful to single-configuration generators. 287 if(CMAKE_BUILD_TYPE) 288 string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) 289 get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION_${build_type}) 290 endif() 291 if(NOT zlib_library) 292 get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION) 293 endif() 294 get_library_name(${zlib_library} zlib_library) 295 set(llvm_system_libs ${llvm_system_libs} "${zlib_library}") 296endif() 297 298if(LLVM_ENABLE_ZSTD) 299 # CMAKE_BUILD_TYPE is only meaningful to single-configuration generators. 300 if(CMAKE_BUILD_TYPE) 301 string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) 302 get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION_${build_type}) 303 endif() 304 if(NOT zstd_library) 305 get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION) 306 endif() 307 get_library_name(${zstd_library} zstd_library) 308 set(llvm_system_libs ${llvm_system_libs} "${zstd_library}") 309endif() 310 311if(LLVM_ENABLE_TERMINFO) 312 if(NOT terminfo_library) 313 get_property(terminfo_library TARGET Terminfo::terminfo PROPERTY LOCATION) 314 endif() 315 get_library_name(${terminfo_library} terminfo_library) 316 set(llvm_system_libs ${llvm_system_libs} "${terminfo_library}") 317endif() 318 319set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}") 320 321 322if(LLVM_INTEGRATED_CRT_ALLOC) 323 if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$") 324 set_property(TARGET LLVMSupport PROPERTY CXX_STANDARD 17) 325 add_compile_definitions(_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) 326 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND 327 "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64") 328 set_property(TARGET LLVMSupport PROPERTY COMPILE_FLAGS "-mcx16") 329 endif() 330 endif() 331endif() 332 333if(LLVM_WITH_Z3) 334 target_include_directories(LLVMSupport SYSTEM 335 PRIVATE 336 ${Z3_INCLUDE_DIR} 337 ) 338endif() 339