2015-12-01 175 views
0

我在R包正與在根下面的目錄結構的頭文件:安裝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文件放到我的安裝目錄中,但我還想在安裝區域中安裝該軟件包的一些頭文件。頭文件位於文件夾中,其擴展名爲.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) 

而且的CMakeLists.txt在src目錄:

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的/庫/,也沒有包括目錄或頭文件。但是,我在臨時生成目錄中看到include目錄(將ls添加到配置中以查看它)。所以基本上問題是將include目錄從臨時構建目錄移動到我的Rlibs區域

+0

你希望頭文件在'/ home/myname/Rlibs /'或其他地方? –

+0

是的,就像'/ home/myname/Rlibs/mypackage /' – hadron

+0

好吧,那麼你可以爲我們發佈構建'.tar.gz'文件的'CMakeLists.txt'部分嗎? –

回答

0

好的,R CMD INSTALL檢查是否有一個名爲「inst」的目錄,並將該目錄中的文件或目錄安裝到庫中安裝路徑。在R包我工作的這個「出師表」包不存在,所以我在飛行中創建與臨時構建目錄下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