You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sentencepiece.patch001 4.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. diff -Npur sentencepiece-0.1.92/src/CMakeLists.txt sentencepiece-0.1.92_bak/src/CMakeLists.txt
  2. --- sentencepiece-0.1.92/src/CMakeLists.txt 2020-06-08 16:25:01.000000000 +0800
  3. +++ sentencepiece-0.1.92_bak/src/CMakeLists.txt 2020-07-02 17:42:33.306933546 +0800
  4. @@ -11,6 +11,46 @@
  5. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6. # See the License for the specific language governing permissions and
  7. # limitations under the License.!
  8. +add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
  9. +
  10. +
  11. +function(protobuf_generate c_var h_var)
  12. + if(NOT ARGN)
  13. + message(SEND_ERROR "Error: ms_protobuf_generate() called without any proto files")
  14. + return()
  15. + endif()
  16. +
  17. + set(${c_var})
  18. + set(${h_var})
  19. +
  20. + find_program(PROTOC_EXE NAMES "protoc" PATHS ${PROTOBUF_INC}/../bin NO_DEFAULT_PATH)
  21. +
  22. + foreach(file ${ARGN})
  23. + get_filename_component(abs_file ${file} ABSOLUTE)
  24. + get_filename_component(file_name ${file} NAME_WE)
  25. + get_filename_component(file_dir ${abs_file} PATH)
  26. + file(RELATIVE_PATH rel_path ${CMAKE_CURRENT_SOURCE_DIR} ${file_dir})
  27. +
  28. + list(APPEND ${c_var} "${CMAKE_BINARY_DIR}/${file_name}.pb.cc")
  29. + list(APPEND ${h_var} "${CMAKE_BINARY_DIR}/${file_name}.pb.h")
  30. +
  31. + add_custom_command(
  32. + OUTPUT "${CMAKE_BINARY_DIR}/${file_name}.pb.cc"
  33. + "${CMAKE_BINARY_DIR}/${file_name}.pb.h"
  34. + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  35. + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}"
  36. + COMMAND ${PROTOC_EXE} -I${file_dir} --cpp_out=${CMAKE_BINARY_DIR} ${abs_file}
  37. + DEPENDS ${PROTOC_EXE} ${abs_file}
  38. + COMMENT "Running C++ protocol buffer compiler on ${file}" VERBATIM)
  39. + endforeach()
  40. +
  41. + set_source_files_properties(${${c_var}} ${${h_var}} PROPERTIES GENERATED TRUE)
  42. + set(${c_var} ${${c_var}} PARENT_SCOPE)
  43. + set(${h_var} ${${h_var}} PARENT_SCOPE)
  44. +
  45. +endfunction()
  46. +
  47. +
  48. if (SPM_USE_BUILTIN_PROTOBUF)
  49. set(SPM_PROTO_HDRS builtin_pb/sentencepiece.pb.h)
  50. @@ -52,12 +92,9 @@ if (SPM_USE_BUILTIN_PROTOBUF)
  51. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite)
  52. include_directories(builtin_pb)
  53. else()
  54. - find_package(Protobuf REQUIRED)
  55. - include_directories(${Protobuf_INCLUDE_DIRS})
  56. - protobuf_generate_cpp(SPM_PROTO_SRCS SPM_PROTO_HDRS sentencepiece.proto)
  57. - protobuf_generate_cpp(SPM_MODEL_PROTO_SRCS SPM_MODEL_PROTO_HDRS sentencepiece_model.proto)
  58. - set(PROTOBUF_LITE_SRCS "")
  59. - include_directories(${PROTOBUF_INCLUDE_DIR})
  60. + include_directories(${PROTOBUF_INC})
  61. + protobuf_generate(SPM_PROTO_SRCS SPM_PROTO_HDRS sentencepiece.proto)
  62. + protobuf_generate(SPM_MODEL_PROTO_SRCS SPM_MODEL_PROTO_HDRS sentencepiece_model.proto)
  63. endif()
  64. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  65. @@ -191,11 +228,13 @@ endif()
  66. add_library(sentencepiece-static STATIC ${SPM_SRCS})
  67. add_library(sentencepiece_train-static STATIC ${SPM_TRAIN_SRCS})
  68. -target_link_libraries(sentencepiece-static INTERFACE ${SPM_LIBS})
  69. +find_library(PROTO_LIB NAMES "libprotobuf.a" PATHS ${PROTOBUF_INC}/../lib NO_DEFAULT_PATH)
  70. +
  71. +target_link_libraries(sentencepiece-static INTERFACE ${PROTO_LIB} ${SPM_LIBS})
  72. target_link_libraries(sentencepiece_train-static INTERFACE sentencepiece-static ${SPM_LIBS})
  73. if (SPM_ENABLE_SHARED)
  74. - target_link_libraries(sentencepiece ${SPM_LIBS})
  75. + target_link_libraries(sentencepiece ${SPM_LIBS} ${PROTO_LIB})
  76. target_link_libraries(sentencepiece_train ${SPM_LIBS} sentencepiece)
  77. set(SPM_INSTALLTARGETS sentencepiece sentencepiece_train sentencepiece-static sentencepiece_train-static)
  78. set_target_properties(sentencepiece sentencepiece_train PROPERTIES SOVERSION 0 VERSION 0.0.0)
  79. @@ -265,7 +304,7 @@ install(TARGETS ${SPM_INSTALLTARGETS}
  80. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  81. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  82. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
  83. -install(FILES sentencepiece_trainer.h sentencepiece_processor.h
  84. +install(FILES sentencepiece_trainer.h sentencepiece_processor.h "${CMAKE_BINARY_DIR}/sentencepiece_model.pb.h"
  85. DESTINATION ${CMAKE_INSTALL_INCDIR})
  86. file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/data" data_dir)