Ok, solved this:
In MyProject.build.cs I added the following lines:
PrivateDependencyModuleNames.AddRange(new string[] { "CustomMeshComponent" });
PrivateIncludePathModuleNames.AddRange(new string[] { "CustomMeshComponent" });
And then in the file which wanted to use this custom mesh component it was enough to include it like that:
#include "CustomMeshComponent.h"