biocmake
provides consistent access to Cmake for
use in building Bioconductor packages. The idea is to check if an
appropriate 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 for end-users to manually install Cmake via
SystemRequirements: cmake
. To find the Cmake
executable:
## [1] "cmake"
This will return either the Cmake command on the PATH
(if it is of a suitable version). or will return the cached path to a
Cmake executable after downloading the binaries (otherwise). Developers
can use this in a system call in their configure
scripts to
build Cmake projects for their own packages.
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 documented 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"
## R version 4.4.3 (2025-02-28)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.2 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.49 BiocStyle_2.35.0
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.37 R6_2.6.1 fastmap_1.2.0
## [4] xfun_0.51 dir.expiry_1.15.0 maketools_1.3.2
## [7] cachem_1.1.0 filelock_1.0.3 htmltools_0.5.8.1
## [10] rmarkdown_2.29 buildtools_1.0.0 lifecycle_1.0.4
## [13] cli_3.6.4 sass_0.4.9 biocmake_0.99.0
## [16] jquerylib_0.1.4 compiler_4.4.3 sys_3.4.3
## [19] tools_4.4.3 evaluate_1.0.3 bslib_0.9.0
## [22] yaml_2.3.10 BiocManager_1.30.25 jsonlite_1.9.1
## [25] rlang_1.1.5