Skip to content

Commit 04d4b01

Browse files
committed
Fixed version discovery with pkg-config
1 parent a51ec4e commit 04d4b01

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/config/discover.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ let major_minor_from_pgconfig () =
5555
in
5656
Fun.protect ~finally:(fun () -> close_in ic) (fun () -> pg_major_minor ic)
5757

58+
let major_minor_from_pkg_config () =
59+
let ic = Unix.open_process_in "pkg-config --modversion libpq" in
60+
Fun.protect ~finally:(fun () -> close_in ic) @@ fun () ->
61+
let version_line = input_line ic in
62+
(* Typically something like "14.1" *)
63+
match String.split_on_char '.' version_line with
64+
| major :: minor :: _ ->
65+
("-DPG_OCAML_MAJOR_VERSION=" ^ major, "-DPG_OCAML_MINOR_VERSION=" ^ minor)
66+
| _ ->
67+
eprintf "Unable to parse libpq version: %s" version_line;
68+
exit 1
69+
5870
let from_pgconfig () =
5971
let cmd = "pg_config --includedir --libdir --version" in
6072
let ic =
@@ -81,7 +93,7 @@ let () =
8193
| Some pc -> (
8294
match C.Pkg_config.query pc ~package:"libpq" with
8395
| Some conf ->
84-
let major, minor = major_minor_from_pgconfig () in
96+
let major, minor = major_minor_from_pkg_config () in
8597
{
8698
conf with
8799
C.Pkg_config.cflags = major :: minor :: conf.cflags;

0 commit comments

Comments
 (0)