Hello
I want to build a c library (specifically libspng) with opam and statically link it into one of my ocaml projects.
I have a few questions about how to do this in the best way.
My opam file currently looks like this:
opam-version: "2.0"
synopsis: "Simple, modern libpng alternative"
description: """
libspng (simple png) is a C library for reading and writing Portable Network Graphics (PNG) format files
with a focus on security and ease of use.
The goal is to provide a fast PNG library with a simpler API than libpng.
"""
maintainer: ["Torben Ewert <torben@ewert-online.com>"]
author: ["randy408@protonmail.com"]
license: "BSD-2-Clause"
homepage: "https://libspng.org/"
bug-reports: "https://github.com/.../issues"
dev-repo: "git+https://github.com/randy408/libspng"
depends: [
"conf-zlib" {build}
"conf-cmake" {build}
]
build-env: [
[CFLAGS = "-O3 -fPIC"]
]
build: [
[
"%{conf-cmake:cmd}%"
"-DCMAKE_MAKE_PROGRAM=make" {os-family = "windows"}
"-GUnix Makefiles" {os-family = "windows"}
"-DCMAKE_HOST_WIN32=true" {os-family = "windows"}
"-DCMAKE_BUILD_TYPE=RELEASE"
"-DCMAKE_INSTALL_PREFIX=%{prefix}%"
]
[make "-j%{jobs}%"]
]
install: [make "install"]
url {
src: "https://github.com/randy408/libspng/archive/refs/tags/v0.7.3.tar.gz"
checksum: ["md5=7d9159a1e08d7dd258ac146537236b67"]
}
Questions:
-
Do I need the source files from libspng or does opam unpack the archive provided in the
url
field?
Without the sources present it always fails withThe source directory "..." does not appear to contain CMakeLists.txt.
. So I guess I need the source files. But what is theurl
field for then? -
Is
%{prefix}%
the correct install prefix?
When installing the package into my ocaml project, the files are moved directly into the local switch folder (_opam/lib/libspng_static.a
, …). That is unlike all other packages, which have a subfolder insidelib
. So I would think that_opam/lib/libspng/libspng_static.a
would be better? -
Should I even do a
make install
or would it be better to provide alibspng.install
file which moves the built files? -
When building on windows (cygwin) the
prefix
variable gets evaluated toD:\a\foo\bar\_opam
which is interpreted as a relative path. So the files get installed into the wrong location.
I “fixed” that by moving the build steps into abuild.sh
file and wrapping the prefix withcygpath
if in a cygwin environment.
Is this behaviour a bug in opam? I would expect, that the prefix (and all other opam vars) are already pointing to the correct cygwin directories when building on windows. -
Should I update the environment variables (ex.
PKG_CONFIG_PATH
) with thesetenv
field?
Thank you in advance for your help! I am still pretty new to opam and am maybe a bit confused about some things
- Torben