how to use conditional inclusion statements in headers used in RcppEigen project

59 Views Asked by At

I have an RcppEigen package that has a bunch of .h header files in it that I copy/pasted from my other library. These header files exist in two places, and right now there is only one difference between copies. In the pure c++ library, I include Eigen with #include <Eigen/Dense>. However, in the RcppEigen project, I need to use #include <RcppEigen.h>.

The problem with the naive solution--to hold on to two nearly-dentical copies of all these header files--is that I have a lot of code duplication.

To fix that I want to include the pure c++ library as a git submodule in the RcppEigen package. I would like to edit the c++ library to use conditional inclusion statements, so that they can be included in both pure c++ projects, as well as RcppEigen projects. I envision something like the following at the tops of the header files:

#ifdef DROPPINGTHISINRPACKAGE
    #include <RcppEigen.h>
#else
    #include <Eigen/Dense>
#endif

I'm confused what I should use for DROPPINGTHISINRPACKAGE, though. What is the customary way to do this in RcppEigen packages? What kinds of things are defined by the preprocessor in these kinds of packages that I can use?

Edit:

sourceCpp appears (to me) to be skipping over these flags being set in Makevars. Running Rcpp::sourceCpp(file = "~/pfexamplesinr/src/likelihoods.cpp") fails and complains that certain features are only available in c++17. It points to the spot in a header from the c++ library:

            #ifndef DROPPINGTHISINRPACKAGE
            if constexpr(debug) 
                std::cout << "time: " << m_now << ", transposed sample: " << m_particles[ii].transpose() << ", log unnorm weight: " << m_logUnNormWeights[ii] << "\n";
            #endif
0

There are 0 best solutions below