[education/rkward] rkward/rbackend: Isolate all R include files into a single header

Thomas Friedrichsmeier null at kde.org
Fri May 10 17:04:24 BST 2024


Git commit f072652b88dfb978f0ec909d3cf69fa3d6f0ad8e by Thomas Friedrichsmeier.
Committed on 03/05/2024 at 16:06.
Pushed by tfry into branch 'master'.

Isolate all R include files into a single header

M  +4    -4    rkward/rbackend/FindR.cmake
A  +59   -0    rkward/rbackend/rkrapi.h     [License: GPL(v2.0+)]
M  +1    -29   rkward/rbackend/rkrbackend.cpp
M  +0    -8    rkward/rbackend/rkrsupport.cpp
M  +1    -2    rkward/rbackend/rkrsupport.h
M  +1    -15   rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
M  +1    -1    rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp

https://invent.kde.org/education/rkward/-/commit/f072652b88dfb978f0ec909d3cf69fa3d6f0ad8e

diff --git a/rkward/rbackend/FindR.cmake b/rkward/rbackend/FindR.cmake
index 3e2c17551..62cd141d0 100644
--- a/rkward/rbackend/FindR.cmake
+++ b/rkward/rbackend/FindR.cmake
@@ -12,11 +12,11 @@ ENDIF(R_EXECUTABLE)
 SET(CMAKE_FIND_APPBUNDLE NEVER)  # Do not get fooled by R GUI on Mac
 FIND_PROGRAM(R_EXECUTABLE R PATH_SUFFIXES lib/R/bin)
 
-IF(R_EXECUTABLE-NOTFOUND)
-	MESSAGE(FATAL_ERROR "Could NOT find R (TODO: name option)")
-ELSE(R_EXECUTABLE-NOTFOUND)
+IF(R_EXECUTABLE)
 	MESSAGE(STATUS "Using R at ${R_EXECUTABLE}")
-ENDIF(R_EXECUTABLE-NOTFOUND)
+ELSE(R_EXECUTABLE)
+	MESSAGE(FATAL_ERROR "Could NOT find R (if R is installed but no in path, call cmake with -DR_ECEUTABLE=/path/to/R)")
+ENDIF(R_EXECUTABLE)
 
 IF(NOT NO_CHECK_R)
     # find out about R architecture (needed for some paths)
diff --git a/rkward/rbackend/rkrapi.h b/rkward/rbackend/rkrapi.h
new file mode 100644
index 000000000..73e86fbc6
--- /dev/null
+++ b/rkward/rbackend/rkrapi.h
@@ -0,0 +1,59 @@
+/*
+rkrapi - This file is part of RKWard (https://rkward.kde.org). Created: Wed May 01 2024
+SPDX-FileCopyrightText: 2024 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
+SPDX-License-Identifier: GPL-2.0-or-later
+*/
+
+/** @file rkrapi.h
+
+Encapsulate R API calls for abstraction over dl_open. WIP
+
+*/
+
+#define R_INTERFACE_PTRS 1
+// for R_CStackStart/Limit
+#define CSTACK_DEFNS 1
+// keep R from defining tons of aliases
+#define R_NO_REMAP 1
+// What the...? "Conflicting definitions" between stdint.h and Rinterface.h despite the #if in Rinterface.h
+#define uintptr_t uintptr_t
+
+// needed to detect CHARSXP encoding
+#define IS_UTF8(x) (Rf_getCharCE(x) == CE_UTF8)
+#define IS_LATIN1(x) (Rf_getCharCE(x) == CE_LATIN1)
+#ifdef TRUE
+#	undef TRUE
+#endif
+#ifdef FALSE
+#	undef FALSE
+#endif
+
+// Common includes
+#include <Rdefines.h>
+#include <R_ext/Rdynload.h>
+#include <R_ext/Callbacks.h>
+#include <R.h>
+#include <Rversion.h>
+#include <Rinternals.h>
+#include <R_ext/Parse.h>
+#include <Rembedded.h>
+#include <R_ext/Riconv.h>
+#define R_USE_PROTOTPYES 1
+#include <R_ext/GraphicsEngine.h>
+
+// rcolor typedef added in R 3.0.0
+#ifndef rcolor
+#define rcolor unsigned int
+#endif
+
+// The following needed only on Windows
+#if defined(_WIN32) || defined(_MSC_VER) || defined(Win32)  // Note: no easy access to Q_OS_WIN at this point
+#	include <R_ext/RStartup.h>
+#	include <R_ext/Utils.h>
+#	include <R_ext/libextern.h>
+#else
+// The following needed only outside of Windows, and Rinterface.h is not even available on Windows
+#	include <Rinterface.h>
+#	include <R_ext/eventloop.h>
+#endif
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index fe80d1c26..bd358206c 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -42,32 +42,9 @@ void* RKRBackend::default_global_context = nullptr;
 #include <stdint.h>
 #include <locale.h>
 
-#define R_INTERFACE_PTRS 1
-// for R_CStackStart/Limit
-#define CSTACK_DEFNS 1
-// keep R from defining tons of aliases
-#define R_NO_REMAP 1
-// What the...? "Conflicting definitions" between stdint.h and Rinterface.h despite the #if in Rinterface.h
-#define uintptr_t uintptr_t
-
-// needed to detect CHARSXP encoding
-#define IS_UTF8(x) (Rf_getCharCE(x) == CE_UTF8)
-#define IS_LATIN1(x) (Rf_getCharCE(x) == CE_LATIN1)
-
-#include <Rdefines.h>
-#include <R_ext/Rdynload.h>
-#include <R_ext/Callbacks.h>
-#include <R.h>
-#include <Rversion.h>
-#include <Rinternals.h>
-#include <R_ext/Parse.h>
-#include <Rembedded.h>
+#include "rkrapi.h"
 
 #ifdef Q_OS_WIN
-#	include <R_ext/RStartup.h>
-#	include <R_ext/Utils.h>
-#	include <R_ext/libextern.h>
-
 	structRstart RK_R_Params;
 
 	extern "C" {
@@ -76,8 +53,6 @@ void* RKRBackend::default_global_context = nullptr;
 		LibExtern uintptr_t R_CStackLimit;
 		LibExtern void R_SaveGlobalEnvToFile(char*);
 	}
-#else
-#	include <Rinterface.h>
 #endif
 
 #ifndef Q_OS_WIN
@@ -165,9 +140,6 @@ void RKRBackend::clearPendingInterrupt () {
 LibExtern void Rf_PrintWarnings (void);
 #endif
 extern "C" void run_Rmainloop (void);
-#ifndef Q_OS_WIN
-#	include <R_ext/eventloop.h>
-#endif
 
 #include "rdata.h"
 
diff --git a/rkward/rbackend/rkrsupport.cpp b/rkward/rbackend/rkrsupport.cpp
index 9c549f0f9..282528550 100644
--- a/rkward/rbackend/rkrsupport.cpp
+++ b/rkward/rbackend/rkrsupport.cpp
@@ -7,14 +7,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 #include "rkrsupport.h"
 
-#include <Rdefines.h>
-#include <Rversion.h>
-#include <R_ext/Riconv.h>
-
-// needed to detect CHARSXP encoding
-#define IS_UTF8(x) (Rf_getCharCE(x) == CE_UTF8)
-#define IS_LATIN1(x) (Rf_getCharCE(x) == CE_LATIN1)
-
 #include "rkrbackend.h"
 #include "../debug.h"
 
diff --git a/rkward/rbackend/rkrsupport.h b/rkward/rbackend/rkrsupport.h
index 0d312fba4..dcfbc23d9 100644
--- a/rkward/rbackend/rkrsupport.h
+++ b/rkward/rbackend/rkrsupport.h
@@ -15,8 +15,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 #include "rdata.h"
 
-#define R_NO_REMAP 1
-#include <Rdefines.h>
+#include "rkrapi.h"
 
 /** Convenience functions for working with R. */
 namespace RKRSupport {
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
index cb065a561..ad3bbedd0 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
@@ -16,21 +16,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include "../rkrsupport.h"
 #include "../rkrbackend.h"
 
-#ifdef TRUE
-#	undef TRUE
-#endif
-#ifdef FALSE
-#	undef FALSE
-#endif
-#define R_USE_PROTOTPYES 1
-
-#include <R_ext/GraphicsEngine.h>
-#include <Rversion.h>
-
-// rcolor typedef added in R 3.0.0
-#ifndef rcolor
-#define rcolor unsigned int
-#endif
+#include "../rkrapi.h"
 
 struct RKGraphicsDeviceDesc {
 	bool init (pDevDesc dev, double pointsize, const QStringList &family, rcolor bg);
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
index 505f9d7e0..88966271a 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
@@ -33,7 +33,7 @@ public:
 }; */
 
 
-#include <R_ext/GraphicsEngine.h>
+#include "../rkrapi.h"
 
 #define RKD_IN_STREAM RKGraphicsDeviceBackendTransmitter::streamer.instream
 #define RKD_OUT_STREAM RKGraphicsDeviceBackendTransmitter::streamer.outstream



More information about the rkward-tracker mailing list