[Rcpp-commits] r390 - in pkg: R inst inst/discovery inst/skeleton

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 17 11:46:18 CET 2010


Author: romain
Date: 2010-01-17 11:46:17 +0100 (Sun, 17 Jan 2010)
New Revision: 390

Added:
   pkg/inst/discovery/
   pkg/inst/discovery/README
   pkg/inst/discovery/cxx0x.c
Modified:
   pkg/R/RcppLdpath.R
   pkg/inst/ChangeLog
   pkg/inst/skeleton/Makevars
Log:
discove c++0x by compiling a discovery script

Modified: pkg/R/RcppLdpath.R
===================================================================
--- pkg/R/RcppLdpath.R	2010-01-17 04:38:49 UTC (rev 389)
+++ pkg/R/RcppLdpath.R	2010-01-17 10:46:17 UTC (rev 390)
@@ -26,11 +26,12 @@
     invisible(flags)
 }
 
+# indicates if Rcpp was compiled with GCC >= 4.3
 canUseCXX0X <- function() .Call( "canUseCXX0X", PACKAGE = "Rcpp" )
 
 ## Provide compiler flags -- i.e. -I/path/to/Rcpp.h
-RcppCxxFlags <- function() {
-    paste("-I", RcppLdPath(), if( canUseCXX0X() ) " -std=c++0x" else "", sep="")
+RcppCxxFlags <- function(cxx0x=FALSE) {
+    paste("-I", RcppLdPath(), if( cxx0x && canUseCXX0X() ) " -std=c++0x" else "", sep="")
 }
 
 ## Shorter names, and call cat() directly
@@ -40,3 +41,22 @@
 # capabilities
 RcppCapabilities <- capabilities <- function() .Call("capabilities", PACKAGE = "Rcpp")
 
+# compile, load and call the cxx0x.c script to identify whether 
+# the compiler is GCC >= 4.3
+RcppCxx0xFlags <- function(){
+	td <- tempfile()
+	dir.create( td ) 
+	here <- getwd() 
+	setwd(td) 
+	on.exit( { setwd(here) ; unlink( td, recursive = TRUE ) } )
+	file.copy( system.file( "discovery", "cxx0x.c", package = "Rcpp" ), td )
+	system( 'R CMD SHLIB cxx0x.c', intern = TRUE )
+	dll <- sprintf( "cxx0x%s", .Platform$dynlib.ext )
+	dyn.load( dll )
+	res <- tryCatch( .Call( "cxx0x" ), error = "" )
+	dyn.unload( dll )
+	res
+}
+
+Cxx0xFlags <- function() cat( RcppCxx0xFlags() )
+

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-17 04:38:49 UTC (rev 389)
+++ pkg/inst/ChangeLog	2010-01-17 10:46:17 UTC (rev 390)
@@ -1,5 +1,15 @@
 2010-01-16  Romain Francois <francoisromain at free.fr>
 
+	* R/RcppLdPath.R : new script RcppCxx0xFlags() and Cxx0xFlags()
+	that compile, load and call a simple C file in order to check 
+	the compiler version and add the -std=c++0x flag
+
+	* inst/discovery/cxx0x.c: discovery script. simple C script that 
+	returns "-std=c++0x" if it is compiled with GCC >= 4.3 and 
+	"" otherwise
+
+2010-01-16  Romain Francois <francoisromain at free.fr>
+
 	* src/Rcpp/Environment.h: Environment gains a new_child method
 	to create an environment enclosed by this
 	* inst/unitTests/runit.environments.R: unit test for new_child

Added: pkg/inst/discovery/README
===================================================================
--- pkg/inst/discovery/README	                        (rev 0)
+++ pkg/inst/discovery/README	2010-01-17 10:46:17 UTC (rev 390)
@@ -0,0 +1,7 @@
+The cxx0x.c script is used by the Rcpp::RcppCxx0xFlags function. 
+When called, the RcppCxx0xFlags compiles and loads this script, and then 
+calls the cxx0x function. 
+
+If compiled with GCC > 4.3 the script returns "-std=c++0x", otherwise
+it returns ""
+

Added: pkg/inst/discovery/cxx0x.c
===================================================================
--- pkg/inst/discovery/cxx0x.c	                        (rev 0)
+++ pkg/inst/discovery/cxx0x.c	2010-01-17 10:46:17 UTC (rev 390)
@@ -0,0 +1,14 @@
+#include <R.h>
+#include <Rdefines.h>
+
+SEXP cxx0x(){
+
+#ifdef __GNUC__
+	#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+	#if GCC_VERSION >= 40300
+	return mkString( "-std=c++0x" ) ;
+	#endif
+#endif
+return mkString( "" ) ;
+}
+

Modified: pkg/inst/skeleton/Makevars
===================================================================
--- pkg/inst/skeleton/Makevars	2010-01-17 04:38:49 UTC (rev 389)
+++ pkg/inst/skeleton/Makevars	2010-01-17 10:46:17 UTC (rev 390)
@@ -1,10 +1,9 @@
-PKG_CXXFLAGS=`Rscript -e "Rcpp:::CxxFlags()"` -I.
-PKG_LIBS = `Rscript -e "Rcpp:::LdFlags()" `
+PKG_CPPFLAGS=$(shell Rscript -e "Rcpp:::CxxFlags()" )
+PKG_LIBS = $(shell Rscript -e "Rcpp:::LdFlags()" )
 
-all: $(SHLIB) hack
+## If C++0x features are desired, uncomment the next lines
+# PKG_CXXFLAGS += $(shell Rscript -e "Rcpp:::Cxx0xFlags()" )
+# all: $(SHLIB) hack
+# hack:
+# 	mkdir tmp; cp $(SHLIB) tmp/ ; rm -fr tmp
 
-# this hack is there to prevent R CMD check from rejecting 
-# our CxxFlags
-hack:
-	mkdir tmp; cp $(SHLIB) tmp/ ; rm -fr tmp
-



More information about the Rcpp-commits mailing list