Issue 177162
Summary confusing error message from cmake
Labels new issue
Assignees
Reporter gyorokpeter
    I'm trying to follow this tutorial:
https://www.freecodecamp.org/news/clang-ast-based-static-analysis-tools/

Now I have the CMakeLists.txt that it's suggesting me to create:
```
set(LLVM_LINK_COMPONENTS support)
set(CMAKE_CXX_COMPILER /usr/bin/clang++)  


add_clang_executable(class-analyzer
 ClassAnalzyer.cpp
  MyFrontendActionFactory.cpp
  MyFrontendAction.cpp
 MyASTConsumer.cpp
  )
target_link_libraries(class-analyzer
  PRIVATE
 clangAST
  clangFrontend
  clangTooling
  )
```
And the files look like this:
```
$ ls clang-tools-extra/class-analyzer/
CMakeLists.txt MyASTConsumer.cpp  MyFrontendAction.cpp MyFrontendActionFactory.cpp
ClassAnalyzer.cpp  MyASTConsumer.h MyFrontendAction.h    MyFrontendActionFactory.h
```
One thing that the tutorial fails to mention is that I should add the following line to the `CMakeLists.txt` in the `clang-tools-extra` directory, otherwise my directory seems to be ignored (is this correct?)
```
add_subdirectory(class-analyzer)
```
But then when I run cmake (using `cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"`) I get the following error:
```
CMake Error at cmake/modules/LLVMProcessSources.cmake:113 (message):
  Found erroneous configuration for source file ClassAnalyzer.cpp

  LLVM's build system enforces that all source files are added to a build
  target, that exactly one build target exists in each directory, and that
  this target lists all files in that directory.  If you want multiple
  targets in the same directory, add PARTIAL_SOURCES_INTENDED to the target
  specification, though it is discouraged.

  Please update
 /.../llvm-project/clang-tools-extra/class-analyzer/CMakeLists.txt


Call Stack (most recent call first):
  cmake/modules/LLVMProcessSources.cmake:59 (llvm_check_source_file_list)
  cmake/modules/AddLLVM.cmake:978 (llvm_process_sources)
  cmake/modules/AddLLVM.cmake:1033 (generate_llvm_objects)
 /.../llvm-project/clang/cmake/modules/AddClang.cmake:160 (add_llvm_executable)
 /.../llvm-project/clang-tools-extra/class-analyzer/CMakeLists.txt:4 (add_clang_executable)
```
In what way is the configuration erroneous?
- all source files are added to a build target - I assume this is true, because I have `add_clang_executable(class-analyzer` which I assume is a "target" and it lists all the .cpp files in the directory (I assume by "source files" it refers to .cpp files)
- that exactly one build target exists in each directory - I assume this is true because the only "target" is `add_clang_executable(class-analyzer`, and there are no other `CMakeLists.txt` files in this directory that might contain other targets
- and that this target lists all files in that directory - this one I was not sure about, because there are also .h files in the directory, but I did try adding them to the list under `add_clang_executable(class-analyzer` and it doesn't change anything, not even the error message, also the error message refers to `ClassAnalyzer.cpp` and not any of the `.h` files
- If you want multiple targets in the same directory - no, I don't think there is any need to put any more targets in that directory

Any idea what I'm doing wrong? It might be helpful to improve the error message to provide more details.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to