newer Find R module

This commit is contained in:
Vítor Santos Costa 2015-11-05 19:28:22 +00:00
parent aa2fb8f0c5
commit 44dc6f06d7
1 changed files with 29 additions and 59 deletions

View File

@ -3,76 +3,46 @@
# - This module locates an installed R distribution.
#
# Defines the following:
# R_COMMAND - Path to R command
# R_HOME - Path to 'R home', as reported by R
# R_INCLUDE_DIR - Path to R include directory
# R_LIBRARY_BASE - Path to R library
# R_LIBRARY_BLAS - Path to Rblas / blas library
# R_LIBRARY_LAPACK - Path to Rlapack / lapack library
# R_LIBRARY_READLINE - Path to readline library
# R_LIBRARIES - Array of: R_LIBRARY_BASE, R_LIBRARY_BLAS, R_LIBRARY_LAPACK, R_LIBRARY_BASE [, R_LIBRARY_READLINE]
#
# VTK_R_HOME - (deprecated, use R_HOME instead) Path to 'R home', as reported by R
#
# Variable search order:
# 1. Attempt to locate and set R_COMMAND
# - If unsuccessful, generate error and prompt user to manually set R_COMMAND
# 2. Use R_COMMAND to set R_HOME
# 3. Locate other libraries in the priority:
# 1. Within a user-built instance of R at R_HOME
# 2. Within an installed instance of R
# 3. Within external system libraries
# 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
#
# Make sure find package macros are included
include( FindPackageHandleStandardArgs )
set(TEMP_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
set(CMAKE_FIND_APPBUNDLE "NEVER")
find_program(R_COMMAND R DOC "R executable.")
if(R_COMMAND)
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.")
set(CMAKE_FIND_APPBUNDLE ${TEMP_CMAKE_FIND_APPBUNDLE})
if(R_COMMAND)
execute_process(WORKING_DIRECTORY .
COMMAND ${R_COMMAND} RHOME
OUTPUT_VARIABLE R_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
# deprecated
if(VTK_R_HOME)
set(R_HOME ${VTK_R_HOME} CACHE PATH "R home directory obtained from R RHOME")
else()
set(R_HOME ${R_ROOT_DIR} CACHE PATH "R home directory obtained from R RHOME")
set(VTK_R_HOME ${R_HOME})
endif()
# /deprecated
# the following command does nothing currently, but will be used when deprecated code is removed
set(R_HOME ${R_ROOT_DIR} CACHE PATH "R home directory obtained from R RHOME")
# 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.).")
find_path(R_INCLUDE_DIR R.h
HINTS ${R_ROOT_DIR}
PATHS /usr/local/lib /usr/local/lib64 /usr/share
PATH_SUFFIXES include R/include
DOC "Path to file R.h")
set(R_LIBRARIES ${R_LIBRARY_BASE})
mark_as_advanced(RSCRIPT_EXECUTABLE R_LIBRARIES R_INCLUDE_DIR R_COMMAND R_LIBRARY_BASE)
find_library(R_LIBRARY_BASE R
HINTS ${R_ROOT_DIR}/lib
DOC "R library (example libR.a, libR.dylib, etc.).")
find_library(R_LIBRARY_BLAS NAMES Rblas blas
HINTS ${R_ROOT_DIR}/lib
DOC "Rblas library (example libRblas.a, libRblas.dylib, etc.).")
set( _REQUIRED_R_VARIABLES R_INCLUDE_DIR R_COMMAND )
find_library(R_LIBRARY_LAPACK NAMES Rlapack lapack
HINTS ${R_ROOT_DIR}/lib
DOC "Rlapack library (example libRlapack.a, libRlapack.dylib, etc.).")
find_library(R_LIBRARY_READLINE readline
HINTS ${R_ROOT_DIR}/lib
DOC "(Optional) system readline library. Only required if the R libraries were built with readline support.")
else()
message(SEND_ERROR "FindR.cmake requires the following variables to be set: R_COMMAND")
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 )
endif()
# Note: R_LIBRARY_BASE is added to R_LIBRARIES twice; this may be due to circular linking dependencies; needs further investigation
set(R_LIBRARIES ${R_LIBRARY_BASE} ${R_LIBRARY_BLAS} ${R_LIBRARY_LAPACK} ${R_LIBRARY_BASE})
if(R_LIBRARY_READLINE)
set(R_LIBRARIES ${R_LIBRARIES} ${R_LIBRARY_READLINE})
endif()
find_package_handle_standard_args(R DEFAULT_MSG ${_REQUIRED_R_VARIABLES} )