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

Clark J. Wang dearvoid at gmail.com
Wed Jun 13 21:21:16 EDT 2007


On 6/14/07, Brandon Van Every <bvanevery at gmail.com> wrote:
>
> On 6/13/07, Clark J. Wang <dearvoid at gmail.com> 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?
>
> The docs for SET_TARGET_PROPERTIES talk about the SUFFIX property.
> You can get any of those properties using GET_TARGET_PROPERTIES.


I've tried GET_TARGET_PROPERTY but it does not work. The SUFFIX property
returns NOTFOUND unless we explicitly set it by calling
SET_TARGET_PROPERTIES. Take the following CMakeLists.txt as an example:

PROJECT(hello)

ADD_LIBRARY(hello SHARED hello.c)

GET_TARGET_PROPERTY(suffix hello SUFFIX)
MESSAGE("suffix = ${suffix}")

SET_TARGET_PROPERTIES(hello PROPERTIES SUFFIX .so)
GET_TARGET_PROPERTY(suffix hello SUFFIX)
MESSAGE("suffix = ${suffix}")

The output of cmake:

$ cmake .
suffix = NOTFOUND
suffix = .so
-- Configuring done
-- Generating done
-- Build files have been written to: /root/cmake/lib_suffix/build
$

I suppose the relationship between GET_TARGET_PROPERTIES and
> SET_TARGET_PROPERTIES is not exactly clear in the docs, although one
> might infer it.
>
>
> Cheers,
> Brandon Van Every
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070614/8dd6bd76/attachment.html


More information about the CMake mailing list