Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ URL: http://www.rcpp.org, http://dirk.eddelbuettel.com/code/rcpp.html, https://g
License: GPL (>= 2)
BugReports: https://github.com/RcppCore/Rcpp/issues
MailingList: Please send questions and comments regarding Rcpp to rcpp-devel@lists.r-forge.r-project.org
RoxygenNote: 5.0.1
36 changes: 36 additions & 0 deletions R/compilerCheck.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
##' Helper function to establish minimal compiler versions, currently limited
##' only to \code{g++} which (particularly for older RHEL/CentOS releases) is
##' too far behind current C++11 standards required for some packages.
##'
##' This function looks up \code{g++} (as well as optional values in the
##' \code{CXX} and \code{CXX1X} environment variables) in the \code{PATH}. For
##' all values found, the output of \code{g++ -v} is analyzed for the version
##' string, which is then compared to the given minimal version.
##' @title Check for Minimal (g++) Compiler Version
##' @param minVersion An object of type \code{package_version}, with a default
##' of version 4.6.0
##' @return A boolean value is returned, indicating if the minimal version is
##' being met
##' @author Dirk Eddelbuettel
compilerCheck <- function(minVersion=package_version("4.6.0")) {

binaries <- c("g++", Sys.getenv("CXX", unset=""), Sys.getenv("CXX1X", unset=""))
binpaths <- lapply(binaries, function(b) { if (b=="") NULL else Sys.which(b) })

allgood <- FALSE
rl <- lapply(binpaths, function(b) {
if (is.null(b)) return(NULL)
con <- pipe(paste(b, "-v 2>&1"), "r") # NB: not --version, but -v
lines <- readLines(con)
close(con)
lines <- lines[grepl("^g.. version", lines)]
if (length(lines) == 0) return(NULL)
ver <- strsplit(lines, " ")[[1]][3] # format is 'gcc version x.y.z ....'
package_version(ver) >= minVersion
})
all(do.call(c, rl)) # drops NULLs
}

## TODO: maybe not limit to gcc/g++
## TODO: maybe be smarter about combination of path, CXX and CXX1X ?
## TODO: maybe make env.var optional arguments too
31 changes: 31 additions & 0 deletions man/compilerCheck.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.