As of format version 3 of the package manifest the build_type tag supports a condition attribute (see REP 149) which allows you to specify two different build types - e.g. one for ROS 1 and another for ROS 2.