Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: overriding Mac OS X libfoo.1.dylib naming convention to libfoo.so.1

Tags:

cmake

We're trying to build shared libraries using CMake on Mac OS X using the shared library naming convention used by Linux, Solaris, etc, that is, libfoo.so.1 instead of libfoo.1.dylib. This is for an internal deployment where we have an existing Linux deployment and want to model the Mac OS X deployment after it so that other tools do not have to be modified.

I am able to change .so to .dylib using

set_target_properties(OpenImageIO
                      PROPERTIES
                      SUFFIX .so)

However, I am unable to get the ordering correct. Trying

set_target_properties(OpenImageIO
                      PROPERTIES
                      OUTPUT_NAME libOpenImageIO.so.${SOVERSION})

ends up with build/macosx/libOpenImageIO/liblibOpenImageIO.so.32.1.2.0.so which suggests that OUTPUT_NAME is only for the base part of the shared library and CMake will always reverse the order of SUFFIX and VERSION.

I've searched through CMake's source code and cannot find where this code is set.

like image 331
Blair Zajac Avatar asked Feb 17 '23 12:02

Blair Zajac


1 Answers

The behaviour of putting the version name in front of the suffix .dylib is hard coded for Mac OS X in the method cmTarget::ComputeVersionedName (see the CMake source file cmTarget.cxx).

You can however trick CMake into generating the desired name by setting the target properties in the following way:

if (APPLE)
    set_property(TARGET OpenImageIO PROPERTY PREFIX "lib")
    set_property(TARGET OpenImageIO PROPERTY OUTPUT_NAME "OpenImageIO.so")
    set_property(TARGET OpenImageIO PROPERTY SUFFIX "")
    set_property(TARGET OpenImageIO PROPERTY SOVERSION "32.1.2.0")
endif()
like image 72
sakra Avatar answered Apr 19 '23 22:04

sakra