albert
albert

Reputation: 9077

Setting path to Clang library in CMake

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?

Upvotes: 5

Views: 8733

Answers (1)

Valeriy Savchenko
Valeriy Savchenko

Reputation: 1614

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)

Upvotes: 13

Related Questions