[CMake] Loading Plugins

J Decker d3ck0r at gmail.com
Fri Oct 31 17:48:07 EDT 2014


really nothing at all to do with cmake; a couple macros and you can support
cross-platform... a few less and you can init interfaces pretty easily....
at the end of init or during early discovery of functions, if they fail you
can fillthe interface with static methods or return a different
interface....

code part of
https://code.google.com/p/c-system-abstraction-component-gui/source/browse/src/streamlib/ffmpeg/ffmpeg_interface.c


#ifdef WIN32
#define lib_format WIDE("avformat-56.dll")
#else

#if defined( __ANDROID__) || defined( __LINUX__ )
#define lib_format WIDE("libavformat.so")
#endif

static struct fmpeg_interface
{
#define declare_func(a,b,c) a (CPROC *b) c
#define setup_func(lib, a,b,c) if( ffmpeg.b=(a(CPROC*)c)LoadFunction( lib,
_WIDE(#b) ) )

declare_func( void, av_register_all,(void) );
declare_func( int, avformat_open_input, (AVFormatContext **ps, const char
*filename, AVInputFormat *fmt, AVDictionary **options) );
/*...*/
} ffmpeg;


void Init( void )
{
 setup_func( lib_format, void, av_register_all,(void) );
setup_func( lib_format, int, avformat_open_input, (AVFormatContext **,
const char *, AVInputFormat *, AVDictionary **) );
setup_func( lib_format, int, avformat_close_input, (AVFormatContext **) );
 }

void LaterUsage( void )
{
ffmpeg.av_register_all();
}

void LaterUsageAsPointer( void )
{
struct fmpeg_interface interface = &ffmpeg; /* or from some other function
*/
interface->av_register_all();
}

if you have intellisense, makes for nice popups of available methods.

On Fri, Oct 31, 2014 at 11:24 AM, Bradley Lowekamp <blowekamp at mail.nih.gov>
wrote:

> Hello,
>
> Yes, this can be done with ITK's object factory mechanism. I would study
> how it's done with ITK's ImageIO plugin mechanism[1], then figure out how
> to adapt the same framework for your interface.
>
> Brad
>
> [1] http://www.itk.org/Wiki/Plugin_IO_mechanisms
>
>
>
> On Oct 31, 2014, at 2:20 PM, Aaron Boxer <boxerab at gmail.com> wrote:
>
> > Hello!
> >
> > I have a C CMake project, and I would like to add the following feature:
> >
> > 1) define an interface for a second dynamic library
> > 2) look in a specified folder at runtime, and try to load this library
> > 3) if loading fails, then get notified of this fact, so that I can use
> statically linked fall-back routines in the parent project.
> >
> > Is this possible?  Any ideas or advice would be greatly appreciated.
> >
> > Thanks,
> > Aaron
> >
> >
> > --
> >
> > Powered by www.kitware.com
> >
> > Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
> >
> > Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
> >
> > CMake Support: http://cmake.org/cmake/help/support.html
> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
> > CMake Training Courses: http://cmake.org/cmake/help/training.html
> >
> > Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> >
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/cmake
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141031/17562246/attachment.html>


More information about the CMake mailing list