Skip to content

Commit a0476db

Browse files
committed
Use TBB_INC & TBB_LIB and update CXXFLAGS
Use TBB_INC & TBB_LIB environment variables and update CXXFLAGS accordingly. To use system TBB, both TBB_INC & TBB_LIB environment variables should be defined and the directories of TBB headers and libraries exist. Signed-off-by: Hamada S. Badr <hamada.s.badr@gmail.com>
1 parent 1ce2854 commit a0476db

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

R/build.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ inlineCxxPlugin <- function() {
4141
}
4242

4343
tbbCxxFlags <- function() {
44-
44+
4545
flags <- c()
46-
46+
4747
# opt-in to TBB on Windows
4848
if (Sys.info()['sysname'] == "Windows")
4949
flags <- paste(flags, "-DRCPP_PARALLEL_USE_TBB=1")
50-
50+
51+
if (dir.exists(Sys.getenv("TBB_INC"))) {
52+
TBB_INC <- normalizePath(Sys.getenv("TBB_INC"))
53+
flags <- paste0("-I", shQuote(TBB_INC))
54+
}
55+
5156
flags
5257
}
5358

@@ -74,10 +79,9 @@ tbbLibPath <- function(suffix = "") {
7479
"SunOS" = paste("libtbb", suffix, ".so", sep = "")
7580
)
7681

77-
tbb <- Sys.getenv("TBB_LIBRARY_FILE")
78-
if (file.exists(tbb)) {
79-
libDir <- dirname(tbb)
80-
normalizePath(file.path(libDir, paste("libtbb", suffix, ".so", sep = "")))
82+
if (dir.exists(Sys.getenv("TBB_LIB"))) {
83+
TBB_LIB <- normalizePath(Sys.getenv("TBB_LIB"))
84+
normalizePath(file.path(TBB_LIB, paste("libtbb", suffix, ".so", sep = "")))
8185
} else {
8286
if ((sysname %in% names(tbbSupported)) && !isSparc()) {
8387
libDir <- "lib/"

src/Makevars.in

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11

2-
PKG_CPPFLAGS = -I../inst/include
32
PKG_CXXFLAGS = @CXX11STD@
43

5-
ifdef TBB_LIBRARY_FILE
6-
PKG_LIBS = -ltbb
4+
ifdef TBB_INC
5+
PKG_CPPFLAGS = -I../inst/include -I$(TBB_INC)
6+
else
7+
PKG_CPPFLAGS = -I../inst/include
8+
endif
9+
10+
ifdef TBB_LIB
11+
PKG_LIBS = -L$(TBB_LIB) -ltbb
712
endif
813

914
ifeq ($(OS), Windows_NT)
@@ -90,8 +95,8 @@ endif
9095
all: tbb $(SHLIB)
9196

9297
tbb:
93-
ifdef TBB_LIBRARY_FILE
94-
echo "Using system (Intel/OneAPI) TBB library: $(TBB_LIBRARY_FILE)"; \
98+
ifdef TBB_LIB
99+
echo "Using system (Intel/OneAPI) TBB library..."; \
95100
mkdir -p ../inst/lib/$(ARCH_DIR); \
96101
rm -rf ../inst/include/serial/ ../inst/include/tbb/; \
97102
rm -rf ../inst/include/tbb_local/
@@ -113,7 +118,7 @@ else
113118
endif
114119

115120
clean:
116-
ifdef TBB_LIBRARY_FILE
121+
ifdef TBB_LIB
117122
echo "Nothing to clean for TBB."
118123
else
119124
(cd tbb/src; make clean)

0 commit comments

Comments
 (0)