Skip to content

Commit

Permalink
Include CmdStan CPPFLAGS when exposing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Jun 27, 2024
1 parent 9878dda commit 7c55d5d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -783,18 +783,22 @@ check_sundials_fpic <- function(verbose) {
rcpp_source_stan <- function(code, env, verbose = FALSE, ...) {
check_sundials_fpic(verbose)
cxxflags <- get_cmdstan_flags("CXXFLAGS")
cppflags <- get_cmdstan_flags("CPPFLAGS")
cmdstanr_includes <- system.file("include", package = "cmdstanr", mustWork = TRUE)
cmdstanr_includes <- paste0(" -I\"", cmdstanr_includes,"\"")
libs <- c("LDLIBS", "LIBSUNDIALS", "TBB_TARGETS", "LDFLAGS_TBB", "SUNDIALS_TARGETS")
libs <- paste(sapply(libs, get_cmdstan_flags), collapse = " ")
if (.Platform$OS.type == "windows") {
libs <- paste(libs, "-fopenmp")
}
if (cmdstan_version() <= "2.30.1") {
cppflags <- paste0(cppflags, " -DCMDSTAN_JSON")
}
withr::with_path(repair_path(file.path(cmdstan_path(),"stan/lib/stan_math/lib/tbb")),
withr::with_makevars(
c(
USE_CXX14 = 1,
PKG_CPPFLAGS = ifelse(cmdstan_version() <= "2.30.1", "-DCMDSTAN_JSON", ""),
PKG_CPPFLAGS = cppflags,
PKG_CXXFLAGS = paste0(cxxflags, cmdstanr_includes, collapse = " "),
PKG_LIBS = libs
),
Expand Down

0 comments on commit 7c55d5d

Please sign in to comment.