Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the problem that protobuf cannot be used as a DEPS argument in cc… #2582

Merged
merged 2 commits into from
Jun 23, 2017

Conversation

Xreki
Copy link
Contributor

@Xreki Xreki commented Jun 23, 2017

Fix #2568
使用了#2569 中的测试代码paddle/framework/example.protopaddle/framework/example.cc
paddle/framework/CMakelist.txt中增加如下内容:

set(CUR_PROTO_GEN
      ${CMAKE_CURRENT_BINARY_DIR}/example.pb.h
      ${CMAKE_CURRENT_BINARY_DIR}/example.pb.cc)
set(PROTO_GEN
      ${PROTO_GEN}
      ${CUR_PROTO_GEN})
add_custom_command(OUTPUT ${CUR_PROTO_GEN}
      COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} 
      --cpp_out ${CMAKE_CURRENT_BINARY_DIR}
      --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/example.proto
      DEPENDS protobuf)

#protobuf_generate_cpp(example_proto_src example_proto_header example.proto)
cc_library(example_proto SRCS ${CMAKE_CURRENT_BINARY_DIR}/example.pb.cc)
include_directories(${CMAKE_BINARY_DIR})
cc_test(example_test SRCS example_test.cc DEPS example_proto protobuf)

注意,生成"*.pb.cc"和"*.pb.h"采用paddle/proto/CMakelist.txt中的方式, 是因为CMake系统自带的macro protobuf_generate_cpp存在以下问题:

  • Paddle在交叉编译和设置了PROTOBUF_ROOT时不会调用find_package(Protobuf),会出现如下错误:
CMake Error at paddle/framework/CMakeLists.txt:18 (protobuf_generate_cpp):
  Unknown CMake command "protobuf_generate_cpp".
  • protobuf_generate_cpp不能设置依赖关系,如果需要使用third_party目录下编译好的protoc,使用make -j12编译可能会出现出现错误:
make[2]: *** No rule to make target `../third_party/install/protobuf/bin/protoc', needed by `paddle/framework/example.pb.cc'.  Stop.
make[1]: *** [paddle/framework/CMakeFiles/example_proto.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有一点问题不确定。。如果没问题,就merge吧

MESSAGE(STATUS "Protobuf protoc executable: ${PROTOBUF_PROTOC_EXECUTABLE}")
MESSAGE(STATUS "Protobuf library: ${PROTOBUF_LIBRARY}")
MESSAGE(STATUS "Protobuf version: ${PROTOBUF_VERSION}")
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})

# Assuming that all the protobuf libraries are of the same type.
IF(${PROTOBUF_LIBRARY} MATCHES "${STATIC_LIBRARY_SUFFIX}$")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太清楚STATIC_LIBRARY_SUFFIX定义在哪?

https://cmake.org/cmake/help/v3.0/variable/CMAKE_STATIC_LIBRARY_SUFFIX.html
是这个变量么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦,这个是我定义在system.cmake里面的。cmake系统本身有定义这个变量吗,我看下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, 都替换成CMake系统变量了,诸如:

  • CMAKE_STATIC_LIBRARY_PREFIX
  • CMAKE_STATIC_LIBRARY_SUFFIX
  • ...

Copy link
Contributor

@gangliao gangliao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Xreki Xreki merged commit a21c881 into PaddlePaddle:develop Jun 23, 2017
@Xreki Xreki deleted the fix_protobuf_dependency branch November 14, 2018 02:37
heavengate pushed a commit to heavengate/Paddle that referenced this pull request Aug 16, 2021
* fix name of pretrain weights

* format, test=document_fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants