Headers don't show up as searchable source

In my project, I do most of my coding in headers files.

However, the include directory is not bolded like the cpp directory and things like code intentions/intellisense don't work in these files (they work fine in .cpp files). It's as if CLion thinks my headers are external source. Classes defined in the headers also do not show up in searches unless I do Cmd-Shift-N a few times (I'm on mac).

I also have another project where this sort of structure is fine, I'm not sure what the magic setting/cmake configuration is required to make this work.  

Any ideas?

4 comments
Comment actions Permalink

Hi Chris.

Please check that all your headers were added in CMakeLists.txt. You can add the following line to your CMakeLists:

file(GLOB_RECURSE headers "*.h")
and then add ${headers} variable to your target. Does that help?

Also we have an issue about automatically adding headers without sources in the CMakeLists.txt in our tracker:
https://youtrack.jetbrains.com/issue/CPP-270
Feel free to comment or upvote.
0
Comment actions Permalink

I'm not explicitly including the headers in a target however they are included the CMakeLists.txt using "include_directories".

If I try to extract a variable in these headers, I get the red tool tip error message "Selected element is not in the project".

0
Comment actions Permalink

Hi Chris.


For now the only way to add headers to CLion project is to add them to some target. We understand that this in not required by CMake, however there is no other way for the IDE to get required data otherwise.
0
Comment actions Permalink

Ah yes, this is what was in another project that works:


FILE(GLOB_RECURSE all_header_files . FOLLOW_SYMLINKS *.h)
add_custom_target(clion_headers_happy SOURCES ${all_header_files})

FILE(GLOB_RECURSE all_cpp_depend_files target FOLLOW_SYMLINKS *.cpp)
add_custom_target(clion_cpp_depend_happy SOURCES ${all_cpp_depend_files})


All good now :)

0

Please sign in to leave a comment.