[Demangle] Add a few more options to the microsoft demangler
[llvm-complete.git] / cmake / modules / FindOCaml.cmake
blob8eba2127df1b361d9b70728d9f09a85753eb3286
1 # CMake find_package() module for the OCaml language.
2 # Assumes ocamlfind will be used for compilation.
3 # http://ocaml.org/
5 # Example usage:
7 # find_package(OCaml)
9 # If successful, the following variables will be defined:
10 # OCAMLFIND
11 # OCAML_VERSION
12 # OCAML_STDLIB_PATH
13 # HAVE_OCAMLOPT
15 # Also provides find_ocamlfind_package() macro.
17 # Example usage:
19 # find_ocamlfind_package(ctypes)
21 # In any case, the following variables are defined:
23 # HAVE_OCAML_${pkg}
25 # If successful, the following variables will be defined:
27 # OCAML_${pkg}_VERSION
29 include( FindPackageHandleStandardArgs )
31 find_program(OCAMLFIND
32              NAMES ocamlfind)
34 if( OCAMLFIND )
35   execute_process(
36     COMMAND ${OCAMLFIND} ocamlc -version
37     OUTPUT_VARIABLE OCAML_VERSION
38     OUTPUT_STRIP_TRAILING_WHITESPACE)
40   execute_process(
41     COMMAND ${OCAMLFIND} ocamlc -where
42     OUTPUT_VARIABLE OCAML_STDLIB_PATH
43     OUTPUT_STRIP_TRAILING_WHITESPACE)
45   execute_process(
46     COMMAND ${OCAMLFIND} ocamlc -version
47     OUTPUT_QUIET
48     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()
54 endif()
56 find_package_handle_standard_args( OCaml DEFAULT_MSG
57   OCAMLFIND
58   OCAML_VERSION
59   OCAML_STDLIB_PATH)
61 mark_as_advanced(
62   OCAMLFIND)
64 function(find_ocamlfind_package pkg)
65   CMAKE_PARSE_ARGUMENTS(ARG "OPTIONAL" "VERSION" "" ${ARGN})
67   execute_process(
68     COMMAND "${OCAMLFIND}" "query" "${pkg}" "-format" "%v"
69     RESULT_VARIABLE result
70     OUTPUT_VARIABLE version
71     ERROR_VARIABLE error
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})
77   endif()
79   if( result EQUAL 0 )
80     set(found TRUE)
81   else()
82     set(found FALSE)
83   endif()
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
88       # it wasn't found.
89       set(found FALSE)
90     elseif( version VERSION_LESS ARG_VERSION )
91       message(FATAL_ERROR
92               "ocamlfind package ${pkg} should have version ${ARG_VERSION} or newer")
93     endif()
94   endif()
96   string(TOUPPER ${pkg} pkg)
98   set(HAVE_OCAML_${pkg} ${found}
99       PARENT_SCOPE)
101   set(OCAML_${pkg}_VERSION ${version}
102       PARENT_SCOPE)
103 endfunction()