Skip to content

Commit

Permalink
Add wrapper generator
Browse files Browse the repository at this point in the history
  • Loading branch information
boutinb committed Mar 12, 2024
1 parent 3fa4b3e commit a7a93a2
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
checkOptions <- function(jsonValue) {
.Call(`_qmlR_checkOptions`, jsonValue)
}

generateAnalysisWrapper <- function(modulePath, qmlFileName, analysisName) {
.Call(`_qmlR_generateAnalysisWrapper`, modulePath, qmlFileName, analysisName)
}

generateModuleWrappers <- function(modulePath) {
.Call(`_qmlR_generateModuleWrappers`, modulePath)
}
207 changes: 207 additions & 0 deletions configure_static
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# To manually specify a location for QT_DIR, JASP_BUILD_DIR or JASPQMLCONTROLSPLUGIN_BUILD_DIR do
#
# options(configure.vars = c(jaspQmlR = "QT_DIR='<path>'"))
# install.packages("jaspQmlR", ...)

if test -f "/etc/redhat-release" && ! grep -Fq Fedora "/etc/redhat-release"; then
echo "on RHEL"
fi

if test -f "/etc/os-release" && grep -Fq Ubuntu "/etc/os-release"; then
echo "on Ubuntu"
fi

if [ "$UNAME" = "Darwin" ]; then
echo "on macOS"
fi

if [ "$UNAME" = "SunOS" ]; then
echo "on SunOS"
fi

if [ "${QT_DIR}" ]; then
echo "Found QT_DIR: ${QT_DIR}"
else
QT_DIR=~/Qt/6.5.2/macos
echo "Use default QT_DIR: ${QT_DIR}"
fi

if [ "${USE_STATIC_LINKING}" ]; then
echo "Use static linking: ${USE_STATIC_LINKING}"
JASPQMLCONTROLSPLUGIN_BUILD_DIR=""

elif [ "${JASPQMLCONTROLSPLUGIN_BUILD_DIR}" ]; then
echo "Found JASPQMLCONTROLSPLUGIN_BUILD_DIR: ${JASPQMLCONTROLSPLUGIN_BUILD_DIR}"
JASPCOMMONLIB_BIN_DIR="${JASPQMLCONTROLSPLUGIN_BUILD_DIR}"/jaspCommonLib

elif [ "${JASP_BUILD_DIR}" ]; then
echo "Found JASP_BUILD_DIR: ${JASP_BUILD_DIR}"
JASPQMLCONTROLSPLUGIN_BUILD_DIR="${JASP_BUILD_DIR}"/jaspQMLControlsPlugin
JASPCOMMONLIB_BIN_DIR="${JASP_BUILD_DIR}"/jaspCommonLib

else
JASPQMLCONTROLSPLUGIN_BUILD_DIR=~/JASP/source/build-jaspQMLControlsPlugin-Qt_6_5_2_for_macOS-Debug
echo "Use default JASPQMLCONTROLSPLUGIN_BUILD_DIR: ${JASPQMLCONTROLSPLUGIN_BUILD_DIR}"
JASPCOMMONLIB_BIN_DIR="${JASPQMLCONTROLSPLUGIN_BUILD_DIR}"/jaspCommonLib
fi


DOWNLOAD_SUCCESS=1

if [ "${JASPCOMMONLIB_SOURCE_DIR}" ]; then

echo "Found JASPCOMMONLIB_SOURCE_DIR: ${JASPCOMMONLIB_SOURCE_DIR}"
DOWNLOAD_SUCCESS=0

else

JASPCOMMONLIB_SOURCE_DIR='../inst/include/jaspCommonLib'
mkdir -p 'inst/include'

echo "seeing if git is available"
if git --version 2>&1 >/dev/null; then

if [ -d 'inst/include/jaspCommonLib' ] && [ -d 'inst/include/jaspCommonLib/.git' ]; then

echo 'Fetching and pulling existing repo'
WORK_TREE="$(pwd)/inst/include/jaspCommonLib"
git --git-dir="${WORK_TREE}/.git" --work-tree="${WORK_TREE}" fetch origin
git --git-dir="${WORK_TREE}/.git" --work-tree="${WORK_TREE}" pull
DOWNLOAD_SUCCESS=0

else

echo 'Cloning c++ dependency jaspCommonLib'
rm -rf 'inst/include/jaspCommonLib'
git clone --depth 1 https://github.com/jasp-stats/jaspCommonLib.git inst/include/jaspCommonLib
DOWNLOAD_SUCCESS=0

fi

fi

if [ "${DOWNLOAD_SUCCESS}" -ne "0" ]; then

echo "seeing if curl is available"
if curl --version 2>&1 >/dev/null; then

echo 'Downloading jaspCommonLib with curl'

rm -rf 'inst/include/jaspCommonLib'
mkdir -p 'inst/include/jaspCommonLib'

curl --silent --location https://api.github.com/repos/jasp-stats/jaspCommonLib/tarball | tar xz --strip=1 --directory inst/include/jaspCommonLib
DOWNLOAD_SUCCESS=$?

fi
fi

if [ "${DOWNLOAD_SUCCESS}" -ne "0" ]; then

echo "seeing if wget is available"
if wget --version 2>&1 >/dev/null; then

echo 'Downloading jaspCommonLib with wget'

rm -rf 'inst/include/jaspCommonLib'
mkdir -p 'inst/include/jaspCommonLib'

wget --quiet --output-document=- https://api.github.com/repos/jasp-stats/jaspCommonLib/tarball | tar xz --strip=1 --directory inst/include/jaspCommonLib
DOWNLOAD_SUCCESS=$?

fi
fi
fi

if [ "${DOWNLOAD_SUCCESS}" -ne "0" ]; then
printf "Installing jaspQmlR failed because the required C++ dependency jaspCommonLib is missing.\n\
Normally this is downloaded automatically if either git, curl, or wget is available, but apparently this failed.\n\
Either download \"https://github.com/jasp-stats/jaspCommonLib\" manually and specify the path through configure.args,\
download git, or download curl.\n\
If you're specifying configure.args manually, note that you must provide the location of jaspCommonLib and the\
location of the parent directory (e.g., the default is '-I\"../inst/include/jaspCommonLib\" -I\"../inst/include\"'))
"
exit 1
fi

SRC_SOURCES="$(cd src/ && ls *.cpp | tr '\n' ' ')"

PKG_LIBS=-g\ -arch\ arm64
#PKG_LIBS=${PKG_LIBS}\ -isysroot\ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk
PKG_LIBS=${PKG_LIBS}\ -mmacosx-version-min=12.5\ -Wl,-search_paths_first\ -Wl,-headerpad_max_install_names
PKG_LIBS=${PKG_LIBS}\ -F${QT_DIR}/lib
PKG_LIBS=${PKG_LIBS}\ "${R_HOME}/library/RInside/lib/libRInside.a"

if [ "${USE_STATIC_LINKING}" ]; then
PKG_LIBS=${PKG_LIBS}\ "${USE_STATIC_LINKING}/JASP/Controls/libjaspcontrolsplugin.a"
else
PKG_LIBS=${PKG_LIBS}\ "${JASPCOMMONLIB_BIN_DIR}/libCommonQt.dylib"
PKG_LIBS=${PKG_LIBS}\ "-Wl,-rpath,${QT_DIR}/lib -Wl,-rpath,${JASPCOMMONLIB_BIN_DIR}"
fi

PKG_CXXFLAGS=-DQT_DIR="${QT_DIR}"\ -DJASP_QML_PLUGIN_DIR="${JASPQMLCONTROLSPLUGIN_BUILD_DIR}"
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -DQT_DEBUG_PLUGINS\ -DQT_CORE_LIB\ -DQT_GUI_LIB\ -DQT_NETWORK_LIB\ -DQT_OPENGL_LIB\ -DQT_QMLINTEGRATION_LIB\ -DQT_QMLMODELS_LIB\ -DQT_QML_LIB\ -DQT_QUICK_LIB
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -I"${R_HOME}/library/RInside/include"
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -I"${JASPCOMMONLIB_SOURCE_DIR}"
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -I"${JASPCOMMONLIB_SOURCE_DIR}/QtUtils"


if [ "${USE_QML_DEBUG}" ]; then

PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/libQt6Core_debug.dylib
PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/libQt6Gui_debug.dylib
PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/libQt6Qml_debug.dylib
PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/libQt6QmlCore_debug.dylib
PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/libQt6QmlModels_debug.dylib
PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/libQt6Quick_debug.dylib
PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/libQt6QuickControls2_debug.dylib
PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/libQt6Network_debug.dylib
PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/libQt6QmlWorkerScript_debug.dylib

PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/include/QtCore
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -iframework\ ${QT_DIR}/lib
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/include/mkspecs/macx-clang
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/include
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/include/QtGui
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/include/QtQml
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/include/QtQuick

else

# PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/QtQuick.framework/Versions/A/QtQuick
# PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/QtQmlModels.framework/Versions/A/QtQmlModels
# PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/QtQml.framework/Versions/A/QtQml
# PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/QtNetwork.framework/Versions/A/QtNetwork
# PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/QtOpenGL.framework/Versions/A/QtOpenGL
# PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/QtGui.framework/Versions/A/QtGui
# PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/QtCore.framework/Versions/A/QtCore
if [ -z "${USE_STATIC_LINKING}" ]; then
PKG_LIBS=${PKG_LIBS}\ ${QT_DIR}/lib/QtQuickControls2.framework/Versions/A/QtQuickControls2
fi

PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/lib/QtCore.framework/Headers
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -iframework\ ${QT_DIR}/lib
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/mkspecs/macx-clang
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/include
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/lib/QtQml.framework/Headers
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/include/QtQmlIntegration
# PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/lib/QtNetwork.framework/Headers
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/lib/QtQuick.framework/Headers
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/lib/QtQuickControls2.framework/Headers
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/lib/QtGui.framework/Headers
# PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/lib/QtQmlModels.framework/Headers
# PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isystem\ ${QT_DIR}/lib/QtOpenGL.framework/Headers

fi

PKG_LIBS=${PKG_LIBS}\ -framework\ IOKit\ -framework\ DiskArbitration\ -Xlinker\ -framework\ -Xlinker\ OpenGL
PKG_LIBS=${PKG_LIBS}\ -Xlinker\ -framework\ -Xlinker\ AGL\ -framework\ AppKit\ -framework\ ImageIO\ -framework\ Metal

PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -g\ -arch\ arm64
#PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -isysroot\ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk
PKG_CXXFLAGS=${PKG_CXXFLAGS}\ -mmacosx-version-min=12.5\ -std=gnu++17\ -MD\ -MT


sed -e "s|@cppflags@|${PKG_CXXFLAGS}|" -e "s|@libflags@|${PKG_LIBS}|" src/Makevars.in > src/Makevars

exit 0
30 changes: 30 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,38 @@ BEGIN_RCPP
END_RCPP
}


// generateAnalysisWrapper
String generateAnalysisWrapper(String modulePath, String qmlFileName, String analysisName);
RcppExport SEXP _generateAnalysisWrapper(SEXP modulePathSEXP, SEXP qmlFileNameSEXP, SEXP analysisNameSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< String >::type modulePath(modulePathSEXP);
Rcpp::traits::input_parameter< String >::type qmlFileName(qmlFileNameSEXP);
Rcpp::traits::input_parameter< String >::type analysisName(analysisNameSEXP);
rcpp_result_gen = Rcpp::wrap(generateAnalysisWrapper(modulePath, qmlFileName, analysisName));
return rcpp_result_gen;
END_RCPP
}

// generateModuleWrappers
String generateModuleWrappers(String modulePath);
RcppExport SEXP _generateModuleWrappers(SEXP modulePathSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< String >::type modulePath(modulePathSEXP);
rcpp_result_gen = Rcpp::wrap(generateModuleWrappers(modulePath));
return rcpp_result_gen;
END_RCPP
}


static const R_CallMethodDef CallEntries[] = {
{"_qmlR_checkOptions", (DL_FUNC) &_checkOptions, 1},
{"_qmlR_generateAnalysisWrapper", (DL_FUNC) &_generateAnalysisWrapper, 3},
{"_qmlR_generateModuleWrappers", (DL_FUNC) &_generateModuleWrappers, 1},
{NULL, NULL, 0}
};

Expand Down
Loading

0 comments on commit a7a93a2

Please sign in to comment.