evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / by-name / ca / casadi / package.nix
blob37bd4b1f567e44f919e58f454dbfe06553d8c61f
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_17, # llvm/Support/Host.h required by casadi 3.6.5 and not available in llvm 18
21   mumps,
22   osqp,
23   pkg-config,
24   pythonSupport ? false,
25   python3Packages,
26   proxsuite,
27   stdenv,
28   sleqp,
29   suitesparse,
30   #sundials,
31   superscs,
32   spral,
33   swig,
34   tinyxml-2,
35   withUnfree ? false,
38 stdenv.mkDerivation (finalAttrs: {
39   pname = "casadi";
40   version = "3.6.7";
42   src = fetchFromGitHub {
43     owner = "casadi";
44     repo = "casadi";
45     rev = finalAttrs.version;
46     hash = "sha256-Mft0qhjdAbU82RgjYuKue5p7EqbTbt3ii5yXSsCFHrQ=";
47   };
49   patches = [
50     (fetchpatch {
51       name = "fix-FindMUMPS.cmake.patch";
52       url = "https://github.com/casadi/casadi/pull/3899/commits/274f4b23f73e60c5302bec0479fe1e92682b63d2.patch";
53       hash = "sha256-3GWEWlN8dKLD6htpnOQLChldcT3hE09JWLeuCfAhY+4=";
54     })
55   ];
57   postPatch =
58     ''
59       # fix case of hpipmConfig.cmake
60       substituteInPlace CMakeLists.txt --replace-fail \
61         "FATROP HPIPM" \
62         "FATROP hpipm"
64       # nix provide lib/clang headers in libclang, not in llvm.
65       substituteInPlace casadi/interfaces/clang/CMakeLists.txt --replace-fail \
66         '$'{CLANG_LLVM_LIB_DIR} \
67         ${lib.getLib llvmPackages_17.libclang}/lib
69       # help casadi find its own libs
70       substituteInPlace casadi/core/casadi_os.cpp --replace-fail \
71         "std::vector<std::string> search_paths;" \
72         "std::vector<std::string> search_paths;
73          search_paths.push_back(\"$out/lib\");"
74     ''
75     + lib.optionalString pythonSupport ''
76       # fix including Python.h issue
77       substituteInPlace swig/python/CMakeLists.txt --replace-fail \
78         "add_library(_casadi MODULE \''${PYTHON_FILE})" \
79         "add_library(_casadi MODULE \''${PYTHON_FILE})
80          target_include_directories(_casadi SYSTEM PRIVATE
81            ${python3Packages.python}/include/python3.${python3Packages.python.sourceVersion.minor})"
83       # I have no clue. without this, it tries to install a non existent file.
84       # maybe a run without SWIG_IMPORT is required before a run with SWIG_IMPORT.
85       # but we need SWIG_IMPORT at some point for something else TODO
86       substituteInPlace swig/python/CMakeLists.txt --replace-fail \
87         "if (SWIG_IMPORT)" \
88         "if (NOT SWIG_IMPORT)"
89     ''
90     + lib.optionalString stdenv.hostPlatform.isDarwin ''
91       # this is only printing stuff, and is not defined on all CPU
92       substituteInPlace casadi/interfaces/hpipm/hpipm_runtime.hpp --replace-fail \
93         "d_print_exp_tran_mat" \
94         "//d_print_exp_tran_mat"
96       # fix missing symbols
97       substituteInPlace cmake/FindCLANG.cmake --replace-fail \
98         "clangBasic)" \
99         "clangBasic clangASTMatchers clangSupport)"
100     '';
102   nativeBuildInputs = [
103     cmake
104     pkg-config
105   ];
107   buildInputs =
108     [
109       #alpaqa
110       blas
111       blasfeo
112       bzip2
113       bonmin
114       cbc
115       clp
116       fatrop
117       highs
118       hpipm
119       ipopt
120       lapack
121       llvmPackages_17.clang
122       llvmPackages_17.libclang
123       llvmPackages_17.llvm
124       mumps
125       osqp
126       proxsuite
127       sleqp
128       suitesparse
129       #sundials
130       superscs
131       spral
132       swig
133       tinyxml-2
134     ]
135     ++ lib.optionals withUnfree [
136       cplex
137       gurobi
138     ]
139     ++ lib.optionals pythonSupport [
140       python3Packages.numpy
141       python3Packages.python
142     ]
143     ++ lib.optionals stdenv.hostPlatform.isDarwin [ llvmPackages_17.openmp ];
145   cmakeFlags = [
146     (lib.cmakeBool "WITH_PYTHON" pythonSupport)
147     (lib.cmakeBool "WITH_PYTHON3" pythonSupport)
148     # We don't mind always setting this cmake variable, it will be read only if
149     # pythonSupport is enabled.
150     "-DPYTHON_PREFIX=${placeholder "out"}/${python3Packages.python.sitePackages}"
151     (lib.cmakeBool "WITH_JSON" false)
152     (lib.cmakeBool "WITH_INSTALL_INTERNAL_HEADERS" true)
153     (lib.cmakeBool "INSTALL_INTERNAL_HEADERS" true)
154     (lib.cmakeBool "ENABLE_EXPORT_ALL" true)
155     (lib.cmakeBool "SWIG_EXPORT" true)
156     (lib.cmakeBool "SWIG_IMPORT" false)
157     (lib.cmakeBool "WITH_OPENMP" true)
158     (lib.cmakeBool "WITH_THREAD" true)
159     (lib.cmakeBool "WITH_OPENCL" false)
160     (lib.cmakeBool "WITH_BUILD_SUNDIALS" true) # ref. https://github.com/casadi/casadi/issues/2125
161     (lib.cmakeBool "WITH_SUNDIALS" true)
162     (lib.cmakeBool "WITH_BUILD_CSPARSE" false)
163     (lib.cmakeBool "WITH_CSPARSE" true)
164     (lib.cmakeBool "WITH_BLASFEO" true)
165     (lib.cmakeBool "WITH_HPIPM" true)
166     (lib.cmakeBool "WITH_FATROP" true)
167     (lib.cmakeBool "WITH_BUILD_FATROP" false)
168     (lib.cmakeBool "WITH_SUPERSCS" false) # packaging too chaotic
169     (lib.cmakeBool "WITH_BUILD_OSQP" false)
170     (lib.cmakeBool "WITH_OSQP" true)
171     (lib.cmakeBool "WITH_PROXQP" true)
172     (lib.cmakeBool "WITH_BUILD_TINYXML" false)
173     (lib.cmakeBool "WITH_TINYXML" true)
174     (lib.cmakeBool "WITH_BUILD_DSDP" true) # not sure where this come from
175     (lib.cmakeBool "WITH_DSDP" true)
176     (lib.cmakeBool "WITH_CLANG" true)
177     (lib.cmakeBool "WITH_LAPACK" true)
178     (lib.cmakeBool "WITH_QPOASES" true)
179     (lib.cmakeBool "WITH_BLOCKSQP" true)
180     (lib.cmakeBool "WITH_SLEQP" true)
181     (lib.cmakeBool "WITH_IPOPT" true)
182     (lib.cmakeBool "WITH_KNITRO" withUnfree)
183     (lib.cmakeBool "WITH_SNOPT" withUnfree)
184     (lib.cmakeBool "WITH_WORHP" withUnfree)
185     (lib.cmakeBool "WITH_CPLEX" withUnfree)
186     (lib.cmakeBool "WITH_GUROBI" withUnfree)
187     (lib.cmakeBool "WITH_BONMIN" true)
188     (lib.cmakeBool "WITH_CBC" true)
189     (lib.cmakeBool "WITH_CLP" true)
190     (lib.cmakeBool "WITH_MUMPS" true)
191     (lib.cmakeBool "WITH_SPRAL" true)
192     (lib.cmakeBool "WITH_HSL" withUnfree)
193     (lib.cmakeBool "WITH_HIGHS" true)
194     #(lib.cmakeBool "WITH_ALPAQA" true)  # this requires casadi...
195   ];
197   doCheck = true;
199   meta = {
200     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";
201     homepage = "https://github.com/casadi/casadi";
202     license = lib.licenses.lgpl3Only;
203     maintainers = with lib.maintainers; [ nim65s ];
204     platforms = lib.platforms.all;
205   };