Skip to content

Commit

Permalink
Try fixing CasADi CMake compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Feb 5, 2024
1 parent c0c00c1 commit 97f6c85
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
CMAKE_GENERATOR_PLATFORM=x64
CMAKE_BUILD_PARALLEL_LEVEL=${{ steps.get_num_cores.outputs.count }}
CIBW_ARCHS: AMD64
CIBW_BEFORE_BUILD: python -m pip install setuptools wheel # skip CasADi and CMake
CIBW_BEFORE_BUILD: python -m pip install setuptools wheel casadi # skip CMake
CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()"

- name: Upload Windows wheels
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ endif()

if(${USE_PYTHON_CASADI})
message("Trying to link against Python casadi package")

# Windows error:
# CMake Error at C:/Users/runneradmin/AppData/Local/Temp/cibw-run-zffsr_52/cp38-win_amd64/build/venv/Lib/site-packages/casadi/cmake/casadi-targets.cmake:74 (message):
# The imported target "casadi" references the file
# "C:/Users/runneradmin/AppData/Local/Temp/cibw-run-zffsr_52/cp38-win_amd64/build/venv/Lib/site-packages/casadi/libcasadi.lib"

# but casadi.lib exists instead of libcasadi.lib, so if on Windows, we need to
# remove the lib prefix from the library names
if(WIN32)
set(CMAKE_FIND_LIBRARY_PREFIXES "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_STATIC_LIBRARY_PREFIX "")
endif()

find_package(casadi CONFIG PATHS ${CASADI_DIR} REQUIRED NO_DEFAULT_PATH)
else()
message("Trying to link against any casadi package apart from the Python one")
Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
requires = [
"setuptools>=64",
"wheel",
# On Windows, use the CasADi vcpkg registry and CMake bundled from MSVC
"casadi>=3.6.3; platform_system!='Windows'",
# Note: the version of CasADi as a build-time dependency should be matched
# cross platforms, so updates to its minimum version here should be accompanied
# by a version bump in https://github.com/pybamm-team/casadi-vcpkg-registry.
# On Windows, use CMake bundled from MSVC
"casadi>=3.6.3",
"cmake; platform_system!='Windows'",
]
build-backend = "setuptools.build_meta"
Expand Down
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ def run(self):
# Build in parallel wherever possible
os.environ["CMAKE_BUILD_PARALLEL_LEVEL"] = str(cpu_count())

if system() == "Windows":
use_python_casadi = False
else:
use_python_casadi = True
use_python_casadi = True

build_type = os.getenv("PYBAMM_CPP_BUILD_TYPE", "RELEASE")
cmake_args = [
Expand Down

0 comments on commit 97f6c85

Please sign in to comment.