feat: basic igh ethercat package support

This commit is contained in:
insleker 2026-04-24 12:01:27 +08:00
parent 13bd9754f8
commit 54b8704ac4
10 changed files with 312 additions and 109 deletions

10
.gitattributes vendored Normal file
View File

@ -0,0 +1,10 @@
*.cmake text eol=lf
*.conf text eol=lf
*.diff text eol=lf
*.md text eol=lf
*.patch text eol=lf
*.py text eol=lf
*.txt text eol=lf
*.yml text eol=lf
*.am text eol=lf
*.in text eol=lf

19
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,19 @@
### Summary
Changes to recipe: **lib/[version]**
#### Motivation
<!-- Please explain why this PR is needed, if it is a bugfix, please describe the bug or link to an existing issue. -->
#### Details
<!-- Explanation of the changes in the PR - this greatly simplifies the task of the reviewing team! -->
---
- [ ] Read the [contributing guidelines](https://github.com/conan-io/conan-center-index/blob/master/CONTRIBUTING.md)
- [ ] Checked that this PR is not a duplicate: [list of PRs by recipe](https://github.com/conan-io/conan-center-index/discussions/24240)
- [ ] If this is a bug fix, please link related issue or provide bug details
- [ ] Tested locally with at least one configuration using a recent version of Conan
---
Add a :+1: reaction to pull requests you find [important](https://github.com/conan-io/conan-center-index/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc) to help the team prioritize, thanks!

152
.gitignore vendored
View File

@ -1,7 +1,39 @@
# Byte-compiled / optimized / DLL files
# Conan specific
**/test_package/build/
**/test_package/build-*/
**/test_package/test_output/
conan.lock
conanbuildinfo.cmake
conanbuildinfo.txt
conaninfo.txt
graph_info.json
build/
.conanrunner/
.conanrc
# CMake
CMakeUserPresets.json
# IDEs
.idea
.vs
.vscode
.project
.pydevproject
.settings/
.ropeproject/
.devcontainer/
## emacs
*~
# Byte-compiled / optimized / DLL files / Cache
__pycache__/
*.py[codz]
**/test_package/__pycache__/
*.pyc
*.py[cod]
*$py.class
tmp/
.DS_Store
# C extensions
*.so
@ -20,7 +52,6 @@ parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
@ -39,17 +70,14 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
@ -59,7 +87,6 @@ cover/
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
@ -72,71 +99,22 @@ instance/
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
#poetry.toml
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
#pdm.lock
#pdm.toml
.pdm-python
.pdm-build/
# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
#pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
# celery beat schedule file
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.envrc
.venv
env/
venv/
@ -148,60 +126,18 @@ venv.bak/
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# scons build files
*.dblite
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/
# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/
# Ruff stuff:
.ruff_cache/
# PyPI configuration file
.pypirc
# Cursor
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
# refer to https://docs.cursor.com/context/ignore-files
.cursorignore
.cursorindexingignore
# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/
# vim temp files
.*.sw?
.sw?
Session.vim
*~
.undodir

View File

@ -1 +1,7 @@
# conan-recipes
The goal of this repo is provide some **non-official** recipes for libraries that has no plan to officially support conan.
* bibliography: [conan-center-index](https://github.com/conan-io/conan-center-index/tree/master)
* [audacity/conan-recipes](https://github.com/audacity/conan-recipes)
* [bkinnightskytw/ethercat](https://gitlab.com/bkinnightskytw/ethercat/-/tree/backport/1.5.3-conan?ref_type=heads)

View File

@ -0,0 +1,92 @@
cmake_minimum_required(VERSION 3.15)
if(NOT DEFINED ETHERCAT_VERSION)
set(ETHERCAT_VERSION 0.0.0)
endif()
project(
ethercat
VERSION ${ETHERCAT_VERSION}
DESCRIPTION "IgH EtherCAT Master userspace client library"
LANGUAGES C)
include(GNUInstallDirs)
option(BUILD_SHARED_LIBS "Build shared library" ON)
set(EC_MAX_NUM_DEVICES
1
CACHE STRING
"Max number of Ethernet devices per master (must match kernel module)")
set(ETHERCAT_SOURCES
lib/common.c
lib/domain.c
lib/master.c
lib/reg_request.c
lib/sdo_request.c
lib/slave_config.c
lib/soe_request.c
lib/voe_handler.c)
set(ETHERCAT_PUBLIC_HEADERS
include/ecrt.h
include/ectty.h)
add_library(ethercat ${ETHERCAT_SOURCES})
add_library(EtherLab::ethercat ALIAS ethercat)
# The userspace library expects a few configure-time defines from autotools.
file(
WRITE ${CMAKE_CURRENT_BINARY_DIR}/config.h
"/* Generated by the Conan recipe. */\n"
"#ifndef CONFIG_H\n"
"#define CONFIG_H\n"
"#ifndef VERSION\n"
"#define VERSION \"${PROJECT_VERSION}\"\n"
"#endif\n"
"#ifndef REV\n"
"#define REV \"\"\n"
"#endif\n"
"#endif\n")
set_target_properties(
ethercat
PROPERTIES PUBLIC_HEADER "${ETHERCAT_PUBLIC_HEADERS}"
SOVERSION 1)
target_compile_definitions(
ethercat PRIVATE EC_MAX_NUM_DEVICES=${EC_MAX_NUM_DEVICES}
VERSION="${PROJECT_VERSION}" REV="")
target_compile_options(
ethercat PRIVATE -fno-strict-aliasing -Wall -Wmissing-prototypes)
target_include_directories(
ethercat
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/lib
${CMAKE_CURRENT_SOURCE_DIR}/master)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/libethercat.map")
target_compile_definitions(ethercat PRIVATE ethercat_EXPORTS)
target_compile_options(ethercat PRIVATE -fvisibility=hidden)
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
target_link_options(
ethercat PRIVATE
"LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/lib/libethercat.map")
endif()
endif()
if(UNIX AND NOT APPLE)
target_link_libraries(ethercat PRIVATE rt)
endif()
install(
TARGETS ethercat
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

View File

@ -0,0 +1,7 @@
sources:
"1.5.3":
url: "https://gitlab.com/etherlab.org/ethercat/-/archive/1.5.3/ethercat-1.5.3.tar.gz"
sha256: "69f6fdee37cfd8bb87834e975b80092b055ea2debf7d31591d43237f6bddc31b"
"1.6.8":
url: "https://gitlab.com/etherlab.org/ethercat/-/archive/1.6.8/ethercat-1.6.8.tar.gz"
sha256: "c6d800ff1a9756b7c19078ac2c480a83d67934e0ed0cc8bde3a3f8770f7b88f4"

View File

@ -0,0 +1,90 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get
import os
class EthercatConan(ConanFile):
name = "ethercat"
license = "LGPL-2.1-only"
author = "Florian Pose <fp@igh.de>"
url = "https://gitlab.com/etherlab.org/ethercat"
description = "IgH EtherCAT Master userspace client library"
topics = ("ethercat", "industrial", "automation", "fieldbus", "realtime")
package_type = "library"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"max_num_devices": ["ANY"],
}
default_options = {
"shared": True,
"fPIC": True,
"max_num_devices": 1,
}
exports_sources = (
"CMakeLists.txt",
"test_package/CMakeLists.txt",
"test_package/conanfile.py",
"test_package/test_package.c",
)
def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")
def configure(self):
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")
def validate(self):
if self.settings.os != "Linux":
raise ConanInvalidConfiguration("IgH EtherCAT Master is only supported on Linux")
try:
max_devices = int(str(self.options.max_num_devices))
except ValueError as exc:
raise ConanInvalidConfiguration("max_num_devices must be an integer") from exc
if max_devices < 1:
raise ConanInvalidConfiguration("max_num_devices must be >= 1")
def layout(self):
cmake_layout(self)
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = self.options.shared
tc.variables["EC_MAX_NUM_DEVICES"] = str(self.options.max_num_devices)
tc.variables["ETHERCAT_VERSION"] = str(self.version)
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
copy(
self,
"COPYING*",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
keep_path=False,
)
cmake = CMake(self)
cmake.install()
def package_info(self):
self.cpp_info.libs = ["ethercat"]
self.cpp_info.set_property("cmake_file_name", "ethercat")
self.cpp_info.set_property("cmake_target_name", "EtherLab::ethercat")
self.cpp_info.set_property("pkg_config_name", "libethercat")
self.cpp_info.system_libs = ["rt", "pthread"]

View File

@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(test_package C)
find_package(ethercat REQUIRED CONFIG)
add_executable(test_package test_package.c)
target_link_libraries(test_package PRIVATE EtherLab::ethercat)

View File

@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
class TestPackageConan(ConanFile):
test_type = "explicit"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"
def requirements(self):
self.requires(self.tested_reference_str)
def layout(self):
cmake_layout(self)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self):
exe = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(exe, env="conanrun")

View File

@ -0,0 +1,9 @@
#include <ecrt.h>
#include <stdio.h>
int main(void)
{
printf("ECRT version magic: %u\n", ecrt_version_magic());
return 0;
}