Re: [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 ?

2020-08-17 Thread Ivan Krylov
On Sat, 15 Aug 2020 19:50:41 +0530
Akshit Achara  wrote:

> 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. 

Just as Makevars is generated during ./configure run from Makefile.in,
you could generate a config.h from a config.h.in and substitute all the
necessary #defines in it. This is how GNU autoconf is typically used in
stand-alone programs [*].

A simpler option would be to add an equivalent of
-DMZN_PATH='"@MZN_PATH"' to PKG_CPPFLAGS in Makevars.in and make sure
that AC_SUBST is called for that variable in configure.ac [**]. Then
the C or C++ code would be able to use MZN_PATH as if it was #defined
in a header file.

-- 
Best regards,
Ivan

[*]
https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Configuration-Headers.html

[**]
https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Makefile-Substitutions.html

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


Re: [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 ?

2020-08-17 Thread Akshit Achara
Dear Andreas,

Thanks for your answer!

I also got an answer from Rcpp-devel list by Nik Pocuca. He suggested me to
create an .RData or .rda file
(say config.RData) in the data folder of my package and then execute the
statement given below in Makevars.in
to save the flag in the .RData file.
$(R_HOME)/bin/Rscript -e "LIBMINIZINC_PATH <- '@MZN_LIBS@';
save(LIBMINIZINC_PATH, file='../data/config.RData')"

This way the flag would be saved in the data file. Then in the script I
call data("config") and the LIBMINIZINC_PATH flag is
loaded in the global environment from where I can access and use it. I am
currently using this solution and haven't faced
any issues.

Thanks,
Akshit


On Mon, Aug 17, 2020 at 3:36 PM Blätte, Andreas 
wrote:

> 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"
>  acharaaks...@gmail.com>:
>
> Hi everyone,
>
> Background:
>
> The package rminizinc 
> provides
> an interface to MiniZinc
>  in R. The
> package
> provides various functionalities to parse, solve and manipulate
> MiniZinc
> models. This is done by using the MiniZinc C++ API (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@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
>

[[alternative HTML version deleted]]

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


Re: [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 ?

2020-08-17 Thread Blätte , Andreas
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" 
:

Hi everyone,

Background:

The package rminizinc  provides
an interface to MiniZinc
 in R. The package
provides various functionalities to parse, solve and manipulate MiniZinc
models. This is done by using the MiniZinc C++ API (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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

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


[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 ?

2020-08-15 Thread Akshit Achara
Hi everyone,

Background:

The package rminizinc  provides
an interface to MiniZinc
 in R. The package
provides various functionalities to parse, solve and manipulate MiniZinc
models. This is done by using the MiniZinc C++ API (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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel