[CMake] How to get suffix of shared library file?

Clark J. Wang dearvoid at gmail.com
Thu Jun 14 00:55:46 EDT 2007


On 6/14/07, Clark J. Wang <dearvoid at gmail.com> wrote:
>
> On 6/14/07, Alan W. Irwin <irwin at beluga.phys.uvic.ca> wrote:
> >
> > On 2007-06-14 08:58+0800 Clark J. Wang wrote:
> >
> > > Shared libs have different suffixes on different OSes. For example on
> > Linux
> > > the suffix is `.so' and on Mac OS X it's `.dylib'. I want to use
> > `dlopen()'
> > > in my code so I want to get the suffix and then define it in a header
> > file.
> > > Can I do that in CMake? And how?
> >
> > You could write a CMake test to create a shared object, gets its full
> > name,
> > and parse for the suffix.  However, that is a non-trivial amount of
> > cmake
> > script development (at least it would be for me) so let me discuss an
> > alternative that might work a little easier for you.
>
>
> I'll try to write a script to do that later.
>

It's not so difficult as I imanged:

PROJECT(hello)
ADD_LIBRARY(hello SHARED hello.c)
GET_TARGET_PROPERTY(fullPath hello LOCATION)
GET_FILENAME_COMPONENT(suffix ${fullPath} EXT)
MESSAGE("suffix = ${suffix}")

To define the suffix in a header file we can call CONFIGURE_FILE.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070614/4d59eb34/attachment.html


More information about the CMake mailing list