Skip to content

Commit 7ed45ef

Browse files
committed
Merge pull request #247 from RcppCore/feature/rcppexports-types
Include pkg_types.h file in exports if it's present in inst/include or src
2 parents 3e5099c + 17a7517 commit 7ed45ef

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2014-02-03 JJ Allaire <jj@rstudio.org>
2+
3+
* R/Attributes.R: Include pkg_types.h file in RcppExports.cpp
4+
if it's present in inst/include or src
5+
* src/attributes.cpp: Include pkg_types.h file in generated
6+
C++ interface file if it's present in inst/include or src
7+
18
2015-02-02 JJ Allaire <jj@rstudio.org>
29

310
* R/exceptions.R: Evaluate R code within an R_toplevelExec block

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 0.11.4.1
3+
Version: 0.11.4.2
44
Date: 2015-02-03
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey,
66
Douglas Bates, and John Chambers

R/Attributes.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,24 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
380380
linkingTo <- .readPkgDescField(pkgDesc, "LinkingTo")
381381
includes <- .linkingToIncludes(linkingTo, TRUE)
382382

383-
# if a master include file is defined for the package then include it
384-
pkgHeader <- paste(pkgname, ".h", sep="")
383+
# if a master include file or types file is in inst/include then use it
384+
typesHeader <- c(paste0(pkgname, "_types.h"), paste0(pkgname, "_types.hpp"))
385+
pkgHeader <- c(paste0(pkgname, ".h"), typesHeader)
385386
pkgHeaderPath <- file.path(pkgdir, "inst", "include", pkgHeader)
386-
if (file.exists(pkgHeaderPath)) {
387+
pkgHeader <- pkgHeader[file.exists(pkgHeaderPath)]
388+
if (length(pkgHeader) > 0) {
387389
pkgInclude <- paste("#include \"../inst/include/",
388390
pkgHeader, "\"", sep="")
389391
includes <- c(pkgInclude, includes)
390392
}
391393

394+
# if a _types file is in src then include it
395+
pkgHeader <- typesHeader
396+
pkgHeaderPath <- file.path(pkgdir, "src", pkgHeader)
397+
pkgHeader <- pkgHeader[file.exists(pkgHeaderPath)]
398+
if (length(pkgHeader) > 0)
399+
includes <- c(paste0("#include \"", pkgHeader ,"\""), includes)
400+
392401
# generate exports
393402
invisible(.Call("compileAttributes", PACKAGE="Rcpp",
394403
pkgdir, pkgname, depends, cppFiles, cppFileBasenames,

inst/NEWS.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
\item Evaluate R code within an \code{R_toplevelExec} block to prevent
1212
user interrupts from bypassing C++ destructors on the stack.
1313
}
14+
\item Changes in Rcpp Attributes:
15+
\itemize{
16+
\item Include pkg_types.h file in RcppExports.cpp if it's present in
17+
inst/include or src.
18+
}
1419
}
1520
}
1621

src/attributes.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,9 +1750,23 @@ namespace attributes {
17501750
if (!includes.empty()) {
17511751
for (std::size_t i=0;i<includes.size(); i++)
17521752
{
1753-
// don't do inst/include here
1754-
if (includes[i].find("#include \"../inst/include/")
1755-
== std::string::npos)
1753+
// some special processing is required here. we exclude
1754+
// the package header file (since it includes this file)
1755+
// and we transorm _types includes into local includes
1756+
std::string preamble = "#include \"../inst/include/";
1757+
std::string pkgInclude = preamble + package() + ".h\"";
1758+
if (includes[i] == pkgInclude)
1759+
continue;
1760+
1761+
// check for _types
1762+
std::string typesInclude = preamble + package() + "_types.h";
1763+
if (includes[i].find(typesInclude) != std::string::npos)
1764+
{
1765+
std::string include = "#include \"" +
1766+
includes[i].substr(preamble.length());
1767+
ostr << include << std::endl;
1768+
}
1769+
else
17561770
{
17571771
ostr << includes[i] << std::endl;
17581772
}

0 commit comments

Comments
 (0)