# CMake find_package() module for the OCaml language.
# Assumes ocamlfind will be used for compilation.
# http://ocaml.org/
#
# Example usage:
#
# find_package(OCaml)
#
# If successful, the following variables will be defined:
# OCAMLFIND
# OCAML_VERSION
# OCAML_STDLIB_PATH
# HAVE_OCAMLOPT
#
# Also provides find_ocamlfind_package() macro.
#
# Example usage:
#
# find_ocamlfind_package(ctypes)
#
# In any case, the following variables are defined:
#
# HAVE_OCAML_${pkg}
#
# If successful, the following variables will be defined:
#
# OCAML_${pkg}_VERSION
include( FindPackageHandleStandardArgs
)
NAMES ocamlfind)
COMMAND ${OCAMLFIND} ocamlc -version
OUTPUT_VARIABLE OCAML_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
COMMAND ${OCAMLFIND} ocamlc -where
OUTPUT_VARIABLE OCAML_STDLIB_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
COMMAND ${OCAMLFIND} ocamlc -version
OUTPUT_QUIET
RESULT_VARIABLE find_ocaml_result)
if( find_ocaml_result
EQUAL 0
)
find_package_handle_standard_args( OCaml DEFAULT_MSG
OCAMLFIND
OCAML_VERSION
OCAML_STDLIB_PATH)
OCAMLFIND)
CMAKE_PARSE_ARGUMENTS(ARG "OPTIONAL" "VERSION" "" ${ARGN})
COMMAND "${OCAMLFIND}" "query" "${pkg}" "-format" "%v"
RESULT_VARIABLE result
OUTPUT_VARIABLE version
ERROR_VARIABLE error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
if( NOT result
EQUAL 0
AND NOT ARG_OPTIONAL
)
if( found
AND ARG_VERSION
)
if( version
VERSION_LESS ARG_VERSION
AND ARG_OPTIONAL
)
# If it's optional and the constraint is not satisfied, pretend
# it wasn't found.
elseif( version
VERSION_LESS ARG_VERSION
)
"ocamlfind package ${pkg} should have version ${ARG_VERSION} or newer")
set(HAVE_OCAML_
${pkg} ${found}
PARENT_SCOPE)
set(OCAML_
${pkg}_VERSION
${version}
PARENT_SCOPE)