From ce45b96f6fbb649f4d0111af2d8fb409836c354d Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Wed, 15 Oct 2025 11:52:45 -0600 Subject: [PATCH] :art: Provide better control over freestanding Problem: - The `SIMULATE_FREESTANDING` macro applies to multiple repos. Sometimes we might want finer-grained control over which elements of which repos are freestanding-compatible, because toolchains differ in what they support. Solution: - Introduce `CONC_FREESTANDING` for this repo control. - Defining `SIMULATE_FREESTANDING` will also control `CONC_FREESTANDING`. --- CMakeLists.txt | 3 ++- include/conc/concurrency.hpp | 7 ++++--- include/conc/detail/freestanding.hpp | 5 +++++ test/fail_no_conc_policy.cpp | 2 +- test/freestanding_conc_injected_policy.cpp | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 include/conc/detail/freestanding.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fcf72fa..a028645 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,8 @@ target_sources( FILES include/conc/atomic.hpp include/conc/concepts.hpp - include/conc/concurrency.hpp) + include/conc/concurrency.hpp + include/conc/detail/freestanding.hpp) if(PROJECT_IS_TOP_LEVEL) add_docs(docs) diff --git a/include/conc/concurrency.hpp b/include/conc/concurrency.hpp index 8fa5865..563a855 100644 --- a/include/conc/concurrency.hpp +++ b/include/conc/concurrency.hpp @@ -1,13 +1,14 @@ #pragma once -#ifdef SIMULATE_FREESTANDING +#include +#include + +#ifdef CONC_FREESTANDING #define HAS_MUTEX 0 #else #define HAS_MUTEX __has_include() #endif -#include - #if HAS_MUTEX #include #endif diff --git a/include/conc/detail/freestanding.hpp b/include/conc/detail/freestanding.hpp new file mode 100644 index 0000000..8cf5c7b --- /dev/null +++ b/include/conc/detail/freestanding.hpp @@ -0,0 +1,5 @@ +#pragma once + +#ifdef SIMULATE_FREESTANDING +#define CONC_FREESTANDING +#endif diff --git a/test/fail_no_conc_policy.cpp b/test/fail_no_conc_policy.cpp index 2f20c26..53b2768 100644 --- a/test/fail_no_conc_policy.cpp +++ b/test/fail_no_conc_policy.cpp @@ -1,4 +1,4 @@ -#define SIMULATE_FREESTANDING +#define CONC_FREESTANDING #include diff --git a/test/freestanding_conc_injected_policy.cpp b/test/freestanding_conc_injected_policy.cpp index 07027c1..621a2b0 100644 --- a/test/freestanding_conc_injected_policy.cpp +++ b/test/freestanding_conc_injected_policy.cpp @@ -1,4 +1,4 @@ -#define SIMULATE_FREESTANDING +#define CONC_FREESTANDING #include #include