Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14 | pmbaty | 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 | # OCAMLFIND |
||
11 | # OCAML_VERSION |
||
12 | # OCAML_STDLIB_PATH |
||
13 | # HAVE_OCAMLOPT |
||
14 | # |
||
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}_VERSION |
||
28 | |||
29 | include( FindPackageHandleStandardArgs ) |
||
30 | |||
31 | find_program(OCAMLFIND |
||
32 | NAMES ocamlfind) |
||
33 | |||
34 | if( OCAMLFIND ) |
||
35 | execute_process( |
||
36 | COMMAND ${OCAMLFIND} ocamlc -version |
||
37 | OUTPUT_VARIABLE OCAML_VERSION |
||
38 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
||
39 | |||
40 | execute_process( |
||
41 | COMMAND ${OCAMLFIND} ocamlc -where |
||
42 | OUTPUT_VARIABLE OCAML_STDLIB_PATH |
||
43 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
||
44 | |||
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() |
||
55 | |||
56 | find_package_handle_standard_args( OCaml DEFAULT_MSG |
||
57 | OCAMLFIND |
||
58 | OCAML_VERSION |
||
59 | OCAML_STDLIB_PATH) |
||
60 | |||
61 | mark_as_advanced( |
||
62 | OCAMLFIND) |
||
63 | |||
64 | function(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 result |
||
70 | OUTPUT_VARIABLE version |
||
71 | ERROR_VARIABLE error |
||
72 | OUTPUT_STRIP_TRAILING_WHITESPACE |
||
73 | 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, 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() |
||
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) |
||
103 | endfunction() |