• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff -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
49 if (SPM_USE_BUILTIN_PROTOBUF)
50   set(SPM_PROTO_HDRS builtin_pb/sentencepiece.pb.h)
51@@ -52,12 +92,9 @@ if (SPM_USE_BUILTIN_PROTOBUF)
52   include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/protobuf-lite)
53   include_directories(builtin_pb)
54 else()
55-  find_package(Protobuf REQUIRED)
56-  include_directories(${Protobuf_INCLUDE_DIRS})
57-  protobuf_generate_cpp(SPM_PROTO_SRCS SPM_PROTO_HDRS sentencepiece.proto)
58-  protobuf_generate_cpp(SPM_MODEL_PROTO_SRCS SPM_MODEL_PROTO_HDRS sentencepiece_model.proto)
59-  set(PROTOBUF_LITE_SRCS "")
60-  include_directories(${PROTOBUF_INCLUDE_DIR})
61+  include_directories(${PROTOBUF_INC})
62+  protobuf_generate(SPM_PROTO_SRCS  SPM_PROTO_HDRS sentencepiece.proto)
63+  protobuf_generate(SPM_MODEL_PROTO_SRCS  SPM_MODEL_PROTO_HDRS sentencepiece_model.proto)
64 endif()
65
66 include_directories(${CMAKE_CURRENT_BINARY_DIR})
67@@ -191,11 +228,13 @@ endif()
68 add_library(sentencepiece-static STATIC ${SPM_SRCS})
69 add_library(sentencepiece_train-static STATIC ${SPM_TRAIN_SRCS})
70
71-target_link_libraries(sentencepiece-static INTERFACE ${SPM_LIBS})
72+find_library(PROTO_LIB NAMES "libprotobuf.a" PATHS ${PROTOBUF_INC}/../lib NO_DEFAULT_PATH)
73+
74+target_link_libraries(sentencepiece-static INTERFACE ${PROTO_LIB} ${SPM_LIBS})
75 target_link_libraries(sentencepiece_train-static INTERFACE sentencepiece-static ${SPM_LIBS})
76
77 if (SPM_ENABLE_SHARED)
78-  target_link_libraries(sentencepiece ${SPM_LIBS})
79+  target_link_libraries(sentencepiece ${SPM_LIBS} ${PROTO_LIB})
80   target_link_libraries(sentencepiece_train ${SPM_LIBS} sentencepiece)
81   set(SPM_INSTALLTARGETS sentencepiece sentencepiece_train sentencepiece-static sentencepiece_train-static)
82   set_target_properties(sentencepiece sentencepiece_train PROPERTIES SOVERSION 0 VERSION 0.0.0)
83@@ -265,7 +304,7 @@ install(TARGETS ${SPM_INSTALLTARGETS}
84   RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
85   LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
86   ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
87-install(FILES sentencepiece_trainer.h sentencepiece_processor.h
88+install(FILES sentencepiece_trainer.h sentencepiece_processor.h "${CMAKE_BINARY_DIR}/sentencepiece_model.pb.h"
89   DESTINATION ${CMAKE_INSTALL_INCDIR})
90
91 file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/data" data_dir)