Attempt to fix ZLIB CMake logic on Windows
[lldb.git] / llvm / lib / Support / CMakeLists.txt
1 if(LLVM_ENABLE_ZLIB)
2   set(imported_libs ZLIB::ZLIB)
3 endif()
4
5 if( MSVC OR MINGW )
6   # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
7   # advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
8   set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32)
9 elseif( CMAKE_HOST_UNIX )
10   if( HAVE_LIBRT )
11     set(system_libs ${system_libs} rt)
12   endif()
13   if( HAVE_LIBDL )
14     set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
15   endif()
16   if( HAVE_BACKTRACE AND NOT "${Backtrace_LIBRARIES}" STREQUAL "" )
17     # On BSDs, CMake returns a fully qualified path to the backtrace library.
18     # We need to remove the path and the 'lib' prefix, to make it look like a
19     # regular short library name, suitable for appending to a -l link flag.
20     get_filename_component(Backtrace_LIBFILE ${Backtrace_LIBRARIES} NAME_WE)
21     STRING(REGEX REPLACE "^lib" "" Backtrace_LIBFILE ${Backtrace_LIBFILE})
22     set(system_libs ${system_libs} ${Backtrace_LIBFILE})
23   endif()
24   if(LLVM_ENABLE_TERMINFO)
25     if(HAVE_TERMINFO)
26       set(system_libs ${system_libs} ${TERMINFO_LIBS})
27     endif()
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 endif( MSVC OR MINGW )
40
41 # Delay load shell32.dll if possible to speed up process startup.
42 set (delayload_flags)
43 if (MSVC)
44   set (delayload_flags delayimp -delayload:shell32.dll -delayload:ole32.dll)
45 endif()
46
47 # Link Z3 if the user wants to build it.
48 if(LLVM_WITH_Z3)
49   set(Z3_LINK_FILES ${Z3_LIBRARIES})
50 else()
51   set(Z3_LINK_FILES "")
52 endif()
53
54 add_llvm_component_library(LLVMSupport
55   AArch64TargetParser.cpp
56   ABIBreak.cpp
57   ARMTargetParser.cpp
58   AMDGPUMetadata.cpp
59   APFloat.cpp
60   APInt.cpp
61   APSInt.cpp
62   ARMBuildAttrs.cpp
63   ARMAttributeParser.cpp
64   ARMWinEH.cpp
65   Allocator.cpp
66   BinaryStreamError.cpp
67   BinaryStreamReader.cpp
68   BinaryStreamRef.cpp
69   BinaryStreamWriter.cpp
70   BlockFrequency.cpp
71   BranchProbability.cpp
72   BuryPointer.cpp
73   CachePruning.cpp
74   circular_raw_ostream.cpp
75   Chrono.cpp
76   COM.cpp
77   CodeGenCoverage.cpp
78   CommandLine.cpp
79   Compression.cpp
80   CRC.cpp
81   ConvertUTF.cpp
82   ConvertUTFWrapper.cpp
83   CrashRecoveryContext.cpp
84   DataExtractor.cpp
85   Debug.cpp
86   DebugCounter.cpp
87   DeltaAlgorithm.cpp
88   DAGDeltaAlgorithm.cpp
89   DJB.cpp
90   Error.cpp
91   ErrorHandling.cpp
92   FileCheck.cpp
93   FileCollector.cpp
94   FileUtilities.cpp
95   FileOutputBuffer.cpp
96   FoldingSet.cpp
97   FormattedStream.cpp
98   FormatVariadic.cpp
99   GlobPattern.cpp
100   GraphWriter.cpp
101   Hashing.cpp
102   InitLLVM.cpp
103   IntEqClasses.cpp
104   IntervalMap.cpp
105   ItaniumManglingCanonicalizer.cpp
106   JSON.cpp
107   KnownBits.cpp
108   LEB128.cpp
109   LineIterator.cpp
110   Locale.cpp
111   LockFileManager.cpp
112   LowLevelType.cpp
113   ManagedStatic.cpp
114   MathExtras.cpp
115   MemoryBuffer.cpp
116   MD5.cpp
117   NativeFormatting.cpp
118   Optional.cpp
119   Parallel.cpp
120   PluginLoader.cpp
121   PrettyStackTrace.cpp
122   RandomNumberGenerator.cpp
123   Regex.cpp
124   ScaledNumber.cpp
125   ScopedPrinter.cpp
126   SHA1.cpp
127   Signposts.cpp
128   SmallPtrSet.cpp
129   SmallVector.cpp
130   SourceMgr.cpp
131   SpecialCaseList.cpp
132   Statistic.cpp
133   StringExtras.cpp
134   StringMap.cpp
135   StringPool.cpp
136   StringSaver.cpp
137   StringRef.cpp
138   SymbolRemappingReader.cpp
139   SystemUtils.cpp
140   TarWriter.cpp
141   TargetParser.cpp
142   ThreadPool.cpp
143   TimeProfiler.cpp
144   Timer.cpp
145   ToolOutputFile.cpp
146   TrigramIndex.cpp
147   Triple.cpp
148   Twine.cpp
149   Unicode.cpp
150   UnicodeCaseFold.cpp
151   VersionTuple.cpp
152   VirtualFileSystem.cpp
153   WithColor.cpp
154   YAMLParser.cpp
155   YAMLTraits.cpp
156   raw_os_ostream.cpp
157   raw_ostream.cpp
158   regcomp.c
159   regerror.c
160   regexec.c
161   regfree.c
162   regstrlcpy.c
163   xxhash.cpp
164   Z3Solver.cpp
165
166 # System
167   Atomic.cpp
168   DynamicLibrary.cpp
169   Errno.cpp
170   Host.cpp
171   Memory.cpp
172   Path.cpp
173   Process.cpp
174   Program.cpp
175   RWMutex.cpp
176   Signals.cpp
177   TargetRegistry.cpp
178   ThreadLocal.cpp
179   Threading.cpp
180   Valgrind.cpp
181   Watchdog.cpp
182
183   ADDITIONAL_HEADER_DIRS
184   Unix
185   Windows
186   ${LLVM_MAIN_INCLUDE_DIR}/llvm/ADT
187   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support
188   ${Backtrace_INCLUDE_DIRS}
189   LINK_LIBS ${system_libs} ${imported_libs} ${delayload_flags} ${Z3_LINK_FILES}
190   )
191
192 set(llvm_system_libs ${system_libs})
193
194 if(LLVM_ENABLE_ZLIB)
195   string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
196   get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION_${build_type})
197   if(NOT zlib_library)
198     get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION)
199   endif()
200   get_filename_component(zlib_library ${zlib_library} NAME)
201   if(CMAKE_STATIC_LIBRARY_PREFIX AND
202      zlib_library MATCHES "^${CMAKE_STATIC_LIBRARY_PREFIX}.*${CMAKE_STATIC_LIBRARY_SUFFIX}$")
203     STRING(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" zlib_library ${zlib_library})
204     STRING(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" zlib_library ${zlib_library})
205   elseif(CMAKE_SHARED_LIBRARY_PREFIX AND
206          zlib_library MATCHES "^${CMAKE_SHARED_LIBRARY_PREFIX}.*${CMAKE_SHARED_LIBRARY_SUFFIX}$")
207     STRING(REGEX REPLACE "^${CMAKE_SHARED_LIBRARY_PREFIX}" "" zlib_library ${zlib_library})
208     STRING(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}$" "" zlib_library ${zlib_library})
209   endif()
210   set(llvm_system_libs ${llvm_system_libs} "${zlib_library}")
211 endif()
212
213 set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")
214
215 if(LLVM_WITH_Z3)
216   target_include_directories(LLVMSupport SYSTEM
217     PRIVATE
218     ${Z3_INCLUDE_DIR}
219     )
220 endif()