Locate system wide libraries in Rcpp Makevars

2019-08-23 16:37发布

问题:

I wrote a C++ package "P". It has an R interface package "RP", built using Rcpp. P used Make directly for compilation, but was switched to CMake for portability. CMake is used to find headers (let's call their collection HF) and static libraries (SL in the rest of the present post) for system wide libraries.

I want to update RP to be able to depend on the CMake evolution of P. In the C++ sources RP/src/*.cpp, HF elements are included, and of course SL are statically linked.

What is the best way to call CMake in RP/src/Makevars to retrieve the locations of HF and SL ? The point here is not to replace the build system of Rcpp, but to leverage the search capabilities of CMake.

At the moment, P (CMake version) and RP build on my machine, using absolute path references in RP/src/Makevars such as:

INC_NLOPT = /usr/local/Cellar/nlopt/2.4.2_2/include
LIB_NLOPT = /usr/local/Cellar/nlopt/2.4.2_2/lib/libnlopt.a

Since we use RP internaly at the moment, we can expect CMake, HF and SL to be installed on every machine we will deploy to.

回答1:

The solution was to create a CMakeFileLists.txt file in RP/src. In this file, a Libvar file containing the required library paths is written using CMake file command. Libvar is then included in Makevars using include.

A configure file at the root of the package is executed to ensure that Libvar is generated before every call to make by R.



标签: c++ r cmake