@@ -35,7 +35,7 @@ sourceCpp <- function(file = "",
3535 cacheDir <- path.expand(cacheDir )
3636 cacheDir <- .sourceCppPlatformCacheDir(cacheDir )
3737 cacheDir <- normalizePath(cacheDir )
38-
38+
3939 # resolve code into a file if necessary. also track the working
4040 # directory to source the R embedded code chunk within
4141 if (! missing(code )) {
@@ -59,12 +59,12 @@ sourceCpp <- function(file = "",
5959
6060 # validate that there are no spaces in the path on windows
6161 if (.Platform $ OS.type == " windows" ) { # #nocov start
62- if (grepl(' ' , basename(file ), fixed = TRUE )) {
62+ if (grepl(' ' , basename(file ), fixed = TRUE )) {
6363 stop(" The filename '" , basename(file ), " ' contains spaces. This " ,
6464 " is not permitted." )
6565 } # #nocov end
6666 }
67-
67+
6868 # get the context (does code generation as necessary)
6969 context <- .Call(" sourceCppContext" , PACKAGE = " Rcpp" ,
7070 file , code , rebuild , cacheDir , .Platform )
@@ -124,9 +124,9 @@ sourceCpp <- function(file = "",
124124 " -o " , shQuote(context $ dynlibFilename ), " " ,
125125 ifelse(rebuild , " --preclean " , " " ),
126126 ifelse(dryRun , " --dry-run " , " " ),
127- paste(shQuote(context $ cppDependencySourcePaths ),
127+ paste(shQuote(context $ cppDependencySourcePaths ),
128128 collapse = " " ), " " ,
129- shQuote(context $ cppSourceFilename ), " " ,
129+ shQuote(context $ cppSourceFilename ), " " ,
130130 sep = " " )
131131 if (showOutput )
132132 cat(cmd , " \n " )
@@ -198,7 +198,7 @@ sourceCpp <- function(file = "",
198198 setwd(rWorkingDir ) # will be reset by previous on.exit handler
199199 source(file = srcConn , echo = TRUE )
200200 }
201-
201+
202202 # cleanup the cache dir if requested
203203 if (cleanupCacheDir )
204204 cleanupSourceCppCache(cacheDir , context $ cppSourcePath , context $ buildDirectory )
@@ -212,19 +212,19 @@ sourceCpp <- function(file = "",
212212
213213
214214# Cleanup a directory used as the cache for a sourceCpp compilation. This will
215- # remove all files from the cache directory that aren't a result of the
216- # compilation that yielded the passed buildDirectory.
215+ # remove all files from the cache directory that aren't a result of the
216+ # compilation that yielded the passed buildDirectory.
217217cleanupSourceCppCache <- function (cacheDir , cppSourcePath , buildDirectory ) {
218218 # normalize cpp source path and build directory # #nocov start
219219 cppSourcePath <- normalizePath(cppSourcePath )
220220 buildDirectory <- normalizePath(buildDirectory )
221-
221+
222222 # determine the parent dir that was used for the compilation then collect all the
223223 # *.cpp files and subdirectories therein
224224 cacheFiles <- list.files(cacheDir , pattern = glob2rx(" *.cpp" ), recursive = FALSE , full.names = TRUE )
225225 cacheFiles <- c(cacheFiles , list.dirs(cacheDir , recursive = FALSE , full.names = TRUE ))
226226 cacheFiles <- normalizePath(cacheFiles )
227-
227+
228228 # determine the list of tiles that were not yielded by the passed sourceCpp
229229 # result and remove them
230230 oldCacheFiles <- cacheFiles [! cacheFiles %in% c(cppSourcePath , buildDirectory )]
@@ -339,7 +339,7 @@ print.bytes <- function( x, ...){ # #nocov start
339339# Evaluate a simple c++ expression
340340evalCpp <- function (code ,
341341 depends = character (),
342- plugins = character (),
342+ plugins = character (),
343343 includes = character (),
344344 rebuild = FALSE ,
345345 cacheDir = getOption(" rcpp.cache.dir" , tempdir()),
@@ -403,7 +403,7 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
403403 .readPkgDescField(pkgDesc , " LinkingTo" , character ()))
404404 depends <- unique(.splitDepends(depends ))
405405 depends <- depends [depends != " R" ]
406-
406+
407407 # determine source directory
408408 srcDir <- file.path(pkgdir , " src" )
409409 if (! file.exists(srcDir ))
@@ -458,11 +458,11 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
458458
459459# built-in C++11 plugin
460460.plugins [[" cpp11" ]] <- function () {
461- if (getRversion() > = " 3.1" )
461+ if (getRversion() > = " 3.1" ) # with recent R versions, R can decide
462462 list (env = list (USE_CXX1X = " yes" ))
463463 else if (.Platform $ OS.type == " windows" )
464464 list (env = list (PKG_CXXFLAGS = " -std=c++0x" ))
465- else
465+ else # g++-4.8.1 or later
466466 list (env = list (PKG_CXXFLAGS = " -std=c++11" ))
467467}
468468
@@ -471,7 +471,9 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
471471 list (env = list (PKG_CXXFLAGS = " -std=c++0x" ))
472472}
473473
474- # built-in C++14 plugin for C++14 standard
474+ # # built-in C++14 plugin for C++14 standard
475+ # # this is the default in g++-6.1 and later
476+ # # per https://gcc.gnu.org/projects/cxx-status.html#cxx14
475477.plugins [[" cpp14" ]] <- function () {
476478 list (env = list (PKG_CXXFLAGS = " -std=c++14" ))
477479}
@@ -481,6 +483,18 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
481483 list (env = list (PKG_CXXFLAGS = " -std=c++1y" ))
482484}
483485
486+ # built-in C++17 plugin for C++17 standard (g++-6 or later)
487+ .plugins [[" cpp17" ]] <- function () {
488+ list (env = list (PKG_CXXFLAGS = " -std=c++17" ))
489+ }
490+
491+ # # built-in C++1z plugin for C++17 standard under development
492+ # # note that as of Feb 2017 this is taken to be a moving target
493+ # # see https://gcc.gnu.org/projects/cxx-status.html
494+ .plugins [[" cpp1z" ]] <- function () {
495+ list (env = list (PKG_CXXFLAGS = " -std=c++1z" ))
496+ }
497+
484498# # built-in OpenMP++11 plugin
485499.plugins [[" openmp" ]] <- function () {
486500 list (env = list (PKG_CXXFLAGS = " -fopenmp" ,
@@ -653,7 +667,7 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
653667 }
654668
655669 # add packages to linkingTo and introspect for plugins
656- for (package in depends ) {
670+ for (package in depends ) {
657671 # #nocov start
658672 # add a LinkingTo for this package
659673 linkingToPackages <- unique(c(linkingToPackages , package ))
@@ -682,14 +696,14 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
682696 srcDir <- dirname(sourceFile )
683697 srcDir <- asBuildPath(srcDir )
684698 buildDirs <- srcDir
685-
699+
686700 # if the source file is in a package then add inst/include
687701 if (.isPackageSourceFile(sourceFile )) { # #nocov start
688702 incDir <- file.path(dirname(sourceFile ), " .." , " inst" , " include" )
689703 incDir <- asBuildPath(incDir )
690704 buildDirs <- c(buildDirs , incDir ) # #nocov end
691705 }
692-
706+
693707 # set CLINK_CPPFLAGS with directory flags
694708 dirFlags <- paste0(' -I"' , buildDirs , ' "' , collapse = " " )
695709 buildEnv $ CLINK_CPPFLAGS <- paste(buildEnv $ CLINK_CPPFLAGS ,
@@ -755,7 +769,7 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
755769 path <- file.path(rToolsPath , " bin" , fsep = " \\ " )
756770 if (! isGcc49 )
757771 path <- c(path , file.path(rToolsPath , " gcc-4.6.3" , " bin" , fsep = " \\ " ))
758-
772+
759773 # if they all exist then return a list with modified
760774 # environment variables for the compilation
761775 if (all(file.exists(path ))) {
@@ -777,11 +791,11 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
777791}
778792
779793
780- # Ensure that the path is suitable for passing as an RTOOLS
794+ # Ensure that the path is suitable for passing as an RTOOLS
781795# environment variable
782796.rtoolsPath <- function (path ) {
783797 path <- gsub(" \\\\ " , " /" , path ) # #nocov start
784- # # R 3.2.0 or later only: path <- trimws(path)
798+ # # R 3.2.0 or later only: path <- trimws(path)
785799 .localsub <- function (re , x ) sub(re , " " , x , perl = TRUE )
786800 path <- .localsub(" [ \t\r\n ]+$" , .localsub(" ^[ \t\r\n ]+" , path ))
787801 if (substring(path , nchar(path )) != " /" )
@@ -1056,7 +1070,7 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
10561070 save(cache , file = index_file , compress = FALSE )
10571071}
10581072
1059- # read the cache from disk
1073+ # read the cache from disk
10601074.sourceCppDynlibReadCache <- function (cacheDir ) {
10611075 index_file <- file.path(cacheDir , " cache.rds" )
10621076 if (file.exists(index_file )) {
@@ -1069,7 +1083,7 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
10691083
10701084# search the cache for an entry that matches the file or code argument
10711085.sourceCppFindCacheEntryIndex <- function (cache , file , code ) {
1072-
1086+
10731087 if (length(cache ) > 0 ) {
10741088 for (i in 1 : length(cache )) {
10751089 entry <- cache [[i ]]
@@ -1080,22 +1094,22 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
10801094 }
10811095 }
10821096 }
1083-
1097+
10841098 # none found
10851099 NULL
10861100}
10871101
10881102# generate an R version / Rcpp version specific cache dir for dynlibs
10891103.sourceCppPlatformCacheDir <- function (cacheDir ) {
1090-
1104+
10911105 dir <- file.path(cacheDir ,
10921106 paste(" sourceCpp" ,
10931107 R.version $ platform ,
10941108 utils :: packageVersion(" Rcpp" ),
10951109 sep = " -" ))
10961110 if (! dir.exists(dir ))
10971111 dir.create(dir , recursive = TRUE )
1098-
1112+
10991113 dir
11001114}
11011115
@@ -1107,13 +1121,13 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
11071121 load(file = token_file )
11081122 else
11091123 token <- 0
1110-
1124+
11111125 # increment
11121126 token <- token + 1
1113-
1127+
11141128 # write it
11151129 save(token , file = token_file )
1116-
1130+
11171131 # return it as a string
11181132 as.character(token )
11191133}
0 commit comments