title: Install header file of R package
body: <p>I am working on an R package with the following directory structure at the root:</p>
  
  <pre><code>CMakeLists.txt
  configure
  configure.win
  NAMESPACE
  DESCRIPTION
  README
  src
  cmake
  examples
  man
  R
  </code></pre>
  
  <p>I build and install like so :</p>
  
  <pre><code>R CMD build . 
  R CMD INSTALL mypackage*.tar.gz -l /home/myname/Rlibs/
  </code></pre>
  
  <p>This installs the <code>.so</code> file into my installation directory, but I'd also like to install some of the header files of the package in my installation area. The header files are in the <code>'src'</code> folder with the <code>.h</code> extension. I can't find a way to do that. Can someone help? BTW As you might see from the directory listing I'm using <code>cmake</code>.</p>
  
  <p><strong>Edit :</strong> 
  The configure file in the root directory looks like this :</p>
  
  <pre><code>#!/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 ""
  </code></pre>
  
  <p>The CMakeLists.txt in the root directory :</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>And the CMakeLists.txt in the <code>src</code> directory :</p>
  
  <pre><code>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) # &lt;-- I added this
  </code></pre>
  
  <p><strong>Edit 2</strong> 
  I get this output from R CMD INSTALL </p>
  
  <pre><code>* 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)
  </code></pre>
  
  <p>Only the .so file ends up in /home/myname/Rlibs/mypackage/libs/, there's no include directory or header file. However I see the include directory in the temporary build directory (added a <code>ls</code> to the configure to see it). So basically the problem is to move the include directory from the temporary build directory to my <code>Rlibs</code> area</p>