Skip to content

Commit

Permalink
pybamm-team#3049 clarify usage of cmake and casadi
Browse files Browse the repository at this point in the history
In the build-time requirements for Windows, we don't use cmake and casadi from pip, but from other sources. This is because we use Visual Studio to compile.
  • Loading branch information
agriyakhetarpal authored and js1tr3 committed Aug 12, 2024
1 parent 2bf363d commit 1427db3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
requires = [
"setuptools",
"wheel",
# On Windows, use the CasADi vcpkg registry and CMake bundled from MSVC
"casadi>=3.6.0; platform_system!='Windows'",
# use CMake bundled from MSVC on Windows
"cmake; platform_system!='Windows'",
]
build-backend = "setuptools.build_meta"
Expand Down Expand Up @@ -72,7 +72,7 @@ examples = [
# Plotting functionality
plot = [
"imageio>=2.9.0",
# Note: matplotlib is loaded for debug plots, but to ensure pybamm runs
# Note: matplotlib is loaded for debug plots, but to ensure PyBaMM runs
# on systems without an attached display, it should never be imported
# outside of plot() methods.
"matplotlib>=2.0",
Expand Down
23 changes: 13 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
from distutils.command.build_ext import build_ext


# ---------- CMake steps for IDAKLU target (non-Windows) -------------------------------


default_lib_dir = (
"" if system() == "Windows" else os.path.join(os.getenv("HOME"), ".local")
)

# ---------- set environment variables for vcpkg on Windows ----------------------------

def set_vcpkg_environment_variables():
if not os.getenv("VCPKG_ROOT_DIR"):
Expand All @@ -41,6 +39,7 @@ def set_vcpkg_environment_variables():
os.getenv("VCPKG_FEATURE_FLAGS"),
)

# ---------- CMakeBuild class (custom build_ext for IDAKLU target) ---------------------

class CMakeBuild(build_ext):
user_options = build_ext.user_options + [
Expand Down Expand Up @@ -119,6 +118,8 @@ def run(self):
if os.path.isfile(os.path.join(build_dir, "CMakeError.log")):
os.remove(os.path.join(build_dir, "CMakeError.log"))

# ---------- configuration for vcpkg on Windows ----------------------------------------

build_env = os.environ
if os.getenv("PYBAMM_USE_VCPKG"):
(
Expand All @@ -130,26 +131,29 @@ def run(self):
build_env["vcpkg_default_triplet"] = vcpkg_default_triplet
build_env["vcpkg_feature_flags"] = vcpkg_feature_flags

# ---------- Run CMake and build IDAKLU module -----------------------------------------

cmake_list_dir = os.path.abspath(os.path.dirname(__file__))
print("-" * 10, "Running CMake for idaklu solver", "-" * 40)
print("-" * 10, "Running CMake for IDAKLU solver", "-" * 40)
subprocess.run(
["cmake", cmake_list_dir] + cmake_args, cwd=build_dir, env=build_env
)
, check=True)

if os.path.isfile(os.path.join(build_dir, "CMakeError.log")):
msg = (
"cmake configuration steps encountered errors, and the idaklu module"
"cmake configuration steps encountered errors, and the IDAKLU module"
" could not be built. Make sure dependencies are correctly "
"installed. See "
"https://docs.pybamm.org/en/latest/source/user_guide/installation/install-from-source.html" # noqa: E501
)
raise RuntimeError(msg)
else:
print("-" * 10, "Building idaklu module", "-" * 40)
print("-" * 10, "Building IDAKLU module", "-" * 40)
subprocess.run(
["cmake", "--build", ".", "--config", "Release"],
cwd=build_dir,
env=build_env,
check=True,
)

# Move from build temp to final position
Expand Down Expand Up @@ -218,7 +222,7 @@ def run(self):
install.run(self)


# ---------- custom wheel build (non-Windows) ------------------------------------------
# ---------- Custom class for building wheels ------------------------------------------


class bdist_wheel(orig.bdist_wheel):
Expand Down Expand Up @@ -250,8 +254,7 @@ def compile_KLU():
# Return True if:
# - Not running on Windows AND
# - CMake is found AND
# - The pybind11 and casadi-headers directories are found
# in the PyBaMM project directory
# - The pybind11/ directory is found in the PyBaMM project directory
CMakeFound = True
PyBind11Found = True
windows = (not system()) or system() == "Windows"
Expand Down

0 comments on commit 1427db3

Please sign in to comment.