API macro not recognised for CLion on Mac for Unreal 4.25.4

Hi fellow devs, I’ve been trying to set up a project for CLion on a Mac, using Unreal 4.25.4. The problem I’m running into is that the ${PROJECTNAME}_API macro is not recognised. As a result, CLion marks nearly all classes in the project as having an invalid type.This API macro is defined in a file called Definitions.${PROJECTNAME}.h and it lives in Intermediate/Build/Development/${PROJECTNAME}

The ${PROJECTNAME}EDITOR | DEBUG Target compiles just fine.

Also, on startup of CLion I get a tooltip warning saying "Some source files are located outside of CMakeLists.txt directory. You can change the project root or ignore this in future.

How I went about setting up the project:

  • Open Unreal 4.25.4
  • Create a new empty game project
  • in the Editor Settings > Source Code, set the Source Code Editor to CLion.
  • Create a C++ Class in C++\ /Classes/$PROJECTNAME
  • Choose File > Refresh CLion Project (Or I think it said ‘generate’ the first time).
  • Close unreal
  • Open unreal again and note that it complains about a missing module called $PROJECTNAME
  • I’ll let it fix it.
  • Choose File > Open CLion
  • After all the symbols have been found, I open the C++ file in CLion
  • Now I notice the error.
  • Choose ${PROJECTNAME}EDITOR | DEBUG as the target and build that.
  • The project compiles without issues. The errors remain.

I can’t seem to find a clean way of solving this. Does anyone have experience with this issue?

Perhaps good to add that the above is only a symptom. As soon as I fix the problem by redefining the macros and including them, there are over 20 more problems waiting. It all comes down that many files that have dependencies to them are described by CLion as “not belonging to a target”, even though they are.

For whoever finds this in the future. One way to make it somewhat work is to add the following to the bottom of your CMakeLists.txt file:

target_precompile_headers(FakeTarget PUBLIC ${ENGINE_HEADER_FILES})
Remove the ${ENGINE_HEADER_FILES} from the add_executable directive.

beware though that “Resolving Reference…” can take up to 3 minutes now. (I’d be grateful if someone could post a solution for that).

For Mac I think it’s best to stick with XCode until a better alternative is provided.