5

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?

Kevin
  • 16,549
  • 8
  • 60
  • 74
albert
  • 8,285
  • 3
  • 19
  • 32

1 Answers1

13

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)
Valeriy Savchenko
  • 1,524
  • 8
  • 19
  • add `project(myTool)`, add `install(TARGETS ${PROJECT_NAME})`, replace `add_llvm_executable` with `add_executable`. another [example CMakeLists.txt for llvm and clang](https://github.com/patrykstefanski/dc-lang/blob/master/CMakeLists.txt) – milahu Feb 10 '22 at 12:06