2014-12-14 12:05:43 +00:00
2014-12-04 07:59:30 +00:00
#
2014-12-14 12:05:43 +00:00
# - This module locates an installed R distribution.
2014-12-04 07:59:30 +00:00
#
2014-12-14 12:05:43 +00:00
# Defines the following:
2014-12-04 07:59:30 +00:00
#
2015-11-05 19:28:22 +00:00
# R_INCLUDE_DIR - Path to R include directory
# R_LIBRARIES - Path to R library
# R_LIBRARY_BASE -
# R_COMMAND - Path to R command
# RSCRIPT_EXECUTABLE - Path to Rscript command
2014-12-04 07:59:30 +00:00
#
2015-11-05 19:28:22 +00:00
# Make sure find package macros are included
include ( FindPackageHandleStandardArgs )
2014-12-14 12:05:43 +00:00
set ( TEMP_CMAKE_FIND_APPBUNDLE ${ CMAKE_FIND_APPBUNDLE } )
set ( CMAKE_FIND_APPBUNDLE "NEVER" )
find_program ( R_COMMAND R DOC "R executable." )
if ( R_COMMAND )
2015-11-05 19:28:22 +00:00
execute_process ( WORKING_DIRECTORY . COMMAND ${ R_COMMAND } RHOME OUTPUT_VARIABLE R_BASE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE )
set ( R_HOME ${ R_BASE_DIR } CACHE PATH "R home directory obtained from R RHOME" )
mark_as_advanced ( R_HOME )
endif ( R_COMMAND )
find_program ( RSCRIPT_EXECUTABLE Rscript DOC "Rscript executable." )
2014-12-04 07:59:30 +00:00
2015-11-05 19:28:22 +00:00
set ( CMAKE_FIND_APPBUNDLE ${ TEMP_CMAKE_FIND_APPBUNDLE } )
2014-12-04 07:59:30 +00:00
2015-11-05 19:28:22 +00:00
# R.h gets installed in all sorts of places -
# ubuntu: /usr/share/R/include, RHEL/Fedora: /usr/include/R/R.h
find_path ( R_INCLUDE_DIR R.h PATHS ${ R_INCLUDE_DIR_HINT } /usr/local/lib /usr/local/lib64 /usr/share /usr/include ${ R_BASE_DIR } PATH_SUFFIXES include R R/include DOC "Path to file R.h" )
find_library ( R_LIBRARY_BASE R PATHS ${ R_BASE_DIR } PATH_SUFFIXES /lib DOC "R library (example libR.a, libR.dylib, etc.)." )
2014-12-04 07:59:30 +00:00
2015-11-05 19:28:22 +00:00
set ( R_LIBRARIES ${ R_LIBRARY_BASE } )
mark_as_advanced ( RSCRIPT_EXECUTABLE R_LIBRARIES R_INCLUDE_DIR R_COMMAND R_LIBRARY_BASE )
2014-12-04 07:59:30 +00:00
2015-11-05 19:28:22 +00:00
set ( _REQUIRED_R_VARIABLES R_INCLUDE_DIR R_COMMAND )
2014-12-04 07:59:30 +00:00
2015-11-05 19:28:22 +00:00
if ( APPLE )
# On linux platform some times the libR.so is not available, however
# on apple a link error results if the library is linked.
list ( APPEND _REQUIRED_R_VARIABLES R_LIBRARIES R_LIBRARY_BASE )
2014-12-14 12:05:43 +00:00
endif ( )
2014-12-04 07:59:30 +00:00
2015-11-05 19:28:22 +00:00
find_package_handle_standard_args ( R DEFAULT_MSG ${ _REQUIRED_R_VARIABLES } )