diff --git a/cmake/FindFilesystem.cmake b/cmake/FindFilesystem.cmake index 93cc9b9c8a3..1d0eb52641a 100644 --- a/cmake/FindFilesystem.cmake +++ b/cmake/FindFilesystem.cmake @@ -103,6 +103,8 @@ if(TARGET std::filesystem) return() endif() +cmake_minimum_required(VERSION 3.10) + include(CMakePushCheckState) include(CheckIncludeFileCXX) @@ -124,6 +126,13 @@ cmake_push_check_state() set(CMAKE_REQUIRED_QUIET ${Filesystem_FIND_QUIETLY}) +# All of our tests required C++17 or later +if(DEFINED CMAKE_CXX_STANDARD) + set(_prior_cmake_cxx_standard ${CMAKE_CXX_STANDARD}) +endif() + +set(CMAKE_CXX_STANDARD 17) + # Normalize and check the component list we were given set(want_components ${Filesystem_FIND_COMPONENTS}) if(Filesystem_FIND_COMPONENTS STREQUAL "") @@ -282,6 +291,12 @@ set(Filesystem_FOUND FORCE ) +if(DEFINED _prior_cmake_cxx_standard) + set(CMAKE_CXX_STANDARD ${_prior_cmake_cxx_standard}) +else() + unset(CMAKE_CXX_STANDARD) +endif() + if(Filesystem_FIND_REQUIRED AND NOT Filesystem_FOUND) message(FATAL_ERROR "Cannot run simple program using std::filesystem") endif()