Skip to content

Commit

Permalink
Fix compilation of wearables and hde Python bindings on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro authored Sep 25, 2024
1 parent 2ec2bce commit 182ad63
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if(HDE_COMPILE_PYTHON_BINDINGS)
# Function to generate __init__.py file for both hde and wearables
# It contains logic to ensure that it works fine on Windows when installing in arbitrary folders,
# See https://docs.python.org/3.8/library/os.html#os.add_dll_directory
function(hde_generate_init_py_file GENERATION_LOCATION_OF_INIT_PY_FILE INSTALLATION_LOCATION_OF_INIT_PY_FILE)
function(hde_generate_init_py_file GENERATION_LOCATION_OF_INIT_PY_FILE INSTALLATION_LOCATION_OF_INIT_PY_FILE PYBIND11_OUTPUT_NAME)
file(WRITE ${GENERATION_LOCATION_OF_INIT_PY_FILE}/__init__.py "")
if(WIN32 AND BUILD_SHARED_LIBS)
if(IS_ABSOLUTE ${INSTALLATION_LOCATION_OF_INIT_PY_FILE})
Expand All @@ -33,7 +33,7 @@ if(HDE_COMPILE_PYTHON_BINDINGS)
file(APPEND ${GENERATION_LOCATION_OF_INIT_PY_FILE}/__init__.py "\n")
endif()

file(APPEND ${GENERATION_LOCATION_OF_INIT_PY_FILE}/__init__.py "from .bindings import *\n")
file(APPEND ${GENERATION_LOCATION_OF_INIT_PY_FILE}/__init__.py "from .${PYBIND11_OUTPUT_NAME} import *\n")
endfunction()

# Install the resulting Python package for the active interpreter
Expand Down
9 changes: 5 additions & 4 deletions bindings/python-hde/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ target_link_libraries(pybind11_hde PRIVATE
${pybind_link_libraries})

# # The generated Python dynamic module must have the same name as the pybind11
# # module, i.e. `bindings`.
# # module, i.e. `hde_bindings`.
set(PYBIND11_BINDINGS_OUTPUT_NAME "hde_bindings")
set_target_properties(pybind11_hde PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${HDE_PYTHON_PACKAGE}"
OUTPUT_NAME "bindings")
OUTPUT_NAME ${PYBIND11_BINDINGS_OUTPUT_NAME})

# Output package is:
#
# hde
# |-- __init__.py (generated from main bindings CMake file)
# `-- bindings.<cpython_extension>
# `-- hde_bindings.<cpython_extension>

install(TARGETS pybind11_hde DESTINATION ${PYTHON_INSTDIR})

# Create the __init__.py file
hde_generate_init_py_file("${HDE_PYTHON_PACKAGE}" "${PYTHON_INSTDIR}")
hde_generate_init_py_file("${HDE_PYTHON_PACKAGE}" "${PYTHON_INSTDIR}" ${PYBIND11_BINDINGS_OUTPUT_NAME})
# Install the __init__.py file
install(FILES "${HDE_PYTHON_PACKAGE}/__init__.py"
DESTINATION ${PYTHON_INSTDIR})
Expand Down
9 changes: 5 additions & 4 deletions bindings/python-wearables/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ target_link_libraries(pybind11_wearables PRIVATE
${pybind_link_libraries})

# # The generated Python dynamic module must have the same name as the pybind11
# # module, i.e. `bindings`.
# # module, i.e. `wearables_bindings`.
set(PYBIND11_BINDINGS_OUTPUT_NAME "wearables_bindings")
set_target_properties(pybind11_wearables PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${WEARABLES_PYTHON_PACKAGE}"
OUTPUT_NAME "bindings")
OUTPUT_NAME ${PYBIND11_BINDINGS_OUTPUT_NAME})

# Output package is:
#
# bipedal_locomotion
# |-- __init__.py (generated from main bindings CMake file)
# `-- bindings.<cpython_extension>
# `-- wearables_bindings.<cpython_extension>

install(TARGETS pybind11_wearables DESTINATION ${PYTHON_INSTDIR})

hde_generate_init_py_file("${WEARABLES_PYTHON_PACKAGE}" "${PYTHON_INSTDIR}")
hde_generate_init_py_file("${WEARABLES_PYTHON_PACKAGE}" "${PYTHON_INSTDIR}" ${PYBIND11_BINDINGS_OUTPUT_NAME})
# Install the __init__.py file
install(FILES "${WEARABLES_PYTHON_PACKAGE}/__init__.py"
DESTINATION ${PYTHON_INSTDIR})
Expand Down

0 comments on commit 182ad63

Please sign in to comment.