I added some C++ code to one of my R packages using Rcpp to help with some intense calculations. The sourceCpp version worked great. However, the same function was many times slower after actually adding it to the package. After some sleuthing, it became apparent that this was a compiler optimization issue. Long story short, I am trying to add a Makevars and Makevars.win file to /src in the package directory to optimize the code when available.
I'd like to submit the updated package to CRAN, so I need to make it pass the appropriate checks. Currently, I'm getting the Warning: Non-portable flags in variable 'PKG_CXXFLAGS'.
I've made various attempts to correct the issue. e.g.,
PKG_CXXFLAGS = -O3
PKG_CXXFLAGS = -g -O -mtune=native
PKG_CXXFLAGS = -mtune=native
PKG_CXXFLAGS = -g
PKG_CXXFLAGS = -g -O3 -Wall -pedantic -mtune=native -frtti -Wno-ignored-attributes -Wno-deprecated-declarations -D_FORTIFY_SOURCE=2 $(LTO)
(The last attempt was from here: https://accio.github.io/programming/2019/04/24/R-Makevars.html, which was supposed to fix the issue.)
I'm still getting the warning. My question is: Is there a simple, platform agnostic approach for encouraging compiler optimization via the Makevars or Makevars.win files in /src?
Since I've not seen any Makevars of this type, I'm guessing the answer is no. If there is an approach using an autoconf, I haven't seen an example that I understand.