File: FindRModule.cmake

package info (click to toggle)
mlpack 4.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,272 kB
  • sloc: cpp: 226,039; python: 1,934; sh: 1,198; lisp: 414; makefile: 85
file content (61 lines) | stat: -rw-r--r-- 2,870 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
53
54
55
56
57
58
59
60
61
# FindRModule.cmake: find a specific R module.
function(find_r_module module)
  string(TOUPPER ${module} module_upper)
  if (NOT R_${module_upper})
    if (ARGC GREATER 1)
      # Not required but we have version constraints.
      set(VERSION_REQ ${ARGV1})
    endif ()
    # A module's location is usually a directory, but for binary modules
    # it's a .so file.
    execute_process(COMMAND ${RSCRIPT_EXECUTABLE} "-e" "find.package('${module}')"
      RESULT_VARIABLE _${module}_status
      OUTPUT_VARIABLE _${module}_location
      ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)

   # Some cleanup in location of R Module.
   string(REGEX MATCHALL "\".*\""  _${module}_location "${_${module}_location}" )
   string(REGEX REPLACE "\"" "" _${module}_location "${_${module}_location}" )

    if (NOT _${module}_status)
      # Now we have to check the version.
      if (VERSION_REQ)
        execute_process(COMMAND ${RSCRIPT_EXECUTABLE} "-e" "packageVersion('${module}')"
            RESULT_VARIABLE _version_status
            OUTPUT_VARIABLE _version_compare
            OUTPUT_STRIP_TRAILING_WHITESPACE)

        # Different versions of R may enclose the version number in different
        # delimiters.  Sometimes, semicolons show up too.
        string(REGEX MATCHALL "[‘'][0-9._]*[’']" _version_compare "${_version_compare}")
        string(REGEX REPLACE ";" "" _version_compare "${_version_compare}")
        string(REGEX REPLACE "[‘']" "" _version_compare "${_version_compare}")
        string(REGEX REPLACE "[’']" "" _version_compare "${_version_compare}")

        # Compare the version of the package using compareVersion().
        execute_process(COMMAND ${RSCRIPT_EXECUTABLE} "-e"
            "compareVersion('${_version_compare}', '${VERSION_REQ}')"
            RESULT_VARIABLE _compareVersion_status
            OUTPUT_VARIABLE _compareVersion_result
            OUTPUT_STRIP_TRAILING_WHITESPACE)

        # Extract compareVersion() result i.e. 1 -> Newer, 0 -> Equal and -1 -> Later.
        string(REGEX REPLACE "\\[\\1\\]" "" _compareVersion_result "${_compareVersion_result}")
        if ("${_compareVersion_result}" GREATER "-1")
          set(R_${module_upper}
            "${_${module}_location} (found suitable version \"${_version_compare}\", minimum required is \"${VERSION_REQ}\")"
            CACHE STRING "Location of R module ${module}"
          )
        else ()
          message(WARNING "Unsuitable version of R module ${module} (${VERSION_REQ} or greater required).")
        endif ()
      else ()
        # No version requirement so we are done.
        set(R_${module_upper} ${_${module}_location} CACHE STRING "Location of R module ${module}")
      endif ()
    endif ()
  endif ()

  include(FindPackageHandleStandardArgs)
  find_package_handle_standard_args(R_${module} DEFAULT_MSG R_${module_upper})
endfunction ()