From 48955026c48de0e04ce20dae3e603ef1c175d3fc Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 16 Feb 2023 02:26:14 -0300 Subject: [PATCH] restructure library location --- lib/version.h.in | 1 - meson.build | 10 +--------- meson_options.txt | 10 ---------- src/lib/include/obelisk.h | 27 +++++++++++++++++++++++++++ {lib => src/lib}/meson.build | 11 ++++++++++- src/lib/obelisk.cpp | 14 ++++++++++++++ {include => src/lib}/version.h.in | 4 +++- src/meson.build | 10 ++-------- src/obelisk.cpp | 5 +++-- src/version.h.in | 1 - 10 files changed, 60 insertions(+), 33 deletions(-) delete mode 120000 lib/version.h.in create mode 100644 src/lib/include/obelisk.h rename {lib => src/lib}/meson.build (63%) create mode 100644 src/lib/obelisk.cpp rename {include => src/lib}/version.h.in (72%) delete mode 120000 src/version.h.in diff --git a/lib/version.h.in b/lib/version.h.in deleted file mode 120000 index 5c3fee4..0000000 --- a/lib/version.h.in +++ /dev/null @@ -1 +0,0 @@ -../include/version.h.in \ No newline at end of file diff --git a/meson.build b/meson.build index b14aca0..4f3a936 100644 --- a/meson.build +++ b/meson.build @@ -29,12 +29,4 @@ if docs_enabled endif endif -lib_enabled = get_option('lib') -if lib_enabled - subdir('lib') -endif - -bin_enabled = get_option('bin') -if bin_enabled - subdir('src') -endif +subdir('src') diff --git a/meson_options.txt b/meson_options.txt index 69bb0db..4dff45a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,13 +1,3 @@ -option('bin', - type: 'boolean', - value: true, - description: 'Build the obelisk compiler' -) -option('lib', - type: 'boolean', - value: true, - description: 'Build the obelisk library' -) option('docs', type: 'boolean', value: true, diff --git a/src/lib/include/obelisk.h b/src/lib/include/obelisk.h new file mode 100644 index 0000000..167183c --- /dev/null +++ b/src/lib/include/obelisk.h @@ -0,0 +1,27 @@ +#include + +/** + * @brief The obelisk namespace contains everything needed to compile obelisk. + * code. + * + */ +namespace obelisk +{ + class Obelisk + { + public: + /** + * @brief Get the obelisk version. + * + * @return std::string The version. + */ + std::string getVersion(); + + /** + * @brief Get the obelisk library so version. + * + * @return int The version. + */ + int getLibVersion(); + }; +} // namespace obelisk diff --git a/lib/meson.build b/src/lib/meson.build similarity index 63% rename from lib/meson.build rename to src/lib/meson.build index 0e17871..3cec326 100644 --- a/lib/meson.build +++ b/src/lib/meson.build @@ -7,14 +7,23 @@ configure_file(input : 'version.h.in', ) obelisk_lib_sources = files( + 'obelisk.cpp' ) sqlite3 = dependency('sqlite3') -library('obelisk', +incdirs = include_directories(['.', 'include']) +lib = library('obelisk', obelisk_lib_sources, + include_directories: incdirs, dependencies : [sqlite3], version : meson.project_version(), soversion : project_version_lib, install : true ) + +libobelisk_dep = declare_dependency( + include_directories : incdirs, + link_with : lib, + sources : obelisk_lib_sources +) diff --git a/src/lib/obelisk.cpp b/src/lib/obelisk.cpp new file mode 100644 index 0000000..b9b4a3f --- /dev/null +++ b/src/lib/obelisk.cpp @@ -0,0 +1,14 @@ +#include "include/obelisk.h" +#include "version.h" + +// TODO: Move the models to the library then link the compiler to the library + +std::string obelisk::Obelisk::getVersion() +{ + return obelisk::version; +} + +int obelisk::Obelisk::getLibVersion() +{ + return obelisk::soVersion; +} diff --git a/include/version.h.in b/src/lib/version.h.in similarity index 72% rename from include/version.h.in rename to src/lib/version.h.in index 1841178..b6b0867 100644 --- a/include/version.h.in +++ b/src/lib/version.h.in @@ -10,5 +10,7 @@ namespace obelisk * @brief The current library version of obelisk. * */ - const std::string soVersion = "@so_version@"; + // clang-format off + const int soVersion = @so_version@; + // clang-format on } // namespace obelisk diff --git a/src/meson.build b/src/meson.build index 051321b..5f5900c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,10 +1,4 @@ -conf_data = configuration_data() -conf_data.set('version', meson.project_version()) -conf_data.set('so_version', project_version_lib) -configure_file(input : 'version.h.in', - output : 'version.h', - configuration : conf_data -) +subdir('lib') obelisk_sources = files( 'obelisk.cpp', @@ -29,7 +23,7 @@ link_args = ' ' + r.stdout().replace('\n', ' ') executable('obelisk', obelisk_sources, - dependencies : [sqlite3], + dependencies : [libobelisk_dep, sqlite3], cpp_args : cpp_args.split(), link_args : link_args.split(), install : true diff --git a/src/obelisk.cpp b/src/obelisk.cpp index 6b6a71d..f790ca9 100644 --- a/src/obelisk.cpp +++ b/src/obelisk.cpp @@ -1,8 +1,9 @@ #include "knowledge_base.h" #include "lexer.h" +#include "lib/include/obelisk.h" +#include "lib/version.h" #include "obelisk.h" #include "parser.h" -#include "version.h" #include #include @@ -123,7 +124,7 @@ int main(int argc, char** argv) return EXIT_SUCCESS; break; case 'v' : - std::cout << "obelisk " << obelisk::version << std::endl; + std::cout << "obelisk " << (new obelisk::Obelisk())->getVersion() << std::endl; return EXIT_SUCCESS; break; default : diff --git a/src/version.h.in b/src/version.h.in deleted file mode 120000 index 5c3fee4..0000000 --- a/src/version.h.in +++ /dev/null @@ -1 +0,0 @@ -../include/version.h.in \ No newline at end of file