{"id":29107520,"url":"https://github.com/jmaerte/cmake-rcpp-template","last_synced_at":"2026-04-10T22:49:10.878Z","repository":{"id":301745415,"uuid":"1010152306","full_name":"jmaerte/cmake-rcpp-template","owner":"jmaerte","description":"A CRAN-ready R package template that integrates the simplicity of CMake with the power of Rcpp, enabling platform-independent linkage to external C/C++ libraries such as OpenCL, OpenGL, and others.","archived":false,"fork":false,"pushed_at":"2025-06-28T15:22:44.000Z","size":1,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-28T15:37:32.125Z","etag":null,"topics":["cmake","cmaketemplate","cpp","cran","cran-r","opencl","opengl","r","rcpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmaerte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-28T13:11:08.000Z","updated_at":"2025-06-28T15:24:45.000Z","dependencies_parsed_at":"2025-06-28T15:48:03.076Z","dependency_job_id":null,"html_url":"https://github.com/jmaerte/cmake-rcpp-template","commit_stats":null,"previous_names":["jmaerte/cmake-rcpp-template"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jmaerte/cmake-rcpp-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmaerte%2Fcmake-rcpp-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmaerte%2Fcmake-rcpp-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmaerte%2Fcmake-rcpp-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmaerte%2Fcmake-rcpp-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmaerte","download_url":"https://codeload.github.com/jmaerte/cmake-rcpp-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmaerte%2Fcmake-rcpp-template/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262539074,"owners_count":23325832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","cmaketemplate","cpp","cran","cran-r","opencl","opengl","r","rcpp"],"created_at":"2025-06-29T05:04:12.912Z","updated_at":"2026-04-10T22:49:05.836Z","avatar_url":"https://github.com/jmaerte.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📦 Template Project: CMake for Rcpp\n\nA **CRAN-ready R package template** that integrates the simplicity of **CMake** with the power of **Rcpp**, enabling platform-independent linkage to external C/C++ libraries such as **OpenCL**, **OpenGL**, and others.\n\n\u003e This template streamlines the development of high-performance R packages that rely on native code, without manual environment configuration.\n\n---\n\n## ✨ Highlights\n\n- ✅ Platform-independent configuration and linkage with **CMake**\n- ✅ Built `tar.gz` does not have any binaries - everything is compiled at package installation.\n- ✅ No manual `Makefile` or environment variable setup required\n- ✅ Clean separation of public/private headers in C++\n- ✅ Simple Rcpp integration — no need to link Rcpp to the external libraries\n- ✅ Example: GPU-accelerated distance matrix using **OpenCL**\n\n---\n\n## 📁 Project Structure\n\n```\ncmake-rcpp-template\n│\t# Package metadata files\n|\t# configure and configure.win handle the installation\n|\n├──\tsrc\n│\t│   # *.cpp define the Rcpp wrapper functions\n│\t│\n│\t└──\tbackend\n│\t\t│   # A standard CMake project\n|\t\t|\n|\t\t├──\tinclude\n│\t\t|\t|\t# public headers; should not include external\n|\t\t|\t└──\t# library headers; otherwise Rcpp needs to link too.\n|\t\t|\n|\t\t├──\tsrc\n|\t\t|\t|\t# *.cpp define the actual implementation of functionality\n|\t\t|\t|\n|\t\t|\t└──\tinternal\n|\t\t|\t\t| \t# Some internal header files that may \n|\t\t|\t\t└──\t# include external library headers.\n|\t\t|\n|\t\t└──\tlib\n|\t\t\t└──\t# Some external library headers.\n|\t\n├──\tR\n|\t└──\t# Caller scripts for the Rcpp functions and other R functions\n|\n├──\tman\n|\t└──\t# Documentation goes here\n|\n└──\tinst\n\t| \t# The library features the possibility to load external\n\t└──\t# resources from this folder.\n```\n\n📝 **Note:** Public headers (`backend/include`) define C/C++ interfaces compatible with `Rcpp`; they should not include external library headers as `Rcpp` does not link against them. Private headers (`backend/src/internal`) manage actual implementation details, allowing clean abstraction.\n\n## ⚙️ Backend with CMake\nThe `src/backend` directory is a standalone **CMake** project. It builds a shared library that is automatically linked to the R package.\n\n* Extend linkage easily in `CMakeLists.txt` for OpenCL, OpenGL, etc.\n\n* CMake handles all platform-dependent paths and setup.\n\n## 📂 The `inst` Folder\n\nThe `inst/` directory contains runtime resources (e.g., `.cl` kernels). During installation, files from `src/backend/kernels` are copied into `inst/kernels` using the `configure` and `configure.win` scripts.\n\n``````r\n# Accessed in R via:\nsystem.file(\"kernels\", package = \"CMakeRcppTemplate\")\n``````\n\nThese paths are injected into the shared library at runtime using the `.onLoad` hook (see `R/CMakeRcppTemplate.R`), enabling dynamic loading of external resources like OpenCL kernels or OpenGL shaders.\n\n## 🔗 Rcpp Integration\n\nThis template uses **manual `SEXP` wrappers** for each Rcpp function (instead of `[[Rcpp::export]]`) to avoid platform-specific issues:\n\n\u003e On some systems, `enterRNGScope` errors to be undefined in `RcppExports.o` even though it was not used in `RcppExports.cpp` when using auto-generated bindings via `compileAttributes()`.\n\nHowever, for simplicity, you *may* choose to use `[[Rcpp::export]]` if you're willing to trade off some portability.\n\n📌 **Important**:\n\n- Add `import(Rcpp)` to the top of your `NAMESPACE` file to avoid errors like:\n\n  ```text\n  Rcpp_precious_remove not provided by package Rcpp.\n  ```\n\n- Manually written R wrappers for `SEXP` functions should defensively check input types, since auto-type checks are not generated without `[[Rcpp::export]]`.\n\n## 📤 Exports\n\nYour package may export:\n\n- `SEXP`-wrapper functions via `Rcpp`\n- High-level R functions that internally call C/C++ via `Rcpp`\n- High-level R functions that are independent of the C/C++ backend\n\n## 🧪 Example Use Case\n\nThis template includes an example GPU-based distance matrix computation via **OpenCL**. No changes are required to Rcpp code when adding new backend libraries — just update the CMake configuration.\n\n## 📚 Resources\n\n- [CMake Documentation](https://cmake.org/documentation/)\n- [Rcpp Package](https://cran.r-project.org/package=Rcpp)\n- [Writing R Extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html)\n\n## 🛠️ Getting Started\n\n1. Clone this repository (use `--recursive` option in order to get the OpenCL headers aswell!)\n2. Modify the `src/backend/` CMake code and `src/*.cpp` `Rcpp`- and `SEXP`-bindings\n3. Add new R functions in the `R/` directory calling your `SEXP`-binding functions\n4. Document functions via `Rmarkdown` in `man`\n5. Adjust the section `copying kernels` in `configure` and `configure.win` according to your external resources.\n6. Build and install using `devtools::install()` or `R CMD INSTALL`\n\n## 🧑‍💻 Contributions\n\nContributions, suggestions, and issues are welcome! Feel free to open a pull request or issue.\n\n## 📄 License\n\nMIT License. See `LICENSE` for details.\n\n\u003e ⚠️ Author's Note: This project was created while I was affiliated with **IAP-GmbH Intelligent Analytics Projects**.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmaerte%2Fcmake-rcpp-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmaerte%2Fcmake-rcpp-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmaerte%2Fcmake-rcpp-template/lists"}