File: FindR.cmake

package info (click to toggle)
harp 1.29-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 57,028 kB
  • sloc: xml: 475,954; ansic: 175,442; sh: 4,898; yacc: 2,186; javascript: 1,510; python: 1,148; makefile: 656; lex: 591
file content (52 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Find the R installation
#
# This module defines
# R_EXECUTABLE, the R executable
# R_INCLUDE_DIR, where to find R.h
# R_LIBRARIES, the R libraries to link against to use R.
# R_FOUND, If false, do not try to use R.
#
# The user may specify the R_EXECUTABLE variable to locate
# the R executable
#
include(CheckLibraryExists)
include(CheckIncludeFile)
include(FindPackageHandleStandardArgs)

if(NOT R_EXECUTABLE)
  set(TEMP_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
  set(CMAKE_FIND_APPBUNDLE "NEVER")
  find_program(R_EXECUTABLE NAMES R)
  set(CMAKE_FIND_APPBUNDLE ${TEMP_CMAKE_FIND_APPBUNDLE})
endif(NOT R_EXECUTABLE)

if(R_EXECUTABLE)
  message(STATUS "Found R executable: ${R_EXECUTABLE}")
  execute_process(COMMAND ${R_EXECUTABLE} RHOME OUTPUT_VARIABLE RHOME)
  string(STRIP ${RHOME} RHOME)
  message(STATUS "Found R home: ${RHOME}")
  set(R_INCLUDE_DIR "${RHOME}/include")
  set(R_LIBRARY_DIR "${RHOME}/lib")
  set(CMAKE_REQUIRED_INCLUDES ${R_INCLUDE_DIR})
  # define needed for R>=4.3 with MSVC because of:
  #   syntax error: missing ';' before identifier 'private_data_c'
  set(CMAKE_REQUIRED_FLAGS "-DR_LEGACY_RCOMPLEX")
endif(R_EXECUTABLE)

check_include_file(R.h HAVE_R_H)

if(NOT WIN32)
find_library(R_LIBRARY NAMES R libR PATHS ${R_LIBRARY_DIR} NO_DEFAULT_PATH)
if(R_LIBRARY)
  message(STATUS "Checking R library: ${R_LIBRARY}")
  check_library_exists(${R_LIBRARY} Rprintf "" HAVE_R_LIBRARY)
endif(R_LIBRARY)
if(HAVE_R_LIBRARY)
  message(STATUS "Found R library: ${R_LIBRARY}")
  set(R_LIBRARIES ${R_LIBRARY})
endif(HAVE_R_LIBRARY)
find_package_handle_standard_args(R DEFAULT_MSG R_EXECUTABLE HAVE_R_LIBRARY HAVE_R_H)
else()
# On Windows there is no global R library to link against
find_package_handle_standard_args(R DEFAULT_MSG R_EXECUTABLE HAVE_R_H)
endif()