Commit 46126881 authored by Kevin Funk's avatar Kevin Funk
Browse files

clang: Force linking against full lib path

Force link against full library path:
  /usr/lib/x86_64-linux-gnu/libclang-5.0.so.1

... instead of:
  -lclang

target_link_libraries has some heuristics where it prefers dropping the
full library path in case the library is detected within alternative
library search paths, cf.
  https://cmake.org/cmake/help/latest/policy/CMP0060.html#policy:CMP0060

This is a problem in case e.g. libclang is detected in one of the
default linker search paths of the compiler in use (in my case compiler
was Clang 6.0 from Ubuntu repositories trying to link against libclang.so from Clang 5.0)
and CMake attempts to link using -lclang instead of the full library path,
thus running into issues like:
  /usr/bin/ld: error: cannot find -lclang
  .../kdevelop/plugins/clang/tests/minimal_visitor.cpp:27: error: undefined reference to 'clang_getCursorExtent'
  ...
parent a278fffd
......@@ -48,16 +48,21 @@ set(CLANG_FOUND FALSE)
if (LLVM_FOUND AND LLVM_LIBRARY_DIRS)
macro(FIND_AND_ADD_CLANG_LIB _libname_)
string(TOUPPER ${_libname_} _prettylibname_)
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} HINTS ${LLVM_LIBRARY_DIRS})
if(CLANG_${_prettylibname_}_LIB)
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} HINTS ${LLVM_LIBRARY_DIRS} ${ARGN})
if (CLANG_${_prettylibname_}_LIB)
add_library(${_libname_} UNKNOWN IMPORTED GLOBAL)
set_property(TARGET ${_libname_} PROPERTY IMPORTED_LOCATION ${CLANG_${_prettylibname_}_LIB})
set(CLANG_LIBS ${CLANG_LIBS} ${CLANG_${_prettylibname_}_LIB})
endif()
endmacro(FIND_AND_ADD_CLANG_LIB)
# note: On Windows there's 'libclang.dll' instead of 'clang.dll' -> search for 'libclang', too
find_library(CLANG_LIBCLANG_LIB NAMES clang libclang HINTS ${LLVM_LIBRARY_DIRS}) # LibClang: high-level C interface
FIND_AND_ADD_CLANG_LIB(clangFrontend)
FIND_AND_ADD_CLANG_LIB(clang NAMES clang libclang HINTS ${LLVM_LIBRARY_DIRS}) # LibClang: high-level C interface
FIND_AND_ADD_CLANG_LIB(clangDriver)
FIND_AND_ADD_CLANG_LIB(clangCodeGen)
FIND_AND_ADD_CLANG_LIB(clangSema)
......@@ -72,13 +77,11 @@ if (LLVM_FOUND AND LLVM_LIBRARY_DIRS)
FIND_AND_ADD_CLANG_LIB(clangARCMigrate)
FIND_AND_ADD_CLANG_LIB(clangEdit)
FIND_AND_ADD_CLANG_LIB(clangFrontendTool)
FIND_AND_ADD_CLANG_LIB(clangRewrite)
FIND_AND_ADD_CLANG_LIB(clangSerialization)
FIND_AND_ADD_CLANG_LIB(clangTooling)
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCheckers)
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerCore)
FIND_AND_ADD_CLANG_LIB(clangStaticAnalyzerFrontend)
FIND_AND_ADD_CLANG_LIB(clangSema)
FIND_AND_ADD_CLANG_LIB(clangRewriteCore)
endif()
......
......@@ -104,7 +104,7 @@ LINK_PUBLIC
KDev::Language
KDev::Project
KDev::Util
${CLANG_LIBCLANG_LIB}
clang
)
install(FILES duchain/gcc_compat.h DESTINATION ${KDE_INSTALL_DATADIR}/kdevclangsupport PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
......
......@@ -19,7 +19,7 @@ add_executable(clang-minimal-visitor WIN32
)
ecm_mark_nongui_executable(clang-minimal-visitor)
target_link_libraries(clang-minimal-visitor
${CLANG_LIBCLANG_LIB}
clang
)
ecm_add_test(test_buddies.cpp
......@@ -48,7 +48,7 @@ ecm_add_test(test_clangutils.cpp
LINK_LIBRARIES
KDev::Tests
Qt5::Test
${CLANG_LIBCLANG_LIB}
clang
KDevClangPrivate
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment