Skip to content

Commit

Permalink
Add a CMake option to select no std::filesystem
Browse files Browse the repository at this point in the history
Cmake option PEGTL_NO_STD_FILESYSTEM will mean there is
*no* implementation of std::filesystem selected at compile
time. This will invariably lead to a broken PEGTL if you set
it and use file operations, but it is intended to allow a configuration
on systems without boost or std::filesystem, which don't need
filesystem access but do want memory parsing. This allows
taojson memory parsers to compile back to macOS 10.13, for instance.

See discussion in issue taocpp#347
  • Loading branch information
baconpaul committed Jul 2, 2023
1 parent b4f456a commit 2720654
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ target_include_directories(pegtl INTERFACE
target_compile_features(pegtl INTERFACE cxx_std_17)

option(PEGTL_USE_BOOST_FILESYSTEM "Override the auto-detection of std::filesystem and use Boost.Filesystem" OFF)
option(PEGTL_NO_STD_FILESYSTEM "Don't link to any std::filesystem; file operations will not work" OFF)

# Try compiling a test program with std::filesystem or one of its alternatives
function(check_filesystem_impl FILESYSTEM_HEADER FILESYSTEM_NAMESPACE OPTIONAL_LIBS OUT_RESULT)
Expand Down Expand Up @@ -82,7 +83,10 @@ function(check_filesystem_impl FILESYSTEM_HEADER FILESYSTEM_NAMESPACE OPTIONAL_L
set(${OUT_RESULT} ${TEST_RESULT} PARENT_SCOPE)
endfunction()

if(PEGTL_USE_BOOST_FILESYSTEM)
if (PEGTL_NO_STD_FILESYSTEM)
target_compile_definitions(${PROJECT_NAME} INTERFACE TAO_PEGTL_NO_STD_FILESYSTEM)
message(STATUS "Skipping std::filesystem in PEGTL; File operations will not work or compile.")
elseif (PEGTL_USE_BOOST_FILESYSTEM)
# Force the use of Boost.Filesystem: #include <boost/filesystem.hpp> // boost::filesystem
find_package(Boost REQUIRED COMPONENTS filesystem)
target_link_libraries(${PROJECT_NAME} INTERFACE Boost::filesystem)
Expand Down

0 comments on commit 2720654

Please sign in to comment.