安装R包的头文件

时间:2015-12-01 10:31:55

标签: c++ r cmake

我正在使用根目录下具有以下目录结构的R包:

CMakeLists.txt
configure
configure.win
NAMESPACE
DESCRIPTION
README
src
cmake
examples
man
R

我像这样构建和安装:

R CMD build . 
R CMD INSTALL mypackage*.tar.gz -l /home/myname/Rlibs/

这会将.so文件安装到我的安装目录中,但我还想在我的安装区域中安装该软件包的一些头文件。标头文件位于'src'文件夹中,扩展名为.h。我找不到办法做到这一点。有人可以帮忙吗?顺便说一句您可能从目录列表中看到我正在使用cmake

修改: 根目录中的配置文件如下所示:

#!/bin/bash -e

set -x

unset CXX
unset CC

which cmake
cmake --version
cmake -H. -B_builds -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="`pwd`/_install" -DCMAKE_SHARED_LIBRARY_PREFIX_CXX=""
cmake --build _builds --config Release --target install

mv _install/lib/mypackage.so src/mypackage.so || echo -n ""

根目录中的CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
project(mypackage)

if(NOT MSVC)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()


if(MSVC AND MYPACKAGE_DISABLE_AUTOLINK)
  add_definitions(-DBOOST_ALL_NO_LIB=1)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

add_subdirectory(src)

src目录中的CMakeLists.txt:

include(GenerateExportHeader)

include_directories("${CMAKE_CURRENT_BINARY_DIR}") 

find_package(GSL REQUIRED)
find_package(Boost REQUIRED filesystem system regex log thread date_time chrono)
find_package(GDAL REQUIRED)

if(NOT WIN32)
  add_definitions(-DBOOST_ALL_DYN_LINK=1)
endif()  

add_library(
    mypackage
    SHARED
    SomeAlgo.cpp
    SomeAlgo.h
    MyParam.h
    SomeList.cpp
    SomeList.h
)
generate_export_header(mypackage)

target_include_directories(mypackage PUBLIC "${R_INCLUDE_DIR}")
target_link_libraries(mypackage "${R_LIBRARIES}")

install(TARGETS mypackage DESTINATION lib)
install(FILES SomeList.h DESTINATION include) # <-- I added this

编辑2 我从R CMD INSTALL获得此输出

* installing *source* package ‘mypackage’ ...
+ unset CXX
+ unset CC
+ which cmake
/usr/bin/cmake
+ cmake --version
cmake version 3.0.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
++ pwd
+ cmake -H. -B_builds -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/RtmpSaU3wb/R.INSTALL761c2555d904/mypackage/_install -DCMAKE_SHARED_LIBRARY_PREFIX_CXX=
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
.....
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/RtmpSaU3wb/R.INSTALL761c2555d904/mypackage/_builds
+ cmake --build _builds --config Release --target install
Scanning dependencies of target mypackage_fpredict
[  3%] Building CXX object src/mypackage/CMakeFiles/mypackage_fpredict.dir/__/OpusReader.cpp.o
....
[100%] Building CXX object src/CMakeFiles/mypackage.dir/mypackage/RBackend.cpp.o
Linking CXX shared library mypackage.so
[100%] Built target mypackage
Install the project...
-- Install configuration: "Release"
-- Installing: /tmp/RtmpSaU3wb/R.INSTALL761c2555d904/mypackage/_install/lib/mypackage.so
-- Removed runtime path from "/tmp/RtmpSaU3wb/R.INSTALL761c2555d904/mypackage/_install/lib/mypackage.so"
+ mv _install/lib/mypackage.so src/mypackage.so
+ echo -n ''
** libs
** arch -
make: Nothing to be done for 'all'.
installing to /home/myname/Rlibs/mypackage/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (mypackage)

只有.so文件最终在/ home / myname / Rlibs / mypackage / libs /中,没有包含目录或头文件。但是我在临时构建目录中看到了include目录(在配置中添加了ls以查看它)。所以基本上问题是将include目录从临时构建目录移动到我的Rlibs区域

1 个答案:

答案 0 :(得分:0)

好的,所以R CMD INSTALL检查是否有名为&#34; inst&#34;的目录。并将该目录中的文件或目录安装到库安装路径中。在R包中,我正在研究这个&#34; inst&#34;包不存在所以我在临时构建目录下使用cmake进行编译时动态创建它,所以我修改了配置文件:

#!/bin/bash -e

set -x

unset CXX
unset CC

which cmake
cmake --version
cmake -H. -B_builds -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="`pwd`/_install" -DCMAKE_SHARED_LIBRARY_PREFIX_CXX=""
cmake --build _builds --config Release --target install

## Added two lines below ##
mkdir inst
mv  _install/include inst

mv _install/lib/mypackage.so src/mypackage.so || echo -n ""

最后我得到/home/myname/Rlibs/mypackage/include/SomeList.h