diff --git a/develop/CMakeLists.txt b/develop/CMakeLists.txt index 162f558..6635253 100644 --- a/develop/CMakeLists.txt +++ b/develop/CMakeLists.txt @@ -17,6 +17,7 @@ include(SetupTargets) add_subdirectory(manuals) add_subdirectory(singles) add_subdirectory(unbench) +add_subdirectory(unshared) add_subdirectory(untests) add_subdirectory(vendors) diff --git a/develop/unshared/CMakeLists.txt b/develop/unshared/CMakeLists.txt new file mode 100644 index 0000000..d8932c8 --- /dev/null +++ b/develop/unshared/CMakeLists.txt @@ -0,0 +1,38 @@ +project(meta.hpp.shared) + +# lib + +file(GLOB_RECURSE META_SHARED_LIB_SOURCES CONFIGURE_DEPENDS + "meta_shared_lib/*.cpp" + "meta_shared_lib/*.hpp") +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${META_SHARED_LIB_SOURCES}) + +add_library(${PROJECT_NAME}.lib SHARED ${META_SHARED_LIB_SOURCES}) +add_library(${PROJECT_NAME}::lib ALIAS ${PROJECT_NAME}.lib) + +target_link_libraries(${PROJECT_NAME}.lib PUBLIC + meta.hpp::meta.hpp + meta.hpp::setup_targets) + +target_include_directories(${PROJECT_NAME}.lib PUBLIC + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/meta_shared_lib) + +include(GenerateExportHeader) +generate_export_header(${PROJECT_NAME}.lib) + +# exe + +file(GLOB_RECURSE META_SHARED_EXE_SOURCES CONFIGURE_DEPENDS + "meta_shared_exe/*.cpp" + "meta_shared_exe/*.hpp") +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${META_SHARED_EXE_SOURCES}) + +add_executable(${PROJECT_NAME}.exe ${META_SHARED_EXE_SOURCES}) + +target_link_libraries(${PROJECT_NAME}.exe PRIVATE + ${PROJECT_NAME}::lib + meta.hpp.vendors::doctest + meta.hpp.vendors::fmt) + +add_test(${PROJECT_NAME}.exe ${PROJECT_NAME}.exe) diff --git a/develop/unshared/meta_shared_exe/meta_shared_exe.cpp b/develop/unshared/meta_shared_exe/meta_shared_exe.cpp new file mode 100644 index 0000000..5d7db62 --- /dev/null +++ b/develop/unshared/meta_shared_exe/meta_shared_exe.cpp @@ -0,0 +1,41 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/meta.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2021-2024, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include + +#include + +TEST_CASE("meta/meta_shared/exe") { + namespace meta = meta_hpp; + namespace shared = meta_shared_lib; + + const meta::scope library_scope = shared::get_library_scope(); + REQUIRE(library_scope); + + // + + const meta::number_type int_type = library_scope.get_typedef("int").as_number(); + REQUIRE(int_type); + + const meta::class_type ivec2_type = library_scope.get_typedef("ivec2").as_class(); + REQUIRE(ivec2_type); + + const meta::constructor ivec2_ctor2 = ivec2_type.get_constructor_with({int_type, int_type}); + REQUIRE(ivec2_ctor2); + + const meta::method ivec2_length2 = ivec2_type.get_method("length2"); + REQUIRE(ivec2_length2); + + // + + const meta::uvalue ivec2_inst = ivec2_ctor2.create(shared::wrap_int(3), shared::wrap_int(4)); + REQUIRE(ivec2_inst); + + const meta::uvalue ivec2_inst_length2 = ivec2_length2.invoke(ivec2_inst); + REQUIRE(ivec2_inst_length2); + + CHECK(shared::unwrap_int(ivec2_inst_length2) == 25); +} diff --git a/develop/unshared/meta_shared_lib/meta_shared_lib.cpp b/develop/unshared/meta_shared_lib/meta_shared_lib.cpp new file mode 100644 index 0000000..b7bb2c7 --- /dev/null +++ b/develop/unshared/meta_shared_lib/meta_shared_lib.cpp @@ -0,0 +1,56 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/meta.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2021-2024, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include "meta_shared_lib.hpp" + +namespace +{ + using namespace meta_shared_lib; + + struct ivec2 { + int x; + int y; + + explicit ivec2(int nv) : x{nv}, y{nv} {} + ivec2(int nx, int ny) : x{nx}, y{ny} {} + + int length2() const noexcept { + return x * x + y * y; + } + }; + + void bind_ivec2() { + meta::class_() + .constructor_() + .constructor_() + .member_("x", &ivec2::x) + .member_("y", &ivec2::y) + .method_("length2", &ivec2::length2); + } + + const auto library_scope = []() -> meta::scope { + bind_ivec2(); + + return meta::local_scope_("library_scope") + .typedef_("int") + .typedef_("ivec2"); + }(); +} + +namespace meta_shared_lib +{ + meta::scope get_library_scope() { + return library_scope; + } + + meta::uvalue wrap_int(int value) { + return value; + } + + int unwrap_int(const meta::uvalue& value) { + return value.as(); + } +} diff --git a/develop/unshared/meta_shared_lib/meta_shared_lib.hpp b/develop/unshared/meta_shared_lib/meta_shared_lib.hpp new file mode 100644 index 0000000..b0c0db1 --- /dev/null +++ b/develop/unshared/meta_shared_lib/meta_shared_lib.hpp @@ -0,0 +1,21 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/meta.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2021-2024, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include + +#include + +namespace meta_shared_lib +{ + namespace meta = meta_hpp; + + META_HPP_SHARED_LIB_EXPORT meta::scope get_library_scope(); + + META_HPP_SHARED_LIB_EXPORT meta::uvalue wrap_int(int value); + META_HPP_SHARED_LIB_EXPORT int unwrap_int(const meta::uvalue& value); +}