I did a lot of work in this area. There are two solutions:
1) Use a package file and public import all modules via it. From this do some form of 'registration' in a module constructor. Using __traits(allMembers, retrieve the imports and with that the other modules. 2) Before compilation create a file that contains a list of all the module names.
I prefer 2 now days.