From 460d15b31d9e559bb1fc017552b6e55386278202 Mon Sep 17 00:00:00 2001 From: Taku Kudo Date: Sun, 21 Aug 2022 12:44:31 +0900 Subject: [PATCH] Fixed the issue of concatinating paths for pkg-config --- CMakeLists.txt | 24 ++++++++++++++++++++++++ sentencepiece.pc.in | 4 ++-- third_party/absl/flags/flag.cc | 20 +++++++++++++++----- third_party/absl/flags/flag.h | 10 ++++++++-- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78379a3..382103b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/sentencepiece.pc.in b/sentencepiece.pc.in index ac7fef6..6a5ba56 100644 --- a/sentencepiece.pc.in +++ b/sentencepiece.pc.in @@ -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. diff --git a/third_party/absl/flags/flag.cc b/third_party/absl/flags/flag.cc index 8e99c0d..5d6642a 100644 --- a/third_party/absl/flags/flag.cc +++ b/third_party/absl/flags/flag.cc @@ -61,8 +61,8 @@ struct FlagFunc { namespace { -using FlagMap = std::map; -using FlagList = std::vector; +using FlagMap = std::map>; +using FlagList = std::vector>; 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 func) { GetFlagList()->emplace_back(func); GetFlagMap()->emplace(name, func); } @@ -140,7 +140,7 @@ Flag::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 @@ -219,4 +219,14 @@ std::vector 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 diff --git a/third_party/absl/flags/flag.h b/third_party/absl/flags/flag.h index e540edf..c522358 100644 --- a/third_party/absl/flags/flag.h +++ b/third_party/absl/flags/flag.h @@ -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 func); + } // namespace internal template @@ -39,7 +40,7 @@ class Flag { private: T value_; - std::unique_ptr func_; + std::shared_ptr func_; }; template @@ -52,6 +53,11 @@ void SetFlag(Flag *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) \