[education/rkward] rkward/rbackend: Calculate relative installation paths to backend process and backend library in cmake

Thomas Friedrichsmeier null at kde.org
Thu Jun 20 21:22:41 BST 2024


Git commit 476578ef8c3bf94edd9be3b96fc3a61583cbaaaa by Thomas Friedrichsmeier.
Committed on 20/06/2024 at 20:22.
Pushed by tfry into branch 'master'.

Calculate relative installation paths to backend process and backend library in cmake

M  +6    -0    rkward/rbackend/CMakeLists.txt
M  +2    -3    rkward/rbackend/rkfrontendtransmitter.cpp

https://invent.kde.org/education/rkward/-/commit/476578ef8c3bf94edd9be3b96fc3a61583cbaaaa

diff --git a/rkward/rbackend/CMakeLists.txt b/rkward/rbackend/CMakeLists.txt
index be7004d2e..7e580bb8d 100644
--- a/rkward/rbackend/CMakeLists.txt
+++ b/rkward/rbackend/CMakeLists.txt
@@ -44,6 +44,9 @@ SET (
 )
 
 ADD_LIBRARY(rbackend STATIC ${rbackend_frontend_SRCS} ${rbackend_shared_SRCS})
+SET(REL_PATH_TO_LIBEXEC ${KDE_INSTALL_LIBEXECDIR})
+CMAKE_PATH(RELATIVE_PATH REL_PATH_TO_LIBEXEC BASE_DIRECTORY ${KDE_INSTALL_BINDIR})
+TARGET_COMPILE_DEFINITIONS(rbackend PUBLIC -DREL_PATH_TO_LIBEXEC="${REL_PATH_TO_LIBEXEC}")
 TARGET_COMPILE_DEFINITIONS(rbackend PUBLIC -DR_EXECUTABLE="${R_EXECUTABLE}")
 TARGET_LINK_LIBRARIES(rbackend rkgraphicsdevice.frontend Qt6::Widgets KF6::TextEditor KF6::WindowSystem)
 
@@ -55,6 +58,9 @@ IF(${DLOPEN_RLIB})
   TARGET_LINK_LIBRARIES(rkward.rbackend.lib rkgraphicsdevice.backend ${CMAKE_THREAD_LIBS_INIT} Qt6::Network Qt6::Core KF6::I18n)
   TARGET_COMPILE_DEFINITIONS(rkward.rbackend.lib PUBLIC RK_DLOPEN_LIBRSO)
   TARGET_COMPILE_DEFINITIONS(rbackend PUBLIC RK_DLOPEN_LIBRSO)
+  SET(REL_PATH_TO_LIB ${KDE_INSTALL_LIBDIR})
+  CMAKE_PATH(RELATIVE_PATH REL_PATH_TO_LIB BASE_DIRECTORY ${KDE_INSTALL_BINDIR})
+  TARGET_COMPILE_DEFINITIONS(rbackend PUBLIC -DREL_PATH_TO_LIB="${REL_PATH_TO_LIB}")
   INSTALL(TARGETS rkward.rbackend.lib DESTINATION ${KDE_INSTALL_LIBDIR})
   IF(APPLE)
     TARGET_LINK_LIBRARIES(rkward.rbackend.lib "-framework CoreFoundation")
diff --git a/rkward/rbackend/rkfrontendtransmitter.cpp b/rkward/rbackend/rkfrontendtransmitter.cpp
index 76c954249..0d16d11fb 100644
--- a/rkward/rbackend/rkfrontendtransmitter.cpp
+++ b/rkward/rbackend/rkfrontendtransmitter.cpp
@@ -208,7 +208,7 @@ void RKFrontendTransmitter::run () {
 #endif
 	if (backend_executable.isEmpty ()) backend_executable = findBackendAtPath (QCoreApplication::applicationDirPath () + "/rbackend");	// for running directly from the build-dir
 	if (backend_executable.isEmpty ()) backend_executable = findBackendAtPath (QCoreApplication::applicationDirPath () + "/../rbackend");	// for running directly from the build-test-dir
-	if (backend_executable.isEmpty ()) backend_executable = findBackendAtPath (QCoreApplication::applicationDirPath () + "/../lib/libexec");
+	if (backend_executable.isEmpty ()) backend_executable = findBackendAtPath (QCoreApplication::applicationDirPath () + "/" + REL_PATH_TO_LIBEXEC); // as calculated from cmake
 #ifdef Q_OS_MACOS
 	if (backend_executable.isEmpty ()) backend_executable = findBackendAtPath (QCoreApplication::applicationDirPath () + "/../../../rbackend");
 	if (backend_executable.isEmpty ()) backend_executable = findBackendAtPath (QCoreApplication::applicationDirPath () + "/../Frameworks/libexec");  // For running from .dmg created by craft --package rkward
@@ -223,8 +223,7 @@ void RKFrontendTransmitter::run () {
 #if defined(RK_DLOPEN_LIBRSO)
 	/** NOTE: For a description of the rationale for this involved loading procedure rkapi.h ! */
 	QString backend_lib = findBackendLibAtPath(QCoreApplication::applicationDirPath()); // for running directly from the build tree, but also covers windows
-	if (backend_lib.isEmpty()) backend_lib = findBackendLibAtPath(QCoreApplication::applicationDirPath() + "/../lib"); // covers rkward in /usr[/local]/bin and lib in /usr/[/local]/lib
-	if (backend_lib.isEmpty()) backend_lib = findBackendLibAtPath(QFileInfo(backend_executable).absolutePath() + "/../lib"); // backend in /usr/lib/libexec and lib in /usr/lib-> regular install on Linux
+	if (backend_lib.isEmpty()) backend_lib = findBackendLibAtPath(QCoreApplication::applicationDirPath() + "/" + REL_PATH_TO_LIB); // regular installation; rel path between bin and lib dir is calculated in cmake
 	if (backend_lib.isEmpty()) backend_lib = findBackendLibAtPath(QFileInfo(backend_executable).absolutePath()); // backend and lib both installed in libexec or similar
 #	if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
 	env.append(QStringLiteral("RK_BACKEND_LIB=") + backend_lib);


More information about the rkward-tracker mailing list