From 91cf8f3c6d500a5da69a19673704939b6e827e68 Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Fri, 13 May 2016 14:03:33 -0500 Subject: [PATCH] first crack at checking compiler versions from R currently limited to g++ --- DESCRIPTION | 1 + R/compilerCheck.R | 36 ++++++++++++++++++++++++++++++++++++ man/compilerCheck.Rd | 31 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 R/compilerCheck.R create mode 100644 man/compilerCheck.Rd diff --git a/DESCRIPTION b/DESCRIPTION index e0c8eda63..514f6afa6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 diff --git a/R/compilerCheck.R b/R/compilerCheck.R new file mode 100644 index 000000000..1db4331cf --- /dev/null +++ b/R/compilerCheck.R @@ -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 diff --git a/man/compilerCheck.Rd b/man/compilerCheck.Rd new file mode 100644 index 000000000..954ac883b --- /dev/null +++ b/man/compilerCheck.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/compilerCheck.R +\name{compilerCheck} +\alias{compilerCheck} +\title{Check for Minimal (g++) Compiler Version} +\usage{ +compilerCheck(minVersion = package_version("4.6.0")) +} +\arguments{ +\item{minVersion}{An object of type \code{package_version}, with a default +of version 4.6.0} +} +\value{ +A boolean value is returned, indicating if the minimal version is + being met +} +\description{ +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. +} +\details{ +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. +} +\author{ +Dirk Eddelbuettel +} +