biocmake 0.99.0
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:
biocmake::find()
## [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.
biocmake::defaultCommand()
## [1] "cmake"
biocmake::defaultMinimumVersion()
## [1] "3.24.0"
biocmake::defaultDownloadVersion()
## [1] "3.30.3"
biocmake::defaultCacheDirectory()
## [1] "/home/biocbuild/.cache/R/biocmake"
For example:
Sys.setenv(BIOCMAKE_CMAKE_MINIMUM_VERSION="3.27.4")
biocmake::defaultMinimumVersion()
## [1] "3.27.4"
sessionInfo()
## R Under development (unstable) (2025-01-20 r87609)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.21-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0 LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB 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: America/New_York
## 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.5.1 bookdown_0.42
## [4] fastmap_1.2.0 xfun_0.50 dir.expiry_1.15.0
## [7] cachem_1.1.0 filelock_1.0.3 htmltools_0.5.8.1
## [10] rmarkdown_2.29 lifecycle_1.0.4 cli_3.6.3
## [13] sass_0.4.9 biocmake_0.99.0 jquerylib_0.1.4
## [16] compiler_4.5.0 tools_4.5.0 evaluate_1.0.3
## [19] bslib_0.9.0 yaml_2.3.10 BiocManager_1.30.25
## [22] jsonlite_1.8.9 rlang_1.1.5