@@ -35,7 +35,7 @@ sourceCpp <- function(file = "",
35
35
cacheDir <- path.expand(cacheDir )
36
36
cacheDir <- .sourceCppPlatformCacheDir(cacheDir )
37
37
cacheDir <- normalizePath(cacheDir )
38
-
38
+
39
39
# resolve code into a file if necessary. also track the working
40
40
# directory to source the R embedded code chunk within
41
41
if (! missing(code )) {
@@ -59,12 +59,12 @@ sourceCpp <- function(file = "",
59
59
60
60
# validate that there are no spaces in the path on windows
61
61
if (.Platform $ OS.type == " windows" ) { # #nocov start
62
- if (grepl(' ' , basename(file ), fixed = TRUE )) {
62
+ if (grepl(' ' , basename(file ), fixed = TRUE )) {
63
63
stop(" The filename '" , basename(file ), " ' contains spaces. This " ,
64
64
" is not permitted." )
65
65
} # #nocov end
66
66
}
67
-
67
+
68
68
# get the context (does code generation as necessary)
69
69
context <- .Call(" sourceCppContext" , PACKAGE = " Rcpp" ,
70
70
file , code , rebuild , cacheDir , .Platform )
@@ -124,9 +124,9 @@ sourceCpp <- function(file = "",
124
124
" -o " , shQuote(context $ dynlibFilename ), " " ,
125
125
ifelse(rebuild , " --preclean " , " " ),
126
126
ifelse(dryRun , " --dry-run " , " " ),
127
- paste(shQuote(context $ cppDependencySourcePaths ),
127
+ paste(shQuote(context $ cppDependencySourcePaths ),
128
128
collapse = " " ), " " ,
129
- shQuote(context $ cppSourceFilename ), " " ,
129
+ shQuote(context $ cppSourceFilename ), " " ,
130
130
sep = " " )
131
131
if (showOutput )
132
132
cat(cmd , " \n " )
@@ -198,7 +198,7 @@ sourceCpp <- function(file = "",
198
198
setwd(rWorkingDir ) # will be reset by previous on.exit handler
199
199
source(file = srcConn , echo = TRUE )
200
200
}
201
-
201
+
202
202
# cleanup the cache dir if requested
203
203
if (cleanupCacheDir )
204
204
cleanupSourceCppCache(cacheDir , context $ cppSourcePath , context $ buildDirectory )
@@ -212,19 +212,19 @@ sourceCpp <- function(file = "",
212
212
213
213
214
214
# 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.
217
217
cleanupSourceCppCache <- function (cacheDir , cppSourcePath , buildDirectory ) {
218
218
# normalize cpp source path and build directory # #nocov start
219
219
cppSourcePath <- normalizePath(cppSourcePath )
220
220
buildDirectory <- normalizePath(buildDirectory )
221
-
221
+
222
222
# determine the parent dir that was used for the compilation then collect all the
223
223
# *.cpp files and subdirectories therein
224
224
cacheFiles <- list.files(cacheDir , pattern = glob2rx(" *.cpp" ), recursive = FALSE , full.names = TRUE )
225
225
cacheFiles <- c(cacheFiles , list.dirs(cacheDir , recursive = FALSE , full.names = TRUE ))
226
226
cacheFiles <- normalizePath(cacheFiles )
227
-
227
+
228
228
# determine the list of tiles that were not yielded by the passed sourceCpp
229
229
# result and remove them
230
230
oldCacheFiles <- cacheFiles [! cacheFiles %in% c(cppSourcePath , buildDirectory )]
@@ -339,7 +339,7 @@ print.bytes <- function( x, ...){ # #nocov start
339
339
# Evaluate a simple c++ expression
340
340
evalCpp <- function (code ,
341
341
depends = character (),
342
- plugins = character (),
342
+ plugins = character (),
343
343
includes = character (),
344
344
rebuild = FALSE ,
345
345
cacheDir = getOption(" rcpp.cache.dir" , tempdir()),
@@ -403,7 +403,7 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
403
403
.readPkgDescField(pkgDesc , " LinkingTo" , character ()))
404
404
depends <- unique(.splitDepends(depends ))
405
405
depends <- depends [depends != " R" ]
406
-
406
+
407
407
# determine source directory
408
408
srcDir <- file.path(pkgdir , " src" )
409
409
if (! file.exists(srcDir ))
@@ -458,11 +458,11 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
458
458
459
459
# built-in C++11 plugin
460
460
.plugins [[" cpp11" ]] <- function () {
461
- if (getRversion() > = " 3.1" )
461
+ if (getRversion() > = " 3.1" ) # with recent R versions, R can decide
462
462
list (env = list (USE_CXX1X = " yes" ))
463
463
else if (.Platform $ OS.type == " windows" )
464
464
list (env = list (PKG_CXXFLAGS = " -std=c++0x" ))
465
- else
465
+ else # g++-4.8.1 or later
466
466
list (env = list (PKG_CXXFLAGS = " -std=c++11" ))
467
467
}
468
468
@@ -471,7 +471,9 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
471
471
list (env = list (PKG_CXXFLAGS = " -std=c++0x" ))
472
472
}
473
473
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
475
477
.plugins [[" cpp14" ]] <- function () {
476
478
list (env = list (PKG_CXXFLAGS = " -std=c++14" ))
477
479
}
@@ -481,6 +483,18 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
481
483
list (env = list (PKG_CXXFLAGS = " -std=c++1y" ))
482
484
}
483
485
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
+
484
498
# # built-in OpenMP++11 plugin
485
499
.plugins [[" openmp" ]] <- function () {
486
500
list (env = list (PKG_CXXFLAGS = " -fopenmp" ,
@@ -653,7 +667,7 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
653
667
}
654
668
655
669
# add packages to linkingTo and introspect for plugins
656
- for (package in depends ) {
670
+ for (package in depends ) {
657
671
# #nocov start
658
672
# add a LinkingTo for this package
659
673
linkingToPackages <- unique(c(linkingToPackages , package ))
@@ -682,14 +696,14 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
682
696
srcDir <- dirname(sourceFile )
683
697
srcDir <- asBuildPath(srcDir )
684
698
buildDirs <- srcDir
685
-
699
+
686
700
# if the source file is in a package then add inst/include
687
701
if (.isPackageSourceFile(sourceFile )) { # #nocov start
688
702
incDir <- file.path(dirname(sourceFile ), " .." , " inst" , " include" )
689
703
incDir <- asBuildPath(incDir )
690
704
buildDirs <- c(buildDirs , incDir ) # #nocov end
691
705
}
692
-
706
+
693
707
# set CLINK_CPPFLAGS with directory flags
694
708
dirFlags <- paste0(' -I"' , buildDirs , ' "' , collapse = " " )
695
709
buildEnv $ CLINK_CPPFLAGS <- paste(buildEnv $ CLINK_CPPFLAGS ,
@@ -755,7 +769,7 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
755
769
path <- file.path(rToolsPath , " bin" , fsep = " \\ " )
756
770
if (! isGcc49 )
757
771
path <- c(path , file.path(rToolsPath , " gcc-4.6.3" , " bin" , fsep = " \\ " ))
758
-
772
+
759
773
# if they all exist then return a list with modified
760
774
# environment variables for the compilation
761
775
if (all(file.exists(path ))) {
@@ -777,11 +791,11 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
777
791
}
778
792
779
793
780
- # Ensure that the path is suitable for passing as an RTOOLS
794
+ # Ensure that the path is suitable for passing as an RTOOLS
781
795
# environment variable
782
796
.rtoolsPath <- function (path ) {
783
797
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)
785
799
.localsub <- function (re , x ) sub(re , " " , x , perl = TRUE )
786
800
path <- .localsub(" [ \t\r\n ]+$" , .localsub(" ^[ \t\r\n ]+" , path ))
787
801
if (substring(path , nchar(path )) != " /" )
@@ -1056,7 +1070,7 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
1056
1070
save(cache , file = index_file , compress = FALSE )
1057
1071
}
1058
1072
1059
- # read the cache from disk
1073
+ # read the cache from disk
1060
1074
.sourceCppDynlibReadCache <- function (cacheDir ) {
1061
1075
index_file <- file.path(cacheDir , " cache.rds" )
1062
1076
if (file.exists(index_file )) {
@@ -1069,7 +1083,7 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
1069
1083
1070
1084
# search the cache for an entry that matches the file or code argument
1071
1085
.sourceCppFindCacheEntryIndex <- function (cache , file , code ) {
1072
-
1086
+
1073
1087
if (length(cache ) > 0 ) {
1074
1088
for (i in 1 : length(cache )) {
1075
1089
entry <- cache [[i ]]
@@ -1080,22 +1094,22 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
1080
1094
}
1081
1095
}
1082
1096
}
1083
-
1097
+
1084
1098
# none found
1085
1099
NULL
1086
1100
}
1087
1101
1088
1102
# generate an R version / Rcpp version specific cache dir for dynlibs
1089
1103
.sourceCppPlatformCacheDir <- function (cacheDir ) {
1090
-
1104
+
1091
1105
dir <- file.path(cacheDir ,
1092
1106
paste(" sourceCpp" ,
1093
1107
R.version $ platform ,
1094
1108
utils :: packageVersion(" Rcpp" ),
1095
1109
sep = " -" ))
1096
1110
if (! dir.exists(dir ))
1097
1111
dir.create(dir , recursive = TRUE )
1098
-
1112
+
1099
1113
dir
1100
1114
}
1101
1115
@@ -1107,13 +1121,13 @@ sourceCppFunction <- function(func, isVoid, dll, symbol) {
1107
1121
load(file = token_file )
1108
1122
else
1109
1123
token <- 0
1110
-
1124
+
1111
1125
# increment
1112
1126
token <- token + 1
1113
-
1127
+
1114
1128
# write it
1115
1129
save(token , file = token_file )
1116
-
1130
+
1117
1131
# return it as a string
1118
1132
as.character(token )
1119
1133
}
0 commit comments