-
Notifications
You must be signed in to change notification settings - Fork 0
Revamp project #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
749c5fa
Remove sequential interface headers and related functionality
Katze719 4274258
Add CMake presets and toolchain files for GCC, Clang, and MSVC
Katze719 b45a036
Update CMake configuration and add module support
Katze719 54a1058
Remove unnecessary processor setting from toolchain files
Katze719 9ef4583
Refactor CMake configuration to automate versioning and enhance toolc…
Katze719 e34925f
Revise README.md for clarity and detail on library features
Katze719 c388182
Add serial port enumeration functionality
Katze719 d3ae8b4
Update cmake/get_version_from_git.cmake
Katze719 e67be2c
Update CMakeLists.txt
Katze719 d14b7b3
Apply suggestions from code review
Katze719 709ec04
Apply suggestions from code review
Katze719 31c2f36
fix: format
Mqxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| include/cpp_core/version.h | ||
| build/ | ||
| .cache/ | ||
|
|
||
| compile_commands.json |
|
Mqxx marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,64 +1,111 @@ | ||
| cmake_minimum_required(VERSION 3.14) | ||
| cmake_minimum_required(VERSION 3.30) | ||
|
|
||
| project(cpp-core | ||
| VERSION 0.1.0 | ||
| DESCRIPTION "Cross-platform helper library shared by cpp-linux-bindings and cpp-windows-bindings" | ||
| LANGUAGES CXX) | ||
| # Export compile commands to root directory | ||
| set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Version information - can be overridden by parent project | ||
| # Version information from Git tags | ||
| # Version is determined automatically from Git tags and cannot be overridden | ||
| # --------------------------------------------------------------------------- | ||
| foreach(_part IN ITEMS MAJOR MINOR PATCH) | ||
| if(NOT DEFINED CPP_CORE_VERSION_${_part} OR CPP_CORE_VERSION_${_part} STREQUAL "") | ||
| set(CPP_CORE_VERSION_${_part} ${PROJECT_VERSION_${_part}}) | ||
| endif() | ||
| endforeach() | ||
| include(${CMAKE_CURRENT_LIST_DIR}/cmake/get_version_from_git.cmake) | ||
|
|
||
| # Get version from Git tags | ||
| get_version_from_git() | ||
| set(CPP_CORE_VERSION_MAJOR ${VERSION_MAJOR} CACHE STRING "Major version number" FORCE) | ||
| set(CPP_CORE_VERSION_MINOR ${VERSION_MINOR} CACHE STRING "Minor version number" FORCE) | ||
| set(CPP_CORE_VERSION_PATCH ${VERSION_PATCH} CACHE STRING "Patch version number" FORCE) | ||
| set(CPP_CORE_VERSION_STRING ${VERSION_STRING} CACHE STRING "Full version string" FORCE) | ||
|
|
||
| # Set PROJECT_VERSION for CMake package config (only MAJOR.MINOR.PATCH, no suffix) | ||
| set(PROJECT_VERSION "${CPP_CORE_VERSION_MAJOR}.${CPP_CORE_VERSION_MINOR}.${CPP_CORE_VERSION_PATCH}") | ||
|
|
||
| project( | ||
| cpp-core | ||
| VERSION ${PROJECT_VERSION} | ||
| DESCRIPTION "Cross-platform helper library shared by cpp-linux-bindings and cpp-windows-bindings" | ||
| LANGUAGES CXX | ||
| ) | ||
|
|
||
| configure_file( | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h.in | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h | ||
| @ONLY) | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h.in | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h | ||
| @ONLY | ||
| ) | ||
|
|
||
| # Header-only library -------------------------------------------------------- | ||
| add_library(cpp_core INTERFACE) | ||
| add_library(cpp_core::cpp_core ALIAS cpp_core) | ||
|
|
||
| # Public include directories | ||
| target_include_directories(cpp_core INTERFACE | ||
| target_include_directories( | ||
| cpp_core | ||
| INTERFACE | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) | ||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
| ) | ||
|
|
||
| # Set C++ standard | ||
| set(CMAKE_CXX_STANDARD 23) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
| set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
Katze719 marked this conversation as resolved.
|
||
|
|
||
| # Require C++23 | ||
| target_compile_features(cpp_core INTERFACE cxx_std_23) | ||
|
|
||
| # Enable C++23 module support | ||
| set(CMAKE_CXX_MODULE_STD 23) | ||
| set(CMAKE_CXX_MODULE_EXTENSIONS OFF) | ||
|
Mqxx marked this conversation as resolved.
Mqxx marked this conversation as resolved.
|
||
|
|
||
| # Install rules -------------------------------------------------------------- | ||
| include(GNUInstallDirs) | ||
|
|
||
| install(TARGETS cpp_core | ||
| EXPORT cpp_coreTargets) | ||
| install( | ||
| TARGETS cpp_core | ||
| EXPORT cpp_coreTargets | ||
| ) | ||
|
|
||
| install(DIRECTORY include/ | ||
| DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
| install( | ||
| DIRECTORY include/ | ||
| DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
| ) | ||
|
|
||
| # CMake package configuration ------------------------------------------------ | ||
| include(CMakePackageConfigHelpers) | ||
|
|
||
| write_basic_package_version_file( | ||
| ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake | ||
| VERSION ${PROJECT_VERSION} | ||
| COMPATIBILITY SameMajorVersion) | ||
| ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake | ||
| VERSION ${PROJECT_VERSION} | ||
| COMPATIBILITY SameMajorVersion | ||
| ) | ||
|
|
||
| configure_package_config_file( | ||
| ${CMAKE_CURRENT_LIST_DIR}/cmake/cpp_core_config.cmake.in | ||
| ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake | ||
| INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) | ||
| ${CMAKE_CURRENT_LIST_DIR}/cmake/cpp_core_config.cmake.in | ||
| ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake | ||
| INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core | ||
| ) | ||
|
|
||
| install(EXPORT cpp_coreTargets | ||
| FILE cpp_coreTargets.cmake | ||
| NAMESPACE cpp_core:: | ||
| DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) | ||
| install( | ||
| EXPORT cpp_coreTargets | ||
| FILE cpp_coreTargets.cmake | ||
| NAMESPACE cpp_core:: | ||
| DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core | ||
| ) | ||
|
|
||
| install(FILES | ||
| install( | ||
| FILES | ||
| ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake | ||
| ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake | ||
| DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) | ||
| DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core | ||
| ) | ||
|
|
||
| if(CMAKE_EXPORT_COMPILE_COMMANDS AND EXISTS "${CMAKE_BINARY_DIR}/compile_commands.json") | ||
| add_custom_target( | ||
| copy-compile-commands | ||
| ALL | ||
| ${CMAKE_COMMAND} -E copy_if_different | ||
| ${CMAKE_BINARY_DIR}/compile_commands.json | ||
| ${CMAKE_SOURCE_DIR}/compile_commands.json | ||
| DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json | ||
| COMMENT "Copying compile_commands.json to project root" | ||
| ) | ||
| endif() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| { | ||
| "version": 3, | ||
| "cmakeMinimumRequired": { | ||
| "major": 3, | ||
| "minor": 30, | ||
| "patch": 0 | ||
| }, | ||
| "configurePresets": [ | ||
| { | ||
| "name": "gcc", | ||
| "displayName": "GCC (g++)", | ||
| "description": "Build using GCC compiler", | ||
| "generator": "Ninja", | ||
| "binaryDir": "${sourceDir}/build/gcc", | ||
| "toolchainFile": "${sourceDir}/cmake/gcc-toolchain.cmake", | ||
| "cacheVariables": { | ||
| "CMAKE_BUILD_TYPE": "Debug" | ||
| } | ||
| }, | ||
| { | ||
| "name": "clang", | ||
| "displayName": "Clang (clang++)", | ||
| "description": "Build using Clang compiler", | ||
| "generator": "Ninja", | ||
| "binaryDir": "${sourceDir}/build/clang", | ||
| "toolchainFile": "${sourceDir}/cmake/clang-toolchain.cmake", | ||
| "cacheVariables": { | ||
| "CMAKE_BUILD_TYPE": "Debug" | ||
| } | ||
| }, | ||
| { | ||
| "name": "msvc", | ||
| "displayName": "MSVC", | ||
| "description": "Build using MSVC compiler", | ||
| "generator": "Visual Studio 17 2022", | ||
| "binaryDir": "${sourceDir}/build/msvc", | ||
| "toolchainFile": "${sourceDir}/cmake/msvc-toolchain.cmake", | ||
| "architecture": { | ||
| "value": "x64", | ||
| "strategy": "external" | ||
| } | ||
| } | ||
| ], | ||
| "buildPresets": [ | ||
| { | ||
| "name": "gcc-debug", | ||
| "displayName": "GCC Debug", | ||
| "configurePreset": "gcc", | ||
| "configuration": "Debug" | ||
| }, | ||
| { | ||
| "name": "gcc-release", | ||
| "displayName": "GCC Release", | ||
| "configurePreset": "gcc", | ||
| "configuration": "Release" | ||
| }, | ||
| { | ||
| "name": "clang-debug", | ||
| "displayName": "Clang Debug", | ||
| "configurePreset": "clang", | ||
| "configuration": "Debug" | ||
| }, | ||
| { | ||
| "name": "clang-release", | ||
| "displayName": "Clang Release", | ||
| "configurePreset": "clang", | ||
| "configuration": "Release" | ||
| }, | ||
| { | ||
| "name": "msvc-debug", | ||
| "displayName": "MSVC Debug", | ||
| "configurePreset": "msvc", | ||
| "configuration": "Debug" | ||
| }, | ||
| { | ||
| "name": "msvc-release", | ||
| "displayName": "MSVC Release", | ||
| "configurePreset": "msvc", | ||
| "configuration": "Release" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,81 +1,76 @@ | ||
| # C++ Core | ||
|
|
||
| Header-only C++ helper library that provides small, cross-platform utilities and a centrally maintained **Version** struct shared by the *cpp-bindings-linux*, *cpp-bindings-windows* and *cpp-bindings-macos* repositories. | ||
| Header-only API definition library for cross-platform serial communication. Defines the **API contract** and **version information** shared by all platform-specific binding implementations. | ||
|
|
||
| > [!NOTE] | ||
| > [!IMPORTANT] | ||
| > | ||
| > This repository contains **headers only**. To obtain a working native library (SO / DLL / dylib) build one of the platform-specific projects instead: | ||
| > - [C++ bindings (Windows)](https://github.com/Serial-IO/cpp-bindings-windows) | ||
| > - [C++ bindings (Linux)](https://github.com/Serial-IO/cpp-bindings-linux) | ||
| > | ||
| > These repositories compile *cpp-core* for you and provide the ready-to-use shared library. | ||
| > **API definitions only** (headers). For implementations and ready-to-use shared libraries: | ||
| > - [cpp-bindings-windows](https://github.com/Serial-IO/cpp-bindings-windows) - Windows (DLL) | ||
| > - [cpp-bindings-linux](https://github.com/Serial-IO/cpp-bindings-linux) - Linux (SO) | ||
| > - [cpp-bindings-macos](https://github.com/Serial-IO/cpp-bindings-macos) - macOS (dylib) | ||
|
|
||
| ## Documentation | ||
| ## Features | ||
|
|
||
| * [Overview](docs/overview.md): Architecture, Build & Quick Start. | ||
| * C++23, zero runtime dependencies | ||
| * Delivered as an INTERFACE target `cpp_core::cpp_core` | ||
| * Fetchable via [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) or regular `find_package` | ||
| * **C++23** header-only API definitions | ||
| * **Cross-platform serial I/O API** (POSIX/Windows compatible) | ||
| * **Centralized version information** from Git tags (`cpp_core::kVersion`) | ||
| * **Status codes** enum for error handling | ||
| * **C-compatible API** for FFI bindings (Rust, Python, Deno, etc.) | ||
|
|
||
| ## Requirements | ||
|
|
||
| * CMake ≥ 3.14 | ||
| * CMake ≥ 3.30 | ||
| * A C++23 compatible compiler (GCC 13+, Clang 16+, MSVC 2022+) | ||
| * Git (for automatic version detection) | ||
|
|
||
| ## Quick Start | ||
| ## Version Information | ||
|
|
||
| 1. Add *cpp-core* with CPM.cmake (recommended way) | ||
| The version is **automatically extracted from Git tags** during CMake configuration and cannot be overridden: | ||
|
|
||
| ```cmake | ||
| # Set the project version once via **cache variables** – | ||
| # ensures the values end up in cpp-core regardless of when CPM configures. | ||
| set(CPP_CORE_VERSION_MAJOR 1 CACHE STRING "") | ||
| set(CPP_CORE_VERSION_MINOR 0 CACHE STRING "") | ||
| set(CPP_CORE_VERSION_PATCH 3 CACHE STRING "") | ||
| * **With Git tag** (e.g., `v1.2.3`): Version is `1.2.3` (or `1.2.3-dirty` if working tree has uncommitted changes) | ||
| * **Without Git tag**: Version is `0.0.0` (or `0.0.0-dirty` if working tree has uncommitted changes) | ||
|
|
||
| CPMAddPackage( | ||
| NAME cpp_core | ||
| GITHUB_REPOSITORY Serial-IO/cpp-core # Fork / Upstream | ||
| GIT_TAG main # or e.g. v0.1.0 | ||
| ) | ||
|
|
||
| add_executable(my_app src/main.cpp) | ||
| target_link_libraries(my_app PRIVATE cpp_core::cpp_core) | ||
| ``` | ||
|
|
||
| > Why cache variables? | ||
| > They guarantee the values exist **before** the `CPMAddPackage()` call. If the variables are set later (or via | ||
| > `OPTIONS ... "CPP_CORE_VERSION_MAJOR=${FOO}"`) and `FOO` is empty at that moment, *cpp-core* falls back to its default version (0.1.0). | ||
|
|
||
| 2. Use in code | ||
| All binding repositories that include this repository will use the same version information, ensuring consistency across platforms. | ||
|
|
||
| ```cpp | ||
| #include <cpp_core/version.h> | ||
| #include <cpp_core/helpers.h> | ||
|
|
||
| int main() { | ||
| constexpr auto v = cpp_core::VERSION; // {1,4,0} | ||
| } | ||
| constexpr auto v = cpp_core::kVersion; // v.major, v.minor, v.patch | ||
| ``` | ||
|
|
||
| ## Alternative: add_subdirectory | ||
| ## Usage in Binding Repositories | ||
|
|
||
| If you include the source code directly as a sub-repository, simply do: | ||
| Binding repositories typically include this repository as a dependency: | ||
|
|
||
| ```cmake | ||
| add_subdirectory(externals/cpp-core) | ||
| # the same version variables can be set before the call | ||
| CPMAddPackage( | ||
| NAME cpp_core | ||
| GITHUB_REPOSITORY Serial-IO/cpp-core | ||
| GIT_TAG v1.2.3 # Version tag determines the API version | ||
| ) | ||
|
|
||
| target_link_libraries(my_binding_library PRIVATE cpp_core::cpp_core) | ||
| ``` | ||
|
|
||
| ## Using the package with `find_package` | ||
| The binding implementation then uses the API definitions: | ||
|
|
||
| After running `cmake --install` (or `make install`) you can locate the package system-wide: | ||
| ```cpp | ||
| #include <cpp_core/serial.h> | ||
| #include <cpp_core/version.h> | ||
|
|
||
| ```cmake | ||
| find_package(cpp_core REQUIRED) | ||
| add_executable(my_app src/main.cpp) | ||
| target_link_libraries(my_app PRIVATE cpp_core::cpp_core) | ||
| // Implement platform-specific functions matching the API | ||
| intptr_t serialOpen( | ||
| void *port, | ||
| int baudrate, | ||
| int data_bits, | ||
| int parity, | ||
| int stop_bits, | ||
| ErrorCallbackT error_callback | ||
| ) { | ||
| // Platform-specific implementation (Windows/Linux/macOS) | ||
| } | ||
| ``` | ||
|
|
||
| ## License | ||
| `Apache-2.0` Check [LICENSE](https://github.com/Serial-IO/cpp-core/blob/main/LICENSE) for more details. | ||
|
|
||
| `Apache-2.0` - Check [LICENSE](LICENSE) for more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Clang Toolchain file for cpp-core | ||
| # Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/clang-toolchain.cmake .. | ||
|
|
||
| # Set the C++ compiler | ||
| set(CMAKE_CXX_COMPILER "clang++") | ||
| set(CMAKE_C_COMPILER "clang") | ||
|
|
||
| # Compiler-specific flags | ||
| set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wpedantic") | ||
| set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -O0") | ||
| set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # GCC Toolchain file for cpp-core | ||
| # Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/gcc-toolchain.cmake .. | ||
|
|
||
| # Set the C++ compiler | ||
| set(CMAKE_CXX_COMPILER "g++") | ||
| set(CMAKE_C_COMPILER "gcc") | ||
|
|
||
| # Compiler-specific flags | ||
| set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wpedantic") | ||
| set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -O0") | ||
| set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.