Skip to content

Commit 0a06b64

Browse files
committed
directly add_subdirectory(nanopb) from torch CMakeLists
currently torch/CMakeLists doesn't know how to find nanopb without some higher-level script (setup.py or build_all.sh) telling it where to look, which is an obstacle towards fully CMake-ifying libtorch.so. This change removes that dependency.
1 parent fed44cb commit 0a06b64

File tree

4 files changed

+5
-29
lines changed

4 files changed

+5
-29
lines changed

tools/cpp_build/build_all.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
set -ex
44
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
55
source $SCRIPTPATH/build_caffe2.sh
6-
source $SCRIPTPATH/build_nanopb.sh
76
source $SCRIPTPATH/build_libtorch.sh

tools/cpp_build/build_libtorch.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ cmake -DUSE_CUDA:BOOL=$USE_CUDA \
2222
-DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE \
2323
-DCMAKE_INSTALL_PREFIX:STRING=$INSTALL_PREFIX \
2424
-DCMAKE_INSTALL_MESSAGE=NEVER \
25+
-Dnanopb_BUILD_GENERATOR:BOOL=OFF \
26+
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON \
2527
-DVERBOSE:BOOL=${VERBOSE:-0} \
2628
-G "$GENERATE" \
2729
$PYTORCHPATH/torch

tools/cpp_build/build_nanopb.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

torch/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ find_library(CAFFE2_GPU_LIBRARY caffe2_gpu
3737
find_library(PROTOBUF_LIBRARY protobuf
3838
NAMES libprotobuf.a libprotobufd.a libprotobuf.lib libprotobufd.lib
3939
PATHS ${CAFFE2_BUILD_LIB_DIR} NO_DEFAULT_PATH)
40-
find_library(NANOPB_LIBRARY protobuf-nanopb
41-
PATHS ${NANOPB_BUILD_PATH} NO_DEFAULT_PATH)
40+
41+
add_subdirectory(../third_party/nanopb protobuf-nanopb)
4242

4343
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
4444
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
@@ -290,7 +290,7 @@ target_link_libraries(torch
290290
${TORCH_CUDA_LIBRARIES}
291291
${CAFFE2_LIBRARY}
292292
${PROTOBUF_LIBRARY}
293-
${NANOPB_LIBRARY}
293+
protobuf-nanopb
294294
)
295295
if(USE_CUDA)
296296
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")

0 commit comments

Comments
 (0)