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

Alexander Neundorf a.neundorf-work at gmx.net
Thu Jun 14 08:24:57 EDT 2007


On Thursday 14 June 2007 00:55, Clark J. Wang wrote:
> 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}")

You could also have a look at Modules/CMakeGenericSystem.cmake and use one of 
the variables defined there.

Alex


More information about the CMake mailing list