brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 8eba212 Raw
104 lines · plain
1# CMake find_package() module for the OCaml language.2# Assumes ocamlfind will be used for compilation.3# http://ocaml.org/4#5# Example usage:6#7# find_package(OCaml)8#9# If successful, the following variables will be defined:10# OCAMLFIND11# OCAML_VERSION12# OCAML_STDLIB_PATH13# HAVE_OCAMLOPT14#15# Also provides find_ocamlfind_package() macro.16#17# Example usage:18#19# find_ocamlfind_package(ctypes)20#21# In any case, the following variables are defined:22#23# HAVE_OCAML_${pkg}24#25# If successful, the following variables will be defined:26#27# OCAML_${pkg}_VERSION28 29include( FindPackageHandleStandardArgs )30 31find_program(OCAMLFIND32             NAMES ocamlfind)33 34if( OCAMLFIND )35  execute_process(36    COMMAND ${OCAMLFIND} ocamlc -version37    OUTPUT_VARIABLE OCAML_VERSION38    OUTPUT_STRIP_TRAILING_WHITESPACE)39 40  execute_process(41    COMMAND ${OCAMLFIND} ocamlc -where42    OUTPUT_VARIABLE OCAML_STDLIB_PATH43    OUTPUT_STRIP_TRAILING_WHITESPACE)44 45  execute_process(46    COMMAND ${OCAMLFIND} ocamlc -version47    OUTPUT_QUIET48    RESULT_VARIABLE find_ocaml_result)49  if( find_ocaml_result EQUAL 0 )50    set(HAVE_OCAMLOPT TRUE)51  else()52    set(HAVE_OCAMLOPT FALSE)53  endif()54endif()55 56find_package_handle_standard_args( OCaml DEFAULT_MSG57  OCAMLFIND58  OCAML_VERSION59  OCAML_STDLIB_PATH)60 61mark_as_advanced(62  OCAMLFIND)63 64function(find_ocamlfind_package pkg)65  CMAKE_PARSE_ARGUMENTS(ARG "OPTIONAL" "VERSION" "" ${ARGN})66 67  execute_process(68    COMMAND "${OCAMLFIND}" "query" "${pkg}" "-format" "%v"69    RESULT_VARIABLE result70    OUTPUT_VARIABLE version71    ERROR_VARIABLE error72    OUTPUT_STRIP_TRAILING_WHITESPACE73    ERROR_STRIP_TRAILING_WHITESPACE)74 75  if( NOT result EQUAL 0 AND NOT ARG_OPTIONAL )76    message(FATAL_ERROR ${error})77  endif()78 79  if( result EQUAL 0 )80    set(found TRUE)81  else()82    set(found FALSE)83  endif()84 85  if( found AND ARG_VERSION )86    if( version VERSION_LESS ARG_VERSION AND ARG_OPTIONAL )87      # If it's optional and the constraint is not satisfied, pretend88      # it wasn't found.89      set(found FALSE)90    elseif( version VERSION_LESS ARG_VERSION )91      message(FATAL_ERROR92              "ocamlfind package ${pkg} should have version ${ARG_VERSION} or newer")93    endif()94  endif()95 96  string(TOUPPER ${pkg} pkg)97 98  set(HAVE_OCAML_${pkg} ${found}99      PARENT_SCOPE)100 101  set(OCAML_${pkg}_VERSION ${version}102      PARENT_SCOPE)103endfunction()104