|
| 1 | +From b207fb6c15dc5ebdabe22a9985cb2ecf39daaf9f Mon Sep 17 00:00:00 2001 |
| 2 | +From: Kreijstal < [email protected]> |
| 3 | +Date: Tue, 25 Feb 2025 10:23:52 +0100 |
| 4 | +Subject: [PATCH] Weird bug where clang requires explicit json definitions |
| 5 | + |
| 6 | +--- |
| 7 | + common/settings/bom_settings.cpp | 3 +- |
| 8 | + common/settings/json_settings.cpp | 1 + |
| 9 | + kicad/tools/kicad_manager_control.cpp | 2 +- |
| 10 | + kicad/update_manager.cpp | 2 +- |
| 11 | + libs/core/include/core/json_serializers.h | 62 ++++++++++++++++++++++- |
| 12 | + 5 files changed, 65 insertions(+), 5 deletions(-) |
| 13 | + |
| 14 | +diff --git a/common/settings/bom_settings.cpp b/common/settings/bom_settings.cpp |
| 15 | +index 69d7fdbe81..8db15dfd97 100644 |
| 16 | +--- a/common/settings/bom_settings.cpp |
| 17 | ++++ b/common/settings/bom_settings.cpp |
| 18 | +@@ -17,10 +17,9 @@ |
| 19 | + * You should have received a copy of the GNU General Public License along |
| 20 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | + */ |
| 22 | +- |
| 23 | ++#include <core/json_serializers.h> |
| 24 | + #include <settings/bom_settings.h> |
| 25 | + #include <nlohmann/json.hpp> |
| 26 | +-#include <core/json_serializers.h> |
| 27 | + #include <wx/translation.h> |
| 28 | + |
| 29 | + |
| 30 | +diff --git a/common/settings/json_settings.cpp b/common/settings/json_settings.cpp |
| 31 | +index 7d946df47d..159e0e09a5 100644 |
| 32 | +--- a/common/settings/json_settings.cpp |
| 33 | ++++ b/common/settings/json_settings.cpp |
| 34 | +@@ -26,6 +26,7 @@ |
| 35 | + |
| 36 | + #include <locale_io.h> |
| 37 | + #include <gal/color4d.h> |
| 38 | ++#include <core/json_serializers.h> |
| 39 | + #include <settings/json_settings.h> |
| 40 | + #include <settings/json_settings_internals.h> |
| 41 | + #include <settings/nested_settings.h> |
| 42 | +diff --git a/kicad/tools/kicad_manager_control.cpp b/kicad/tools/kicad_manager_control.cpp |
| 43 | +index 4401cf82b5..91be5e24a5 100644 |
| 44 | +--- a/kicad/tools/kicad_manager_control.cpp |
| 45 | ++++ b/kicad/tools/kicad_manager_control.cpp |
| 46 | +@@ -17,7 +17,7 @@ |
| 47 | + * You should have received a copy of the GNU General Public License along |
| 48 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 49 | + */ |
| 50 | +- |
| 51 | ++#include <core/json_serializers.h> |
| 52 | + #include <wildcards_and_files_ext.h> |
| 53 | + #include <env_vars.h> |
| 54 | + #include <executable_names.h> |
| 55 | +diff --git a/kicad/update_manager.cpp b/kicad/update_manager.cpp |
| 56 | +index d854a73a75..47556598b0 100644 |
| 57 | +--- a/kicad/update_manager.cpp |
| 58 | ++++ b/kicad/update_manager.cpp |
| 59 | +@@ -28,6 +28,7 @@ |
| 60 | + #include <string> |
| 61 | + #include <sstream> |
| 62 | + |
| 63 | ++#include <core/json_serializers.h> |
| 64 | + #include "settings/settings_manager.h" |
| 65 | + #include "settings/kicad_settings.h" |
| 66 | + #include <notifications_manager.h> |
| 67 | +@@ -39,7 +40,6 @@ |
| 68 | + #include <dialogs/dialog_update_notice.h> |
| 69 | + |
| 70 | + #include <nlohmann/json.hpp> |
| 71 | +-#include <core/json_serializers.h> |
| 72 | + |
| 73 | + #include <wx/log.h> |
| 74 | + #include <wx/event.h> |
| 75 | +diff --git a/libs/core/include/core/json_serializers.h b/libs/core/include/core/json_serializers.h |
| 76 | +index b5079fc209..285e951c89 100644 |
| 77 | +--- a/libs/core/include/core/json_serializers.h |
| 78 | ++++ b/libs/core/include/core/json_serializers.h |
| 79 | +@@ -25,6 +25,7 @@ |
| 80 | + #define JSON_SERIALIZERS_H_ |
| 81 | + |
| 82 | + #include <nlohmann/json.hpp> |
| 83 | ++#include <wx/gdicmn.h> |
| 84 | + #include <wx/string.h> |
| 85 | + #include <optional> |
| 86 | + |
| 87 | +@@ -89,7 +90,66 @@ struct adl_serializer<std::optional<T>> |
| 88 | + } |
| 89 | + } |
| 90 | + }; |
| 91 | ++ |
| 92 | ++// Clang-specific stubs for wxPoint, wxSize, wxRect |
| 93 | ++#ifdef __clang__ |
| 94 | ++template <> |
| 95 | ++ struct adl_serializer<wxPoint> |
| 96 | ++ { |
| 97 | ++ static void to_json(json& j, const wxPoint& p) |
| 98 | ++ { |
| 99 | ++ j["x"] = p.x; |
| 100 | ++ j["y"] = p.y; |
| 101 | ++ } |
| 102 | ++ |
| 103 | ++ static void from_json(const json& j, wxPoint& p) |
| 104 | ++ { |
| 105 | ++ j.at("x").get_to(p.x); |
| 106 | ++ j.at("y").get_to(p.y); |
| 107 | ++ } |
| 108 | ++ }; |
| 109 | ++ |
| 110 | ++ template <> |
| 111 | ++ struct adl_serializer<wxSize> |
| 112 | ++ { |
| 113 | ++ static void to_json(json& j, const wxSize& s) |
| 114 | ++ { |
| 115 | ++ j["width"] = s.GetWidth(); |
| 116 | ++ j["height"] = s.GetHeight(); |
| 117 | ++ } |
| 118 | ++ |
| 119 | ++ static void from_json(const json& j, wxSize& s) |
| 120 | ++ { |
| 121 | ++ int w, h; |
| 122 | ++ j.at("width").get_to(w); |
| 123 | ++ j.at("height").get_to(h); |
| 124 | ++ s = wxSize(w, h); // Use constructor |
| 125 | ++ } |
| 126 | ++ }; |
| 127 | ++ |
| 128 | ++ template <> |
| 129 | ++ struct adl_serializer<wxRect> |
| 130 | ++ { |
| 131 | ++ static void to_json(json& j, const wxRect& r) |
| 132 | ++ { |
| 133 | ++ j["x"] = r.x; |
| 134 | ++ j["y"] = r.y; |
| 135 | ++ j["width"] = r.width; |
| 136 | ++ j["height"] = r.height; |
| 137 | ++ } |
| 138 | ++ |
| 139 | ++ static void from_json(const json& j, wxRect& r) |
| 140 | ++ { |
| 141 | ++ int x, y, w, h; |
| 142 | ++ j.at("x").get_to(x); |
| 143 | ++ j.at("y").get_to(y); |
| 144 | ++ j.at("width").get_to(w); |
| 145 | ++ j.at("height").get_to(h); |
| 146 | ++ r = wxRect(x, y, w, h); // Use constructor instead of Set |
| 147 | ++ } |
| 148 | ++ }; |
| 149 | ++#endif // __clang__ |
| 150 | + } // namespace nlohmann |
| 151 | + |
| 152 | + |
| 153 | +-#endif // JSON_SERIALIZERS_H_ |
| 154 | +\ No newline at end of file |
| 155 | ++#endif // JSON_SERIALIZERS_H_ |
| 156 | +-- |
| 157 | +2.43.0 |
| 158 | + |
0 commit comments