1 # CMake find_package() module for the OCaml language.
2 # Assumes ocamlfind will be used for compilation.
9 # If successful, the following variables will be defined:
15 # Also provides find_ocamlfind_package() macro.
19 # find_ocamlfind_package(ctypes)
21 # In any case, the following variables are defined:
25 # If successful, the following variables will be defined:
27 # OCAML_${pkg}_VERSION
29 include( FindPackageHandleStandardArgs )
31 find_program(OCAMLFIND
36 COMMAND ${OCAMLFIND} ocamlc -version
37 OUTPUT_VARIABLE OCAML_VERSION
38 OUTPUT_STRIP_TRAILING_WHITESPACE)
41 COMMAND ${OCAMLFIND} ocamlc -where
42 OUTPUT_VARIABLE OCAML_STDLIB_PATH
43 OUTPUT_STRIP_TRAILING_WHITESPACE)
46 COMMAND ${OCAMLFIND} ocamlc -version
48 RESULT_VARIABLE find_ocaml_result)
49 if( find_ocaml_result EQUAL 0 )
50 set(HAVE_OCAMLOPT TRUE)
52 set(HAVE_OCAMLOPT FALSE)
56 find_package_handle_standard_args( OCaml DEFAULT_MSG
64 function(find_ocamlfind_package pkg)
65 CMAKE_PARSE_ARGUMENTS(ARG "OPTIONAL" "VERSION" "" ${ARGN})
68 COMMAND "${OCAMLFIND}" "query" "${pkg}" "-format" "%v"
69 RESULT_VARIABLE result
70 OUTPUT_VARIABLE version
72 OUTPUT_STRIP_TRAILING_WHITESPACE
73 ERROR_STRIP_TRAILING_WHITESPACE)
75 if( NOT result EQUAL 0 AND NOT ARG_OPTIONAL )
76 message(FATAL_ERROR ${error})
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, pretend
90 elseif( version VERSION_LESS ARG_VERSION )
92 "ocamlfind package ${pkg} should have version ${ARG_VERSION} or newer")
96 string(TOUPPER ${pkg} pkg)
98 set(HAVE_OCAML_${pkg} ${found}
101 set(OCAML_${pkg}_VERSION ${version}