Context : One of the currently favored scenarios for the formation of globular clusters ( GCs ) with multiple stellar populations is that an initial massive stellar system forms ( ‘ first generation ’ , FG ) , subsequently giving rise to gaseous ejecta which is converted into a second generation ( SG ) of stars to form a GC . How such GCs with such FG and SG populations form and evolve , however , remains unclear . Aims : We therefore investigate , for the first time , the sequential formation processes of both FG and SG stars from star-forming massive gas clumps in gas-rich dwarf disk galaxies . Methods : We adopt a novel approach to resolve the two-stage formation of GCs in hydrodynamical simulations of dwarf galaxies . In the new simulations , new gas particles that are much less massive than their parent star particle are generated around each new star particle when the new star enters into the asymptotic giant branch ( AGB ) phase . Furthermore , much finer maximum time step width ( \sim 10 ^ { 5 } yr ) and smaller softening length ( \sim 2 pc ) are adopted for such AGB gas particles to properly resolve the ejection of gas from AGB stars and AGB feedback effects . Therefore , secondary star formation from AGB ejecta can be properly investigated in galaxy-scale simulations . Results : An FG stellar system can first form from a massive gas clump developing due to gravitational instability within its host gas-rich dwarf galaxy . Initially the FG stellar system is not a single massive cluster , but instead is composed of several irregular stellar clumps ( or filaments ) with a total mass larger than 10 ^ { 6 } M _ { \odot } . While the FG system is dynamically relaxing , gaseous ejecta from AGB stars can be gravitationally trapped by the FG system and subsequently converted into new stars to form a compact SG stellar system within the FG system . Interestingly , about 40 % of AGB ejecta is from stars that do not belong to the FG system ( ‘ external gas accretion ’ ) . FG and SG stellar systems have different amplitudes of internal rotation and V / \sigma . The mass-density ( M _ { SG } - \rho _ { SG } ) relation for SG stellar systems can be approximated as \rho _ { SG } \propto M _ { SG } ^ { 1.5 } . There can be a threshold total mass of GC host galaxies ( M _ { th } = [ 5 - 23 ] \times { 10 } ^ { 9 } M _ { \odot } ) beyond which the formation of GCs with compact SG stellar systems is possible . Both the initial baryonic mass fraction and the gas mass fraction in dwarfs are crucial parameters that determine whether or not GCs can contain multiple stellar populations . GCs with compact SG stellar systems are more likely to form in dwarf disks with larger gas mass fractions and higher surface mass densities . Formation of binary GCs with SGs and the subsequent GC merging are clearly seen in some models . The derived external gas-accretion process in FG systems initially consisting of stellar clumps will need to be investigated further in more sophisticated simulations . Conclusions :