Fixed the issue of concatinating paths for pkg-config
authorTaku Kudo <taku@google.com>
Sun, 21 Aug 2022 03:44:31 +0000 (12:44 +0900)
committerKentaro Hayashi <kenhys@xdump.org>
Mon, 21 Nov 2022 13:43:46 +0000 (13:43 +0000)
Signed-off-by: Kentaro Hayashi <kenhys@gmail.com>
Gbp-Pq: Name 0024-Fixed-the-issue-of-concatinating-paths-for-pkg-confi.patch

CMakeLists.txt
sentencepiece.pc.in
third_party/absl/flags/flag.cc
third_party/absl/flags/flag.h

index 78379a3276971dba01e5fcf5244743cc68cc1d08..382103bdd83d507f7bcbfe8282a7060de2d22552 100644 (file)
@@ -94,6 +94,30 @@ if (NOT DEFINED CMAKE_INSTALL_INCDIR)
   set(CMAKE_INSTALL_INCDIR include)
 endif()
 
+# SPDX-License-Identifier: (MIT OR CC0-1.0)
+# Copyright 2020 Jan Tojnar
+# https://github.com/jtojnar/cmake-snips
+#
+# Modelled after Python’s os.path.join
+# https://docs.python.org/3.7/library/os.path.html#os.path.join
+# Windows not supported
+function(join_paths joined_path first_path_segment)
+    set(temp_path "${first_path_segment}")
+    foreach(current_segment IN LISTS ARGN)
+        if(NOT ("${current_segment}" STREQUAL ""))
+            if(IS_ABSOLUTE "${current_segment}")
+                set(temp_path "${current_segment}")
+            else()
+                set(temp_path "${temp_path}/${current_segment}")
+            endif()
+        endif()
+    endforeach()
+    set(${joined_path} "${temp_path}" PARENT_SCOPE)
+endfunction()
+
+join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
+join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
+
 configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "config.h")
 configure_file("${PROJECT_SOURCE_DIR}/sentencepiece.pc.in" "sentencepiece.pc" @ONLY)
 
index ac7fef68c3958a51e125442be0278ee34c6daec2..6a5ba56d5fa17a992bb58474ad439fe485dad271 100644 (file)
@@ -1,7 +1,7 @@
 prefix=@prefix@
 exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
+libdir=@libdir_for_pc_file@
+includedir=@includedir_for_pc_file@
 
 Name: @PROJECT_NAME@
 Description: Unsupervised text tokenizer and detokenizer for Neural Network-based text generation.
index 8e99c0dde99c6c3696b01df2c1f40d5da61345aa..5d6642a9352ff4c4315935647d8649032a8c7a70 100644 (file)
@@ -61,8 +61,8 @@ struct FlagFunc {
 
 namespace {
 
-using FlagMap = std::map<std::string, FlagFunc *>;
-using FlagList = std::vector<FlagFunc *>;
+using FlagMap = std::map<std::string, std::shared_ptr<FlagFunc>>;
+using FlagList = std::vector<std::shared_ptr<FlagFunc>>;
 
 FlagMap *GetFlagMap() {
   static auto *flag_map = new FlagMap;
@@ -111,7 +111,7 @@ std::string PrintHelp(const char *programname) {
   os << PACKAGE_STRING << "\n\n";
   os << "Usage: " << programname << " [options] files\n\n";
 
-  for (const auto *func : *GetFlagList()) {
+  for (auto func : *GetFlagList()) {
     os << "   --" << func->name << " (" << func->help << ")";
     os << "  type: " << func->type << " default: " << func->default_value
        << '\n';
@@ -123,7 +123,7 @@ std::string PrintHelp(const char *programname) {
 }
 }  // namespace
 
-void RegisterFlag(const std::string &name, FlagFunc *func) {
+void RegisterFlag(const std::string &name, std::shared_ptr<FlagFunc> func) {
   GetFlagList()->emplace_back(func);
   GetFlagMap()->emplace(name, func);
 }
@@ -140,7 +140,7 @@ Flag<T>::Flag(const char *name, const char *type, const char *help,
   func_->set_value = [this](const std::string &value) {
     this->set_value_as_str(value);
   };
-  RegisterFlag(name, func_.get());
+  RegisterFlag(name, func_);
 }
 
 template <typename T>
@@ -219,4 +219,14 @@ std::vector<char *> ParseCommandLine(int argc, char *argv[]) {
 
   return output_args;
 }
+
+void CleanupFlags() {
+  static bool is_shutdown = false;
+  if (!is_shutdown) {
+    delete internal::GetFlagList();
+    delete internal::GetFlagMap();
+    is_shutdown = true;
+  }
+}
+
 }  // namespace absl
index e540edfee44eae8decef5bb33e47dcfa1c6ddea5..c52235835c326ac2c30bfb82946fa786eb807f2e 100644 (file)
@@ -24,7 +24,8 @@ namespace absl {
 namespace internal {
 struct FlagFunc;
 
-void RegisterFlag(const std::string &name, FlagFunc *func);
+void RegisterFlag(const std::string &name, std::shared_ptr<FlagFunc> func);
+
 }  // namespace internal
 
 template <typename T>
@@ -39,7 +40,7 @@ class Flag {
 
  private:
   T value_;
-  std::unique_ptr<internal::FlagFunc> func_;
+  std::shared_ptr<internal::FlagFunc> func_;
 };
 
 template <typename T>
@@ -52,6 +53,11 @@ void SetFlag(Flag<T> *flag, const V &v) {
   const T value(v);
   flag->set_value(value);
 }
+
+#define HAS_ABSL_CLEANUP_FLAGS
+
+void CleanupFlags();
+
 }  // namespace absl
 
 #define ABSL_FLAG(Type, name, defautl_value, help) \