How to set a path prefix to be applied to all #include relative paths?

My workgroup uses CMake, and all the #include paths in our code are relative to a fixed folderpath X. For example, foo.cpp might #include "baz/foo.h" even though foo.cpp and foo.h are both in folder X/baz/. Is there a way to configure CLion to know about this so it will stop offering to add #include's for me?

If there is no way, where can I turn off this specific kind of assistance?

0
11 comments

Hi David.

Sorry for the delay.
If you have your header search paths configured via CMake, CLion shouldn't offer to correct the existing includes. Could you please attach a screenshot to show what behaviour is undesired for you?

0
I can't provide a screencap because the code is proprietary. But here's a description...

1) Tools > CMake > ChangeProjectRoot shows folder1/cmake

2) All of the code is under folder1/src/.../folder2/

3) A portion of class1.cpp...

#include "folder2/class1.h"
#include "folder2/class2.h"

#include "folder2/class3.h"

using std::string;
using std::map;

class Class1::Impl
{
public:
Class2 GetToken(const Class3 &word, double *result);
};

All of the Class's above are shown as unresolved, and putting the text cursor on "word" in the signature causes popup "? class Class3 from class3.h ?"
0

I think you did not add include dictories in CMakeLists.txt.
open CMakeLIsts.txt and add the following line:

include_directories("folder1/src/.../folder2")    //between the "" write down the directory of your header files

and in the source code, just use "class1.h"... no "folder2/class1.h"

hope this can help

0

I need to correct some of what I said. You pointed me to CMakeLists.txt; there are several in this repo and the top one is at folder1/. I just changed my cmake root to that, but it doesn't make a difference.

That file contains,

include("${SCRIPT_DIR}/someName.cmake")

and several later entries like:

add_subdirectory("src/library/")

I'd really prefer not to touch either the cmake config or the #include paths because this project is widely shared and not owned by me.

0

David,

Could you please specify do you have include_directories or target_include_directories commands in your CMakeLists.txt? If yes, what they contain?

0

Anna, the cmake file doesn't have the directives you mention. (And I would like to avoid modifying that file.)

...but some of the files loaded by folder1/CMakeLists.txt do have include_directories("${someName}" ${anotherName})

0

Can I provide any other helpful info?

0

David, sorry for the delay.

I've noticed you have your project root set to "folder1/cmake", although your root CMakeLists.txt file is located at "folder1/CMakeLists.txt". Have I got it right? Are there any particular reasons you've changed the project root? If no, could you please try to set project root to "folder1" and report the results?

0

Hi Anna. Earlier I reported, "there are several in this repo and the top one is at folder1/. I just changed my cmake root to that, but it doesn't make a difference." I just confirmed that that is my project root, and many class references are shown as not resolved.

0

David, it seems that include_directories in your CMake configuration are set in the way that CLion does not understand. We've not encountered similar issues recently so it is hard to say without knowing more details about project structure and how exactly include_directories are set. As a workaround you might try to disable auto-import pop-up via Editor | General | Auto-import. The pop-up with include suggestion won’t show up in that case, though you’ll still be able to invoke an auto-import when necessary using an intention action (Alt+Enter). Also could you please clarify if your project compiles successfully from CLion? Is it possible for you to provide the CMakeLists.txt files without the actual source code so we can take a look?

0

Yes, Run > Build does get to 100%.

It will take me a week or more to create an anonymized clone of the cmake files as they appear across the folder structure and send to you as a zip, but I do want to.

Thanks for the tip about how to disable "auto import". It's now much easier to see what's around the line of the caret.

0

Please sign in to leave a comment.