ned14 / llfio

P1031 low level file i/o and filesystem library for the C++ standard
https://ned14.github.io/llfio/
Other
880 stars 45 forks source link

Configuration mismatch when integrating via CPM - span_lite::span vs std::span #128

Closed APokorny closed 9 months ago

APokorny commented 10 months ago

I tried to use llfio via CPM (which is a fetchcontent wrapper - similar to quickcpplib - downloads during configure step, then runs add_subdirectoy for the download/clone location and builds with the normal build step):

CPMAddPackage("gh:ned14/llfio#418a2e9")
..
target_compile_feature(my_app PRIVATE cxx_std_20)

If I then use llfio in the project, llfio will decide to use std::span. For some reason llfio internally did decide to build with span_lite. So all std::span are span_lite::span. This obviously leads to linker errors.

I can force llfio to behave differently by setting the standard globally:

set(CMAKE_CXX_STANDARD 20)
CPMAddPackage("gh:ned14/llfio#418a2e9")
..
target_compile_feature(my_app PRIVATE cxx_std_20)

I am unsure if this is actually an issue inside llfio, or just a paper-cut you have to be aware of.

ned14 commented 10 months ago

You do need to use LLFIO in the same C++ standard as how it was built. Or use it in header only mode.

BurningEnlightenment commented 9 months ago

Note that you don't need to set CMAKE_CXX_STANDARD globally in your CMakeLists.txt (which is generally considered to be a bad practice). You can instead pass it as an option to CPM like so:

# _llfio_CXX_STANDARD := max(20, ${CMAKE_CXX_STANDARD})
if (CMAKE_CXX_STANDARD GREATER 20)
  set(_llfio_CXX_STANDARD ${CMAKE_CXX_STANDARD})
else()
  set(_llfio_CXX_STANDARD 20)
endif()
CPMAddPackage(
  NAME llfio
  GITHUB_REPOSITORY ned14/llfio
  GIT_TAG 418a2e9
  OPTIONS
    "CMAKE_CXX_STANDARD ${_llfio_CXX_STANDARD}"
)

Alternatively you can use the span alias from the llfio namespace to ensure compatibility with C++17 builds.