11
22
3+ # Output the LD flags for building against TBB. These flags are propagated
4+ # to sourceCpp via the inlineCxxPlugin (defined below) and to packages
5+ # via a line in Makevars.win like this:
6+ #
7+ # PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppParallel::LdFlags()")
8+ #
9+ # Note that this is only required for Windows builds (on Linux and OS X no
10+ # explicit link to TBB is required).
11+ RcppParallelLibs <- function () {
12+ cat(tbbLdFlags())
13+ }
314
4- inlineCxxPlugin <- function () {
515
6- # For sourceCpp on Windows we need to explicitly link against tbb.dll
7- if (Sys.info()[' sysname' ] == " Windows" ) {
8- tbb <- tbbLibPath()
9- pkgLibs <- paste(" -L" , asBuildPath(dirname(tbb )),
10- " -ltbb" , sep = " " )
11- env <- list (PKG_LIBS = pkgLibs )
12- } else {
13- env <- list ()
14- }
15-
16+ # Inline plugin used by sourceCpp to link to the TBB library
17+ inlineCxxPlugin <- function () {
1618 list (
17- env = env ,
19+ env = list ( PKG_LIBS = tbbLdFlags()) ,
1820 includes = " #include <RcppParallel.h>" ,
1921 LinkingTo = " RcppParallel" ,
2022 body = function ( x ) x ,
@@ -23,6 +25,19 @@ inlineCxxPlugin <- function() {
2325}
2426
2527
28+ # Return the linker flags requried for TBB on this platform
29+ tbbLdFlags <- function () {
30+ # on Windows we need to explicitly link against tbb.dll
31+ if (Sys.info()[' sysname' ] == " Windows" ) {
32+ tbb <- tbbLibPath()
33+ paste(" -L" , asBuildPath(dirname(tbb )), " -ltbb" , sep = " " )
34+ } else {
35+ " "
36+ }
37+ }
38+
39+
40+ # Determine the platform-specific path to the TBB library
2641tbbLibPath <- function () {
2742 sysname <- Sys.info()[' sysname' ]
2843 tbbSupported <- list (
@@ -41,14 +56,15 @@ tbbLibPath <- function() {
4156 }
4257}
4358
59+
60+ # Helper function to ape the behavior of the R build system
61+ # when providing paths to libraries
4462asBuildPath <- function (path ) {
45-
4663 if (.Platform $ OS.type == " windows" ) {
4764 path <- normalizePath(path )
4865 if (grepl(' ' , path , fixed = TRUE ))
4966 path <- utils :: shortPathName(path )
5067 path <- gsub(" \\\\ " , " /" , path )
5168 }
52-
5369 return (path )
5470}
0 commit comments