From 749c5faa1be922c565fcb25613aa59af16114277 Mon Sep 17 00:00:00 2001 From: Katze719 Date: Fri, 14 Nov 2025 17:51:30 +0100 Subject: [PATCH 01/12] Remove sequential interface headers and related functionality - Deleted multiple sequential interface headers to streamline the codebase and eliminate unused functionality. - Updated `cpp_core.h` to remove references to the deleted headers, enhancing organization and maintainability. These changes are part of ongoing refactoring efforts to improve header management and code clarity. --- include/cpp_core.h | 1 - include/cpp_core/interface/sequential.h | 18 ------- .../sequential/serial_abort_read_sequential.h | 26 --------- .../serial_abort_write_sequential.h | 26 --------- .../serial_clear_buffer_in_sequential.h | 28 ---------- .../serial_clear_buffer_out_sequential.h | 28 ---------- .../sequential/serial_close_sequential.h | 26 --------- .../sequential/serial_drain_sequential.h | 26 --------- .../serial_in_bytes_total_sequential.h | 26 --------- .../serial_in_bytes_waiting_sequential.h | 28 ---------- .../serial_out_bytes_total_sequential.h | 28 ---------- .../serial_out_bytes_waiting_sequential.h | 28 ---------- .../sequential/serial_read_line_sequential.h | 32 ----------- .../sequential/serial_read_sequential.h | 32 ----------- .../serial_read_until_sequence_sequential.h | 35 ------------ .../sequential/serial_read_until_sequential.h | 33 ------------ .../sequential/serial_write_sequential.h | 32 ----------- include/cpp_core/internal/sequential/call.h | 32 ----------- .../internal/sequential/dispatch_state.h | 29 ---------- .../sequential/ensure_worker_running.h | 23 -------- .../internal/sequential/execute_in_queue.h | 53 ------------------- .../internal/sequential/handle_states.h | 25 --------- .../internal/sequential/handle_states_mutex.h | 17 ------ .../internal/sequential/state_for_handle.h | 23 -------- .../internal/sequential/worker_loop.h | 34 ------------ 25 files changed, 689 deletions(-) delete mode 100644 include/cpp_core/interface/sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_abort_read_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_abort_write_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_clear_buffer_in_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_clear_buffer_out_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_close_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_drain_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_in_bytes_total_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_in_bytes_waiting_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_out_bytes_total_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_out_bytes_waiting_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_read_line_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_read_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_read_until_sequence_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_read_until_sequential.h delete mode 100644 include/cpp_core/interface/sequential/serial_write_sequential.h delete mode 100644 include/cpp_core/internal/sequential/call.h delete mode 100644 include/cpp_core/internal/sequential/dispatch_state.h delete mode 100644 include/cpp_core/internal/sequential/ensure_worker_running.h delete mode 100644 include/cpp_core/internal/sequential/execute_in_queue.h delete mode 100644 include/cpp_core/internal/sequential/handle_states.h delete mode 100644 include/cpp_core/internal/sequential/handle_states_mutex.h delete mode 100644 include/cpp_core/internal/sequential/state_for_handle.h delete mode 100644 include/cpp_core/internal/sequential/worker_loop.h diff --git a/include/cpp_core.h b/include/cpp_core.h index 59edc64..1f50732 100644 --- a/include/cpp_core.h +++ b/include/cpp_core.h @@ -13,7 +13,6 @@ */ #include "cpp_core/error_callback.h" -#include "cpp_core/interface/sequential.h" #include "cpp_core/serial.h" #include "cpp_core/status_codes.h" #include "cpp_core/version.h" diff --git a/include/cpp_core/interface/sequential.h b/include/cpp_core/interface/sequential.h deleted file mode 100644 index e4731c6..0000000 --- a/include/cpp_core/interface/sequential.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -// Sequential wrappers -#include "sequential/serial_abort_read_sequential.h" -#include "sequential/serial_abort_write_sequential.h" -#include "sequential/serial_clear_buffer_in_sequential.h" -#include "sequential/serial_clear_buffer_out_sequential.h" -#include "sequential/serial_close_sequential.h" -#include "sequential/serial_drain_sequential.h" -#include "sequential/serial_in_bytes_total_sequential.h" -#include "sequential/serial_in_bytes_waiting_sequential.h" -#include "sequential/serial_out_bytes_total_sequential.h" -#include "sequential/serial_out_bytes_waiting_sequential.h" -#include "sequential/serial_read_line_sequential.h" -#include "sequential/serial_read_sequential.h" -#include "sequential/serial_read_until_sequence_sequential.h" -#include "sequential/serial_read_until_sequential.h" -#include "sequential/serial_write_sequential.h" diff --git a/include/cpp_core/interface/sequential/serial_abort_read_sequential.h b/include/cpp_core/interface/sequential/serial_abort_read_sequential.h deleted file mode 100644 index b9dd5a1..0000000 --- a/include/cpp_core/interface/sequential/serial_abort_read_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_abort_read.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialAbortRead - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialAbortReadSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { return serialAbortRead(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_abort_write_sequential.h b/include/cpp_core/interface/sequential/serial_abort_write_sequential.h deleted file mode 100644 index c7e42cc..0000000 --- a/include/cpp_core/interface/sequential/serial_abort_write_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_abort_write.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialAbortWrite - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialAbortWriteSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { return serialAbortWrite(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_clear_buffer_in_sequential.h b/include/cpp_core/interface/sequential/serial_clear_buffer_in_sequential.h deleted file mode 100644 index 6288caa..0000000 --- a/include/cpp_core/interface/sequential/serial_clear_buffer_in_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_clear_buffer_in.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialClearBufferIn - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialClearBufferInSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialClearBufferIn(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_clear_buffer_out_sequential.h b/include/cpp_core/interface/sequential/serial_clear_buffer_out_sequential.h deleted file mode 100644 index 3d58d98..0000000 --- a/include/cpp_core/interface/sequential/serial_clear_buffer_out_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_clear_buffer_out.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialClearBufferOut - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialClearBufferOutSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialClearBufferOut(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_close_sequential.h b/include/cpp_core/interface/sequential/serial_close_sequential.h deleted file mode 100644 index 7c9aa0a..0000000 --- a/include/cpp_core/interface/sequential/serial_close_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_close.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialClose - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialCloseSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { return serialClose(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_drain_sequential.h b/include/cpp_core/interface/sequential/serial_drain_sequential.h deleted file mode 100644 index 5216b39..0000000 --- a/include/cpp_core/interface/sequential/serial_drain_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_drain.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialDrain - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialDrainSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { return serialDrain(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_in_bytes_total_sequential.h b/include/cpp_core/interface/sequential/serial_in_bytes_total_sequential.h deleted file mode 100644 index 9f40ac7..0000000 --- a/include/cpp_core/interface/sequential/serial_in_bytes_total_sequential.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_in_bytes_total.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialInBytesTotal - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialInBytesTotalSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int64_t - { - return cpp_core::internal::sequential::call(handle, [=] { return serialInBytesTotal(handle, error_callback); }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_in_bytes_waiting_sequential.h b/include/cpp_core/interface/sequential/serial_in_bytes_waiting_sequential.h deleted file mode 100644 index eb5ee6b..0000000 --- a/include/cpp_core/interface/sequential/serial_in_bytes_waiting_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_in_bytes_waiting.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialInBytesWaiting - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialInBytesWaitingSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialInBytesWaiting(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_out_bytes_total_sequential.h b/include/cpp_core/interface/sequential/serial_out_bytes_total_sequential.h deleted file mode 100644 index 6528871..0000000 --- a/include/cpp_core/interface/sequential/serial_out_bytes_total_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_out_bytes_total.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialOutBytesTotal - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialOutBytesTotalSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int64_t - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialOutBytesTotal(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_out_bytes_waiting_sequential.h b/include/cpp_core/interface/sequential/serial_out_bytes_waiting_sequential.h deleted file mode 100644 index 82abef2..0000000 --- a/include/cpp_core/interface/sequential/serial_out_bytes_waiting_sequential.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_out_bytes_waiting.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialOutBytesWaiting - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialOutBytesWaitingSequential( - int64_t handle, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialOutBytesWaiting(handle, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_read_line_sequential.h b/include/cpp_core/interface/sequential/serial_read_line_sequential.h deleted file mode 100644 index dae9685..0000000 --- a/include/cpp_core/interface/sequential/serial_read_line_sequential.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_read_line.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialReadLine - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialReadLineSequential( - int64_t handle, - void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialReadLine(handle, buffer, buffer_size, timeout_ms, multiplier, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_read_sequential.h b/include/cpp_core/interface/sequential/serial_read_sequential.h deleted file mode 100644 index 88ca226..0000000 --- a/include/cpp_core/interface/sequential/serial_read_sequential.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_read.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialRead - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialReadSequential( - int64_t handle, - void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialRead(handle, buffer, buffer_size, timeout_ms, multiplier, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_read_until_sequence_sequential.h b/include/cpp_core/interface/sequential/serial_read_until_sequence_sequential.h deleted file mode 100644 index cdcc6d4..0000000 --- a/include/cpp_core/interface/sequential/serial_read_until_sequence_sequential.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_read_until_sequence.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialReadUntilSequence - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialReadUntilSequenceSequential( - int64_t handle, - void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - void *sequence, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialReadUntilSequence( - handle, buffer, buffer_size, timeout_ms, multiplier, sequence, error_callback - ); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_read_until_sequential.h b/include/cpp_core/interface/sequential/serial_read_until_sequential.h deleted file mode 100644 index 1b1780f..0000000 --- a/include/cpp_core/interface/sequential/serial_read_until_sequential.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_read_until.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialReadUntil - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialReadUntilSequential( - int64_t handle, - void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - void *until_char, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialReadUntil(handle, buffer, buffer_size, timeout_ms, multiplier, until_char, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/interface/sequential/serial_write_sequential.h b/include/cpp_core/interface/sequential/serial_write_sequential.h deleted file mode 100644 index be82826..0000000 --- a/include/cpp_core/interface/sequential/serial_write_sequential.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "../../error_callback.h" -#include "../../internal/sequential/call.h" -#include "../serial_write.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * @copydoc serialWrite - * @note Sequential variant: guarantees execution in the exact order the calls were made across threads. - */ - inline MODULE_API auto serialWriteSequential( - int64_t handle, - const void *buffer, - int buffer_size, - int timeout_ms, - int multiplier, - ErrorCallbackT error_callback = nullptr - ) -> int - { - return cpp_core::internal::sequential::call(handle, [=] { - return serialWrite(handle, buffer, buffer_size, timeout_ms, multiplier, error_callback); - }); - } - -#ifdef __cplusplus -} -#endif diff --git a/include/cpp_core/internal/sequential/call.h b/include/cpp_core/internal/sequential/call.h deleted file mode 100644 index 3404f58..0000000 --- a/include/cpp_core/internal/sequential/call.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "execute_in_queue.h" -#include "state_for_handle.h" -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Executes the given callable in the sequential dispatch queue associated with the specified handle. - * - * This helper forwards the callable to executeInQueue() together with the - * DispatchState that belongs to @p handle, thereby ensuring that all calls - * targeting the same handle are processed strictly sequentially. - * - * @tparam FunctionT Type of the invocable object. - * @param handle Handle identifying the sequential queue. - * @param function Callable object to execute. Can return any type (including void). - * @return Whatever @p function returns. - */ -template -auto call( - int64_t handle, - FunctionT &&function -) -> decltype(function()) -{ - return executeInQueue( - ::cpp_core::internal::sequential::internal::stateForHandle(handle), std::forward(function) - ); -} -} // namespace cpp_core::internal::sequential diff --git a/include/cpp_core/internal/sequential/dispatch_state.h b/include/cpp_core/internal/sequential/dispatch_state.h deleted file mode 100644 index 0436427..0000000 --- a/include/cpp_core/internal/sequential/dispatch_state.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Holds the queue and synchronisation primitives used by the sequential dispatch system. - */ -struct DispatchState -{ - // Mutex protecting queue + condition_variable. - std::mutex mutex; - - // Condition variable to wake the worker thread when new jobs arrive. - std::condition_variable condition_variable; - - // FIFO containing packaged thunks (jobs). - std::queue> queue; - - // Indicates if the worker thread is already launched. - std::once_flag worker_started; -}; -} // namespace cpp_core::internal::sequential diff --git a/include/cpp_core/internal/sequential/ensure_worker_running.h b/include/cpp_core/internal/sequential/ensure_worker_running.h deleted file mode 100644 index d82aea7..0000000 --- a/include/cpp_core/internal/sequential/ensure_worker_running.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "dispatch_state.h" -#include "worker_loop.h" -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Starts the worker thread for @p state if it is not already running. - * - * The worker thread executes workerLoop() on the given DispatchState. A - * call_once flag inside the state guarantees that the thread is only created - * the first time this function is invoked. - * - * @param state DispatchState whose queue should be processed by the worker. - */ -inline void ensureWorkerRunning(DispatchState &state) -{ - std::call_once(state.worker_started, [&state] { std::thread([&state] { workerLoop(state); }).detach(); }); -} -} // namespace cpp_core::internal::sequential diff --git a/include/cpp_core/internal/sequential/execute_in_queue.h b/include/cpp_core/internal/sequential/execute_in_queue.h deleted file mode 100644 index 19e9a03..0000000 --- a/include/cpp_core/internal/sequential/execute_in_queue.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include "dispatch_state.h" -#include "ensure_worker_running.h" -#include -#include -#include -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Queues the given callable in @p state and returns its result. - * - * The function first makes sure a worker thread is active via - * ensureWorkerRunning(). It then enqueues the callable and blocks until the - * callable has completed, forwarding the return value (if any). - * - * @tparam FunctionT Type of the callable object. - * @param state DispatchState that owns the queue and synchronisation primitives. - * @param function Callable object to execute. Can return any type. - * @return Result produced by @p function or void if it returns void. - */ -template -auto executeInQueue( - DispatchState &state, - FunctionT &&function -) -> decltype(function()) -{ - using FunctionReturnT = decltype(function()); - - auto task_ptr = std::make_shared>(std::forward(function)); - auto future = task_ptr->get_future(); - - ensureWorkerRunning(state); - - { - std::lock_guard lock(state.mutex); - state.queue.emplace([task_ptr]() { (*task_ptr)(); }); - } - state.condition_variable.notify_one(); - - if constexpr (std::is_void_v) - { - future.get(); - } - else - { - return future.get(); - } -} -} // namespace cpp_core::internal::sequential diff --git a/include/cpp_core/internal/sequential/handle_states.h b/include/cpp_core/internal/sequential/handle_states.h deleted file mode 100644 index 0741a4e..0000000 --- a/include/cpp_core/internal/sequential/handle_states.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "dispatch_state.h" -#include -#include -#include - -namespace cpp_core::internal::sequential::internal -{ -/** - * @brief Gives access to the global handle -> DispatchState map. - * - * The map is lazily initialised on first access and is intended to be - * protected by handleStatesMutex(). - * - * @return Reference to the singleton unordered_map storing all DispatchStates. - */ -inline auto handleStates() -> std::unordered_map< - int64_t, - cpp_core::internal::sequential::DispatchState> & -{ - static std::unordered_map instance; - return instance; -} -} // namespace cpp_core::internal::sequential::internal diff --git a/include/cpp_core/internal/sequential/handle_states_mutex.h b/include/cpp_core/internal/sequential/handle_states_mutex.h deleted file mode 100644 index 5d2b6a8..0000000 --- a/include/cpp_core/internal/sequential/handle_states_mutex.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include - -namespace cpp_core::internal::sequential::internal -{ -/** - * @brief Returns the mutex guarding access to handleStates(). - * - * @return Reference to the singleton std::mutex. - */ -inline auto handleStatesMutex() -> std::mutex & -{ - static std::mutex instance; - return instance; -} -} // namespace cpp_core::internal::sequential::internal diff --git a/include/cpp_core/internal/sequential/state_for_handle.h b/include/cpp_core/internal/sequential/state_for_handle.h deleted file mode 100644 index c0e62cb..0000000 --- a/include/cpp_core/internal/sequential/state_for_handle.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "handle_states.h" -#include "handle_states_mutex.h" -#include -#include - -namespace cpp_core::internal::sequential::internal -{ -/** - * @brief Retrieves the DispatchState associated with the specified handle. - * - * The global map is protected by a mutex to make this operation thread-safe. - * - * @param handle Identifier of the sequential dispatch queue. - * @return Reference to the corresponding DispatchState object. - */ -inline auto stateForHandle(int64_t handle) -> cpp_core::internal::sequential::DispatchState & -{ - std::lock_guard lock(handleStatesMutex()); - return handleStates()[handle]; -} -} // namespace cpp_core::internal::sequential::internal diff --git a/include/cpp_core/internal/sequential/worker_loop.h b/include/cpp_core/internal/sequential/worker_loop.h deleted file mode 100644 index 6961ae6..0000000 --- a/include/cpp_core/internal/sequential/worker_loop.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "dispatch_state.h" -#include -#include -#include -#include - -namespace cpp_core::internal::sequential -{ -/** - * @brief Blocking loop that continuously processes jobs from @p state. - * - * Intended to run on a background thread created by ensureWorkerRunning(). - * The loop waits on a condition variable until a job is available, executes - * it and then repeats indefinitely. - * - * @param state DispatchState providing the job queue and synchronisation primitives. - */ -inline void workerLoop(DispatchState &state) -{ - for (;;) - { - std::function job; - { - std::unique_lock lock(state.mutex); - state.condition_variable.wait(lock, [&state] { return !state.queue.empty(); }); - job = std::move(state.queue.front()); - state.queue.pop(); - } - job(); - } -} -} // namespace cpp_core::internal::sequential From 4274258f8827c46beba4812babc823f3e68353f1 Mon Sep 17 00:00:00 2001 From: Katze719 Date: Fri, 14 Nov 2025 18:00:56 +0100 Subject: [PATCH 02/12] Add CMake presets and toolchain files for GCC, Clang, and MSVC - Introduced `CMakePresets.json` to define build configurations for GCC, Clang, and MSVC compilers. - Added toolchain files for GCC (`gcc-toolchain.cmake`), Clang (`clang-toolchain.cmake`), and MSVC (`msvc-toolchain.cmake`) to specify compiler settings and flags. - Each toolchain file sets the C++ standard to C++23 and includes appropriate compiler flags for different build types (Debug and Release). These additions enhance the build system's flexibility and support for multiple compilers, facilitating easier project setup and configuration. --- CMakePresets.json | 82 +++++++++++++++++++++++++++++++++++++ cmake/clang-toolchain.cmake | 23 +++++++++++ cmake/gcc-toolchain.cmake | 22 ++++++++++ cmake/msvc-toolchain.cmake | 31 ++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 CMakePresets.json create mode 100644 cmake/clang-toolchain.cmake create mode 100644 cmake/gcc-toolchain.cmake create mode 100644 cmake/msvc-toolchain.cmake diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..59df3b2 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,82 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 14, + "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++-21)", + "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" + } + ] +} diff --git a/cmake/clang-toolchain.cmake b/cmake/clang-toolchain.cmake new file mode 100644 index 0000000..4cfb6be --- /dev/null +++ b/cmake/clang-toolchain.cmake @@ -0,0 +1,23 @@ +# Clang Toolchain file for cpp-core +# Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/clang-toolchain.cmake .. + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) + +# Set the C++ compiler +set(CMAKE_CXX_COMPILER "clang++-21") +set(CMAKE_C_COMPILER "clang-21") + +# Set C++ standard +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# 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") + +# Enable C++23 features +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23") + diff --git a/cmake/gcc-toolchain.cmake b/cmake/gcc-toolchain.cmake new file mode 100644 index 0000000..547450f --- /dev/null +++ b/cmake/gcc-toolchain.cmake @@ -0,0 +1,22 @@ +# GCC Toolchain file for cpp-core +# Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/gcc-toolchain.cmake .. + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) + +# Set the C++ compiler +set(CMAKE_CXX_COMPILER "g++") +set(CMAKE_C_COMPILER "gcc") + +# Set C++ standard +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# 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") + +# Enable C++23 features +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23") diff --git a/cmake/msvc-toolchain.cmake b/cmake/msvc-toolchain.cmake new file mode 100644 index 0000000..6cf4b2f --- /dev/null +++ b/cmake/msvc-toolchain.cmake @@ -0,0 +1,31 @@ +# MSVC Toolchain file for cpp-core +# Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/msvc-toolchain.cmake .. + +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) + +# Set the C++ compiler +set(CMAKE_CXX_COMPILER "cl") +set(CMAKE_C_COMPILER "cl") + +# Set C++ standard +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# MSVC-specific flags +# /W4 = Enable all warnings +# /WX = Treat warnings as errors (optional, comment out if not desired) +# /permissive- = Conformance mode +# /Zc:__cplusplus = Enable updated __cplusplus macro +# /std:c++latest = Use latest C++ standard (C++23) +set(CMAKE_CXX_FLAGS_INIT "/W4 /permissive- /Zc:__cplusplus /std:c++latest") +set(CMAKE_CXX_FLAGS_DEBUG_INIT "/Zi /Od /MDd") +set(CMAKE_CXX_FLAGS_RELEASE_INIT "/O2 /DNDEBUG /MD") + +# MSVC-specific definitions +add_definitions(-D_CRT_SECURE_NO_WARNINGS) + +# Optional: Set specific MSVC toolset version if needed +# set(CMAKE_GENERATOR_TOOLSET "v143") + From b45a036e8ce27901cd0bde03fb9a9a6b225a874a Mon Sep 17 00:00:00 2001 From: Katze719 Date: Fri, 14 Nov 2025 21:34:57 +0100 Subject: [PATCH 03/12] Update CMake configuration and add module support - Increased minimum CMake version requirement to 3.30. - Enabled export of compile commands and added support for C++23 modules in CMake configuration. - Introduced a new static library `hello_module` with a simple module implementation and a corresponding test executable. - Updated `.gitignore` to include `compile_commands.json` for better build management. These changes enhance the build system's capabilities and introduce modular programming support. --- .gitignore | 2 +- CMakeLists.txt | 27 ++++++++++++++++++++++++++- CMakePresets.json | 2 +- cmake/clang-toolchain.cmake | 5 +++-- cmake/gcc-toolchain.cmake | 5 +++-- cmake/msvc-toolchain.cmake | 9 ++++----- test/hello.cxx | 9 +++++++++ test/main.cpp | 8 ++++++++ 8 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 test/hello.cxx create mode 100644 test/main.cpp diff --git a/.gitignore b/.gitignore index 8d5694f..7afadea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ include/cpp_core/version.h build/ .cache/ - +compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fabd8e..133c553 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,13 @@ -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 # --------------------------------------------------------------------------- @@ -31,6 +34,10 @@ target_include_directories(cpp_core INTERFACE # 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) + # Install rules -------------------------------------------------------------- include(GNUInstallDirs) @@ -62,3 +69,21 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) + +# Module test ---------------------------------------------------------------- +add_library(hello_module STATIC) +target_sources(hello_module + PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES + FILES test/hello.cxx +) + +add_executable(module_test test/main.cpp) +target_link_libraries(module_test PRIVATE hello_module) + +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" +) diff --git a/CMakePresets.json b/CMakePresets.json index 59df3b2..fcb239b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,7 +2,7 @@ "version": 3, "cmakeMinimumRequired": { "major": 3, - "minor": 14, + "minor": 30, "patch": 0 }, "configurePresets": [ diff --git a/cmake/clang-toolchain.cmake b/cmake/clang-toolchain.cmake index 4cfb6be..cb93cd3 100644 --- a/cmake/clang-toolchain.cmake +++ b/cmake/clang-toolchain.cmake @@ -18,6 +18,7 @@ set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wpedantic") set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -O0") set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") -# Enable C++23 features -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23") +# Enable C++23 module support +set(CMAKE_CXX_MODULE_STD 23) +set(CMAKE_CXX_MODULE_EXTENSIONS OFF) diff --git a/cmake/gcc-toolchain.cmake b/cmake/gcc-toolchain.cmake index 547450f..ece38c1 100644 --- a/cmake/gcc-toolchain.cmake +++ b/cmake/gcc-toolchain.cmake @@ -18,5 +18,6 @@ set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wpedantic") set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -O0") set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") -# Enable C++23 features -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23") +# Enable C++23 module support +set(CMAKE_CXX_MODULE_STD 23) +set(CMAKE_CXX_MODULE_EXTENSIONS OFF) diff --git a/cmake/msvc-toolchain.cmake b/cmake/msvc-toolchain.cmake index 6cf4b2f..4492b26 100644 --- a/cmake/msvc-toolchain.cmake +++ b/cmake/msvc-toolchain.cmake @@ -13,9 +13,12 @@ set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +# Enable C++23 module support +set(CMAKE_CXX_MODULE_STD 23) +set(CMAKE_CXX_MODULE_EXTENSIONS OFF) + # MSVC-specific flags # /W4 = Enable all warnings -# /WX = Treat warnings as errors (optional, comment out if not desired) # /permissive- = Conformance mode # /Zc:__cplusplus = Enable updated __cplusplus macro # /std:c++latest = Use latest C++ standard (C++23) @@ -25,7 +28,3 @@ set(CMAKE_CXX_FLAGS_RELEASE_INIT "/O2 /DNDEBUG /MD") # MSVC-specific definitions add_definitions(-D_CRT_SECURE_NO_WARNINGS) - -# Optional: Set specific MSVC toolset version if needed -# set(CMAKE_GENERATOR_TOOLSET "v143") - diff --git a/test/hello.cxx b/test/hello.cxx new file mode 100644 index 0000000..09ce60d --- /dev/null +++ b/test/hello.cxx @@ -0,0 +1,9 @@ +export module hello; + +export int add( + int a, + int b +) +{ + return a + b; +} diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..177877e --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,8 @@ +import hello; +#include + +int main() +{ + std::cout << "2 + 3 = " << add(2, 3) << std::endl; + return 0; +} From 54a1058d407a092928a21df5df1973431321341a Mon Sep 17 00:00:00 2001 From: Katze719 Date: Fri, 14 Nov 2025 21:37:40 +0100 Subject: [PATCH 04/12] Remove unnecessary processor setting from toolchain files - Deleted the line setting CMAKE_SYSTEM_PROCESSOR in the GCC, Clang, and MSVC toolchain files to simplify configuration. - This change streamlines the toolchain setup without affecting the build process. These modifications enhance the clarity and maintainability of the CMake configuration. --- cmake/clang-toolchain.cmake | 1 - cmake/gcc-toolchain.cmake | 1 - cmake/msvc-toolchain.cmake | 1 - 3 files changed, 3 deletions(-) diff --git a/cmake/clang-toolchain.cmake b/cmake/clang-toolchain.cmake index cb93cd3..2e47d7c 100644 --- a/cmake/clang-toolchain.cmake +++ b/cmake/clang-toolchain.cmake @@ -2,7 +2,6 @@ # Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/clang-toolchain.cmake .. set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) # Set the C++ compiler set(CMAKE_CXX_COMPILER "clang++-21") diff --git a/cmake/gcc-toolchain.cmake b/cmake/gcc-toolchain.cmake index ece38c1..321a3bb 100644 --- a/cmake/gcc-toolchain.cmake +++ b/cmake/gcc-toolchain.cmake @@ -2,7 +2,6 @@ # Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/gcc-toolchain.cmake .. set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) # Set the C++ compiler set(CMAKE_CXX_COMPILER "g++") diff --git a/cmake/msvc-toolchain.cmake b/cmake/msvc-toolchain.cmake index 4492b26..4d5ea77 100644 --- a/cmake/msvc-toolchain.cmake +++ b/cmake/msvc-toolchain.cmake @@ -2,7 +2,6 @@ # Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/msvc-toolchain.cmake .. set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) # Set the C++ compiler set(CMAKE_CXX_COMPILER "cl") From 9ef458355055324510066e5e9a716de81008a506 Mon Sep 17 00:00:00 2001 From: Katze719 Date: Fri, 28 Nov 2025 15:09:33 +0100 Subject: [PATCH 05/12] Refactor CMake configuration to automate versioning and enhance toolchain files - Introduced a new script `get_version_from_git.cmake` to automatically determine versioning from Git tags, replacing manual version settings. - Updated `CMakeLists.txt` to utilize the new versioning system and removed redundant version definitions. - Simplified toolchain files for GCC, Clang, and MSVC by removing unnecessary settings and ensuring consistent C++ standard enforcement. - Updated `cpp_core_config.cmake.in` to set version variables for parent projects. These changes improve the maintainability and clarity of the CMake configuration while ensuring accurate versioning based on Git history. --- CMakeLists.txt | 82 ++++++++++++++++--------------- CMakePresets.json | 2 +- cmake/clang-toolchain.cmake | 15 +----- cmake/cpp_core_config.cmake.in | 6 +++ cmake/gcc-toolchain.cmake | 11 ----- cmake/get_version_from_git.cmake | 83 ++++++++++++++++++++++++++++++++ cmake/msvc-toolchain.cmake | 11 ----- include/cpp_core/version.h.in | 9 ++-- test/hello.cxx | 9 ---- test/main.cpp | 8 --- 10 files changed, 140 insertions(+), 96 deletions(-) create mode 100644 cmake/get_version_from_git.cmake delete mode 100644 test/hello.cxx delete mode 100644 test/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 133c553..830d008 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,26 +1,33 @@ 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) @@ -28,8 +35,13 @@ add_library(cpp_core::cpp_core ALIAS cpp_core) # Public include directories target_include_directories(cpp_core INTERFACE - $ - $) + $ + $) + +# Set C++ standard +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) # Require C++23 target_compile_features(cpp_core INTERFACE cxx_std_23) @@ -42,43 +54,33 @@ set(CMAKE_CXX_MODULE_EXTENSIONS OFF) include(GNUInstallDirs) install(TARGETS cpp_core - EXPORT cpp_coreTargets) + EXPORT cpp_coreTargets) install(DIRECTORY include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + 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) + FILE cpp_coreTargets.cmake + NAMESPACE cpp_core:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) - -# Module test ---------------------------------------------------------------- -add_library(hello_module STATIC) -target_sources(hello_module - PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES - FILES test/hello.cxx -) - -add_executable(module_test test/main.cpp) -target_link_libraries(module_test PRIVATE hello_module) + ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) add_custom_target(copy-compile-commands ALL ${CMAKE_COMMAND} -E copy_if_different diff --git a/CMakePresets.json b/CMakePresets.json index fcb239b..0c9fa5c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -19,7 +19,7 @@ }, { "name": "clang", - "displayName": "Clang (clang++-21)", + "displayName": "Clang (clang++)", "description": "Build using Clang compiler", "generator": "Ninja", "binaryDir": "${sourceDir}/build/clang", diff --git a/cmake/clang-toolchain.cmake b/cmake/clang-toolchain.cmake index 2e47d7c..72d8016 100644 --- a/cmake/clang-toolchain.cmake +++ b/cmake/clang-toolchain.cmake @@ -1,23 +1,12 @@ # Clang Toolchain file for cpp-core # Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/clang-toolchain.cmake .. -set(CMAKE_SYSTEM_NAME Generic) - # Set the C++ compiler -set(CMAKE_CXX_COMPILER "clang++-21") -set(CMAKE_C_COMPILER "clang-21") - -# Set C++ standard -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) +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") -# Enable C++23 module support -set(CMAKE_CXX_MODULE_STD 23) -set(CMAKE_CXX_MODULE_EXTENSIONS OFF) - diff --git a/cmake/cpp_core_config.cmake.in b/cmake/cpp_core_config.cmake.in index 65434e4..be99792 100644 --- a/cmake/cpp_core_config.cmake.in +++ b/cmake/cpp_core_config.cmake.in @@ -2,4 +2,10 @@ include("${CMAKE_CURRENT_LIST_DIR}/cpp_coreTargets.cmake") +# Set version variables for parent projects +set(CPP_CORE_VERSION_MAJOR @CPP_CORE_VERSION_MAJOR@) +set(CPP_CORE_VERSION_MINOR @CPP_CORE_VERSION_MINOR@) +set(CPP_CORE_VERSION_PATCH @CPP_CORE_VERSION_PATCH@) +set(CPP_CORE_VERSION_STRING "@CPP_CORE_VERSION_STRING@") + check_required_components(cpp_core) diff --git a/cmake/gcc-toolchain.cmake b/cmake/gcc-toolchain.cmake index 321a3bb..6f16511 100644 --- a/cmake/gcc-toolchain.cmake +++ b/cmake/gcc-toolchain.cmake @@ -1,22 +1,11 @@ # GCC Toolchain file for cpp-core # Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/gcc-toolchain.cmake .. -set(CMAKE_SYSTEM_NAME Generic) - # Set the C++ compiler set(CMAKE_CXX_COMPILER "g++") set(CMAKE_C_COMPILER "gcc") -# Set C++ standard -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - # 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") - -# Enable C++23 module support -set(CMAKE_CXX_MODULE_STD 23) -set(CMAKE_CXX_MODULE_EXTENSIONS OFF) diff --git a/cmake/get_version_from_git.cmake b/cmake/get_version_from_git.cmake new file mode 100644 index 0000000..7ef96ba --- /dev/null +++ b/cmake/get_version_from_git.cmake @@ -0,0 +1,83 @@ +# Function to get version from Git tags +# If a tag exists (e.g., v1.2.3 or 1.2.3), use it (with -dirty suffix if working tree is dirty) +# If no tag exists, use 0.0.0 (with -dirty suffix if working tree is dirty) + +function(get_version_from_git) + # Check if we're in a git repository + find_package(Git QUIET) + if(NOT Git_FOUND) + set(VERSION_MAJOR 0 PARENT_SCOPE) + set(VERSION_MINOR 0 PARENT_SCOPE) + set(VERSION_PATCH 0 PARENT_SCOPE) + set(VERSION_STRING "0.0.0-dev-no-git" PARENT_SCOPE) + return() + endif() + + # Get the latest tag + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + + # Check if working tree is dirty + execute_process( + COMMAND ${GIT_EXECUTABLE} diff --quiet --exit-code + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_DIRTY_RESULT + ERROR_QUIET + ) + + # Get short commit hash + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + + if(GIT_TAG) + # Extract version from tag (remove 'v' prefix if present) + string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_TAG}") + string(REGEX REPLACE "^v?[0-9]+\\.([0-9]+)\\..*" "\\1" VERSION_MINOR "${GIT_TAG}") + string(REGEX REPLACE "^v?[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_TAG}") + + # If regex didn't match, try simpler pattern + if(NOT VERSION_MAJOR MATCHES "^[0-9]+$") + string(REGEX REPLACE "^v?([0-9]+)" "\\1" VERSION_MAJOR "${GIT_TAG}") + endif() + if(NOT VERSION_MINOR MATCHES "^[0-9]+$") + set(VERSION_MINOR "0") + endif() + if(NOT VERSION_PATCH MATCHES "^[0-9]+$") + set(VERSION_PATCH "0") + endif() + + # Check if dirty - if dirty, mark the version with -dirty suffix + if(GIT_DIRTY_RESULT) + set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-dirty") + else() + set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") + endif() + else() + # No tag found, use 0.0.0 (with -dirty if dirty) + set(VERSION_MAJOR "0") + set(VERSION_MINOR "0") + set(VERSION_PATCH "0") + if(GIT_DIRTY_RESULT) + set(VERSION_STRING "0.0.0-dirty") + else() + set(VERSION_STRING "0.0.0") + endif() + endif() + + # Return values to parent scope + set(VERSION_MAJOR ${VERSION_MAJOR} PARENT_SCOPE) + set(VERSION_MINOR ${VERSION_MINOR} PARENT_SCOPE) + set(VERSION_PATCH ${VERSION_PATCH} PARENT_SCOPE) + set(VERSION_STRING ${VERSION_STRING} PARENT_SCOPE) +endfunction() + diff --git a/cmake/msvc-toolchain.cmake b/cmake/msvc-toolchain.cmake index 4d5ea77..fe07716 100644 --- a/cmake/msvc-toolchain.cmake +++ b/cmake/msvc-toolchain.cmake @@ -1,21 +1,10 @@ # MSVC Toolchain file for cpp-core # Usage: cmake -DCMAKE_TOOLCHAIN_FILE=cmake/msvc-toolchain.cmake .. -set(CMAKE_SYSTEM_NAME Windows) - # Set the C++ compiler set(CMAKE_CXX_COMPILER "cl") set(CMAKE_C_COMPILER "cl") -# Set C++ standard -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -# Enable C++23 module support -set(CMAKE_CXX_MODULE_STD 23) -set(CMAKE_CXX_MODULE_EXTENSIONS OFF) - # MSVC-specific flags # /W4 = Enable all warnings # /permissive- = Conformance mode diff --git a/include/cpp_core/version.h.in b/include/cpp_core/version.h.in index 4b398fc..ac76ee0 100644 --- a/include/cpp_core/version.h.in +++ b/include/cpp_core/version.h.in @@ -10,8 +10,11 @@ struct Version unsigned int patch; }; -// Generated at configure time. Parent project can override the numbers via -// -DCPP_CORE_VERSION_XXX=... or CPM OPTIONS -inline constexpr Version kVersion{@CPP_CORE_VERSION_MAJOR@U, @CPP_CORE_VERSION_MINOR@U, @CPP_CORE_VERSION_PATCH@U}; +// Generated at configure time from Git tags (or dirty build version if no tag). +// Version is determined automatically from Git tags and cannot be overridden. +inline constexpr Version kVersion +{ + @CPP_CORE_VERSION_MAJOR@U, @CPP_CORE_VERSION_MINOR@U, @CPP_CORE_VERSION_PATCH@U +}; } // namespace cpp_core diff --git a/test/hello.cxx b/test/hello.cxx deleted file mode 100644 index 09ce60d..0000000 --- a/test/hello.cxx +++ /dev/null @@ -1,9 +0,0 @@ -export module hello; - -export int add( - int a, - int b -) -{ - return a + b; -} diff --git a/test/main.cpp b/test/main.cpp deleted file mode 100644 index 177877e..0000000 --- a/test/main.cpp +++ /dev/null @@ -1,8 +0,0 @@ -import hello; -#include - -int main() -{ - std::cout << "2 + 3 = " << add(2, 3) << std::endl; - return 0; -} From e34925fc5cf1dde07eba737afda5ca3aa5d91786 Mon Sep 17 00:00:00 2001 From: Katze719 Date: Fri, 28 Nov 2025 15:22:06 +0100 Subject: [PATCH 06/12] Revise README.md for clarity and detail on library features - Updated the description to reflect the library's purpose as a header-only API definition for cross-platform serial communication. - Enhanced the features section to highlight key functionalities, including C++23 compatibility and centralized version information. - Improved instructions for obtaining platform-specific bindings and clarified versioning details. - Removed the outdated overview documentation file to streamline the repository. These changes aim to provide clearer guidance and improve the overall presentation of the library's capabilities. --- README.md | 90 ++++++++++++++++-------------------- docs/overview.md | 117 ----------------------------------------------- 2 files changed, 39 insertions(+), 168 deletions(-) delete mode 100644 docs/overview.md diff --git a/README.md b/README.md index 067d997..9d45f7e 100644 --- a/README.md +++ b/README.md @@ -1,81 +1,69 @@ # 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 -#include -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 +#include -```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. diff --git a/docs/overview.md b/docs/overview.md deleted file mode 100644 index d69985c..0000000 --- a/docs/overview.md +++ /dev/null @@ -1,117 +0,0 @@ -# cpp-core – Library Overview - -Welcome to **cpp-core**, a header-only, cross-platform C++23 helper library that bundles utilities frequently needed in systems programming and embedded scenarios. Besides multiple compile-time helpers it exposes a fully-featured **C API for serial communication**, making the library consumable from virtually any language (Rust, Python, Deno, …). - -> ⚠️ **Looking for a ready-to-use shared library?** Build one of the platform bindings instead of cpp-core itself: -> • Windows → [cpp-bindings-windows](https://github.com/Serial-IO/cpp-bindings-windows) -> • Linux → [cpp-bindings-linux](https://github.com/Serial-IO/cpp-bindings-linux) - -> Looking for the raw function list? See the [C API reference](api_reference.md). -> -> Want to call the library from TypeScript? Jump straight to the [Deno FFI guide](deno_ffi.md). - ---- - -## What ships with cpp-core? - -| Area | Header | Highlights | -|------|--------|------------| -| Versioning | `cpp_core/version.h` | Compile-time `constexpr` version struct, filled during the build. -| Helpers | `cpp_core/helpers.h` | Collection of lightweight, header-only helper templates. -| Serial I/O | `cpp_core/serial.h` | Cross-platform serial helper built on the POSIX/Win32 APIs (see [C API reference](api_reference.md)). -| Error Codes| `cpp_core/status_codes.h` | Unified negative error codes shared across languages and bindings. - -All headers live in the `include/` tree and are directly usable after installation. - ---- - -## Directory structure - -``` -cpp-core/ -├── cmake/ # CMake helper modules -├── docs/ # You are here 📚 -├── include/ -│ └── cpp_core/ # Public headers (header-only!) -└── test/ # Unit tests (if enabled) -``` - ---- - -## Building the library - -### 1. Fetch & configure - -```bash -# clone -$ git clone https://github.com/Serial-IO/cpp-core.git -$ cd cpp-core - -# create an out-of-tree build directory -$ cmake -B build -DCMAKE_BUILD_TYPE=Release -``` - -### 2. Build & install (header-only) - -```bash -$ cmake --build build --target install -``` - -`install` copies the headers (and *optionally* a shared library, see below) to your default prefix (`/usr/local`, `Program Files/`, …). - -### 3. Building a shared library for FFI consumers - -Deno, Python and other FFI users expect a shared library (`*.so`, `*.dll`, `*.dylib`). Enable it like so: - -```bash -# add the switch – all code remains header-only for C++ callers -$ cmake -B build-shared -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -$ cmake --build build-shared --config Release - -# resulting artifact (Linux) -$ ls build-shared -libcpp_core.so # rename or copy as needed, e.g. to libserial.so -``` - -> **Tip**: keep the header files close to your FFI project so you can re-generate bindings easily. - ---- - -## Minimal C example - -```c -#include -#include - -int main() { - intptr_t h = serialOpen("/dev/ttyUSB0", 115200, 8, 0, 0); - if (h <= 0) { - fprintf(stderr, "open failed: %ld\n", (long)h); - return 1; - } - - const char msg[] = "hello\n"; - serialWriteLine(h, msg, sizeof msg - 1, 1000); - - char buf[64]; - int n = serialReadLine(h, buf, sizeof buf, 1000); - fwrite(buf, 1, n, stdout); - - serialClose(h); -} -``` - -For a deep dive into every parameter head over to the [C API reference](api_reference.md). - ---- - -## Going further - -* **Deno, Node, Python & Rust**: see the dedicated [Deno FFI guide](deno_ffi.md) which includes a complete TypeScript example and hints for other languages. -* **Questions / issues** – open a ticket on GitHub; contributions are welcome! - ---- - -## License - -cpp-core is licensed under the terms of the Apache-2.0 license. See [LICENSE](../LICENSE) for details. From c3881821da25e7bb34437f6ea0af255b7b3080ee Mon Sep 17 00:00:00 2001 From: Katze719 Date: Fri, 28 Nov 2025 15:26:28 +0100 Subject: [PATCH 07/12] Add serial port enumeration functionality - Introduced a new header file `serial_list_ports.h` to provide a function for enumerating available serial ports on the system. - Updated `serial.h` to include the new `serial_list_ports.h` header, enhancing the library's capabilities for serial communication. These changes expand the API to facilitate easier access to serial port information. --- .../interface/{serial_get_ports_info.h => serial_list_ports.h} | 2 +- include/cpp_core/serial.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename include/cpp_core/interface/{serial_get_ports_info.h => serial_list_ports.h} (96%) diff --git a/include/cpp_core/interface/serial_get_ports_info.h b/include/cpp_core/interface/serial_list_ports.h similarity index 96% rename from include/cpp_core/interface/serial_get_ports_info.h rename to include/cpp_core/interface/serial_list_ports.h index 665f981..0a5d34a 100644 --- a/include/cpp_core/interface/serial_get_ports_info.h +++ b/include/cpp_core/interface/serial_list_ports.h @@ -17,7 +17,7 @@ extern "C" * @param error_callback [optional] Callback to invoke on error. Defined in error_callback.h. Default is `nullptr`. * @return Number of ports found or a negative error code from ::cpp_core::StatusCodes on error. */ - MODULE_API auto serialGetPortsInfo( + MODULE_API auto serialListPorts( void (*callback_fn)( const char *port, const char *path, diff --git a/include/cpp_core/serial.h b/include/cpp_core/serial.h index e7e142a..c8bc160 100644 --- a/include/cpp_core/serial.h +++ b/include/cpp_core/serial.h @@ -11,9 +11,9 @@ #include "interface/serial_clear_buffer_out.h" #include "interface/serial_close.h" #include "interface/serial_drain.h" -#include "interface/serial_get_ports_info.h" #include "interface/serial_in_bytes_total.h" #include "interface/serial_in_bytes_waiting.h" +#include "interface/serial_list_ports.h" #include "interface/serial_open.h" #include "interface/serial_out_bytes_total.h" #include "interface/serial_out_bytes_waiting.h" From d3ae8b42712e3f2c47c105bdfa74dce8b2da7d4b Mon Sep 17 00:00:00 2001 From: Katze719 <38188106+Katze719@users.noreply.github.com> Date: Fri, 28 Nov 2025 15:33:17 +0100 Subject: [PATCH 08/12] Update cmake/get_version_from_git.cmake Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cmake/get_version_from_git.cmake | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cmake/get_version_from_git.cmake b/cmake/get_version_from_git.cmake index 7ef96ba..5a71921 100644 --- a/cmake/get_version_from_git.cmake +++ b/cmake/get_version_from_git.cmake @@ -31,13 +31,6 @@ function(get_version_from_git) ) # Get short commit hash - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET - ) if(GIT_TAG) # Extract version from tag (remove 'v' prefix if present) From e67be2c4f6e7750e303732af5fa1e30e53316010 Mon Sep 17 00:00:00 2001 From: Katze719 <38188106+Katze719@users.noreply.github.com> Date: Fri, 28 Nov 2025 15:33:38 +0100 Subject: [PATCH 09/12] Update CMakeLists.txt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- CMakeLists.txt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 830d008..c42afa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,10 +82,12 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) -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" -) +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() From d14b7b3e2e7b3875dc79349a53189fc134b1b810 Mon Sep 17 00:00:00 2001 From: Katze719 <38188106+Katze719@users.noreply.github.com> Date: Sat, 29 Nov 2025 20:45:00 +0100 Subject: [PATCH 10/12] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cmake/msvc-toolchain.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/msvc-toolchain.cmake b/cmake/msvc-toolchain.cmake index fe07716..0691dce 100644 --- a/cmake/msvc-toolchain.cmake +++ b/cmake/msvc-toolchain.cmake @@ -15,4 +15,4 @@ set(CMAKE_CXX_FLAGS_DEBUG_INIT "/Zi /Od /MDd") set(CMAKE_CXX_FLAGS_RELEASE_INIT "/O2 /DNDEBUG /MD") # MSVC-specific definitions -add_definitions(-D_CRT_SECURE_NO_WARNINGS) +add_compile_definitions(_CRT_SECURE_NO_WARNINGS) From 709ec04ad34baadb6e0690722fcd4d71706f3a5b Mon Sep 17 00:00:00 2001 From: Katze719 <38188106+Katze719@users.noreply.github.com> Date: Sat, 29 Nov 2025 22:13:51 +0100 Subject: [PATCH 11/12] Apply suggestions from code review Co-authored-by: Mqx <62719703+Mqxx@users.noreply.github.com> --- CMakeLists.txt | 25 ++++++++++++++++--------- README.md | 9 ++++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c42afa9..8d22421 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,15 +19,18 @@ set(CPP_CORE_VERSION_STRING ${VERSION_STRING} CACHE STRING "Full version string" # 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 +project( + cpp-core VERSION ${PROJECT_VERSION} DESCRIPTION "Cross-platform helper library shared by cpp-linux-bindings and cpp-windows-bindings" - LANGUAGES CXX) + LANGUAGES CXX +) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.h - @ONLY) + @ONLY +) # Header-only library -------------------------------------------------------- add_library(cpp_core INTERFACE) @@ -65,12 +68,14 @@ include(CMakePackageConfigHelpers) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake VERSION ${PROJECT_VERSION} - COMPATIBILITY SameMajorVersion) + 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) + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core +) install(EXPORT cpp_coreTargets FILE cpp_coreTargets.cmake @@ -83,10 +88,12 @@ install(FILES 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 + 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" ) diff --git a/README.md b/README.md index 9d45f7e..0333f95 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,14 @@ The binding implementation then uses the API definitions: #include // 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) { +intptr_t serialOpen( + void *port, + int baudrate, + int data_bits, + int parity, + int stop_bits, + ErrorCallbackT error_callback +) { // Platform-specific implementation (Windows/Linux/macOS) } ``` From 31c2f36a204ca3f3e3b0925121cdbaeffd8af417 Mon Sep 17 00:00:00 2001 From: Mqx <62719703+Mqxx@users.noreply.github.com> Date: Sat, 29 Nov 2025 22:46:15 +0100 Subject: [PATCH 12/12] fix: format --- CMakeLists.txt | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d22421..ffee20c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,9 +37,12 @@ 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 + $ + $ +) # Set C++ standard set(CMAKE_CXX_STANDARD 23) @@ -56,11 +59,15 @@ set(CMAKE_CXX_MODULE_EXTENSIONS OFF) # 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) @@ -77,15 +84,19 @@ configure_package_config_file( INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core ) -install(EXPORT cpp_coreTargets +install( + EXPORT cpp_coreTargets FILE cpp_coreTargets.cmake NAMESPACE cpp_core:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core +) -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core) +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cpp_coreConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cpp_core +) if(CMAKE_EXPORT_COMPILE_COMMANDS AND EXISTS "${CMAKE_BINARY_DIR}/compile_commands.json") add_custom_target(