[R-pkg-devel] How to retrieve a flag set in configure.ac (filled in Makevars.in) during package installation in an R or C++ script ?

Blätte, Andreas @ndre@@@b|@ette @end|ng |rom un|-due@de
Mon Aug 17 12:06:19 CEST 2020


Dear Akshit,

in the configure script of my package RcppCWB, I use the command line call 'R CMD config ...' to get the installation flags. 

Calling 'R CMD config' will display options. For your scenario, you can use 'R CMD config CPPFLAGS' to get the value of CPPFLAGS. 

To call R CMD config safely, you will need to prepend $R_HOME/bin. In the configure script of RcppCWB, I need to detect the compiler used and I do it using this snippet:
CC_R=`$R_HOME/bin/R CMD config CC`

More experienced people following R-package-devel than myself may be aware of a better solution, and I would also be happy to learn about it.

Kind regards
Andreas 


Am 15.08.20, 16:25 schrieb "R-package-devel im Auftrag von Akshit Achara" <r-package-devel-bounces using r-project.org im Auftrag von acharaakshit using gmail.com>:

    Hi everyone,

    Background:

    The package rminizinc <https://github.com/acharaakshit/RMiniZinc> provides
    an interface to MiniZinc
    <https://www.minizinc.org/tutorial/minizinc-tute.pdf> in R. The package
    provides various functionalities to parse, solve and manipulate MiniZinc
    models. This is done by using the MiniZinc C++ API (libminizinc
    <https://github.com/MiniZinc/libminizinc>).

    The installation requires linking of the library an including the header
    files for which PKG_LIBS flag(-L/path/to/libminizinc -lmzn) , and
    PKG_CPPFLAGS (-I/path/to/libminizinc/include) are filled in Makevars.in
    which is set by configure based on the path of the library provided by the
    user using --configure-args or if the user doesn't provide any arguments, a
    default path is passed from configure (using configure.ac).

    Question:

    In one of my Rcpp functions mzn_parse() which is used to parse MiniZinc
    models, I sometimes need to use the files in the subdirectories of the
    libminizinc library. To access these files, I need to use the path of
    libminizinc (which can change per installation). I want to extract this
    path from either Makevars or configure to use it in my package. Is there
    any way I could retrieve this path in my scripts?

    Please let me know if this question is not relevant to the mailing list.

    The Makevars.in looks like this:

    CXX_STD = CXX11
    PKG_CPPFLAGS = -I. @MZN_INCLUDE@
    PKG_LIBS = @MZN_LIBS@
    OBJECTS.tests = cpp_tests/test-runner.o cpp_tests/test-mzn_parse.o
    cpp_tests/test-
    set_params.o cpp_tests/test-mzn_eval.o cpp_tests/test-sol_parse.o
    cpp_tests/test-
    getMissingPars.o
    OBJECTS.sources = RcppExports.o set_params.o mzn_parse.o mzn_eval.o sol_parse.o
    getMissingPars.o
    OBJECTS.helpers = filetoString.o helper_parse.o expDetails.o pathStringcheck.o
    OBJECTS = $(OBJECTS.sources) $(OBJECTS.tests) $(OBJECTS.helpers)
    $(SOURCES:.cpp=.o)
    strippedLib: $(SHLIB)
        if test -e "/usr/bin/strip"; then /usr/bin/strip --strip-debug
    $(SHLIB); fi.phony: strippedLib
    all: clean
    clean:
        rm -f $(OBJECTS.sources) $(OBJECTS.tests) $(OBJECTS.helpers)  *.so

    Thanks!

    	[[alternative HTML version deleted]]

    ______________________________________________
    R-package-devel using r-project.org mailing list
    https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list