From fee37fc4020463ab29d82121338d9395928c4ece Mon Sep 17 00:00:00 2001 From: martinjrobins Date: Fri, 1 Apr 2022 15:29:26 +0100 Subject: [PATCH] #1863 use CMake to find casadi library on system --- CMakeLists.txt | 18 +++++++++++------- docs/install/install-from-source.rst | 5 ----- setup.py | 15 +-------------- tox.ini | 1 - 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb3566beb0..87d7639654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 diff --git a/docs/install/install-from-source.rst b/docs/install/install-from-source.rst index 5a5457b5ee..f03dc67eae 100644 --- a/docs/install/install-from-source.rst +++ b/docs/install/install-from-source.rst @@ -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. @@ -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 diff --git a/setup.py b/setup.py index 413fe427c2..9b3c441b38 100644 --- a/setup.py +++ b/setup.py @@ -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" @@ -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. diff --git a/tox.ini b/tox.ini index ba50c6eff5..b726a45952 100644 --- a/tox.ini +++ b/tox.ini @@ -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