6

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?

2

1 Answer 1

2
+25

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") 
Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunately, since paths in clang are relative, even if I add this, CMake will fail: ``` fatal error: clang/AST/Attr.h: No such file or directory #include "clang/AST/Attr.h" ^~~~~~~~~~~~~~~~~~ ``` Due to how the include statements are in the clang source code itself -- it's all relative from the top directory
@gust: I think you can solve that by adding some -I rules to your compiler command, so it finds the headers relative to whatever directory you specify.
-I rules to compilers?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.