Skip to content

Commit

Permalink
#1863 use CMake to find casadi library on system
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Apr 1, 2022
1 parent fc4a458 commit fee37fc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ if(NOT PYBIND11_DIR)
set(PYBIND11_DIR pybind11)
endif()

if(NOT CASADI_DIR)
set(CASADI_DIR casadi-headers)
endif()

add_subdirectory(${PYBIND11_DIR})
pybind11_add_module(idaklu
pybamm/solvers/c_solvers/idaklu_python.cpp
Expand All @@ -43,12 +39,20 @@ pybind11_add_module(idaklu
pybamm/solvers/c_solvers/solution.hpp
)

if(NOT CASADI_DIR)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"import casadi as _; print(_.__path__[0])"
OUTPUT_VARIABLE CASADI_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
find_package(casadi CONFIG PATHS ${CASADI_DIR} REQUIRED)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
# Sundials
find_package(SUNDIALS)
target_include_directories(idaklu PRIVATE ${SUNDIALS_INCLUDE_DIR}
${CASADI_DIR})
target_link_libraries(idaklu PRIVATE ${SUNDIALS_LIBRARIES})
target_include_directories(idaklu PRIVATE ${SUNDIALS_INCLUDE_DIR})
target_link_libraries(idaklu PRIVATE ${SUNDIALS_LIBRARIES} casadi)

# link suitesparse
# if using vcpkg, use config mode to
Expand Down
5 changes: 0 additions & 5 deletions docs/install/install-from-source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ Next, clone the pybind11 and casadi-headers repositories:
# in the PyBaMM/ directory
git clone https://github.com/pybind/pybind11.git
git clone https://github.com/pybamm-team/casadi-headers.git
That's it.

Expand All @@ -104,10 +103,6 @@ If you'd rather do things yourself,
2. Compile and install SuiteSparse (PyBaMM only requires the ``KLU`` component).
3. Compile and install SUNDIALS.
4. Clone the pybind11 repository in the ``PyBaMM/`` directory (make sure the directory is named ``pybind11``).
5. Put the Casadi header files in the ``casadi-headers`` subdirectory in the ``PyBaMM/``
directory. You can get these header files as part of the full Casadi source
distribution [here](https://github.com/casadi/casadi.git), or you can clone just the
headers from https://github.com/pybamm-team/casadi-headers.git


PyBaMM ships with a python script that automates points 2. and 3. You can run it with
Expand Down
15 changes: 1 addition & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def compile_KLU():
# in the PyBaMM project directory
CMakeFound = True
PyBind11Found = True
CasadiFound = True
windows = (not system()) or system() == "Windows"

msg = "Running on Windows" if windows else "Not running on windows"
Expand All @@ -121,19 +120,7 @@ def compile_KLU():
)
logger.info(msg)

casadi_dir = os.path.join(pybamm_project_dir, "casadi-headers")
try:
open(os.path.join(casadi_dir, "casadi", "casadi.hpp"))
logger.info("Found casadi directory ({})".format(casadi_dir))
except FileNotFoundError:
CasadiFound = False
msg = (
"Could not find casadi directory ({})."
" Skipping compilation of KLU module.".format(casadi_dir)
)
logger.info(msg)

return CMakeFound and PyBind11Found and CasadiFound
return CMakeFound and PyBind11Found


# Build the list of package data files to be included in the PyBaMM package.
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ deps =
commands =
python {toxinidir}/scripts/install_KLU_Sundials.py
- git clone https://github.com/pybind/pybind11.git {toxinidir}/pybind11
- git clone https://github.com/pybamm-team/casadi-headers.git {toxinidir}/casadi-headers

[testenv:flake8]
skip_install = true
Expand Down

0 comments on commit fee37fc

Please sign in to comment.