Relocatable module of image loader
authorNicholas Guriev <guriev-ns@ya.ru>
Wed, 16 Oct 2019 18:16:12 +0000 (21:16 +0300)
committerJongmin Lee <jm105.lee@samsung.com>
Mon, 11 Nov 2019 20:58:10 +0000 (05:58 +0900)
CMakeLists.txt
cmake/config.h.in
meson.build
meson_options.txt
src/vector/stb/CMakeLists.txt
src/vector/stb/meson.build
src/vector/vimageloader.cpp

index 82c1a3f..ead190e 100644 (file)
@@ -36,7 +36,10 @@ option(LOTTIE_TEST "Build LOTTIE AUTOTESTS" OFF)
 option(LOTTIE_CCACHE "Enable LOTTIE ccache SUPPORT" OFF)
 option(LOTTIE_ASAN "Compile with asan" OFF)
 
-CONFIGURE_FILE(${CMAKE_CURRENT_LIST_DIR}/cmake/config.h.in config.h)
+set(LOTTIE_MODULE_PATH "${CMAKE_SHARED_LIBRARY_PREFIX}rlottie-image-loader${CMAKE_SHARED_LIBRARY_SUFFIX}"
+    CACHE STRING "Absolute or relative path to dynamic loader plugin.")
+
+configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/config.h.in config.h)
 
 target_include_directories(rlottie
     PRIVATE
index e120bba..ca42a9e 100644 (file)
@@ -4,6 +4,8 @@
 #define LOTTIE_IMAGE_MODULE_SUPPORT
 #endif
 
+#define LOTTIE_IMAGE_MODULE_PLUGIN "@LOTTIE_MODULE_PATH@"
+
 #cmakedefine LOTTIE_THREAD
 
 #ifdef LOTTIE_THREAD
index e4d1669..f8374e0 100644 (file)
@@ -18,6 +18,25 @@ endif
 
 if get_option('module') == true
     config_h.set10('LOTTIE_IMAGE_MODULE_SUPPORT', true)
+
+    if meson.get_compiler('cpp').get_id() != 'msvc'
+      lib_prefix = 'lib'
+    else
+      lib_prefix = ''
+    endif
+    if host_machine.system() == 'darwin'
+      lib_suffix = '.dylib'
+    elif host_machine.system() == 'windows'
+      lib_suffix = '.dll'
+    else
+      lib_suffix = '.so'
+    endif
+    if get_option('moduledir') != ''
+      config_h.set_quoted('LOTTIE_IMAGE_MODULE_PLUGIN',
+        get_option('prefix') / get_option('moduledir') / lib_prefix + 'rlottie-image-loader' + lib_suffix)
+    else
+      config_h.set_quoted('LOTTIE_IMAGE_MODULE_PLUGIN', lib_prefix + 'rlottie-image-loader' + lib_suffix)
+    endif
 endif
 
 if get_option('cache') == true
index deafc02..c81dfbc 100644 (file)
@@ -13,6 +13,10 @@ option('module',
    value: true,
    description: 'Enable module support in rlottie')
 
+option('moduledir',
+   type: 'string',
+   description: 'Dynamic plugins directory')
+
 option('log',
    type: 'boolean',
    value: false,
index dd96ec5..54b6bc1 100644 (file)
@@ -5,12 +5,21 @@ if(LOTTIE_MODULE)
     target_compile_options(rlottie-image-loader PRIVATE
                            -fvisibility=hidden
                           )
+
+    get_filename_component(LOTTIE_MODULE_FILENAME ${LOTTIE_MODULE_PATH} NAME)
+    get_filename_component(LOTTIE_MODULE_DIR ${LOTTIE_MODULE_PATH} DIRECTORY)
+    if (NOT LOTTIE_MODULE_DIR)
+        set(LOTTIE_MODULE_DIR ${LIB_INSTALL_DIR})
+    endif()
+
     set_target_properties(rlottie-image-loader PROPERTIES
                           DEFINE_SYMBOL LOT_BUILD
+                          PREFIX ""
+                          SUFFIX ""
+                          OUTPUT_NAME ${LOTTIE_MODULE_FILENAME}
                          )
     install(TARGETS rlottie-image-loader
-            LIBRARY DESTINATION ${LIB_INSTALL_DIR}
-            ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
+            LIBRARY DESTINATION ${LOTTIE_MODULE_DIR}
            )
 else()
     target_sources(rlottie
index e04bde7..49be076 100644 (file)
@@ -2,10 +2,12 @@
 source_file = ['stb_image.cpp']
 
 if get_option('module') == true
+    rlottie_image_loader_dir = get_option('moduledir') != '' ? get_option('moduledir') : get_option('libdir')
     rlottie_image_loader_lib = shared_library('rlottie-image-loader',
                                               source_file,
                                               include_directories : [include_directories('.'), config_dir],
                                               install : true,
+                                              install_dir : rlottie_image_loader_dir,
                                               cpp_args : compiler_flags,
                                               gnu_symbol_visibility : 'hidden',
                                              )
index 03c269a..c2446be 100644 (file)
@@ -1,13 +1,14 @@
 #include "vimageloader.h"
 #include "config.h"
 #include "vdebug.h"
-#ifndef _WIN32
-#include <dlfcn.h>
-#else
-#include <windows.h>
-#endif
 #include <cstring>
 
+#ifdef _WIN32
+# include <windows.h>
+#else
+# include <dlfcn.h>
+#endif  // _WIN32
+
 using lottie_image_load_f = unsigned char *(*)(const char *filename, int *x,
                                                int *y, int *comp, int req_comp);
 using lottie_image_load_data_f = unsigned char *(*)(const char *data, int len,
@@ -36,11 +37,11 @@ struct VImageLoader::Impl {
     lottie_image_load_data_f imageFromData{nullptr};
 
 #ifdef LOTTIE_IMAGE_MODULE_SUPPORT
-#ifdef _WIN32
+# ifdef _WIN32
     HMODULE dl_handle{nullptr};
     bool    moduleLoad()
     {
-        dl_handle = LoadLibraryA("librlottie-image-loader.dll");
+        dl_handle = LoadLibraryA(LOTTIE_IMAGE_MODULE_PLUGIN);
         return (dl_handle == nullptr);
     }
     void moduleFree()
@@ -56,7 +57,7 @@ struct VImageLoader::Impl {
         imageFromData = reinterpret_cast<lottie_image_load_data_f>(
                         GetProcAddress(dl_handle, "lottie_image_load_from_data"));
     }
-#else
+# else  // _WIN32
     void *dl_handle{nullptr};
     void  init()
     {
@@ -72,22 +73,13 @@ struct VImageLoader::Impl {
     {
         if (dl_handle) dlclose(dl_handle);
     }
-#ifdef __APPLE__
     bool moduleLoad()
     {
-        dl_handle = dlopen("librlottie-image-loader.dylib", RTLD_LAZY);
+        dl_handle = dlopen(LOTTIE_IMAGE_MODULE_PLUGIN, RTLD_LAZY);
         return (dl_handle == nullptr);
     }
-#else
-    bool moduleLoad()
-    {
-        dl_handle = dlopen("librlottie-image-loader.so", RTLD_LAZY);
-        return (dl_handle == nullptr);
-    }
-#endif
-#endif
-#else
-    void *dl_handle{nullptr};
+# endif  // _WIN32
+#else  // LOTTIE_IMAGE_MODULE_SUPPORT
     void  init()
     {
         imageLoad = lottie_image_load;
@@ -96,7 +88,7 @@ struct VImageLoader::Impl {
     }
     void moduleFree() {}
     bool moduleLoad() { return false; }
-#endif
+#endif  // LOTTIE_IMAGE_MODULE_SUPPORT
 
     Impl()
     {