+
+# Test that required 2017 standard library features work.
+# Note that this check also requires linking to succeed.
+set (SAMPLE_CODE_TO_TEST_CXX17 "
+#include <string>
+#include <string_view>
+#include <optional>
+int main(int argc, char **argv) {
+ std::optional<std::string> input(argv[0]);
+ std::string_view view(input.value());
+ return int(view[0]);
+}")
+check_cxx_source_compiles("${SAMPLE_CODE_TO_TEST_CXX17}" CXX17_COMPILES)
+
+if (CXX17_COMPILES)
+ # The compiler has been set up properly to find a standard
+ # library, and if so GROMACS should leave it alone.
+ return()
+endif()
+
+# The compiler couldn't use the standard libary for an unknown reason.
+# See if the compiler is using libstdc++ (via libstc++ heuristics). If so,
+# then we may be able to help the compiler find the standard library.