biocmake
provides consistent access to Cmake for
use in building Bioconductor packages. The idea is to check if a
suitably recent version of Cmake is already available on the host
machine, and if not, download and install a local copy of Cmake managed
by biocmake.
This avoids end-users having to manually install Cmake via
SystemRequirements: cmake. To find the Cmake
executable:
## [1] "cmake"
This will return either a Cmake command on the PATH (if
the version is recent enough) or the cached path to a Cmake executable
after downloading the binaries (otherwise). Developers can call
find() in their configure scripts to build
Cmake projects during their own package’s installation.
Let’s mock up a Cmake project.
project <- tempfile()
dir.create(project)
write(file=file.path(project, "CMakeLists.txt"), '
cmake_minimum_required(VERSION 3.25)
project(bctest VERSION 2.0.1 LANGUAGES CXX)
add_library(superfoo src/superfoo.cpp)
target_include_directories(superfoo PUBLIC include)
')
dir.create(file.path(project, "src"))
write(file=file.path(project, "src", "superfoo.cpp"), '
int superfoo(int a, int b) {
return a + b;
}
')
dir.create(file.path(project, "include"))
write(file=file.path(project, "include", "superfoo.h"), '
#ifndef SUPERFOO_H
#define SUPERFOO_H
int superfoo(int, int);
#endif
')We then use biocmake
to build it through the Cmake executable identified by
find(). The configure() command collects some
compilation settings used to build R itself and propagates this to the
Cmake project, e.g., to ensure that the same compilers are used.
# Removing some of the configuration parameters that we don't need.
config <- biocmake::configure(c.compiler=FALSE, fortran.compiler=FALSE)
config.args <- biocmake::formatArguments(config)
cmake <- biocmake::find()
build <- tempfile()
status <- system2(cmake, c(config.args, "-S", project, "-B", build))
stopifnot(status == 0L)
status <- system2(cmake, c("--build", build))
stopifnot(status == 0L)Developers should execute these commands in their package’s
configure(.win) file. This ensures that the CMake project
is built first so that it is available for linking to the package’s
shared library.
Most default behaviors of biocmake are captured in the following functions, which can in turn be controlled by environment variables.
## [1] "cmake"
## [1] "3.24.0"
## [1] "3.30.3"
## [1] "/github/home/.cache/R/biocmake"
For example:
## [1] "3.27.4"
We can also forcibly override the behavior of find() by
setting the BIOCMAKE_FIND_OVERRIDE to some other Cmake
executable or command.
## R version 4.5.1 (2025-06-13)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.3 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.50 BiocStyle_2.37.1
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.37 R6_2.6.1 fastmap_1.2.0
## [4] xfun_0.54 dir.expiry_1.17.0 maketools_1.3.2
## [7] cachem_1.1.0 filelock_1.0.3 htmltools_0.5.8.1
## [10] rmarkdown_2.30 buildtools_1.0.0 lifecycle_1.0.4
## [13] cli_3.6.5 sass_0.4.10 biocmake_1.3.0
## [16] jquerylib_0.1.4 compiler_4.5.1 sys_3.4.3
## [19] tools_4.5.1 evaluate_1.0.5 bslib_0.9.0
## [22] yaml_2.3.10 BiocManager_1.30.26 jsonlite_2.0.0
## [25] rlang_1.1.6