|
| 1 | +# - try to find perl modules, passed as COMPONENTS |
| 2 | +# |
| 3 | +# Non-cache variable you might use in your CMakeLists.txt: |
| 4 | +# PERLMODULES_FOUND |
| 5 | +# |
| 6 | +# Requires these CMake modules: |
| 7 | +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) |
| 8 | +# |
| 9 | +# Original Author: |
| 10 | +# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> |
| 11 | +# http://academic.cleardefinition.com |
| 12 | +# Iowa State University HCI Graduate Program/VRAC |
| 13 | +# |
| 14 | +# Copyright Iowa State University 2012. |
| 15 | +# Distributed under the Boost Software License, Version 1.0. |
| 16 | +# (See accompanying file LICENSE_1_0.txt or copy at |
| 17 | +# http://www.boost.org/LICENSE_1_0.txt) |
| 18 | + |
| 19 | +if(NOT PERL_FOUND) |
| 20 | + find_package(Perl QUIET) |
| 21 | +endif() |
| 22 | + |
| 23 | +set(_deps_check) |
| 24 | +if(PERL_FOUND) |
| 25 | + foreach(module ${PerlModules_FIND_COMPONENTS}) |
| 26 | + string(REPLACE "::" "/" modfilename "${module}.pm") |
| 27 | + string(REPLACE "::" "_" modvarname "PERLMODULES_${module}_MODULE") |
| 28 | + string(TOUPPER "${modvarname}" modvarname) |
| 29 | + list(APPEND _deps_check ${modvarname}) |
| 30 | + if(NOT ${modvarname}) |
| 31 | + if(NOT PerlModules_FIND_QUIETLY) |
| 32 | + message(STATUS "Checking for perl module ${module}") |
| 33 | + endif() |
| 34 | + execute_process(COMMAND |
| 35 | + "${PERL_EXECUTABLE}" |
| 36 | + "-e" |
| 37 | + "use ${module}; print \$INC{\"${modfilename}\"}" |
| 38 | + RESULT_VARIABLE result_code |
| 39 | + OUTPUT_VARIABLE filename |
| 40 | + ERROR_VARIABLE error_info |
| 41 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 42 | + if(result_code EQUAL 0) |
| 43 | + if(NOT PerlModules_FIND_QUIETLY) |
| 44 | + message(STATUS |
| 45 | + "Checking for perl module ${module} - found at ${filename}") |
| 46 | + endif() |
| 47 | + set(${modvarname} |
| 48 | + "${filename}" |
| 49 | + CACHE |
| 50 | + FILEPATH |
| 51 | + "Location found for module ${module}" |
| 52 | + FORCE) |
| 53 | + mark_as_advanced(${modvarname}) |
| 54 | + else() |
| 55 | + if(NOT PerlModules_FIND_QUIETLY) |
| 56 | + message(STATUS "Checking for perl module ${module} - failed") |
| 57 | + endif() |
| 58 | + set(${modvarname} |
| 59 | + "NOTFOUND" |
| 60 | + CACHE |
| 61 | + FILEPATH |
| 62 | + "No location found for module ${module}" |
| 63 | + FORCE) |
| 64 | + file(APPEND |
| 65 | + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 66 | + "Determining if the Perl module ${module} exists failed with the following error output:\n" |
| 67 | + "${error_info}\n\n") |
| 68 | + endif() |
| 69 | + endif() |
| 70 | + endforeach() |
| 71 | +endif() |
| 72 | + |
| 73 | +include(FindPackageHandleStandardArgs) |
| 74 | +find_package_handle_standard_args(PerlModules |
| 75 | + DEFAULT_MSG |
| 76 | + PERL_FOUND |
| 77 | + ${_deps_check}) |
0 commit comments