  We use a set of high-resolution hydrodynamical simulations of clusters of
galaxies to study the build-up of the intracluster light (ICL), an interesting
and likely significant component of their total stellar mass. Our sample of
groups and clusters includes AGN feedback and is of high enough resolution to
accurately resolve galaxy populations down to the smallest galaxies that are
expected to significantly contribute to the stellar mass budget. We describe
and test four different methods to identify the ICL in simulations, thereby
allowing us to assess the reliability of the measurements. For all of the
methods, we consistently find a very significant ICL stellar fraction (~45%)
which exceeds the values typically inferred from observations. However, we show
that this result is robust with respect to numerical resolution and integration
accuracy, remarkably insensitive to changes in the star formation model, and
almost independent of halo mass. It is also almost invariant when black hole
growth is included, even though AGN feedback successfully prevents excessive
overcooling in clusters and leads to a drastically improved agreement of the
simulated cluster galaxy population with observations. In particular, the
luminosities of central galaxies and the ages of their stellar populations are
much more realistic when including AGN. In the light of these findings, it
appears challenging to construct a simulation model that simultaneously matches
the cluster galaxy population and at the same time produces a low ICL
component. We find that intracluster stars are preferentially stripped in a
cluster's densest region from massive galaxies that fall into the cluster at
z>1. Surprisingly, some of the intracluster stars also form in the intracluster
medium inside cold gas clouds that are stripped out of infalling galaxies.
