CSerialPort icon indicating copy to clipboard operation
CSerialPort copied to clipboard

Normalize C Binding Interface, Improve CMake Integration

Open tayne3 opened this issue 9 months ago • 0 comments

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 avatar Mar 30 '25 06:03 tayne3