Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ target_include_directories(core
$<INSTALL_INTERFACE:include>
)
target_compile_features(core PUBLIC cxx_std_17)
if(EDUCE_CORE_CHARCONV_DEFS)
target_compile_definitions(core PUBLIC ${EDUCE_CORE_CHARCONV_DEFS})
endif()
set_target_properties(core
PROPERTIES
PUBLIC_HEADER "${public_hdrs}"
Expand Down
48 changes: 28 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,24 @@ examples.
conversion. Both were introduced in C++17 but floating-point support arrived
later and is gated on the runtime library version (e.g. macOS 13.3+).

CMake probes for both at configure time and reports the results:

- **`CXX_CHARCONV_FP_FROM_CHARS`** — whether `std::from_chars` supports
`float`. If not, `EDUCE_CORE_NEED_CHARCONV_FP` is defined and `to_numeric`
falls back to `std::stof` / `std::stod` / `std::stold`.
- **`CXX_CHARCONV_FP_TO_CHARS`** — whether `std::to_chars` supports `float`.
`to_string_view` requires this unconditionally; no fallback is provided.

When linking against the `educelab::core` CMake target, `EDUCE_CORE_NEED_CHARCONV_FP`
is propagated automatically. If using the library header-only, check the CMake
cache variable and set the definition manually:
CMake probes for both at configure time via `CheckCharconvFP.cmake` and reports
the results as compile definitions (only emitted when the corresponding
function+type combination is absent):

- **`from_chars` fallbacks** — `to_numeric` falls back to `std::stof` /
`std::stod` / `std::stold` for any type whose definition is set:
- `EDUCE_CORE_NEED_FROM_CHARS_FLOAT`
- `EDUCE_CORE_NEED_FROM_CHARS_DOUBLE`
- `EDUCE_CORE_NEED_FROM_CHARS_LONG_DOUBLE`
- **`to_chars` fallbacks** — `to_string` / `to_string_view` fall back to
`std::snprintf` for any type whose definition is set:
- `EDUCE_CORE_NEED_TO_CHARS_FLOAT`
- `EDUCE_CORE_NEED_TO_CHARS_DOUBLE`
- `EDUCE_CORE_NEED_TO_CHARS_LONG_DOUBLE`

These definitions are attached to the `educelab::core` target as `PUBLIC`
compile definitions, so they propagate automatically to any target that links
against it:

```cmake
# Import libcore
Expand All @@ -368,17 +375,18 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(libcore)

# Add an executable which has access to the libcore headers
# Definitions are propagated automatically — no extra step needed.
add_executable(foo foo.cpp)
target_include_directories(foo
PUBLIC
$<BUILD_INTERFACE:${libcore_SOURCE_DIR}/include>
)
target_link_libraries(foo PRIVATE educelab::core)
```

If using the headers without linking against the CMake target, check the CMake
cache variables and set the needed definitions manually:

# Propagate the to_numeric fallback definition if needed
if(EDUCE_CORE_NEED_CHARCONV_FP)
target_compile_definitions(foo PRIVATE EDUCE_CORE_NEED_CHARCONV_FP)
endif()
```cmake
foreach(_def IN LISTS EDUCE_CORE_CHARCONV_DEFS)
target_compile_definitions(foo PRIVATE ${_def})
endforeach()
```

### Data caching
Expand Down
11 changes: 6 additions & 5 deletions cmake/CheckCharconvFP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
# in macOS 13.3; long double availability differs further.
#
# For each (function, type) combination a separate compile-time probe is run.
# When unavailable, a per-type preprocessor definition is set so String.hpp
# can activate the appropriate fallback specialisation without over-disabling
# types that are actually supported.
# When unavailable, a per-type preprocessor definition is appended to the
# EDUCE_CORE_CHARCONV_DEFS list so the caller can attach it to the library
# target via target_compile_definitions.
#
# Definitions emitted (only when the corresponding function+type is absent):
# Definitions collected into EDUCE_CORE_CHARCONV_DEFS (only when the
# corresponding function+type is absent):
# EDUCE_CORE_NEED_FROM_CHARS_FLOAT
# EDUCE_CORE_NEED_FROM_CHARS_DOUBLE
# EDUCE_CORE_NEED_FROM_CHARS_LONG_DOUBLE
Expand Down Expand Up @@ -47,7 +48,7 @@ macro(_charconv_probe _direction _typename _snippet _defname)
")
check_cxx_source_compiles("${_probe_code}" _CXX_CHARCONV_${_defname})
if(NOT _CXX_CHARCONV_${_defname})
add_compile_definitions(EDUCE_CORE_${_defname})
list(APPEND EDUCE_CORE_CHARCONV_DEFS EDUCE_CORE_${_defname})
endif()
endmacro()

Expand Down
3 changes: 1 addition & 2 deletions conductor/product.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ EduceLab developers building C++ applications and libraries.
1. Provide a stable, reusable foundation for all EduceLab C++ projects
2. Offer well-tested, header-friendly types (Vec, Mat, Image, Mesh, UVMap, etc.)
3. Minimize external dependencies while maximizing utility
4. Provide standard Mesh IO (OBJ and PLY read/write) including UV maps, texture
paths, and compile-time vertex trait detection (`has_normal`, `has_color`)
4. Provide standard Mesh IO (OBJ and PLY read/write) including UV maps and texture paths

## Current Version

Expand Down
Loading