-
-
Notifications
You must be signed in to change notification settings - Fork 8
Fix CasADi in config mode, and use pybind11's FindPython mode
#62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
7925749
e8f94fd
53034d4
ace85d4
a1e6005
69a8263
8eed3b0
9c2008c
17518f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||
| cmake_minimum_required(VERSION 3.13) | ||||||
| cmake_policy(SET CMP0074 NEW) | ||||||
| cmake_minimum_required(VERSION 3.26) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The earliest version of CMake to support the new |
||||||
|
|
||||||
| set(CMAKE_VERBOSE_MAKEFILE ON) | ||||||
|
|
||||||
| if (DEFINED ENV{VCPKG_ROOT_DIR} AND NOT DEFINED VCPKG_ROOT_DIR) | ||||||
|
|
@@ -32,6 +32,7 @@ endif () | |||||
| # casadi seems to compile without the newer versions of std::string | ||||||
| add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0) | ||||||
|
|
||||||
| set(PYBIND11_FINDPYTHON ON) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will help with WASM builds :) |
||||||
| find_package(pybind11 CONFIG REQUIRED) | ||||||
|
|
||||||
| # Check Casadi build flag | ||||||
|
|
@@ -91,73 +92,35 @@ if (NOT DEFINED USE_PYTHON_CASADI) | |||||
| set(USE_PYTHON_CASADI TRUE) | ||||||
| endif () | ||||||
|
|
||||||
| if (${USE_PYTHON_CASADI}) | ||||||
| execute_process( | ||||||
| COMMAND "${PYTHON_EXECUTABLE}" -c | ||||||
| "import os; import sysconfig; print(os.path.join(sysconfig.get_path('purelib'), 'casadi', 'cmake'))" | ||||||
| OUTPUT_VARIABLE CASADI_DIR | ||||||
| OUTPUT_STRIP_TRAILING_WHITESPACE) | ||||||
|
|
||||||
| if (CASADI_DIR) | ||||||
| file(TO_CMAKE_PATH ${CASADI_DIR} CASADI_DIR) | ||||||
| message("Found Python casadi path: ${CASADI_DIR}") | ||||||
| else () | ||||||
| message(FATAL_ERROR "Did not find casadi path") | ||||||
| endif () | ||||||
|
|
||||||
| message("Trying to link against Python casadi package in ${CASADI_DIR}") | ||||||
| if (EXISTS "${CASADI_DIR}/casadiConfig.cmake" OR EXISTS "${CASADI_DIR}/casadi-config.cmake") | ||||||
| find_package(casadi CONFIG PATHS ${CASADI_DIR} NO_DEFAULT_PATH) | ||||||
| else () | ||||||
| message(WARNING "CasADi CMake config not found in ${CASADI_DIR}. Proceeding without find_package; using include and library paths discovered from the Python package.") | ||||||
| endif () | ||||||
|
|
||||||
| execute_process( | ||||||
| COMMAND "${PYTHON_EXECUTABLE}" -c | ||||||
| "import casadi; from pathlib import Path; print(Path(casadi.__file__).parent / 'include')" | ||||||
| OUTPUT_VARIABLE CASADI_INCLUDE_DIR | ||||||
| OUTPUT_STRIP_TRAILING_WHITESPACE) | ||||||
|
|
||||||
| if (CASADI_INCLUDE_DIR) | ||||||
| file(TO_CMAKE_PATH ${CASADI_INCLUDE_DIR} CASADI_INCLUDE_DIR) | ||||||
| message("Found Python CasADi include directory: ${CASADI_INCLUDE_DIR}") | ||||||
| target_include_directories(idaklu PRIVATE ${CASADI_INCLUDE_DIR}) | ||||||
| else () | ||||||
| message(FATAL_ERROR "Could not find CasADi include directory") | ||||||
| endif () | ||||||
| execute_process( | ||||||
| COMMAND "${Python_EXECUTABLE}" -c | ||||||
|
||||||
| COMMAND "${Python_EXECUTABLE}" -c | |
| COMMAND "${Python3_EXECUTABLE}" -c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect; FindPython defines Python_EXECUTABLE and not Python3_EXECUTABLE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that the previous version of this command, i.e.,
import os; import sysconfig; print(os.path.join(sysconfig.get_path('purelib'), 'casadi', 'cmake'))thinks that it finds CasADi in something like /Users/agriyakhetarpal/Desktop/pybammsolvers/venv/lib/python3.12/site-packages/casadi/cmake, which will never exist – this is because it just constructs the path for where CasADi would be placed.
What we needed to do here is to import casadi – this is always guaranteed to work as we require casadi as a build-time dependency, and hence is available in sys.modules during build isolation. I switched to this, and we correctly get the build-time CasADi:
/private/var/folders/b3/2bq1m1_50bs4c7305j8vxcqr0000gn/T/pip-build-env-ihqwpmd7/overlay/lib/python3.12/site-packages/casadi/cmake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This policy is too old; it prevents us from using https://cmake.org/cmake/help/latest/module/FindPython.html as it gets disabled when this policy is enabled.