Skip to content

Commit

Permalink
Change python bindings native module from pybgcode to _bgcode
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasmeszaros committed Nov 6, 2023
1 parent 07c4d3a commit 17f993d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
26 changes: 15 additions & 11 deletions pybgcode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,34 @@ endif()

find_package(Boost ${Boost_VER} REQUIRED COMPONENTS nowide)

pybind11_add_module(pybgcode MODULE pybgcode.cpp)
pybind11_add_module(_bgcode MODULE pybgcode.cpp)

target_link_libraries(pybgcode PRIVATE LibBGCode::bgcode_convert Boost::nowide)
target_link_libraries(_bgcode PRIVATE LibBGCode::bgcode_convert Boost::nowide)

target_compile_definitions(pybgcode PRIVATE
MODULE_NAME=pybgcode
target_compile_definitions(_bgcode PRIVATE
MODULE_NAME=$<TARGET_FILE_BASE_NAME:_bgcode>
VERSION_INFO="${PY_FULL_VERSION}"
)

# Hide all symbols by default (including external libraries on Linux)
set_target_properties(pybgcode PROPERTIES
set_target_properties(_bgcode PROPERTIES
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN true)
VISIBILITY_INLINES_HIDDEN true
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pybgcode)

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_options(pybgcode PRIVATE "LINKER:--exclude-libs,ALL")
target_link_options(_bgcode PRIVATE "LINKER:--exclude-libs,ALL")
endif()

if (PY_BUILD_CMAKE_MODULE_NAME)
# Install the Python module
install(TARGETS pybgcode
install(TARGETS _bgcode
EXCLUDE_FROM_ALL
COMPONENT python_modules
DESTINATION ${PY_BUILD_CMAKE_MODULE_NAME})
# Install the debug file for the Python module (Windows only)
if (WIN32)
install(FILES $<TARGET_PDB_FILE:pybgcode>
install(FILES $<TARGET_PDB_FILE:_bgcode>
EXCLUDE_FROM_ALL
COMPONENT python_modules
DESTINATION ${PY_BUILD_CMAKE_MODULE_NAME}
Expand All @@ -80,8 +81,11 @@ set (TEST_DATA_DIR ${CMAKE_CURRENT_LIST_DIR}/../tests/data)
# Prepare the test files to be available
configure_file(${TEST_DATA_DIR}/mini_cube_b_ref.gcode ${CMAKE_CURRENT_BINARY_DIR}/test.gcode)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/pybgcode DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

# Define the test for ctest and inject the correct PYTHONPATH env var for its runtime
add_test(NAME test_pybgcode COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_convert.py CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})
set_property(TEST test_pybgcode PROPERTY ENVIRONMENT PYTHONPATH=$<TARGET_FILE_DIR:pybgcode>)
#$<TARGET_FILE_DIR:_bgcode>:
set_property(TEST test_pybgcode PROPERTY ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR})

add_custom_target(build_and_test COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS pybgcode)
add_custom_target(build_and_test COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS _bgcode)
2 changes: 1 addition & 1 deletion pybgcode/pybgcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct FILEWrapper {
~FILEWrapper() { close(); }
};

PYBIND11_MODULE(pybgcode, m) {
PYBIND11_MODULE(MODULE_NAME, m) {
using namespace bgcode;

static constexpr size_t MaxBuffSz = 2048;
Expand Down
4 changes: 2 additions & 2 deletions pybgcode/pybgcode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .pybgcode import *
from ._bgcode import *

"""Prusa Block & Binary G-code reader / writer / converter"""
__version__ = pybgcode.version()
__version__ = _bgcode.version()

0 comments on commit 17f993d

Please sign in to comment.