One solution I can think of is to create a custom target that generates B.tar.gz and then uses the install command to add the generated B.tar.gz Below is an example of the CMakeLists.txt file that I used to create the desired result.
cmake_minimum_required(VERSION 2.8) project(pack_multiple_example)
source share