How to deal with YCM plugin error caused by lack of -I flag passed by ycm-generator?

96 Views Asked by At

Let's say I am using the youcompleteme and ycm generator plugins with vim,
and in my CMakeLists.txt file I have something like this: configure_file(src/config.hpp.in config.hpp)
My project directory structure looks like this:

> tree
.
├── CMakeLists.txt
└── src
    ├── config.hpp.in
    └── main.cpp

Now, when, in my src/main.cpp file, I have:
#include "config.hpp"
The code compiles, because I add
target_include_directories(target BEFORE PRIVATE "${PROJECT_BINARY_DIR}")
to the CMakeLists.txt file, but because the file included is a file generated from a template,
ycm generator fails to add the build directory (because that is where the config.hpp file ends up)
to the flags list, and thus ycm gives me an error that no such file exists. I can append this flag manually like so:

flags = [
     '-x',
     'c++',
     '-I/tmp/tmp36Q3_Q',
     '-Ibuild'
]

But as you can see from the snippet, there already seems to be an -I flag
appended to the flags list. The name of the directory doesn't really mean anything to me.
It does make me wonder, if perhaps ycm generator attempted to find my build directory,
and failed for some reason, like a missing option in cmake?

Does anyone know how to get ycm generator to pass the location
of the generated file to the include dirs automatically?

To be more precise, I would like to add that I've been generating the .ycm_extra_conf.py file
from vim, in the root of the project, with the command :YcmGenerateConfig.

1

There are 1 best solutions below

0
On

I have applied a workaround. I modified the output location in the configure_file option to the source directory like so:
configure_file(src/config.hpp.in "${CMAKE_CURRENT_SOURCE_DIR}"/src/config.hpp)
This way, ycm only complains until i "./configure" the project.