Wade
Wade

Reputation: 345

Use another compiler when install R packages with Rcpp and CMake

What I'm doing I'm developing an R interface/package for C++ codes with Rcpp and CMake. Because openmp and c++11 should be supported, so I have a preference on compilers.

Problem I know that I can always put Makevars under ~/.R (Unix) to change the compiler R uses when install packages. But as a developer, it is not recommended to do so.

It is recommended to use configure file to do that. However, I don't quite know how to achieve this, because I'm writing configure file by myself and calling cmake inside my configure. I don't know what to write in configure file to search for a specific compiler.

Hope the description is clear. Thank you.

I have attached my configure file content below.

```

set -x
set -e

which cmake

rm -rf _builds

# call cmake that will set compiler flags in src/Makevars
# and download dependencies
cmake -H. -B_builds

```

Upvotes: 2

Views: 1685

Answers (2)

Qiang Kou
Qiang Kou

Reputation: 522

As I understand, you want to detect if the compiler supports openmp and C++11.

There are many existing packages using configure to detect openmp support. One example is ARTP2 (https://github.com/zhangh12/ARTP2/blob/master/configure.ac), which has been mentioned in the "Writing R extension" as an example. You can also use the configure script in xgboost by me (https://github.com/dmlc/xgboost/blob/master/R-package/configure.ac) as an example. We leave OPENMP_CXXFLAGS blank if the compiler doesn't support openmp.

For C++11 support, you can try AX_CXX_COMPILE_STDCXX_11. But this will require a new version of autoconf.

I think you can also try AC_PROG_CXX to select compilers, like icc.

Upvotes: 1

DaBookshah
DaBookshah

Reputation: 196

I've been using CMake for building R packages for quite a while, see https://github.com/rohan-shah/mpMap2 for an example.

I completely bypass the R build system though, so I don't use configure at all.

Upvotes: 1

Related Questions