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)
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.
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;
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';
}
} // 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);
}
func_->set_value = [this](const std::string &value) {
this->set_value_as_str(value);
};
- RegisterFlag(name, func_.get());
+ RegisterFlag(name, func_);
}
template <typename T>
return output_args;
}
+
+void CleanupFlags() {
+ static bool is_shutdown = false;
+ if (!is_shutdown) {
+ delete internal::GetFlagList();
+ delete internal::GetFlagMap();
+ is_shutdown = true;
+ }
+}
+
} // 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>
private:
T value_;
- std::unique_ptr<internal::FlagFunc> func_;
+ std::shared_ptr<internal::FlagFunc> func_;
};
template <typename T>
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) \