Skip to content

Commit be741fc

Browse files
committed
On CMake-based build path, set LLVM_LIBS by running `llvm-config'.
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.
1 parent 8bbe27e commit be741fc

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

clang_delta/CMakeLists.txt

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## -*- mode: CMake -*-
22
##
3-
## Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018 The University of Utah
3+
## Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 The University of Utah
44
## All rights reserved.
55
##
66
## This file is distributed under the University of Illinois Open Source
@@ -57,16 +57,28 @@ include_directories(${CLANG_INCLUDE_DIRS}) # only works for LLVM post-4.0
5757

5858
link_directories(${LLVM_LIBRARY_DIRS})
5959

60-
llvm_map_components_to_libnames(LLVM_LIBS
61-
coverage
62-
irreader
63-
mcparser
64-
objcarcopts
65-
option
66-
passes
67-
profiledata
68-
support
69-
)
60+
# Set LLVM_LIBS by running `llvm-config'.
61+
#
62+
find_program(LLVM_CONFIG_EXECUTABLE
63+
NAMES "llvm-config${CMAKE_EXECUTABLE_SUFFIX}"
64+
PATHS "${LLVM_TOOLS_BINARY_DIR}"
65+
NO_DEFAULT_PATH
66+
DOC "llvm-config executable")
67+
if(NOT LLVM_CONFIG_EXECUTABLE)
68+
message(FATAL_ERROR
69+
"Required `llvm-config${CMAKE_EXECUTABLE_SUFFIX}` tool was not found")
70+
endif()
71+
message(STATUS "Found llvm-config: ${LLVM_CONFIG_EXECUTABLE}")
72+
execute_process(
73+
COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs
74+
coverage irreader mcparser objcarcopts option passes profiledata support
75+
OUTPUT_VARIABLE LLVM_LIBS
76+
OUTPUT_STRIP_TRAILING_WHITESPACE
77+
RESULT_VARIABLE status
78+
)
79+
if(status)
80+
message(FATAL_ERROR "`${LLVM_CONFIG_EXECUTABLE}` failed")
81+
endif()
7082

7183
set(CLANG_LIBS
7284
clangStaticAnalyzerFrontend

0 commit comments

Comments
 (0)