build-support/vm: don't depend on the "unix" module (#375355)
[NixPkgs.git] / pkgs / by-name / ca / casadi / package.nix
blobc8a33978313bc64cde097008937b14329a91ad6e
2   #alpaqa,
3   blas,
4   blasfeo,
5   bonmin,
6   bzip2,
7   cbc,
8   clp,
9   cmake,
10   cplex,
11   fatrop,
12   fetchFromGitHub,
13   fetchpatch,
14   gurobi,
15   highs,
16   hpipm,
17   lib,
18   ipopt,
19   lapack,
20   llvmPackages,
21   mumps,
22   ninja,
23   osqp,
24   pkg-config,
25   pythonSupport ? false,
26   python3Packages,
27   proxsuite,
28   stdenv,
29   sleqp,
30   suitesparse,
31   #sundials,
32   superscs,
33   spral,
34   swig,
35   tinyxml-2,
36   withUnfree ? false,
39 stdenv.mkDerivation (finalAttrs: {
40   pname = "casadi";
41   version = "3.6.7";
43   src = fetchFromGitHub {
44     owner = "casadi";
45     repo = "casadi";
46     rev = finalAttrs.version;
47     hash = "sha256-Mft0qhjdAbU82RgjYuKue5p7EqbTbt3ii5yXSsCFHrQ=";
48   };
50   patches = [
51     (fetchpatch {
52       name = "fix-FindMUMPS.cmake.patch";
53       url = "https://github.com/casadi/casadi/pull/3899/commits/274f4b23f73e60c5302bec0479fe1e92682b63d2.patch";
54       hash = "sha256-3GWEWlN8dKLD6htpnOQLChldcT3hE09JWLeuCfAhY+4=";
55     })
56     # update include file path and link with clangAPINotes
57     # https://github.com/casadi/casadi/issues/3969
58     ./clang-19.diff
59   ];
61   postPatch =
62     ''
63       # fix case of hpipmConfig.cmake
64       substituteInPlace CMakeLists.txt --replace-fail \
65         "FATROP HPIPM" \
66         "FATROP hpipm"
68       # nix provide lib/clang headers in libclang, not in llvm.
69       substituteInPlace casadi/interfaces/clang/CMakeLists.txt --replace-fail \
70         '$'{CLANG_LLVM_LIB_DIR} \
71         ${lib.getLib llvmPackages.libclang}/lib
73       # help casadi find its own libs
74       substituteInPlace casadi/core/casadi_os.cpp --replace-fail \
75         "std::vector<std::string> search_paths;" \
76         "std::vector<std::string> search_paths;
77          search_paths.push_back(\"$out/lib\");"
78     ''
79     + lib.optionalString pythonSupport ''
80       # fix including Python.h issue
81       substituteInPlace swig/python/CMakeLists.txt --replace-fail \
82         "add_library(_casadi MODULE \''${PYTHON_FILE})" \
83         "add_library(_casadi MODULE \''${PYTHON_FILE})
84          target_include_directories(_casadi SYSTEM PRIVATE
85            ${python3Packages.python}/include/python3.${python3Packages.python.sourceVersion.minor})"
87       # I have no clue. without this, it tries to install a non existent file.
88       # maybe a run without SWIG_IMPORT is required before a run with SWIG_IMPORT.
89       # but we need SWIG_IMPORT at some point for something else TODO
90       substituteInPlace swig/python/CMakeLists.txt --replace-fail \
91         "if (SWIG_IMPORT)" \
92         "if (NOT SWIG_IMPORT)"
93     ''
94     + lib.optionalString stdenv.hostPlatform.isDarwin ''
95       # this is only printing stuff, and is not defined on all CPU
96       substituteInPlace casadi/interfaces/hpipm/hpipm_runtime.hpp --replace-fail \
97         "d_print_exp_tran_mat" \
98         "//d_print_exp_tran_mat"
100       # fix missing symbols
101       substituteInPlace cmake/FindCLANG.cmake --replace-fail \
102         "clangBasic)" \
103         "clangBasic clangASTMatchers clangSupport)"
104     '';
106   nativeBuildInputs = [
107     cmake
108     ninja
109     pkg-config
110   ];
112   buildInputs =
113     [
114       #alpaqa
115       blas
116       blasfeo
117       bzip2
118       bonmin
119       cbc
120       clp
121       fatrop
122       highs
123       hpipm
124       ipopt
125       lapack
126       llvmPackages.clang
127       llvmPackages.libclang
128       llvmPackages.llvm
129       mumps
130       osqp
131       proxsuite
132       sleqp
133       suitesparse
134       #sundials
135       superscs
136       spral
137       swig
138       tinyxml-2
139     ]
140     ++ lib.optionals withUnfree [
141       cplex
142       gurobi
143     ]
144     ++ lib.optionals pythonSupport [
145       python3Packages.numpy
146       python3Packages.python
147     ]
148     ++ lib.optionals stdenv.hostPlatform.isDarwin [ llvmPackages.openmp ];
150   cmakeFlags = [
151     (lib.cmakeBool "WITH_PYTHON" pythonSupport)
152     (lib.cmakeBool "WITH_PYTHON3" pythonSupport)
153     # We don't mind always setting this cmake variable, it will be read only if
154     # pythonSupport is enabled.
155     "-DPYTHON_PREFIX=${placeholder "out"}/${python3Packages.python.sitePackages}"
156     (lib.cmakeBool "WITH_JSON" false)
157     (lib.cmakeBool "WITH_INSTALL_INTERNAL_HEADERS" true)
158     (lib.cmakeBool "INSTALL_INTERNAL_HEADERS" true)
159     (lib.cmakeBool "ENABLE_EXPORT_ALL" true)
160     (lib.cmakeBool "SWIG_EXPORT" true)
161     (lib.cmakeBool "SWIG_IMPORT" false)
162     (lib.cmakeBool "WITH_OPENMP" true)
163     (lib.cmakeBool "WITH_THREAD" true)
164     (lib.cmakeBool "WITH_OPENCL" false)
165     (lib.cmakeBool "WITH_BUILD_SUNDIALS" true) # ref. https://github.com/casadi/casadi/issues/2125
166     (lib.cmakeBool "WITH_SUNDIALS" true)
167     (lib.cmakeBool "WITH_BUILD_CSPARSE" false)
168     (lib.cmakeBool "WITH_CSPARSE" true)
169     (lib.cmakeBool "WITH_BLASFEO" true)
170     (lib.cmakeBool "WITH_HPIPM" true)
171     (lib.cmakeBool "WITH_FATROP" true)
172     (lib.cmakeBool "WITH_BUILD_FATROP" false)
173     (lib.cmakeBool "WITH_SUPERSCS" false) # packaging too chaotic
174     (lib.cmakeBool "WITH_BUILD_OSQP" false)
175     (lib.cmakeBool "WITH_OSQP" true)
176     (lib.cmakeBool "WITH_PROXQP" true)
177     (lib.cmakeBool "WITH_BUILD_TINYXML" false)
178     (lib.cmakeBool "WITH_TINYXML" true)
179     (lib.cmakeBool "WITH_BUILD_DSDP" true) # not sure where this come from
180     (lib.cmakeBool "WITH_DSDP" true)
181     (lib.cmakeBool "WITH_CLANG" true)
182     (lib.cmakeBool "WITH_LAPACK" true)
183     (lib.cmakeBool "WITH_QPOASES" true)
184     (lib.cmakeBool "WITH_BLOCKSQP" true)
185     (lib.cmakeBool "WITH_SLEQP" true)
186     (lib.cmakeBool "WITH_IPOPT" true)
187     (lib.cmakeBool "WITH_KNITRO" withUnfree)
188     (lib.cmakeBool "WITH_SNOPT" withUnfree)
189     (lib.cmakeBool "WITH_WORHP" withUnfree)
190     (lib.cmakeBool "WITH_CPLEX" withUnfree)
191     (lib.cmakeBool "WITH_GUROBI" withUnfree)
192     (lib.cmakeBool "WITH_BONMIN" true)
193     (lib.cmakeBool "WITH_CBC" true)
194     (lib.cmakeBool "WITH_CLP" true)
195     (lib.cmakeBool "WITH_MUMPS" true)
196     (lib.cmakeBool "WITH_SPRAL" true)
197     (lib.cmakeBool "WITH_HSL" withUnfree)
198     (lib.cmakeBool "WITH_HIGHS" true)
199     #(lib.cmakeBool "WITH_ALPAQA" true)  # this requires casadi...
200   ];
202   doCheck = true;
204   meta = {
205     description = "CasADi is a symbolic framework for numeric optimization implementing automatic differentiation in forward and reverse modes on sparse matrix-valued computational graphs. It supports self-contained C-code generation and interfaces state-of-the-art codes such as SUNDIALS, IPOPT etc. It can be used from C++, Python or Matlab/Octave";
206     homepage = "https://github.com/casadi/casadi";
207     license = lib.licenses.lgpl3Only;
208     maintainers = with lib.maintainers; [ nim65s ];
209     platforms = lib.platforms.all;
210   };