llvm.org GIT mirror llvm / a20946b
llvm-config: Add preliminary Windows support Summary: This patch adds Windows support for a few of the llvm-config commands, including cflags, ldflags, libs, and system-libs. Currently llvm-config is untested, so this patch adds tests for the commands that it fixes as well. Reviewers: rnk Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D16762 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260263 91177308-0d34-0410-b5e6-96231b3b80d8 Ehsan Akhgari 4 years ago
9 changed file(s) with 113 addition(s) and 62 deletion(s). Raw diff Collapse all Expand all
0 set(system_libs)
1 if( NOT MSVC )
2 if( MINGW )
3 # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
4 set(system_libs ${system_libs} psapi shell32 ole32 uuid)
5 elseif( CMAKE_HOST_UNIX )
6 if( HAVE_LIBRT )
7 set(system_libs ${system_libs} rt)
1 if( MSVC OR MINGW )
2 # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
3 set(system_libs ${system_libs} psapi shell32 ole32 uuid)
4 elseif( CMAKE_HOST_UNIX )
5 if( HAVE_LIBRT )
6 set(system_libs ${system_libs} rt)
7 endif()
8 if( HAVE_LIBDL )
9 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
10 endif()
11 if(LLVM_ENABLE_TERMINFO)
12 if(HAVE_TERMINFO)
13 set(system_libs ${system_libs} ${TERMINFO_LIBS})
814 endif()
9 if( HAVE_LIBDL )
10 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
11 endif()
12 if(LLVM_ENABLE_TERMINFO)
13 if(HAVE_TERMINFO)
14 set(system_libs ${system_libs} ${TERMINFO_LIBS})
15 endif()
16 endif()
17 if( LLVM_ENABLE_THREADS AND HAVE_LIBATOMIC )
18 set(system_libs ${system_libs} atomic)
19 endif()
20 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
21 set(system_libs ${system_libs} pthread)
22 endif()
23 if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
24 set(system_libs ${system_libs} z)
25 endif()
26 set(system_libs ${system_libs} m)
27 endif( MINGW )
28 endif( NOT MSVC )
15 endif()
16 if( LLVM_ENABLE_THREADS AND HAVE_LIBATOMIC )
17 set(system_libs ${system_libs} atomic)
18 endif()
19 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
20 set(system_libs ${system_libs} pthread)
21 endif()
22 if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
23 set(system_libs ${system_libs} z)
24 endif()
25 set(system_libs ${system_libs} m)
26 endif( MSVC OR MINGW )
2927
3028 add_llvm_library(LLVMSupport
3129 APFloat.cpp
0 RUN: llvm-config --cflags 2>&1 | FileCheck %s
1 RUN: llvm-config --cppflags 2>&1 | FileCheck %s
2 RUN: llvm-config --cxxflags 2>&1 | FileCheck %s
3 CHECK: -I
4 CHECK: {{[/\\]}}include
5 CHECK-NOT: error
6 CHECK-NOT: warning
0 RUN: llvm-config --ldflags 2>&1 | FileCheck %s
1 CHECK: -L
2 CHECK: {{[/\\]}}lib
3 CHECK-NOT: error
4 CHECK-NOT: warning
0 RUN: llvm-config --libs core 2>&1 | FileCheck %s
1 CHECK: LLVMCore
2 CHECK: LLVMSupport
3 CHECK-NOT: error
4 CHECK-NOT: warning
0 RUN: llvm-config --system-libs 2>&1 | FileCheck %s
1 UNSUPPORTED: system-windows
2 CHECK: -l
3 CHECK-NOT: error
4 CHECK-NOT: warning
0 RUN: llvm-config --system-libs 2>&1 | FileCheck %s
1 REQUIRED: system-windows
2 CHECK-NOT: -l
3 CHECK: psapi.lib shell32.lib ole32.lib uuid.lib
4 CHECK-NOT: error
5 CHECK-NOT: warning
1010 # Compute the substitution values for various items.
1111 get_property(LLVM_SYSTEM_LIBS_LIST TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
1212 foreach(l ${LLVM_SYSTEM_LIBS_LIST})
13 set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
13 if(MSVC)
14 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
15 else()
16 set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
17 endif()
1418 endforeach()
1519 string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
1620
7878 bool IncludeNonInstalled, bool GetComponentNames,
7979 const std::function
8080 *GetComponentLibraryPath,
81 std::vector *Missing) {
81 std::vector *Missing,
82 const std::string &DirSep) {
8283 // Lookup the component.
8384 AvailableComponent *AC = ComponentMap.lookup(Name);
8485 assert(AC && "Invalid component name!");
9798 for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {
9899 VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,
99100 RequiredLibs, IncludeNonInstalled, GetComponentNames,
100 GetComponentLibraryPath, Missing);
101 GetComponentLibraryPath, Missing, DirSep);
101102 }
102103
103104 if (GetComponentNames) {
109110 if (AC->Library) {
110111 if (Missing && GetComponentLibraryPath) {
111112 std::string path = (*GetComponentLibraryPath)(AC->Library);
113 if (DirSep == "\\") {
114 std::replace(path.begin(), path.end(), '/', '\\');
115 }
112116 if (!sys::fs::exists(path))
113117 Missing->push_back(path);
114118 }
124128 /// \param IncludeNonInstalled - Whether non-installed components should be
125129 /// reported.
126130 /// \param GetComponentNames - True if one would prefer the component names.
127 static std::vector
128 ComputeLibsForComponents(const std::vector &Components,
129 bool IncludeNonInstalled, bool GetComponentNames,
130 const std::function
131 *GetComponentLibraryPath,
132 std::vector *Missing) {
131 static std::vector ComputeLibsForComponents(
132 const std::vector &Components, bool IncludeNonInstalled,
133 bool GetComponentNames, const std::function
134 *GetComponentLibraryPath,
135 std::vector *Missing, const std::string &DirSep) {
133136 std::vector RequiredLibs;
134137 std::set VisitedComponents;
135138
154157
155158 VisitComponent(ComponentLower, ComponentMap, VisitedComponents,
156159 RequiredLibs, IncludeNonInstalled, GetComponentNames,
157 GetComponentLibraryPath, Missing);
160 GetComponentLibraryPath, Missing, DirSep);
158161 }
159162
160163 // The list is now ordered with leafs first, we want the libraries to printed
219222 /// \brief Expand the semi-colon delimited LLVM_DYLIB_COMPONENTS into
220223 /// the full list of components.
221224 std::vector GetAllDyLibComponents(const bool IsInDevelopmentTree,
222 const bool GetComponentNames) {
225 const bool GetComponentNames,
226 const std::string &DirSep) {
223227 std::vector DyLibComponents;
224228
225229 StringRef DyLibComponentsStr(LLVM_DYLIB_COMPONENTS);
237241
238242 return ComputeLibsForComponents(DyLibComponents,
239243 /*IncludeNonInstalled=*/IsInDevelopmentTree,
240 GetComponentNames, nullptr, nullptr);
244 GetComponentNames, nullptr, nullptr, DirSep);
241245 }
242246
243247 int main(int argc, char **argv) {
346350 /// in the first place. This can't be done at configure/build time.
347351
348352 StringRef SharedExt, SharedVersionedExt, SharedDir, SharedPrefix, StaticExt,
349 StaticPrefix, StaticDir = "lib";
353 StaticPrefix, StaticDir = "lib", DirSep = "/";
350354 const Triple HostTriple(Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE));
351355 if (HostTriple.isOSWindows()) {
352356 SharedExt = "dll";
353357 SharedVersionedExt = LLVM_DYLIB_VERSION ".dll";
354 StaticExt = "a";
358 if (HostTriple.isOSCygMing()) {
359 StaticExt = "a";
360 StaticPrefix = SharedPrefix = "lib";
361 } else {
362 StaticExt = "lib";
363 DirSep = "\\";
364 std::replace(ActiveObjRoot.begin(), ActiveObjRoot.end(), '/', '\\');
365 std::replace(ActivePrefix.begin(), ActivePrefix.end(), '/', '\\');
366 std::replace(ActiveBinDir.begin(), ActiveBinDir.end(), '/', '\\');
367 std::replace(ActiveLibDir.begin(), ActiveLibDir.end(), '/', '\\');
368 std::replace(ActiveIncludeOption.begin(), ActiveIncludeOption.end(), '/',
369 '\\');
370 }
355371 SharedDir = ActiveBinDir;
356372 StaticDir = ActiveLibDir;
357 StaticPrefix = SharedPrefix = "lib";
358373 } else if (HostTriple.isOSDarwin()) {
359374 SharedExt = "dylib";
360375 SharedVersionedExt = LLVM_DYLIB_VERSION ".dylib";
393408 bool LinkDyLib = (std::strcmp(LLVM_LINK_DYLIB, "ON") == 0);
394409
395410 if (BuiltDyLib) {
396 DyLibExists = sys::fs::exists(SharedDir + "/" + DyLibName);
411 std::string path((SharedDir + DirSep + DyLibName).str());
412 if (DirSep == "\\") {
413 std::replace(path.begin(), path.end(), '/', '\\');
414 }
415 DyLibExists = sys::fs::exists(path);
397416 if (!DyLibExists) {
398417 // The shared library does not exist: don't error unless the user
399418 // explicitly passes --link-shared.
428447 /// Maps Unixizms to the host platform.
429448 auto GetComponentLibraryFileName = [&](const StringRef &Lib,
430449 const bool Shared) {
431 std::string LibFileName = Lib;
432 StringRef LibName;
433 if (GetComponentLibraryNameSlice(Lib, LibName)) {
434 if (Shared) {
435 LibFileName = (SharedPrefix + LibName + "." + SharedExt).str();
436 } else {
437 // default to static
438 LibFileName = (StaticPrefix + LibName + "." + StaticExt).str();
439 }
450 std::string LibFileName;
451 if (Shared) {
452 LibFileName = (SharedPrefix + Lib + "." + SharedExt).str();
453 } else {
454 // default to static
455 LibFileName = (StaticPrefix + Lib + "." + StaticExt).str();
440456 }
441457
442458 return LibFileName;
445461 auto GetComponentLibraryPath = [&](const StringRef &Name, const bool Shared) {
446462 auto LibFileName = GetComponentLibraryFileName(Name, Shared);
447463 if (Shared) {
448 return (SharedDir + "/" + LibFileName).str();
464 return (SharedDir + DirSep + LibFileName).str();
449465 } else {
450 return (StaticDir + "/" + LibFileName).str();
466 return (StaticDir + DirSep + LibFileName).str();
451467 }
452468 };
453469
474490 } else if (Arg == "--cxxflags") {
475491 OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n';
476492 } else if (Arg == "--ldflags") {
477 OS << "-L" << ActiveLibDir << ' ' << LLVM_LDFLAGS << '\n';
493 OS << ((HostTriple.isWindowsMSVCEnvironment()) ? "-LIBPATH:" : "-L")
494 << ActiveLibDir << ' ' << LLVM_LDFLAGS << '\n';
478495 } else if (Arg == "--system-libs") {
479496 PrintSystemLibs = true;
480497 } else if (Arg == "--libs") {
495512
496513 Components.push_back(AvailableComponents[j].Name);
497514 if (AvailableComponents[j].Library && !IsInDevelopmentTree) {
498 if (DyLibExists &&
499 !sys::fs::exists(GetComponentLibraryPath(
500 AvailableComponents[j].Library, false))) {
501 Components = GetAllDyLibComponents(IsInDevelopmentTree, true);
515 std::string path(
516 GetComponentLibraryPath(AvailableComponents[j].Library, false));
517 if (DirSep == "\\") {
518 std::replace(path.begin(), path.end(), '/', '\\');
519 }
520 if (DyLibExists && !sys::fs::exists(path)) {
521 Components =
522 GetAllDyLibComponents(IsInDevelopmentTree, true, DirSep);
502523 std::sort(Components.begin(), Components.end());
503524 break;
504525 }
576597 std::vector RequiredLibs = ComputeLibsForComponents(
577598 Components,
578599 /*IncludeNonInstalled=*/IsInDevelopmentTree, false,
579 &GetComponentLibraryPathFunction, &MissingLibs);
600 &GetComponentLibraryPathFunction, &MissingLibs, DirSep);
580601 if (!MissingLibs.empty()) {
581602 switch (LinkMode) {
582603 case LinkModeShared:
606627 if (PrintSharedMode) {
607628 std::unordered_set FullDyLibComponents;
608629 std::vector DyLibComponents =
609 GetAllDyLibComponents(IsInDevelopmentTree, false);
630 GetAllDyLibComponents(IsInDevelopmentTree, false, DirSep);
610631
611632 for (auto &Component : DyLibComponents) {
612633 FullDyLibComponents.insert(Component);
412412 if library_name is None:
413413 library_name_as_cstr = 'nullptr'
414414 else:
415 library_name_as_cstr = '"lib%s.a"' % library_name
415 library_name_as_cstr = '"%s"' % library_name
416416 if is_installed:
417417 is_installed_as_cstr = 'true'
418418 else: