When charging batteries, from any source, it's important to be able to measure the voltage of the target battery, and control the current going into the battery (by lowering the voltage.)
You can then set up the right way (profile) to charge the battery based on how many cells, what cell type, etc.
The easiest way to do that these days is to build a switching DC/DC converter to get the voltage to where you want, use a current sensor on the output of the converter, and make the converter controllable from a microcontroller (typically by using a digital potentiometer or similar tied into the feedback voltage divider of the DC/DC converter circuit.)
You then program the microcontroller to provide the right voltage and current variations for the battery you are charging.