How to include generated headers? (created in ${PROJECT_BINARY_DIR})
Answered
I've been struggling getting CLion to scan the binary output area for headers generated from Protobuf .proto files. cmake doesn't have a problem as I've added the ${PROJECT_BINARY_DIR}/protobuf to the include path using INCLUDE_DIRECTORIES. But CLion seems to ignore it. I've also tried explicitly marking the directory under PROJECT_BINARY_DIR as 'Project Sources and Headers' but that doesn't seem to override the default exclusion of all directories under the build area.
Please sign in to leave a comment.
To be clear, the problem I'm seeing in CLion is the generated Protobuf headers are labeled as "Cannot find 'some_code.pb.h'" and anything referencing code in the headers is red in the IDE. The project compiles without issue.
Hello!
I tested the use of Protobuf with the following CMakeLists.txt:
The files generated after Run | Build were successfully indexed by CLion.
Could you please try such simple project or https://github.com/prograholic/blog/tree/master/protobuf_tests - are the generated files indexed and found successfully by CLion?
I tried using CMAKE_CURRENT_BINARY_DIR instead of PROJECT_BINARY_DIR and I also tried invalidating the cache (with File->Invalidate Caches/Restart) but still no luck. However, when I switched from my release build to debug it did find the generated header files. I've switched back to release and it's still finding the headers in the debug binary output area. Kind of odd, but at least it works now. Thanks.
Just in case:
If you want to reset the CMake cache, you need to do Tools | CMake | Reset Cache and Reload Project.
If you want to reset the CLion cache, you need to do File | Invalidate Caches/Restart.
Hi Anna,
Does the CMake construct also work when CMake refers to ToolChain configured to remote m/c? I have downloaded protobuf plugin and can see "Protobuf Support" in preferences. What I don't understand is how to configure "Custom Include Path"? I really want to maximize use of this plugin while doing remote
Thanks, Vijay
I also have the same problem in the header file in CLion 2024.1 (Build #CL-241.14494.288, built on April 5, 2024). And the problem solved when i switched debug and release configuration and back!