Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(812)

Side by Side Diff: tools/llvm-config/llvm-config.cpp

Issue 1196003003: Make `llvm-config` detect whether or not LLVM is a shared library. If it is, then only try to link … (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Review changes. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/llvm-config/Makefile ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===-- llvm-config.cpp - LLVM project configuration utility --------------===// 1 //===-- llvm-config.cpp - LLVM project configuration utility --------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This tool encapsulates information about an LLVM project configuration for 10 // This tool encapsulates information about an LLVM project configuration for
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // If no components were specified, default to "all". 342 // If no components were specified, default to "all".
343 if (Components.empty()) 343 if (Components.empty())
344 Components.push_back("all"); 344 Components.push_back("all");
345 345
346 // Construct the list of all the required libraries. 346 // Construct the list of all the required libraries.
347 std::vector<StringRef> RequiredLibs; 347 std::vector<StringRef> RequiredLibs;
348 ComputeLibsForComponents(Components, RequiredLibs, 348 ComputeLibsForComponents(Components, RequiredLibs,
349 /*IncludeNonInstalled=*/IsInDevelopmentTree); 349 /*IncludeNonInstalled=*/IsInDevelopmentTree);
350 350
351 if (PrintLibs || PrintLibNames || PrintLibFiles) { 351 if (PrintLibs || PrintLibNames || PrintLibFiles) {
352 // If LLVM was built as a shared library, there will be only one thing
353 // that users should link against.
354 const bool IsSharedLib = (std::strcmp(BUILD_SHARED_LIBS, "ON") == 0);
355 const bool WasBuiltWithCMake = (std::strcmp(WAS_BUILT_WITH_CMAKE, "ON") == 0);
356 // CMake correctly builds components as separate shared libraries, however
357 // autoconfig/make builds components a static libraries and then links
358 // them all together to form a single shared library. Thus, only when
359 // `WAS_BUILT_WITH_CMAKE` and `BUILD_SHARED_LIBS` are `ON` do we override
360 // `RequiredLibs` with the single library name.
361 if (IsSharedLib && !WasBuiltWithCMake) {
362 RequiredLibs.clear();
363 std::string Name = "libLLVM-" PACKAGE_VERSION;
364 const Triple HostTriple(LLVM_DEFAULT_TARGET_TRIPLE);
365 if (HostTriple.isOSWindows()) {
366 Name += ".dll";
367 } else if (HostTriple.isOSDarwin()) {
368 Name += ".dylib";
369 } else {
370 // default to linux' ext:
371 Name += ".so";
372 }
373 RequiredLibs.push_back(Name);
374 }
375
352 for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) { 376 for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
353 StringRef Lib = RequiredLibs[i]; 377 StringRef Lib = RequiredLibs[i];
354 if (i) 378 if (i)
355 OS << ' '; 379 OS << ' ';
356 380
357 if (PrintLibNames) { 381 if (PrintLibNames) {
358 OS << Lib; 382 OS << Lib;
359 } else if (PrintLibFiles) { 383 } else if (PrintLibFiles) {
360 OS << ActiveLibDir << '/' << Lib; 384 OS << ActiveLibDir << '/' << Lib;
361 } else if (PrintLibs) { 385 } else if (PrintLibs) {
362 // If this is a typical library name, include it using -l. 386 // If this is a typical library name, include it using -l.
363 if (Lib.startswith("lib") && Lib.endswith(".a")) { 387 if (Lib.startswith("lib")) {
364 OS << "-l" << Lib.slice(3, Lib.size()-2); 388 size_t FromEnd = 0;
365 continue; 389 do {
390 if (Lib.endswith(".a")) {
391 FromEnd = 2;
392 } else if (Lib.endswith(".so")) {
393 FromEnd = 3;
394 } else if (Lib.endswith(".dylib")) {
395 FromEnd = 6;
396 } else {
397 FromEnd = 0;
398 break;
399 }
400 OS << "-l" << Lib.slice(3, Lib.size() - FromEnd);
401 } while(false);
402 if (FromEnd != 0) { continue; }
366 } 403 }
367 404
368 // Otherwise, print the full path. 405 // Otherwise, print the full path.
369 OS << ActiveLibDir << '/' << Lib; 406 OS << ActiveLibDir << '/' << Lib;
370 } 407 }
371 } 408 }
372 OS << '\n'; 409 OS << '\n';
373 } 410 }
374 411
375 // Print SYSTEM_LIBS after --libs. 412 // Print SYSTEM_LIBS after --libs.
376 // FIXME: Each LLVM component may have its dependent system libs. 413 // FIXME: Each LLVM component may have its dependent system libs.
377 if (PrintSystemLibs) 414 if (PrintSystemLibs)
378 OS << LLVM_SYSTEM_LIBS << '\n'; 415 OS << LLVM_SYSTEM_LIBS << '\n';
379 } else if (!Components.empty()) { 416 } else if (!Components.empty()) {
380 errs() << "llvm-config: error: components given, but unused\n\n"; 417 errs() << "llvm-config: error: components given, but unused\n\n";
381 usage(); 418 usage();
382 } 419 }
383 420
384 return 0; 421 return 0;
385 } 422 }
OLDNEW
« no previous file with comments | « tools/llvm-config/Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698