Skip to content

Normalize C Binding Interface, Improve CMake Integration #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tayne3
Copy link

@tayne3 tayne3 commented Mar 30, 2025

Normalize C Binding Interface, Improve CMake Integration (规范化 C 绑定接口,改进 CMake 集成)

  1. 规范化 C 绑定接口

    • 在C头文件中将空参数列表改为void,符合C语言标准
    • 在C++源代码中将NULL替换为nullptr,遵循现代C++风格
  2. CMake构建系统优化:

    • 添加输出目录的条件检查,避免覆盖父项目设置
    • 使用 target_include_directories 添加头文件搜索路径, 直接链接库对象即可继承, 无需再额外调用 target_include_directories(demo CSerialPort-4.3.2/bindings/c/)
    • 根据编译器类型添加rt库链接(针对GNU C编译器), 避免在低版本linux下编译出错
    • 通过 CSERIALPORT_BUILD_EXAMPLES 标志使示例构建成为可选项, 避免将 CSerialPort 作为子模块导入时编译示例程序
    • 优化源文件列表格式,提高可读性

这些变更增强了 CSerialPort 的 C 绑定,以及消除了作为依赖项使用时需要修改源代码的情况。

tayne3 added 3 commits March 30, 2025 14:19
…t-based support

- Add conditional checks for output directories to avoid overriding parent project settings
- Optimize source file list format for better readability
- Use target_include_directories instead of global include_directories
- Add rt library linking based on compiler type (for GNU C compiler)
- Make example building optional (CSERIALPORT_BUILD_EXAMPLES)

These improvements make it easier to integrate the CSerialPort C binding as a submodule in other projects without source code modifications.
- Change empty parameter lists to void in C header, conforming to C standard
- Replace NULL with nullptr in C++ source, using modern C++ style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant