Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown CMake command "add_clang_executable"

I am trying to build a clang tool, and I am trying to debug it using CLion. However, I can't get it to compile as a standalone binary. Currently I have this in my CMakeLists.txt:

add_clang_executable(clang_my_tool my_tool_util.h my_tool_util.cpp ClangMyTool.cpp)

target_link_libraries(clang_my_tool PRIVATE clangTooling)

However, it's giving me the error message:

Unknown CMake command "add_clang_executable".

I know I need to add an directory, but I don't know which one to add.

My llvm directory looks something like this:

llvm
|-build
  |- ...
|
|-clang
  |-tools
    |-clang_my_tool
      |-ClangMyTool.cpp
      |-my_tool_util.h
      |-my_tool_util.c
      |-CMakeLists.txt
|- ... other directories...

What do I add to my CMakeLists.txt?

like image 701
gust Avatar asked Oct 27 '22 17:10

gust


1 Answers

You need to include the LLVM CMakeLists.txt file which defines add_clang_executable(). Currently that file is here (and may well already be installed on your system): https://github.com/llvm/llvm-project/blob/master/clang/cmake/modules/AddClang.cmake

If you figure out the path to that file on your system, add this to your own CMakeLists.txt:

include("/path/to/AddClang.cmake")
like image 176
John Zwinck Avatar answered Nov 08 '22 12:11

John Zwinck