From 239b5be2197a3ca8a2c52f3f6b06ad9ee0d694f9 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Thu, 16 May 2024 11:50:57 +0530 Subject: [PATCH] ChatON+: Cleanup integration with CMake Rename chaton-meta hpp to cpp and include this cpp file which brings in the compile time built-in global chaton configurable template data into the common library, and avoid the nop hpp file references. Update chaton.hpp to not include the meta-cpp, instead just make a reference to the global ChatTemplates instance, so that the hpp can be used as a header file proper. Avoid pragma once in the chaton-meta.cpp, including the script, which helps create it. --- common/CMakeLists.txt | 3 +-- common/chaton.hpp | 5 ++--- common/{chaton_meta.hpp => chaton_meta.cpp} | 1 - scripts/chaton-meta-json-to-hpp.py | 4 ++-- 4 files changed, 5 insertions(+), 8 deletions(-) rename common/{chaton_meta.hpp => chaton_meta.cpp} (99%) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a07566c0e..f34249532 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -65,8 +65,7 @@ add_library(${TARGET} STATIC train.cpp ngram-cache.h ngram-cache.cpp - chaton.hpp - groupkv.hpp + chaton_meta.cpp ) if (BUILD_SHARED_LIBS) diff --git a/common/chaton.hpp b/common/chaton.hpp index 17bd59be7..b2046d198 100644 --- a/common/chaton.hpp +++ b/common/chaton.hpp @@ -537,9 +537,8 @@ public: }; -// The compiled-in configurable template data (the meta) -#include "chaton_meta.hpp" -//ChatTemplates gCT = {{}}; +// The compiled-in configurable template data (the meta) from chaton_meta.cpp +extern ChatTemplates gCT; inline bool chaton_tmpl_exists(const std::string &tmpl) { diff --git a/common/chaton_meta.hpp b/common/chaton_meta.cpp similarity index 99% rename from common/chaton_meta.hpp rename to common/chaton_meta.cpp index 3516d5bb9..d0013b519 100644 --- a/common/chaton_meta.hpp +++ b/common/chaton_meta.cpp @@ -1,5 +1,4 @@ //This is auto created/converted from chaton-meta-json file -#pragma once #include "chaton.hpp" diff --git a/scripts/chaton-meta-json-to-hpp.py b/scripts/chaton-meta-json-to-hpp.py index d72c4cdf5..3329b9b7f 100755 --- a/scripts/chaton-meta-json-to-hpp.py +++ b/scripts/chaton-meta-json-to-hpp.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Convert chaton meta json file to c++ hpp file +# Convert chaton meta json file to equivalent c++ cpp format # by Humans for All import sys @@ -19,7 +19,7 @@ def kv_bool(j, tmpl, k1, comma): fp=open(sys.argv[1]) j=json.load(fp) print("//This is auto created/converted from chaton-meta-json file") -print("#pragma once\n\n#include \"chaton.hpp\"\n\nChatTemplates gCT = {{") +print("\n\n#include \"chaton.hpp\"\n\nChatTemplates gCT = {{") for tmpl in j: print("\t{{ \"{}\", {{".format(tmpl))