I guess this can be done using a custom install script. This functionality already exists. You can tell the installer which parts of the base OS you need and which additional ports will need to be installed.
Have a look at
sysinstall(8) and
/usr/src/usr.bin/sysinstall/install.cfg.