Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A script to copy Tensorflow headers to build custom C++ applications
# inspired by a part of:
# Assumes Tensorflow libraries and were built with Bazel,
# and the ${TF_ROOT}/tensorflow/contrib/makefile/ script was executed.
set -o nounset
set -o errexit
set -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# clean
rm -rf ${INSTALL_DIR}
mkdir -p ${INCLUDE_DIR}
mkdir -p ${LIB_DIR}
# copy the library to the install directory
cp ${SOURCE_DIR}/bazel-bin/tensorflow/ ${LIB_DIR}/ || exit 0
cp ${SOURCE_DIR}/bazel-bin/tensorflow/ ${LIB_DIR}/ || exit 0
# Copy the TF includes to $INSTALL_DIR/include/google and remove unneeded items:
mkdir -p ${INCLUDE_DIR}/google/tensorflow
cp -r ${SOURCE_DIR}/tensorflow ${INCLUDE_DIR}/google/tensorflow/
find ${INCLUDE_DIR}/google/tensorflow/tensorflow -type f ! -name "*.h" -delete
# Copy all generated files from bazel-genfiles:
cd ${SOURCE_DIR}/bazel-genfiles/
for f in $(find ${SOURCE_DIR}/ -name "*.h"); do cp --parents $f ${INCLUDE_DIR}/google/tensorflow/; done
cd ${DIR}
# Copy the third party Eigen 3 bindings
mkdir -p ${INCLUDE_DIR}/google/tensorflow/third_party
cp -r ${SOURCE_DIR}/third_party/eigen3 ${INCLUDE_DIR}/google/tensorflow/third_party
# Copy the Eigen 3 implementation
mkdir -p ${INSTALL_DIR}/include/eigen3
cp -r ${SOURCE_DIR}/tensorflow/contrib/makefile/downloads/eigen/Eigen \
${SOURCE_DIR}/tensorflow/contrib/makefile/downloads/eigen/unsupported \
# Copy protobuf includes
cp -r ${SOURCE_DIR}/tensorflow/contrib/makefile/downloads/protobuf/build/include/* ${INCLUDE_DIR}/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.