Skip to content

Commit

Permalink
Added LSBRelease patching
Browse files Browse the repository at this point in the history
Add lsb release code name to the LD_LIBRARY_PATH
Use local Qt library only when is greater than system
  • Loading branch information
sandman7920 committed Jul 22, 2021
1 parent d98683f commit 6f55ca6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 2.8.12)
project(AppImageQt5run)

set(APP_NAME "appimage.qt5run")
Expand All @@ -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}/$<CONFIG>/${APP_NAME}"
COMMAND ${PATCH_ELF} --remove-needed libQt5Core.so.5 "$<TARGET_FILE:${APP_NAME}>"
)
33 changes: 33 additions & 0 deletions LSBRelease.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "LSBRelease.h"

#include <cstdio>
#include <cstring>

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);
}
14 changes: 14 additions & 0 deletions LSBRelease.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef LSBRELEASE_H
#define LSBRELEASE_H

#include <string>

struct LSBRelease {
LSBRelease();
std::string id{};
std::string release{};
std::string code_name{};
std::string description{};
};

#endif // LSBRELEASE_H
4 changes: 2 additions & 2 deletions QtInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "LSBRelease.h"
#include "QtInfo.h"

#include <cstring>
#include <iostream>
#include <string>
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6f55ca6

Please sign in to comment.