[CMake] Setting install_name on Mac OSX 10.5

Gerrick Bivins gbivins at objectreservoir.com
Tue Oct 21 10:05:07 EDT 2008


I dug around in the UseSwig.cmake file and the SWIG_ADD_MODULE macro is the
source of the problems. It removes the prefix and only creates a MODULE. I
copied the macro and modified it in my CMakeLists.txt file to simply call
add_library with the SHARED option as listed below and install_name is
defined properly:
#
# Create Swig shared module
#
MACRO(SWIG_ADD_SHARED_MODULE name language)
  SWIG_MODULE_INITIALIZE(${name} ${language})
  SET(swig_dot_i_sources)
  SET(swig_other_sources)
  FOREACH(it ${ARGN})
    IF(${it} MATCHES ".*\\.i$")
      SET(swig_dot_i_sources ${swig_dot_i_sources} "${it}")
    ELSE(${it} MATCHES ".*\\.i$")
      SET(swig_other_sources ${swig_other_sources} "${it}")
    ENDIF(${it} MATCHES ".*\\.i$")
  ENDFOREACH(it)

  SET(swig_generated_sources)
  FOREACH(it ${swig_dot_i_sources})
    SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source ${it})
    SET(swig_generated_sources ${swig_generated_sources}
"${swig_generated_source}")
  ENDFOREACH(it)
  GET_DIRECTORY_PROPERTY(swig_extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
  SET_DIRECTORY_PROPERTIES(PROPERTIES
    ADDITIONAL_MAKE_CLEAN_FILES
"${swig_extra_clean_files};${swig_generated_sources}")
  ADD_LIBRARY(${SWIG_MODULE_${name}_REAL_NAME}
    SHARED                   <===========change to generate shared library
    ${swig_generated_sources}
    ${swig_other_sources})
  ##SET_TARGET_PROPERTIES(${SWIG_MODULE_${name}_REAL_NAME}
  ##  PROPERTIES PREFIX "")          <==leave the prefix in tact
ENDMACRO(SWIG_ADD_SHARED_MODULE)

Not sure if this is the appropriate way to handle this or if the UseSwig
should define a different macro. It looks like this was created for a
specific language (tcl or python maybe) but I'm just guessing.

Gerrick



On 10/20/08 5:23 PM, "Gerrick Bivins" <gbivins at objectreservoir.com> wrote:

> Hi Mike,
> The generated jni libraries have no prefix and the ".so" suffix.
> I can only find two macros defined for swig but that could be just be my
> ignorance:
> 
> SWIG_ADD_MODULE(name language interfacefile)  ==> generate a module named
> "name" for language "language" given the swig interface file "interfacefile)
> 
> SWIG_LINK_LIBRARIES( name linklib1 linklib2...) ==> link the module "name"
> to linklib1,linklib2...etc
> 
> I was told in previous post that the .so suffix didn't matter, but with java
> it seems to matter.
> 
> Gerrick
> 
> On 10/20/08 5:12 PM, "Michael Jackson" <mike.jackson at bluequartz.net> wrote:
> 
>> I can suggest all sorts of ways to set the install_name of the
>> libraries BUT I would rather figure out _why_ the swig generated
>> libraries are getting the "../../lib" prefix in the first place.
>> 
>> I don't have any experience with swig so I can only guess at this
>> point. Does swig have its own settings for Install_name on OS X?
>> 
>> Also, which libraries are not correct:
>>    The c/c++ libraries?
>>    The generated jni libraries?
>> 
>> All? Both?
>> 
>> _________________________________________________________
>> Mike Jackson                  mike.jackson at bluequartz.net
>> BlueQuartz Software                    www.bluequartz.net
>> Principal Software Engineer                  Dayton, Ohio
>> 
>> On Oct 20, 2008, at 5:43 PM, Gerrick Bivins wrote:
>> 
>>> Hello all,
>>> I¹m trying to use swig (SWIG_ADD_MODULE, SWIG_LINK_LIBRARIES) to
>>> generate java bindings for a library (contains a couple of sub
>>> libraries, similar to VTK¹s setup). I haven¹t been able to load the
>>> generated shared libraries.
>>> There were a couple of issues:
>>> € My jvm won¹t load shared libraries unless they are named
>>> ³lib{libName}.dylib². Default creates {libName}.so. I was able to
>>> modify the properties of my of my targets to change the prefix to
>>> ³lib² and the suffix to ³.dylib² and the libs began to load but
>>> € My jvm won¹t load the generated shared libraries because the
>>> install_name  is set to ³../../lib{libName}.dylib. If I manually
>>> change them to simply be lib{libName}.dylib, the shared libs load.
>>> 
>>> I looked at this link:
>>> http://www.cmake.org/pipermail/cmake/2006-October/011530.html
>>> 
>>>  And tried setting the ³INSTALL_NAME_DIR² property to ³², but this
>>> didn¹t work.
>>> Any suggestions? I¹m trying to simply create the shared libraries,
>>> not bundles or  frameworks.
>>> I¹m using cmake 2.6.2 on Mac OSX 10.5.
>>> Gerrick
>>> 
>>> _______________________________________________
>>> CMake mailing list
>>> CMake at cmake.org
>>> http://www.cmake.org/mailman/listinfo/cmake
>> 
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
> 
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list