Setting path to Clang library in CMake

夙愿已清 提交于 2020-08-26 07:41:57

问题


I build llvm from git and want to use the libraries in a project, especially the libclang. The "makefiles" are generated by means of CMake and for the LLVM part I found the setting LLVM_DIR to reroute the path for the llvm libraries, but for Clang I cannot find such a variable and I still see in my link line (it is a Cygwin system): /usr/lib/libclang.dll.a /usr/lib/libclangTooling.dll.a.

Question: which environment variable do I set to get the right build Clang libraries?


回答1:


The variable is Clang_DIR.

Just in case, I attach a minimalistic example of CMakeLists.txt file as well.

cmake_minimum_required(VERSION 3.12)

# Find CMake file for Clang
find_package(Clang REQUIRED)

# Add path to LLVM modules
set(CMAKE_MODULE_PATH
  ${CMAKE_MODULE_PATH}
  "${LLVM_CMAKE_DIR}"
  )

# import LLVM CMake functions
include(AddLLVM)

include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${CLANG_INCLUDE_DIRS})

add_definitions(${LLVM_DEFINITIONS})
add_definitions(${CLANG_DEFINITIONS})

add_llvm_executable(myTool main.cpp)
set_property(TARGET myTool PROPERTY CXX_STANDARD 11)
target_link_libraries(myTool PRIVATE clangTooling)


来源:https://stackoverflow.com/questions/55921707/setting-path-to-clang-library-in-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!