2015-10-13 08:25:49 +01:00
2016-08-20 03:40:01 +01:00
# PROJECT ( YAP_REAL C )
2015-10-13 08:25:49 +01:00
2017-02-20 15:28:46 +00:00
#
2017-10-17 00:13:09 +01:00
# - 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
#
2018-05-20 18:40:56 +01:00
set_package_properties ( R PROPERTIES
D E S C R I P T I O N " T h e R P r o j e c t f o r S t a t i s t i c a l C o m p u t i n g . "
U R L " h t t p s : / / w w w . r - p r o j e c t . o r g / " )
2017-10-17 00:13:09 +01:00
2018-05-20 18:40:56 +01:00
find_program (
R _ C O M M A N D
N A M E S R r
)
if ( R_COMMAND )
# find the R binary
MESSAGE ( STATUS "Looking for R executable" )
IF ( NOT R_EXECUTABLE )
FIND_PROGRAM ( R_EXECUTABLE R )
IF ( R_EXECUTABLE-NOTFOUND )
MESSAGE ( FATAL_ERROR "Could NOT find R (TODO: name option)" )
ELSE ( R_EXECUTABLE-NOTFOUND )
MESSAGE ( STATUS "Using R at ${R_EXECUTABLE}" )
ENDIF ( R_EXECUTABLE-NOTFOUND )
ENDIF ( NOT R_EXECUTABLE )
# find R_HOME
MESSAGE ( STATUS "Looking for R_HOME" )
IF ( NOT R_HOME )
EXECUTE_PROCESS (
C O M M A N D $ { R _ E X E C U T A B L E } " - - s l a v e " " - - n o - s a v e " " - e " " cat ( R.home( ) ) "
O U T P U T _ V A R I A B L E R _ H O M E )
ENDIF ( NOT R_HOME )
IF ( NOT R_HOME )
MESSAGE ( FATAL_ERROR "Could NOT determine R_HOME (probably you misspecified the location of R)" )
ELSE ( NOT R_HOME )
MESSAGE ( STATUS "R_HOME is ${R_HOME}" )
ENDIF ( NOT R_HOME )
# find R include dir
MESSAGE ( STATUS "Looking for R include files" )
IF ( NOT R_INCLUDEDIR )
IF ( WIN32 OR APPLE ) # This version of the test will not work with R < 2.9.0, but the other version (in the else part) will not work on windows or apple (but we do not really need to support ancient versions of R, there).
EXECUTE_PROCESS (
C O M M A N D $ { R _ E X E C U T A B L E } " - - s l a v e " " - - n o - s a v e " " - e " " cat ( R.home('include' ) ) "
O U T P U T _ V A R I A B L E R _ I N C L U D E D I R )
ELSE ( WIN32 OR APPLE )
EXECUTE_PROCESS (
C O M M A N D $ { R _ E X E C U T A B L E } C M D s h - c " e c h o - n $ R _ I N C L U D E _ D I R "
O U T P U T _ V A R I A B L E R _ I N C L U D E D I R )
ENDIF ( WIN32 OR APPLE )
ELSE ( NOT R_INCLUDEDIR )
MESSAGE ( STATUS "Location specified by user" )
ENDIF ( NOT R_INCLUDEDIR )
IF ( NOT R_INCLUDEDIR )
SET ( R_INCLUDEDIR ${ R_HOME } /include )
MESSAGE ( STATUS "Not findable via R. Guessing" )
ENDIF ( NOT R_INCLUDEDIR )
MESSAGE ( STATUS "Include files should be at ${R_INCLUDEDIR}. Checking for R.h" )
IF ( NOT R_H )
FIND_FILE ( R_H
R . h
P A T H S $ { R _ I N C L U D E D I R }
N O _ D E F A U L T _ P A T H )
ENDIF ( NOT R_H )
IF ( NOT R_H )
MESSAGE ( FATAL_ERROR "Not found" )
ELSE ( NOT R_H )
MESSAGE ( STATUS "Found at ${R_H}" )
GET_FILENAME_COMPONENT ( R_INCLUDEDIR ${ R_H }
P A T H )
ENDIF ( NOT R_H )
# check for existence of libR.so
IF ( NOT LIBR_SO )
MESSAGE ( STATUS "Checking for existence of R shared library" )
FIND_LIBRARY ( LIBR_SO
R
P A T H S $ { R _ H O M E } / l i b $ { R _ S H A R E D L I B D I R } $ { R _ H O M E } / b i n
N O _ D E F A U L T _ P A T H )
endif ( NOT LIBR_SO )
IF ( NOT LIBR_SO )
MESSAGE ( FATAL_ERROR "Not found. Make sure the location of R was detected correctly, above, and R was compiled with the --enable-shlib option" )
ELSE ( NOT LIBR_SO )
MESSAGE ( STATUS "Exists at ${LIBR_SO}" )
GET_FILENAME_COMPONENT ( R_SHAREDLIBDIR ${ LIBR_SO }
P A T H )
SET ( R_USED_LIBS R )
ENDIF ( NOT LIBR_SO )
2015-10-13 08:25:49 +01:00
2018-05-20 18:40:56 +01:00
# for at least some versions of R, we seem to have to link against -lRlapack. Else loading some
# R packages will fail due to unresolved symbols, or we can't link against -lR.
# However, we can't do this unconditionally,
# as this is not available in some configurations of R
MESSAGE ( STATUS "Checking whether we should link against Rlapack library" )
FIND_LIBRARY ( LIBR_LAPACK
R l a p a c k
P A T H S $ { R _ S H A R E D L I B D I R }
N O _ D E F A U L T _ P A T H )
IF ( NOT LIBR_LAPACK )
MESSAGE ( STATUS "No, it does not exist in ${R_SHAREDLIBDIR}" )
ELSE ( NOT LIBR_LAPACK )
MESSAGE ( STATUS "Yes, ${LIBR_LAPACK} exists" )
SET ( R_USED_LIBS ${ R_USED_LIBS } Rlapack )
IF ( WIN32 OR APPLE )
ELSE ( WIN32 OR APPLE )
# needed when linking to Rlapack on linux for some unknown reason.
# apparently not needed on windows (let's see, when it comes back to bite us, though)
# and compiling on windows is hard enough even without requiring libgfortran, too.
SET ( R_USED_LIBS ${ R_USED_LIBS } gfortran )
ENDIF ( WIN32 OR APPLE )
ENDIF ( NOT LIBR_LAPACK )
# for at least some versions of R, we seem to have to link against -lRlapack. Else loading some
# R packages will fail due to unresolved symbols, or we can't link against -lR.
# However, we can't do this unconditionally,
# as this is not available in some configurations of R
MESSAGE ( STATUS "Checking whether we should link against Rblas library" )
FIND_LIBRARY ( LIBR_BLAS
R b l a s
P A T H S $ { R _ S H A R E D L I B D I R }
N O _ D E F A U L T _ P A T H )
IF ( NOT LIBR_BLAS )
MESSAGE ( STATUS "No, it does not exist in ${R_SHAREDLIBDIR}" )
ELSE ( NOT LIBR_BLAS )
MESSAGE ( STATUS "Yes, ${LIBR_BLAS} exists" )
SET ( R_USED_LIBS ${ R_USED_LIBS } Rblas )
ENDIF ( NOT LIBR_BLAS )
# find R package library location
IF ( WIN32 )
SET ( PATH_SEP ";" )
ELSE ( WIN32 )
SET ( PATH_SEP ":" )
ENDIF ( WIN32 )
MESSAGE ( STATUS "Checking for R package library location to use" )
IF ( NOT R_LIBDIR )
EXECUTE_PROCESS (
C O M M A N D $ { R _ E X E C U T A B L E } " - - s l a v e " " - - n o - s a v e " " - e " " cat ( paste(unique ( c(.Library.site, .Library ) ) , c o l l a p s e = ' $ { P A T H _ S E P } ' ) ) "
O U T P U T _ V A R I A B L E R _ L I B D I R )
ELSE ( NOT R_LIBDIR )
MESSAGE ( STATUS "Location specified by user" )
ENDIF ( NOT R_LIBDIR )
# strip whitespace
STRING ( REGEX REPLACE "[ \n]+"
" " R _ L I B D I R
" $ { R _ L I B D I R } " )
# strip leading colon(s)
STRING ( REGEX REPLACE "^${PATH_SEP}+"
" " R _ L I B D I R
" $ { R _ L I B D I R } " )
# strip trailing colon(s)
STRING ( REGEX REPLACE "${PATH_SEP}+$"
" " R _ L I B D I R
" $ { R _ L I B D I R } " )
# find first path
STRING ( REGEX REPLACE "${PATH_SEP}"
" " R _ L I B D I R
" $ { R _ L I B D I R } " )
IF ( NOT R_LIBDIR )
MESSAGE ( STATUS "Not reliably determined or specified. Guessing." )
SET ( R_LIBDIR ${ R_HOME } /library )
ENDIF ( NOT R_LIBDIR )
SET ( R_LIBDIRS ${ R_LIBDIR } )
SEPARATE_ARGUMENTS ( R_LIBDIRS )
SET ( R_LIBDIR )
FOREACH ( CURRENTDIR ${ R_LIBDIRS } )
IF ( NOT USE_R_LIBDIR )
IF ( EXISTS ${ CURRENTDIR } )
SET ( R_LIBDIR ${ CURRENTDIR } )
SET ( USE_R_LIBDIR 1 )
ELSE ( EXISTS ${ CURRENTDIR } )
MESSAGE ( STATUS "${CURRENTDIR} does not exist. Skipping" )
ENDIF ( EXISTS ${ CURRENTDIR } )
ENDIF ( NOT USE_R_LIBDIR )
ENDFOREACH ( CURRENTDIR ${ R_LIBDIRS } )
IF ( NOT EXISTS ${ R_LIBDIR } )
MESSAGE ( FATAL_ERROR "No existing library location found" )
ELSE ( NOT EXISTS ${ R_LIBDIR } )
MESSAGE ( STATUS "Will use ${R_LIBDIR}" )
ENDIF ( NOT EXISTS ${ R_LIBDIR } )
endif ( )
#macro_optional_find_package (R ON)
if ( R_INCLUDEDIR AND R_LIBDIR )
add_feature_info ( R yes "Real" )
set ( REAL_SOURCES
2015-10-13 08:25:49 +01:00
r e a l . c
)
2017-05-02 07:42:21 +01:00
set ( REAL_PL
r e a l . p l
)
2017-10-11 02:24:15 +01:00
add_to_group ( REAL_PL pl_library )
2017-05-02 07:42:21 +01:00
2015-10-13 08:25:49 +01:00
include_directories (
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
2018-05-20 18:40:56 +01:00
$ { R _ I N C L U D E D I R }
2015-10-13 08:25:49 +01:00
)
2017-12-13 16:56:10 +00:00
list ( APPEND CMAKE_REQUIRED_INCLUDES
2015-10-13 08:25:49 +01:00
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
2017-12-13 16:56:10 +00:00
$ { R _ I N C L U D E _ D I R }
2015-10-13 08:25:49 +01:00
)
2017-09-06 01:09:46 +01:00
add_lib ( real ${ REAL_SOURCES } )
2018-05-22 00:25:32 +01:00
target_link_libraries ( real ${ LIBR_SO } libYap )
2015-10-13 08:25:49 +01:00
2017-05-02 07:42:21 +01:00
check_include_files ( "stdio.h;R.h" HAVE_R_H )
check_include_files ( "R.h;Rembedded.h" HAVE_R_EMBEDDED_H )
2015-10-13 08:25:49 +01:00
check_include_files ( "Rembedded.h;Rinterface.h" HAVE_R_INTERFACE_H )
configure_file ( "rconfig.h.cmake" "rconfig.h" )
install ( TARGETS real
2017-12-05 15:14:57 +00:00
R U N T I M E D E S T I N A T I O N $ { Y A P _ I N S T A L L _ D L L D I R }
A R C H I V E D E S T I N A T I O N $ { Y A P _ I N S T A L L _ D L L D I R }
L I B R A R Y D E S T I N A T I O N $ { Y A P _ I N S T A L L _ D L L D I R }
2015-10-13 08:25:49 +01:00
)
install ( FILES real.pl
D E S T I N A T I O N $ { l i b p l }
)
2017-10-17 00:13:09 +01:00
endif ( )