Assuming your recipe will be almost identical in the CPU and GPU cases, the intended solution for this use-case is to create a recipe with build variants.
For your use-case, you probably don't need to read through all of the documentation. Here's a simple (but complete) example.
First, create conda_build_config.yaml in your recipe directory, and define a variable and list each of the possible values it can have. This instructs conda-build to build your recipe TWICE -- once for each of the values you listed.
Also, that variable can be used in meta.yaml, within selectors and jinja templates.
In this silly example, we'll pretend our package should depend on EITHER zlib or xz, but not both. We'll select between the two using a variable named foo.
recipe/
├── build.sh
├── conda_build_config.yaml
└── meta.yaml
# recipe/conda_build_config.yaml
foo:
- bar
- baz
# recipe/meta.yaml
package:
name: mypackage-{{ foo }}
version: 0.1
requirements:
run:
- zlib # [foo=='bar']
- xz # [foo=='baz']
Now try building the recipe:
conda build recipe
Notice that it builds both "variants". Near the end the output, it prints:
# If you want to upload package(s) to anaconda.org later, type:
anaconda upload /opt/miniconda/conda-bld/osx-64/package-bar-0.1-h11ff1f9_0.tar.bz2
anaconda upload /opt/miniconda/conda-bld/osx-64/package-baz-0.1-he38177a_0.tar.bz2
So in your case, use a variable to switch between the cpu and gpu versions of your package. In your recipe requirements, select the particular version of tensorflow you need using a selector as shown above.
Also note that the variable you defined in conda_build_config.yaml is available as an environment variable in build.sh, in case you need to run different build commands in each case.
# recipe/build.sh
echo "Now building variant: ${foo}"