From cf2584b07dbf09c9b616a286aa061e87e51c698a Mon Sep 17 00:00:00 2001 From: Stuart Miller Date: Fri, 1 Dec 2023 09:38:42 -0600 Subject: [PATCH] Conditionally remove support for std::filesystem on systems that don't support it. --- include/mav/MessageSet.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/include/mav/MessageSet.h b/include/mav/MessageSet.h index 54c90da..b87da1c 100644 --- a/include/mav/MessageSet.h +++ b/include/mav/MessageSet.h @@ -35,7 +35,6 @@ #define MAV_MESSAGESET_H #include -#include #include #include @@ -45,6 +44,15 @@ #include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml_utils.hpp" +#ifdef _LIBCPP_VERSION +#if _LIBCPP_VERSION < 11000 +#define _NO_STD_FILESYSTEM +#endif +#endif +#ifndef _NO_STD_FILESYSTEM +#include +#endif + namespace mav { class XMLParser { @@ -104,7 +112,7 @@ namespace mav { } public: - +#ifndef _NO_STD_FILESYSTEM static XMLParser forFile(const std::string &file_name) { auto file = std::make_shared>(file_name.c_str()); auto doc = std::make_shared>(); @@ -112,6 +120,7 @@ namespace mav { return {file, doc, std::filesystem::path{file_name}.parent_path().string()}; } +#endif // _NO_STD_FILESYSTEM static XMLParser forXMLString(const std::string &xml_string) { // pass by value on purpose, rapidxml mutates the string on parse @@ -131,7 +140,7 @@ namespace mav { if (!root_node) { throw std::runtime_error("Root node \"mavlink\" not found"); } - +#ifndef _NO_STD_FILESYSTEM for (auto include_element = root_node->first_node("include"); include_element != nullptr; include_element = include_element->next_sibling("include")) { @@ -141,6 +150,7 @@ namespace mav { (std::filesystem::path{_root_xml_folder_path} / include_name).string()); sub_parser.parse(out_enum, out_messages, out_message_ids); } +#endif // _NO_STD_FILESYSTEM auto enums_node = root_node->first_node("enums"); if (enums_node) { @@ -215,6 +225,7 @@ namespace mav { public: MessageSet() = default; +#ifndef _NO_STD_FILESYSTEM explicit MessageSet(const std::string &xml_path) { addFromXML(xml_path); } @@ -223,6 +234,7 @@ namespace mav { XMLParser parser = XMLParser::forFile(file_path); parser.parse(_enums, _messages, _message_ids); } +#endif // _NO_STD_FILESYSTEM void addFromXMLString(const std::string &xml_string) { XMLParser parser = XMLParser::forXMLString(xml_string);