From de4715cd864043368707bb7d6b81dd059a3925ce Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sat, 8 Jun 2024 20:29:28 +0200 Subject: [PATCH] Add support for installing the client and the locales --- client/CMakeLists.txt | 6 ++++++ client/asset.cpp | 33 +++++++++++++++++++++++++++++---- client/asset.h | 1 + 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 323208cb..160b36c7 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -139,6 +139,10 @@ target_compile_options(wivrn PRIVATE -Wno-missing-field-initializers -Wno-unused target_include_directories(wivrn PRIVATE .) +if(NOT ANDROID) + install(TARGETS wivrn) +endif() + target_link_libraries(wivrn simdjson wivrn-common wivrn-external) if (CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -196,6 +200,8 @@ foreach(PO_DIR IN LISTS PO_DIRS) DEPENDS ${PO_FILE}) set(MO_FILES ${MO_FILES} ${MO_FILE}) + install(FILES ${MO_FILE} DESTINATION ${CMAKE_INSTALL_DATADIR}/locale/${LANG}/LC_MESSAGES) + endforeach() add_custom_target(translations ALL DEPENDS ${MO_FILES}) diff --git a/client/asset.cpp b/client/asset.cpp index fd94baa4..efb578a4 100644 --- a/client/asset.cpp +++ b/client/asset.cpp @@ -58,16 +58,28 @@ asset::~asset() #else +static std::filesystem::path get_exe_path() +{ + // Linux only: see https://stackoverflow.com/a/1024937 + return std::filesystem::read_symlink("/proc/self/exe"); +} + static std::filesystem::path get_asset_root() { const char * path = std::getenv("WIVRN_ASSET_ROOT"); if (path && strcmp(path, "")) return path; - // Linux only: see https://stackoverflow.com/a/1024937 - auto exe = std::filesystem::read_symlink("/proc/self/exe"); + return get_exe_path().parent_path().parent_path() / "share" / "wivrn" / "assets"; +} - return exe.parent_path().parent_path() / "share" / "wivrn" / "assets"; +static std::filesystem::path get_locale_root() +{ + const char * path = std::getenv("WIVRN_LOCALE_ROOT"); + if (path && strcmp(path, "")) + return path; + + return get_exe_path().parent_path().parent_path() / "share" / "locale"; } std::filesystem::path asset::asset_root() @@ -76,6 +88,12 @@ std::filesystem::path asset::asset_root() return root; } +std::filesystem::path asset::locale_root() +{ + static std::filesystem::path root = get_locale_root(); + return root; +} + asset::asset(const std::filesystem::path & path) { assert(path.is_relative()); @@ -85,7 +103,14 @@ asset::asset(const std::filesystem::path & path) spdlog::debug("Loading file asset {}", path.string()); - bytes = utils::read_whole_file(asset_root() / path); + if (path.native().starts_with("locale/")) + { + bytes = utils::read_whole_file(locale_root() / path.native().substr(7)); + } + else + { + bytes = utils::read_whole_file(asset_root() / path); + } } #endif diff --git a/client/asset.h b/client/asset.h index ed4c7432..f3866a2c 100644 --- a/client/asset.h +++ b/client/asset.h @@ -35,6 +35,7 @@ class asset std::span bytes; #else static std::filesystem::path asset_root(); + static std::filesystem::path locale_root(); std::vector bytes; #endif