Skip to content

Commit

Permalink
Started to add template files for Linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
hkbinaurics committed May 31, 2024
1 parent 856402a commit 214785f
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 1 deletion.
122 changes: 122 additions & 0 deletions flutter/project_templates/linux/ayfcorepack/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# The Flutter tooling requires that developers have CMake 3.10 or later
# installed. You should not increase this version, as doing so will cause
# the plugin to fail to compile for some customers of the plugin.
cmake_minimum_required(VERSION 3.10)

# Project-level configuration.
set(PROJECT_NAME "ayfcorepack")
project(${PROJECT_NAME} LANGUAGES CXX)

set(AYF_PROJECT ayfbinrender-native-config)
set(AYF_VERBOSE_INFO TRUE)
set(AYF_CORE_PACK_LIB lib${AYF_PROJECT}_import.so)
set(AYF_CORE_PACK_INCLUDE ${AYF_PROJECT})

# This value is used when generating builds using this plugin, so it must
# not be changed.
set(PLUGIN_NAME "ayfcorepack_plugin")

# =======================================================
# Link to ayf sdk
# =======================================================
if(AYF_VERBOSE_INFO)
message("Module <${PROJECT_NAME}> in folder ${CMAKE_CURRENT_SOURCE_DIR}")
endif()

if(NOT DEFINED ENV{AYF_SDK_PATH})
message(FATAL_ERROR "Environment variable AYF_SDK_PATH not set.")
endif()
set(AYF_SDK_PATH $ENV{AYF_SDK_PATH})

cmake_path(CONVERT ${AYF_SDK_PATH} TO_CMAKE_PATH_LIST AYF_SDK_PATH)
if(NOT EXISTS ${AYF_SDK_PATH})
message(FATAL_ERROR "SDK folder ${AYF_SDK_PATH} does not exist!!")
else()
if(AYF_VERBOSE_INFO)
message("----> Linking with SDK folder ${AYF_SDK_PATH}!!")
endif()
endif()

list(APPEND PLUGIN_SOURCES
"ayfcorepack_plugin.cc"
"include/ayfcorepack/ayfcorepack_plugin.h"
"../common/ayf-sdk-local-headers.h"
"${AYF_SDK_PATH}/software/codeFragments/jvxApplications/native-config/exports/windows/exports-flutter-native-config.def"
"${AYF_SDK_PATH}/include/${AYF_CORE_PACK_INCLUDE}/include/${AYF_PROJECT}.h"
)

# Define the plugin library target. Its name must not be changed (see comment
# on PLUGIN_NAME above).
#
# Any new source files that you add to the plugin should be added here.
add_library(${PLUGIN_NAME} SHARED
${PLUGIN_SOURCES}
)

# Apply a standard set of build settings that are configured in the
# application-level CMakeLists.txt. This can be removed for plugins that want
# full control over build settings.
apply_standard_settings(${PLUGIN_NAME})

# Symbols are hidden by default to reduce the chance of accidental conflicts
# between plugins. This should not be removed; any symbols that should be
# exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro.
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)

# Source include directories and library dependencies. Add any plugin-specific
# dependencies here.
target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)

include(${AYF_SDK_PATH}/cmake/cmake-sdk/cmake-ayf-minimal-header-includes.cmake)
get_property(AYF_MINIMAL_SDK_HEADER_INCLUDES GLOBAL PROPERTY AYF_MINIMAL_SDK_HEADER_INCLUDES)
if(AYF_VERBOSE_INFO)
message("----> Found the following headers for linking libraries in the SDK: AYF_MINIMAL_SDK_HEADER_INCLUDES = ${AYF_MINIMAL_SDK_HEADER_INCLUDES}")
endif()

target_include_directories(${PLUGIN_NAME} PRIVATE
${AYF_MINIMAL_SDK_HEADER_INCLUDES}
${AYF_SDK_PATH}/include/${AYF_CORE_PACK_INCLUDE}/include
../common
)

target_link_directories(${PLUGIN_NAME} PRIVATE
"${AYF_SDK_PATH}/lib"
"${AYF_SDK_PATH}/bin"
"${AYF_SDK_PATH}/lib/jvxComponents-static"
)

target_link_libraries(${PLUGIN_NAME} PRIVATE

# This is the minimum package libs aggregation:
${AYF_CORE_PACK_LIB}
jvx-system-base_static
)

target_compile_features(${PLUGIN_NAME} PRIVATE cxx_std_17)

target_compile_options(${PLUGIN_NAME} PRIVATE "-Wno-error")
target_compile_options(${PLUGIN_NAME} PRIVATE "-Wno-unused-variable")
target_compile_options(${PLUGIN_NAME} PRIVATE "-Wno-unused-function")
target_compile_definitions(${PLUGIN_NAME} PRIVATE "AYF_PROJECT=${AYF_PROJECT}")

set(AYF_COPY_DLLS
"${AYF_SDK_PATH}/bin/${AYF_CORE_PACK_LIB}"
)
if(AYF_VERBOSE_INFO)
message("----> Copying dlls ${AYF_COPY_DLLS}")
endif()


# List of absolute paths to libraries that should be bundled with the plugin.
# This list could contain prebuilt libraries, or libraries created by an
# external build triggered from this build file.
set(ayfcorepack_bundled_libraries
""
${AYF_COPY_DLLS}
PARENT_SCOPE
)
98 changes: 98 additions & 0 deletions flutter/project_templates/linux/ayfcorepack/ayfcorepack_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "include/ayfcorepack/ayfcorepack_plugin.h"

#include <flutter_linux/flutter_linux.h>
#include <gtk/gtk.h>
#include <sys/utsname.h>

#include <cstring>

#include <string>
#include "../common/ayf-sdk-local-headers.h"
#include "jvx_platform.h"

#define AYFCOREPACK_PLUGIN(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), ayfcorepack_plugin_get_type(), \
AyfcorepackPlugin))

struct _AyfcorepackPlugin {
GObject parent_instance;
};

G_DEFINE_TYPE(AyfcorepackPlugin, ayfcorepack_plugin, g_object_get_type())

// Called when a method call is received from Flutter.
static void ayfcorepack_plugin_handle_method_call(
AyfcorepackPlugin* self,
FlMethodCall* method_call) {
g_autoptr(FlMethodResponse) response = nullptr;

const gchar* method = fl_method_call_get_name(method_call);

if (strcmp(method, "getPlatformVersion") == 0) {
struct utsname uname_data = {};
uname(&uname_data);
g_autofree gchar *version = g_strdup_printf("Linux %s", uname_data.version);
g_autoptr(FlValue) result = fl_value_new_string(version);
response = FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}
else if (strcmp(method, "getEntryPoints") == 0)
{
// https://levelup.gitconnected.com/writing-plugins-for-linux-in-flutter-38e46bd7872f
// https://api.flutter.dev/linux-embedder/fl__value_8h.html

g_autoptr(FlValue) mapReturn = fl_value_new_map();
//flutter::EncodableMap retMap;

std::string externalAccessModuleName = JVX_GET_CURRENT_MODULE_PATH((void*)flutter_config_open);
fl_value_set(mapReturn, fl_value_new_string("loadedModule"),
fl_value_new_string(externalAccessModuleName.c_str()));
//ayfcorepack::AyfcorepackPlugin::fileNameModule.c_str()));
// retMap[flutter::EncodableValue("loadedModule")] = flutter::EncodableValue(ayfcorepack::AyfcorepackPlugin::fileNameModule);

fl_value_set(mapReturn, fl_value_new_string("moduleEntryAddress"), fl_value_new_int((intptr_t)flutter_config_open));
//retMap[flutter::EncodableValue("moduleEntryAddress")] = flutter::EncodableValue((intptr_t)flutter_config_open);

fl_value_set(mapReturn, fl_value_new_string("moduleEntrySymbol"), fl_value_new_string("flutter_config_open"));
// retMap[flutter::EncodableValue("moduleEntrySymbol")] = flutter::EncodableValue("flutter_config_open");

//result->Success(retMap);
response = FL_METHOD_RESPONSE(fl_method_success_response_new(mapReturn));
}
else {
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
}

fl_method_call_respond(method_call, response, nullptr);
}

static void ayfcorepack_plugin_dispose(GObject* object) {
G_OBJECT_CLASS(ayfcorepack_plugin_parent_class)->dispose(object);
}

static void ayfcorepack_plugin_class_init(AyfcorepackPluginClass* klass) {
G_OBJECT_CLASS(klass)->dispose = ayfcorepack_plugin_dispose;
}

static void ayfcorepack_plugin_init(AyfcorepackPlugin* self) {}

static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call,
gpointer user_data) {
AyfcorepackPlugin* plugin = AYFCOREPACK_PLUGIN(user_data);
ayfcorepack_plugin_handle_method_call(plugin, method_call);
}

void ayfcorepack_plugin_register_with_registrar(FlPluginRegistrar* registrar) {
AyfcorepackPlugin* plugin = AYFCOREPACK_PLUGIN(
g_object_new(ayfcorepack_plugin_get_type(), nullptr));

g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
g_autoptr(FlMethodChannel) channel =
fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar),
"ayfcorepack",
FL_METHOD_CODEC(codec));
fl_method_channel_set_method_call_handler(channel, method_call_cb,
g_object_ref(plugin),
g_object_unref);

g_object_unref(plugin);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef FLUTTER_PLUGIN_AYFCOREPACK_PLUGIN_H_
#define FLUTTER_PLUGIN_AYFCOREPACK_PLUGIN_H_

#include <flutter_linux/flutter_linux.h>

G_BEGIN_DECLS

#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define FLUTTER_PLUGIN_EXPORT
#endif

typedef struct _AyfcorepackPlugin AyfcorepackPlugin;
typedef struct {
GObjectClass parent_class;
} AyfcorepackPluginClass;

FLUTTER_PLUGIN_EXPORT GType ayfcorepack_plugin_get_type();

FLUTTER_PLUGIN_EXPORT void ayfcorepack_plugin_register_with_registrar(
FlPluginRegistrar* registrar);

G_END_DECLS

#endif // FLUTTER_PLUGIN_AYFCOREPACK_PLUGIN_H_
10 changes: 10 additions & 0 deletions flutter/project_templates/linux/common/ayf-sdk-local-headers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __AYF_SDK_LOCAL_HEADERS_H__
#define __AYF_SDK_LOCAL_HEADERS_H__

#define JVX_COMPONENT_ACCESS_CALLING_CONVENTION
#include "jvx_sdk.h"
#include "jvx.h"
#include "flutter_native_host_config.h"
#include "ayfstarter-native-config.h"

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AudYoFloUiModelSpecific extends AudYoFloUiModel
'Hallo Test', "/settings/testme", "Description");

AudYoFloUiModelSpecific(String routeInit) : super(routeInit) {
textApp = 'ayfstarter';
textApp = 'starter_app';
imageNameApp =
'packages/ayfstarter/images/ayfstarter_icons/ayfstarter-logo.png';

Expand Down

0 comments on commit 214785f

Please sign in to comment.