This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/cmake/FindR.cmake
Vítor Santos Costa 44dc6f06d7 newer Find R module
2015-11-05 19:28:22 +00:00

49 lines
1.8 KiB
CMake

#
# - This module locates an installed R distribution.
#
# Defines the following:
#
# 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})
# 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.).")
set(R_LIBRARIES ${R_LIBRARY_BASE})
mark_as_advanced(RSCRIPT_EXECUTABLE R_LIBRARIES R_INCLUDE_DIR R_COMMAND R_LIBRARY_BASE)
set( _REQUIRED_R_VARIABLES R_INCLUDE_DIR 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()
find_package_handle_standard_args(R DEFAULT_MSG ${_REQUIRED_R_VARIABLES} )