Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.pyc
build/
myactuator_rmd_py.egg-info/

dist/
47 changes: 45 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.20)
project(myactuator_rmd VERSION 0.0.1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(PYTHON_BINDINGS "Building Python bindings" OFF)
option(BUILD_TESTING "Build unit and integration tests" OFF)
option(SETUP_TEST_IFNAME "Set-up the test VCAN interface automatically" OFF)
Expand Down Expand Up @@ -39,7 +42,26 @@ target_include_directories(myactuator_rmd PUBLIC
$<INSTALL_INTERFACE:include>
)
set(MYACTUATOR_RMD_LIBRARIES "")
target_link_libraries(myactuator_rmd PUBLIC

# --- Check for CAN frame member name ---
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#include <linux/can.h>
int main() {
struct can_frame frame;
frame.can_dlc = 0;
return 0;
}" HAVE_CAN_DLC)

if(HAVE_CAN_DLC)
message(STATUS "Detected can_frame.can_dlc member - using this field name.")
target_compile_definitions(myactuator_rmd PUBLIC HAVE_CAN_DLC)
else()
message(STATUS "Using can_frame.len member for newer Linux CAN versions.")
endif()
# --------------------------------------

target_link_libraries(myactuator_rmd PUBLIC
${MYACTUATOR_RMD_LIBRARIES}
)
install(DIRECTORY include/
Expand All @@ -57,14 +79,35 @@ if(PYTHON_BINDINGS)
Development
Interpreter
)
find_package(pybind11 CONFIG REQUIRED)

# --- Dynamically find pybind11 CMake directory ---
execute_process(
COMMAND "${Python3_EXECUTABLE}" -m pybind11 --cmakedir
OUTPUT_VARIABLE PYBIND11_CMAKE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE PYBIND11_RESULT
ERROR_QUIET
)
if(PYBIND11_RESULT EQUAL 0 AND IS_DIRECTORY "${PYBIND11_CMAKE_DIR}")
set(pybind11_DIR "${PYBIND11_CMAKE_DIR}")
message(STATUS "Found pybind11 CMake dir via Python: ${pybind11_DIR}")
else()
message(WARNING "Could not find pybind11 CMake dir via 'python3 -m pybind11 --cmakedir'. Falling back to standard find_package.")
endif()
# -------------------------------------------------

find_package(pybind11 REQUIRED)

pybind11_add_module(myactuator_rmd_py
bindings/myactuator_rmd.cpp
)
target_compile_features(myactuator_rmd_py PUBLIC
cxx_std_17
)
# Add HAVE_CAN_DLC definition if needed by bindings (unlikely, but for completeness)
if(HAVE_CAN_DLC)
target_compile_definitions(myactuator_rmd_py PUBLIC HAVE_CAN_DLC)
endif()
target_link_libraries(myactuator_rmd_py PUBLIC
myactuator_rmd
)
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include myactuator_rmd_py.pyi
1 change: 1 addition & 0 deletions include/myactuator_rmd/can/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <chrono>
#include <ostream>
#include <ratio>
#include <string>

#include <linux/can.h>
#include <sys/time.h>
Expand Down
67 changes: 67 additions & 0 deletions install_myactuator_rmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

# install_myactuator_rmd.sh
# Installs the myactuator_rmd_py package from the current directory.
# Assumes prerequisites like Python 3, pip, a C++ compiler, and CMake are installed.

# Exit immediately if a command exits with a non-zero status.
set -e

# --- Configuration ---
# Specify the path to your CMake executable if it's not in the default PATH
# or if you need a specific version (like the one from snap).
# Leave empty to use the default 'cmake' found in PATH.
CMAKE_EXECUTABLE="/snap/bin/cmake"
# Project directory (assumes the script is run from the project root)
PROJECT_DIR="$(pwd)"

# --- Prerequisite Checks ---
echo "Checking prerequisites..."

# Check for Python 3 & pip
if ! command -v python3 &> /dev/null; then
echo "Error: python3 not found."
exit 1
fi
if ! python3 -m pip --version &> /dev/null; then
echo "Error: pip not found for python3."
exit 1
fi
echo "Python 3 and pip found."

# Determine CMake command
if [ -n "$CMAKE_EXECUTABLE" ]; then
if ! command -v "$CMAKE_EXECUTABLE" &> /dev/null; then
echo "Error: Specified CMAKE_EXECUTABLE '$CMAKE_EXECUTABLE' not found."
exit 1
fi
CMAKE_CMD="$CMAKE_EXECUTABLE"
echo "Using specified CMake: $CMAKE_CMD"
else
if ! command -v cmake &> /dev/null; then
echo "Error: cmake not found in PATH. Install CMake or set CMAKE_EXECUTABLE."
exit 1
fi
CMAKE_CMD="cmake"
echo "Using CMake from PATH: $(command -v cmake)"
fi

# --- Installation Steps ---
echo "Starting installation of myactuator_rmd_py..."

# 1. Install/Upgrade required packages (using --user to match previous successful install)
echo "Installing/upgrading required packages..."
python3 -m pip install --upgrade pip wheel build pybind11 setuptools --user

# 2. Build the wheel
echo "Building wheel for myactuator_rmd_py from $PROJECT_DIR..."
export CMAKE_COMMAND="$CMAKE_CMD"
python3 -m pip wheel . --no-deps -w dist/

# 3. Install the wheel
echo "Installing the wheel..."
python3 -m pip install --user --force-reinstall dist/myactuator_rmd_py*.whl

echo ""
echo "Installation of myactuator_rmd_py completed successfully!"
exit 0
Loading