Skip to content

Commit

Permalink
Fixed generation of bindings in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Dafarra committed Jan 13, 2025
1 parent a39eb13 commit 4d86cef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if(FRAMEWORK_COMPILE_PYTHON_BINDINGS)
add_subdirectory(python)

# Create the __init__.py file
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/__init__.py "")
file(WRITE ${BLF_PYTHON_PACKAGE}/__init__.py "")

# If we are on Windows and BUILD_SHARED_LIBS is ON, handle the fact that
# the Python interpreter does not look into PATH to find dll (see https://docs.python.org/3.8/library/os.html#os.add_dll_directory)
Expand All @@ -68,6 +68,12 @@ if(FRAMEWORK_COMPILE_PYTHON_BINDINGS)
file(APPEND "${BLF_PYTHON_PACKAGE}/__init__.py" "if(library_dll_path != os.path.join(os.environ.get('CONDA_PREFIX', ''),'Library','bin') and library_dll_path != os.path.join(os.environ.get('CONDA_PREFIX', ''),'bin')):${NEW_LINE}")
file(APPEND "${BLF_PYTHON_PACKAGE}/__init__.py" " if(os.path.exists(library_dll_path)):${NEW_LINE}")
file(APPEND "${BLF_PYTHON_PACKAGE}/__init__.py" " os.add_dll_directory(library_dll_path)${NEW_LINE}")

# For running tests, we need to add also the path where the dependecies are installed.
# We add idyntree to update the dll path for the tests.
file(APPEND "${BLF_PYTHON_PACKAGE}/__init__.py" "import idyntree${NEW_LINE}")


endif()

file(APPEND "${BLF_PYTHON_PACKAGE}/__init__.py" "from .bindings import *${NEW_LINE}from . import utils${NEW_LINE}")
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ target_link_libraries(pybind11_blf PRIVATE
# # The generated Python dynamic module must have the same name as the pybind11
# # module, i.e. `bindings`.
set_target_properties(pybind11_blf PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${BLF_PYTHON_PACKAGE}"
LIBRARY_OUTPUT_DIRECTORY $<1:${BLF_PYTHON_PACKAGE}> # Prevent appending Release/Debug to the output path in Windows
OUTPUT_NAME "bindings")

if(FRAMEWORK_TEST_PYTHON_BINDINGS)
Expand Down

0 comments on commit 4d86cef

Please sign in to comment.