Skip to content

Commit

Permalink
On CMake-based build path, set LLVM_LIBS by running `llvm-config'.
Browse files Browse the repository at this point in the history
Previously, we determined the value of LLVM_LIBS by invoking
`llvm_map_components_to_libnames()`, a CMake function provided by LLVM's
CMake stuff.  Apparently this does not work so well with some vendors'
distributions of LLVM.  See pull request #189.

With this commit, we now set LLVM_LIBS by invoking the `llvm-config`
tool.  Aside, this is how the Automake-based build path has worked for a
long time.

The content of this commit is based upon the patch authored by Pranav
Kant (GitHub user @pranavk) in #189.  I expanded his code somewhat,
aiming to make it more portable and robust.

Unlike the patch suggested in #189, this commit does *not* add LLVM_LIBS
to the call to `target_link_libraries()`.  That change is not necessary
on any platforms that I have access to, and it is not clear to me that
the underlying problem has been dealt with.  (The problem related to
linking against some prepackaged versions of LLVM.)  See the message for
commit b5da960.

This patch "works for me" on several platforms, but it should be tested
more widely.  I don't think that I have access to any of the platforms
where the vendor makes a problematic distribution.
  • Loading branch information
eeide committed Apr 25, 2019
1 parent 8bbe27e commit be741fc
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions clang_delta/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## -*- mode: CMake -*-
##
## Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018 The University of Utah
## Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 The University of Utah
## All rights reserved.
##
## This file is distributed under the University of Illinois Open Source
Expand Down Expand Up @@ -57,16 +57,28 @@ include_directories(${CLANG_INCLUDE_DIRS}) # only works for LLVM post-4.0

link_directories(${LLVM_LIBRARY_DIRS})

llvm_map_components_to_libnames(LLVM_LIBS
coverage
irreader
mcparser
objcarcopts
option
passes
profiledata
support
)
# Set LLVM_LIBS by running `llvm-config'.
#
find_program(LLVM_CONFIG_EXECUTABLE
NAMES "llvm-config${CMAKE_EXECUTABLE_SUFFIX}"
PATHS "${LLVM_TOOLS_BINARY_DIR}"
NO_DEFAULT_PATH
DOC "llvm-config executable")
if(NOT LLVM_CONFIG_EXECUTABLE)
message(FATAL_ERROR
"Required `llvm-config${CMAKE_EXECUTABLE_SUFFIX}` tool was not found")
endif()
message(STATUS "Found llvm-config: ${LLVM_CONFIG_EXECUTABLE}")
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs
coverage irreader mcparser objcarcopts option passes profiledata support
OUTPUT_VARIABLE LLVM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE status
)
if(status)
message(FATAL_ERROR "`${LLVM_CONFIG_EXECUTABLE}` failed")
endif()

set(CLANG_LIBS
clangStaticAnalyzerFrontend
Expand Down

0 comments on commit be741fc

Please sign in to comment.