I think there is a bit of misconception with what SLAM does, just remember that SLAM stands for; Simultaneous Localization and Mapping, what you want is to explore the map (autonomously of course) so that while you explore it the map is built up, then the key term here is "exploration" (this is not a SLAM business). On the internet you can find many alternatives to explore environments, among the most popular you can find rrt_exploration, frontier_exploration and ros2_explorer.
Regarding going home when the map is finished, it is a bit difficult to answer since you must define or the library/package you use certain metrics with which you can consider that the map is complete.
I hope this answer sheds some light on your question.