package dune-configurator

  1. Overview
  2. Docs
Helper library for gathering system configuration

Install

Dune Dependency

Authors

Maintainers

Sources

dune-3.8.0.tbz
sha256=f7e2970bfab99c7766ff1a05deff5ad7f82cb2471abca6f72449572293f5f6b4
sha512=3b3a566f63842c314de2c0a660c5f7714bc90f8303c82d82e3021aee84980eff1886d15c9b9d4ea0047a411d799fb39d5f2ea70a92bdeb629e00d3d5d5f2d994

doc/index.html

dune-configurator - Helper library for gathering system configuration

dune-configurator is a small library that helps writing OCaml scripts that test features available on the system, in order to generate config.h files for instance.

Among other things, dune-configurator allows one to:

  • test if a C program compiles
  • query pkg-config
  • import #define from OCaml header files
  • generate a config.h file

API Documentation

The entry point for this library is Configurator.V1.

Example

The following happens in a dune project that contains some C code that needs to link against libpng.

The following program (discover/discover.ml) uses dune-configurator to query pkg-config and create cflags.sexp and libs.sexp:

let () =
  Configurator.V1.main ~name:"libpng"
    (fun c ->
       let pkg_config =
         match Configurator.V1.Pkg_config.get c with
         | Some p -> p
         | None -> failwith "Cannot find pkg-config"
       in
       let conf = Configurator.V1.Pkg_config.query ~package:"libpng" in
       Configurator.V1.Flags.write_sexp "cflags.sexp" conf.cflags;
       Configurator.V1.Flags.write_sexp "libs.sexp" conf.libs)

It can be built using the following discover/dune file:

(executable
 (name discover)
 (libraries dune-configurator))

(rule
 (targets cflags.sexp libs.sexp)
 (action
  (run ./discover.exe)))

And used when building the C code in the following dune file:

(library
 (name png)
 (foreign_stubs
  (language c)
  (names bindings)
  (flags :standard (:include discover/cflags.sexp)))
 (c_library_flags :standard (:include discover/libs.sexp)))
OCaml

Innovation. Community. Security.