Skip to content

Commit 6322ab2

Browse files
author
Benjamin Sparks
committedMar 24, 2025
nlopt: Add support for Python and Octave binding generation
1 parent 3ddf642 commit 6322ab2

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed
 

‎pkgs/development/libraries/nlopt/default.nix

+27-20
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
stdenv,
44
fetchFromGitHub,
55
cmake,
6-
octave ? null,
7-
libiconv,
6+
# Optionally build python bindings
7+
withPython ? false,
8+
# Optionally build octave bindings
9+
withOctave ? false,
10+
# For retrieving optional dependencies related to the aforementioned bindings
11+
pkgs,
812
}:
9-
1013
stdenv.mkDerivation rec {
1114
pname = "nlopt";
1215
version = "2.7.1";
@@ -18,26 +21,30 @@ stdenv.mkDerivation rec {
1821
sha256 = "sha256-TgieCX7yUdTAEblzXY/gCN0r6F9TVDh4RdNDjQdXZ1o=";
1922
};
2023

21-
nativeBuildInputs = [ cmake ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];
22-
buildInputs = [ octave ];
23-
24-
configureFlags =
25-
[
26-
"--with-cxx"
27-
"--enable-shared"
28-
"--with-pic"
29-
"--without-guile"
30-
"--without-python"
31-
"--without-matlab"
32-
]
33-
++ lib.optionals (octave != null) [
34-
"--with-octave"
35-
"M_INSTALL_DIR=$(out)/${octave.sitePath}/m"
36-
"OCT_INSTALL_DIR=$(out)/${octave.sitePath}/oct"
24+
nativeBuildInputs =
25+
[ cmake ]
26+
## The octave bindings are vendored within the repository, and therefore do not require further effort.
27+
##
28+
## Building the python bindings requires SWIG, and numpy in addition to the CXX routines.
29+
++ lib.optionals withPython [
30+
pkgs.swig
31+
(pkgs.python3.withPackages (p: [ p.numpy ]))
3732
];
3833

34+
cmakeFlags = [
35+
"-DBUILD_SHARED_LIBS=OFF"
36+
"-DNLOPT_CXX=ON"
37+
"-DNLOPT_PYTHON=${if withPython then "ON" else "OFF"}"
38+
"-DNLOPT_OCTAVE=${if withOctave then "ON" else "OFF"}"
39+
"-DNLOPT_MATLAB=OFF"
40+
"-DNLOPT_GUILE=OFF"
41+
"-DNLOPT_SWIG=${if withPython then "ON" else "OFF"}"
42+
];
43+
44+
doCheck = true;
45+
3946
postFixup = ''
40-
substituteInPlace $out/lib/cmake/nlopt/NLoptLibraryDepends.cmake --replace \
47+
substituteInPlace $out/lib/cmake/nlopt/NLoptLibraryDepends.cmake --replace-fail \
4148
'INTERFACE_INCLUDE_DIRECTORIES "''${_IMPORT_PREFIX}/' 'INTERFACE_INCLUDE_DIRECTORIES "'
4249
'';
4350

‎pkgs/top-level/all-packages.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -4298,7 +4298,7 @@ with pkgs;
42984298

42994299
nifskope = libsForQt5.callPackage ../tools/graphics/nifskope { };
43004300

4301-
nlopt = callPackage ../development/libraries/nlopt { octave = null; };
4301+
nlopt = callPackage ../development/libraries/nlopt { };
43024302

43034303
notation = callPackage ../by-name/no/notation/package.nix {
43044304
buildGoModule = buildGo123Module;

0 commit comments

Comments
 (0)
Failed to load comments.