diff --git a/CMakeLists.txt b/CMakeLists.txt index f68f769..8a9f567 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.12) project(AppImageQt5run) set(APP_NAME "appimage.qt5run") @@ -25,9 +25,9 @@ include_directories(SYSTEM ${QT_ROOT}/include) include_directories(SYSTEM ${QT_ROOT}/include/QtCore) link_directories(${QT_ROOT}/lib) -add_executable(${APP_NAME} QtInfo.cpp main.cpp) +add_executable(${APP_NAME} QtInfo.cpp LSBRelease.cpp main.cpp) target_link_libraries(${APP_NAME} -Wl,--rpath-link=${QT_ROOT}/lib -lQt5Core -ldl) add_custom_command(TARGET ${APP_NAME} POST_BUILD - COMMAND ${PATCH_ELF} --remove-needed libQt5Core.so.5 "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$/${APP_NAME}" + COMMAND ${PATCH_ELF} --remove-needed libQt5Core.so.5 "$" ) diff --git a/LSBRelease.cpp b/LSBRelease.cpp new file mode 100644 index 0000000..1e10413 --- /dev/null +++ b/LSBRelease.cpp @@ -0,0 +1,33 @@ +#include "LSBRelease.h" + +#include +#include + +LSBRelease::LSBRelease() { + FILE *fp = fopen("/etc/lsb-release", "rb"); + if (fp == nullptr) + return; + + char key[128]; + char value[128]; + + key[127] = value[127] = 0; + + while (fscanf(fp, "%127[^=]=%127[^\n]\n", key, value) == 2) { + if (strncmp(key, "DISTRIB_ID", 128) == 0) { + id = value; + } else if (strncmp(key, "DISTRIB_RELEASE", 128) == 0) { + release = value; + } else if (strncmp(key, "DISTRIB_CODENAME", 128) == 0) { + code_name = value; + } else if (strncmp(key, "DISTRIB_DESCRIPTION", 128) == 0) { + description = value; + if (description.front() == '"' && description.back() == '"') { + description.erase(0, 1); + description.pop_back(); + } + } + } + + fclose(fp); +} diff --git a/LSBRelease.h b/LSBRelease.h new file mode 100644 index 0000000..4c1ed85 --- /dev/null +++ b/LSBRelease.h @@ -0,0 +1,14 @@ +#ifndef LSBRELEASE_H +#define LSBRELEASE_H + +#include + +struct LSBRelease { + LSBRelease(); + std::string id{}; + std::string release{}; + std::string code_name{}; + std::string description{}; +}; + +#endif // LSBRELEASE_H diff --git a/QtInfo.cpp b/QtInfo.cpp index e029410..455fa56 100644 --- a/QtInfo.cpp +++ b/QtInfo.cpp @@ -41,8 +41,8 @@ Info QtInfo::getInfo(const std::string &appPath, const char *exe, bool debug) { bool use_system = false; FILE *always_local = fopen(std::string(appPath).append("/qt5.always_local").c_str(), "r"); if (always_local == nullptr) { - if (system_version > local_version) { - DBG("local Qt5 version is lower than system\nuse system (check dependencies)") << std::endl; + if (system_version >= local_version) { + DBG("local Qt5 version is lower than or equal to system\nuse system (check dependencies)") << std::endl; use_system = checkDeps(system_lib, exe, debug); if (debug) { if (use_system) { diff --git a/main.cpp b/main.cpp index 2c2cdcb..b6bff04 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,6 @@ +#include "LSBRelease.h" #include "QtInfo.h" + #include #include #include @@ -61,13 +63,19 @@ int main(int /*argc*/, char *argv[]) { c = std::toupper(c); } if (current_desktop.find("KDE") == std::string::npos && current_desktop.find("LXQT") == std::string::npos) { - setenv("QT_QPA_PLATFORMTHEME", "gtk2", 0); + char *qpa_theme = getenv("QT_QPA_PLATFORMTHEME"); + setenv("QT_QPA_PLATFORMTHEME", "gtk2", qpa_theme != nullptr && strncmp(qpa_theme, "appmenu-qt5", 11) == 0); if (debug) { std::cerr << "QT_QPA_PLATFORMTHEME=" << getenv("QT_QPA_PLATFORMTHEME") << std::endl; } } } + LSBRelease lsb_release; + if (!lsb_release.code_name.empty()) { + info.ld_path.push_back(':'); + info.ld_path.append(appPath).append("../lib_").append(lsb_release.code_name); + } setenv("LD_LIBRARY_PATH", info.ld_path.c_str(), 1); setenv("QT_PLUGIN_PATH", info.qt_plugins.c_str(), 1);