Clion 2020.3 for MacOSX - "This file does not belong to any project target", despite it being listed in the CMakeLists.txt

The issue I'm facing is two-sided. One where Unreal Engine might not be generating my project CLion project correctly. But the other side is: what does it require on CLion's side to allow code insight to function.

I have read so many posts about this ("This file does not belong to any project target") now, the solution is always the same (add it to the CMakeLists.txt and/or renew caches), but this doesn't seem to help me in this case:
So I followed the guides* on how to setup Unreal Engine 4.25.4 with MacOSX C2020.3 CLion. This gives me a CLion project. Compilation works fine, so it's operable.

*Guides:
https://blog.jetbrains.com/clion/2016/10/clion-and-ue4/
https://medium.com/@mccubbin/ue4-unreal-engine-4-clion-setup-for-mac-635d1af78d8 

However, one particular header is found by the inspect functionality of CLion and it's making coding impossible. The comments on this post show I'm not alone on this:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006705279-CLion-2019-3-w-UE4-4-23-1

I burned so many hours now on solving the problem. I got a lot wiser but still didn't get to a solution.

Situation
When generating the CLion project from Unreal Engine, a CMakeLists.txt file is created which points to a lot of other .cmake files that hold includes.

Unreal will produce another generated file for each new cpp class when the CMake files are constructed:
For example, MainCharacter.cpp adds MainCharacter.gen.cpp
MainCharacter.h creates MainCharacter.generated.h
These generated header files are understood fine by CLion, despite that they are not explicitly mentioned in the CMake files. The way they get included is through a CMake include_directories() directive.

So far so good, but there is another file that holds a lot of macros (mainly #define), called Definitions.myproject.h
Whatever I try, this file does not get detected by CLion. They are not explicitly mentioned in the CMake file, nor is its folder, but they do get scoped in several .d files.

The executable is setup like so:

add_executable(FakeTarget ${ENGINE_HEADER_FILES} ${ENGINE_SOURCE_FILES} ${ENGINE_CSHARP_FILES} ${ENGINE_SHADER_FILES} ${ENGINE_CONFIG_FILES} ${PROJECT_HEADER_FILES} ${PROJECT_SOURCE_FILES} ${PROJECT_CSHARP_FILES} ${PROJECT_SHADER_FILES} ${PROJECT_CONFIG_FILES})


After each attempt of changing the CMake file I run:

  • Tools > CMake > Reset Cache and Reload Project
  • File > Invalidate Caches / Restart...

This is what I've tried to solve the problem

  • Explicitly adding the folder that contains Definitions.myproject.h to the cmake file using an include_directories() directive.
  • Explicitly adding the header to the cmake file that lists all of the included headers $PROJECT_HEADER_FILES
  • Right-click in the project hierarchy and choose "mark directory as ..." > "Project Sources and Headers"
  • Copy the Definitions.myproject.h to the source directory add that header to the included headers $PROJECT_HEADER_FILES

The only thing that works is to add an #include macro on each file that requires the definitions (which is almost all of them)

#include "Definitions.myproject.h"

This only helps you on your own files, but since most any type inherits from another, you'll get the problem on the engine files my classes inherit from. It's perhaps also good to point out that opening the inherited classes cpp, CLion shows "This file does not belong to any project target, code insight features might not work properly.".This is however not reality. To follow a specific file:

/Users/Shared/Epic\ Games/UE_4.25/Engine/Source/Runtime/Engine/Classes/GameFramework/Character.h 

This file gets explicitly added to cmake-headers-ue4.cmake through a set directive

set(ENGINE_HEADER_FILES 
"/Users/Shared/Epic\ Games/UE_4.25/Engine/Source/Runtime/Engine/Classes/GameFramework/Character.h"
)

In CmakeLists.txt this file is added as an included:

include("/Users/paulvanvulpen/dev/git/private/unreal/darksouls/Intermediate/ProjectFiles/cmake-headers-ue4.cmake")

And to the executable through the add_executable directive

add_executable(FakeTarget ${ENGINE_HEADER_FILES} ${ENGINE_SOURCE_FILES} ${ENGINE_CSHARP_FILES} ${ENGINE_SHADER_FILES} ${ENGINE_CONFIG_FILES} ${PROJECT_HEADER_FILES} ${PROJECT_SOURCE_FILES} ${PROJECT_CSHARP_FILES} ${PROJECT_SHADER_FILES} ${PROJECT_CONFIG_FILES})


So why doesn't code insight work? What can I do?

0

Please sign in to leave a comment.