Skip to content

Commit db7768b

Browse files
committed
Install protobuf version compatible with the current TensorFlow version
1 parent 74aed59 commit db7768b

3 files changed

Lines changed: 30 additions & 13 deletions

File tree

tensorflow_cc/CMakeLists.txt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ option(REQUIRE_CUDA "Make sure to find and use CUDA (implies ALLOW_CUDA)." OFF)
1111
set(LOCAL_RAM_RESOURCES 4096 CACHE STRING "The amount of local RAM resources passed to bazel scheduler (e.g., 4096).")
1212
set(LOCAL_CPU_RESOURCES HOST_CPUS CACHE STRING "The amount of local CPU cores passed to bazel scheduler (e.g., 2).")
1313
set(TENSORFLOW_TAG "v${version}" CACHE STRING "The tensorflow release tag to be checked out (default v${version}).")
14-
option(SYSTEM_PROTOBUF "Link to system protobuf." OFF)
14+
option(INSTALL_PROTOBUF "Install protobuf compatible with tensorflow version." OFF)
1515
set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard for building and linking the library (e.g., 14).")
1616

1717
# -------------
@@ -32,6 +32,9 @@ configure_file("cmake/build_tensorflow.sh.in" "build_tensorflow.sh" @ONLY)
3232
# ----------------------------------------------
3333

3434
include(TensorflowBase)
35+
if(INSTALL_PROTOBUF)
36+
include(ProtobufExternal)
37+
endif()
3538

3639
# ------------------------------
3740
# Define Tensorflow_CC Interface
@@ -40,6 +43,10 @@ include(TensorflowBase)
4043
add_library(tensorflow_cc INTERFACE)
4144
target_compile_features(tensorflow_cc INTERFACE "cxx_std_${CMAKE_CXX_STANDARD}")
4245

46+
if(INSTALL_PROTOBUF)
47+
add_dependencies(tensorflow_cc protobuf-external)
48+
endif()
49+
4350
# The include folders are sometimes contained under bazel-bin/bin/ and sometimes just bazel-bin.
4451
target_include_directories(
4552
tensorflow_cc INTERFACE
@@ -53,17 +60,6 @@ target_link_libraries(
5360
"${CMAKE_INSTALL_PREFIX}/lib/libtensorflow_cc.so.${PROJECT_VERSION_MAJOR}"
5461
dl pthread
5562
)
56-
if(SYSTEM_PROTOBUF)
57-
find_package(Protobuf REQUIRED)
58-
target_include_directories(
59-
tensorflow_cc INTERFACE
60-
"${Protobuf_INCLUDE_DIRS}"
61-
)
62-
target_link_libraries(
63-
tensorflow_cc INTERFACE
64-
"${Protobuf_LIBRARIES}"
65-
)
66-
endif()
6763

6864
# ----------------------------------------
6965
# Configure CMake Config and Version Files
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set(PROTOBUF_ARCHIVE https://github.com/protocolbuffers/protobuf/archive/v3.9.2.zip)
2+
3+
ExternalProject_Add(
4+
protobuf-external
5+
PREFIX protobuf
6+
URL "${PROTOBUF_ARCHIVE}"
7+
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf"
8+
CMAKE_CACHE_ARGS
9+
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
10+
"-Dprotobuf_BUILD_TESTS:BOOL=OFF"
11+
"-Dprotobuf_BUILD_EXAMPLES:BOOL=OFF"
12+
"-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}"
13+
SOURCE_SUBDIR cmake
14+
BUILD_ALWAYS 1
15+
STEP_TARGETS build
16+
INSTALL_COMMAND ""
17+
)
18+
19+
install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/protobuf/cmake_install.cmake")
20+

tensorflow_cc/cmake/TensorflowBase.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ ExternalProject_Add(
1111
BUILD_IN_SOURCE 1
1212
UPDATE_COMMAND ""
1313
CONFIGURE_COMMAND ""
14-
BUILD_COMMAND "${CMAKE_CURRENT_BINARY_DIR}/build_tensorflow.sh"
14+
BUILD_COMMAND echo "*" > "${CMAKE_CURRENT_BINARY_DIR}/tensorflow/.bazelversion"
15+
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/build_tensorflow.sh"
1516
INSTALL_COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/cmake/copy_links.sh" bazel-bin
1617
# The include folders are sometimes contained under bazel-bin/bin/ and sometimes just bazel-bin.
1718
# Later, we include both so let's make sure they both exist so that CMake does not complain.

0 commit comments

Comments
 (0)