20 llvmPackages_17, # llvm/Support/Host.h required by casadi 3.6.5 and not available in llvm 18
24 pythonSupport ? false,
38 stdenv.mkDerivation (finalAttrs: {
42 src = fetchFromGitHub {
45 rev = finalAttrs.version;
46 hash = "sha256-Mft0qhjdAbU82RgjYuKue5p7EqbTbt3ii5yXSsCFHrQ=";
51 name = "fix-FindMUMPS.cmake.patch";
52 url = "https://github.com/casadi/casadi/pull/3899/commits/274f4b23f73e60c5302bec0479fe1e92682b63d2.patch";
53 hash = "sha256-3GWEWlN8dKLD6htpnOQLChldcT3hE09JWLeuCfAhY+4=";
59 # fix case of hpipmConfig.cmake
60 substituteInPlace CMakeLists.txt --replace-fail \
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\");"
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 \
88 "if (NOT SWIG_IMPORT)"
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"
97 substituteInPlace cmake/FindCLANG.cmake --replace-fail \
99 "clangBasic clangASTMatchers clangSupport)"
102 nativeBuildInputs = [
121 llvmPackages_17.clang
122 llvmPackages_17.libclang
135 ++ lib.optionals withUnfree [
139 ++ lib.optionals pythonSupport [
140 python3Packages.numpy
141 python3Packages.python
143 ++ lib.optionals stdenv.hostPlatform.isDarwin [ llvmPackages_17.openmp ];
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...
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;