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?
请先登录再写评论。
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?
1) Tools > CMake > ChangeProjectRoot shows folder1/cmake
2) All of the code is under folder1/src/.../folder2/
3) A portion of class1.cpp...
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 ?"
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
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.
David,
Could you please specify do you have include_directories or target_include_directories commands in your CMakeLists.txt? If yes, what they contain?
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})
Can I provide any other helpful info?
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?
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.
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?
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.