397 lines · plain
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 all5# 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 we8# check if the current platform is able to compile global std::mutex with this9# 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( WIN32 )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 # ntdll required for RtlGetLastNtStatus in lib/Support/ErrorHandling.cpp.44 set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32 ws2_32 ntdll)45elseif( CMAKE_HOST_UNIX )46 if( HAVE_LIBRT )47 set(system_libs ${system_libs} rt)48 endif()49 if( HAVE_LIBDL )50 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})51 endif()52 if( HAVE_BACKTRACE AND NOT "${Backtrace_LIBRARIES}" STREQUAL "" )53 # On BSDs, CMake returns a fully qualified path to the backtrace library.54 # We need to remove the path and the 'lib' prefix, to make it look like a55 # regular short library name, suitable for appending to a -l link flag.56 get_filename_component(Backtrace_LIBFILE ${Backtrace_LIBRARIES} NAME_WE)57 STRING(REGEX REPLACE "^lib" "" Backtrace_LIBFILE ${Backtrace_LIBFILE})58 set(system_libs ${system_libs} ${Backtrace_LIBFILE})59 endif()60 set(system_libs ${system_libs} ${LLVM_ATOMIC_LIB})61 set(system_libs ${system_libs} ${LLVM_PTHREAD_LIB})62 if( UNIX AND NOT (BEOS OR HAIKU) )63 set(system_libs ${system_libs} m)64 endif()65 if( UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "SunOS" )66 set(system_libs ${system_libs} kstat socket)67 endif()68 if( FUCHSIA )69 set(system_libs ${system_libs} zircon)70 endif()71 if ( HAIKU )72 add_compile_definitions(_BSD_SOURCE)73 set(system_libs ${system_libs} bsd network)74 endif()75endif( WIN32 )76 77set(WL "")78if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.25"79 AND MSVC80 AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")81 #IntelLLVM requires to pass linker flags with a wrapper82 set(WL "$<$<OR:$<LINK_LANG_AND_ID:C,IntelLLVM>,$<LINK_LANG_AND_ID:CXX,IntelLLVM>,$<LINK_LANG_AND_ID:Fortran,IntelLLVM>>:-Qoption,link,>")83endif()84 85# Delay load shell32.dll if possible to speed up process startup.86set (delayload_flags)87if (MSVC)88 # When linking with Swift, `swiftc.exe` is used as the linker drive rather89 # than invoking `link.exe` directly. In such a case, the flags should be90 # marked as `-Xlinker` to pass them directly to the linker. As a temporary91 # workaround simply elide the delay loading.92 set (delayload_flags $<$<NOT:$<LINK_LANGUAGE:Swift>>:delayimp ${WL}-delayload:shell32.dll ${WL}-delayload:ole32.dll>)93endif()94 95# Link Z3 if the user wants to build it.96if(LLVM_WITH_Z3)97 set(system_libs ${system_libs} ${Z3_LIBRARIES})98endif()99 100# Override the C runtime allocator on Windows and embed it into LLVM tools & libraries101if(LLVM_INTEGRATED_CRT_ALLOC)102 if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")103 message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC only works with CMAKE_MSVC_RUNTIME_LIBRARY set to MultiThreaded or MultiThreadedDebug.")104 endif()105 106 string(REGEX REPLACE "(/|\\\\)$" "" LLVM_INTEGRATED_CRT_ALLOC "${LLVM_INTEGRATED_CRT_ALLOC}")107 108 if(NOT EXISTS "${LLVM_INTEGRATED_CRT_ALLOC}")109 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.")110 endif()111 112 if((LLVM_INTEGRATED_CRT_ALLOC MATCHES "rpmalloc$") OR LLVM_ENABLE_RPMALLOC)113 add_compile_definitions(ENABLE_OVERRIDE ENABLE_PRELOAD)114 set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/rpmalloc/rpmalloc.c")115 list(APPEND delayload_flags "${WL}-INCLUDE:malloc")116 elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$")117 set(ALLOCATOR_FILES "${LLVM_INTEGRATED_CRT_ALLOC}/src/snmalloc/override/new.cc")118 set(system_libs ${system_libs} "mincore.lib" "${WL}-INCLUDE:malloc")119 elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "mimalloc$")120 set(MIMALLOC_LIB "${LLVM_INTEGRATED_CRT_ALLOC}/out/msvc-x64/Release/mimalloc-static.lib")121 if(NOT EXISTS "${MIMALLOC_LIB}")122 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")123 endif()124 set(system_libs ${system_libs} "${MIMALLOC_LIB}" "${WL}-INCLUDE:malloc")125 endif()126endif()127 128# FIXME: We are currently guarding AIX headers with _XOPEN_SOURCE=700.129# See llvm/CMakeLists.txt. However, we need _SC_NPROCESSORS_ONLN in130# unistd.h and it is guarded by _ALL_SOURCE, so we remove the _XOPEN_SOURCE131# guard here. We should remove the guards all together once AIX cleans up132# the system headers.133if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")134 remove_definitions("-D_XOPEN_SOURCE=700")135endif()136 137add_subdirectory(BLAKE3)138add_subdirectory(LSP)139 140add_llvm_component_library(LLVMSupport141 ABIBreak.cpp142 AMDGPUMetadata.cpp143 APFixedPoint.cpp144 APFloat.cpp145 APInt.cpp146 APSInt.cpp147 ARMBuildAttributes.cpp148 AArch64AttributeParser.cpp149 AArch64BuildAttributes.cpp150 ARMAttributeParser.cpp151 ARMWinEH.cpp152 AllocToken.cpp153 Allocator.cpp154 AutoConvert.cpp155 Base64.cpp156 BalancedPartitioning.cpp157 BinaryStreamError.cpp158 BinaryStreamReader.cpp159 BinaryStreamRef.cpp160 BinaryStreamWriter.cpp161 BlockFrequency.cpp162 BranchProbability.cpp163 BuryPointer.cpp164 CachePruning.cpp165 Caching.cpp166 circular_raw_ostream.cpp167 Chrono.cpp168 COM.cpp169 CodeGenCoverage.cpp170 CommandLine.cpp171 Compression.cpp172 CRC.cpp173 ConvertUTF.cpp174 ConvertEBCDIC.cpp175 ConvertUTFWrapper.cpp176 CrashRecoveryContext.cpp177 CSKYAttributes.cpp178 CSKYAttributeParser.cpp179 DataExtractor.cpp180 Debug.cpp181 DebugCounter.cpp182 DeltaAlgorithm.cpp183 DeltaTree.cpp184 DivisionByConstantInfo.cpp185 DAGDeltaAlgorithm.cpp186 DJB.cpp187 DXILABI.cpp188 DynamicAPInt.cpp189 ELFAttributes.cpp190 ELFAttrParserCompact.cpp191 ELFAttrParserExtended.cpp192 Error.cpp193 ErrorHandling.cpp194 ExponentialBackoff.cpp195 ExtensibleRTTI.cpp196 FileCollector.cpp197 FileUtilities.cpp198 FileOutputBuffer.cpp199 FloatingPointMode.cpp200 FoldingSet.cpp201 FormattedStream.cpp202 FormatVariadic.cpp203 GlobPattern.cpp204 GraphWriter.cpp205 HexagonAttributeParser.cpp206 HexagonAttributes.cpp207 InitLLVM.cpp208 InstructionCost.cpp209 IntEqClasses.cpp210 IntervalMap.cpp211 Jobserver.cpp212 JSON.cpp213 KnownBits.cpp214 KnownFPClass.cpp215 LEB128.cpp216 LineIterator.cpp217 Locale.cpp218 LockFileManager.cpp219 ManagedStatic.cpp220 MathExtras.cpp221 MemAlloc.cpp222 MemoryBuffer.cpp223 MemoryBufferRef.cpp224 ModRef.cpp225 MD5.cpp226 MSP430Attributes.cpp227 MSP430AttributeParser.cpp228 Mustache.cpp229 NativeFormatting.cpp230 OptimizedStructLayout.cpp231 Optional.cpp232 OptionStrCmp.cpp233 PGOOptions.cpp234 Parallel.cpp235 PluginLoader.cpp236 PrettyStackTrace.cpp237 RandomNumberGenerator.cpp238 Regex.cpp239 RewriteBuffer.cpp240 RewriteRope.cpp241 RISCVAttributes.cpp242 RISCVAttributeParser.cpp243 RISCVISAUtils.cpp244 ScaledNumber.cpp245 ScopedPrinter.cpp246 SHA1.cpp247 SHA256.cpp248 Signposts.cpp249 SipHash.cpp250 SlowDynamicAPInt.cpp251 SmallPtrSet.cpp252 SmallVector.cpp253 SourceMgr.cpp254 SpecialCaseList.cpp255 Statistic.cpp256 StringExtras.cpp257 StringMap.cpp258 StringSaver.cpp259 StringRef.cpp260 SuffixTreeNode.cpp261 SuffixTree.cpp262 SystemUtils.cpp263 TarWriter.cpp264 TextEncoding.cpp265 ThreadPool.cpp266 TimeProfiler.cpp267 Timer.cpp268 ToolOutputFile.cpp269 TrieRawHashMap.cpp270 Twine.cpp271 Unicode.cpp272 UnicodeCaseFold.cpp273 UnicodeNameToCodepoint.cpp274 UnicodeNameToCodepointGenerated.cpp275 VersionTuple.cpp276 VirtualFileSystem.cpp277 VirtualOutputBackend.cpp278 VirtualOutputBackends.cpp279 VirtualOutputConfig.cpp280 VirtualOutputError.cpp281 VirtualOutputFile.cpp282 WithColor.cpp283 YAMLParser.cpp284 YAMLTraits.cpp285 raw_os_ostream.cpp286 raw_ostream.cpp287 raw_ostream_proxy.cpp288 raw_socket_stream.cpp289 regcomp.c290 regerror.c291 regexec.c292 regfree.c293 regstrlcpy.c294 xxhash.cpp295 Z3Solver.cpp296 297 ${ALLOCATOR_FILES}298 $<TARGET_OBJECTS:LLVMSupportBlake3>299 300# System301 Atomic.cpp302 DynamicLibrary.cpp303 Errno.cpp304 Memory.cpp305 Path.cpp306 Process.cpp307 Program.cpp308 ProgramStack.cpp309 RWMutex.cpp310 Signals.cpp311 Threading.cpp312 Valgrind.cpp313 Watchdog.cpp314 zOSLibFunctions.cpp315 316 ADDITIONAL_HEADER_DIRS317 Unix318 Windows319 ${LLVM_MAIN_INCLUDE_DIR}/llvm/ADT320 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support321 ${Backtrace_INCLUDE_DIRS}322 323 LINK_LIBS324 ${system_libs} ${imported_libs} ${delayload_flags}325 326 LINK_COMPONENTS327 Demangle328 )329 330# Link ICU library if it is an external library.331if(ICU_FOUND)332 target_link_libraries(LLVMSupport333 PRIVATE334 ${ICU_LIBRARIES}335 )336endif()337 338set(llvm_system_libs ${system_libs})339 340# This block is only needed for llvm-config. When we deprecate llvm-config and341# move to using CMake export, this block can be removed.342if(LLVM_ENABLE_ZLIB)343 # CMAKE_BUILD_TYPE is only meaningful to single-configuration generators.344 if(CMAKE_BUILD_TYPE)345 string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)346 get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION_${build_type})347 endif()348 if(NOT zlib_library)349 get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION)350 endif()351 get_library_name(${zlib_library} zlib_library)352 set(llvm_system_libs ${llvm_system_libs} "${zlib_library}")353endif()354 355if(LLVM_ENABLE_ZSTD)356 # CMAKE_BUILD_TYPE is only meaningful to single-configuration generators.357 if(CMAKE_BUILD_TYPE)358 string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)359 get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION_${build_type})360 endif()361 if(NOT zstd_library)362 get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION)363 endif()364 if (zstd_target STREQUAL zstd::libzstd_shared)365 get_library_name(${zstd_library} zstd_library)366 set(llvm_system_libs ${llvm_system_libs} "${zstd_library}")367 else()368 set(llvm_system_libs ${llvm_system_libs} "${zstd_STATIC_LIBRARY}")369 endif()370endif()371 372set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")373 374 375if(LLVM_INTEGRATED_CRT_ALLOC)376 if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "snmalloc$")377 set_property(TARGET LLVMSupport PROPERTY CXX_STANDARD 17)378 add_compile_definitions(_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)379 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND380 "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64")381 set_property(TARGET LLVMSupport PROPERTY COMPILE_FLAGS "-mcx16")382 endif()383 endif()384endif()385 386if(LLVM_WITH_Z3)387 target_include_directories(LLVMSupport SYSTEM388 PRIVATE389 ${Z3_INCLUDE_DIR}390 )391endif()392 393target_include_directories(LLVMSupport394 PRIVATE395 ${LLVM_THIRD_PARTY_DIR}/siphash/include396)397