[CMake] Platform specific output file advice
Tristan Carel
tristan.carel at gmail.com
Tue Sep 18 07:42:10 EDT 2007
On 9/16/07, Alan W. Irwin <irwin at beluga.phys.uvic.ca> wrote:
> On 2007-09-16 13:23+1000 Nicholas Yue wrote:
>
> > Hi,
> >
> > I have been successfully using CMake with SWIG to compile language
> > extensions for Java/Python/Ruby on Linux.
> >
> > -- for RUBY
> > SWIG_ADD_MODULE ( ribclient ruby ribclient.i ParameterList.cpp )
> > SWIG_LINK_LIBRARIES ( ribclient utils 3delight ruby )
> >
> > -- for Java
> > SWIG_ADD_MODULE ( ribclient java RIBClient.i ParameterList.cpp )
> > SWIG_LINK_LIBRARIES ( ribclient utils 3delight )
> >
> > The build produces *.so file on both Linux and OSX but on OSX, Ruby
> > extension must end with .bundle and Java extension must be prefix with
> > 'lib" and postfix with ".jnilib"
> >
> > Manually renaming the file works as the content has been correctly
> > compile by the Makefiles generated by CMake.
> >
> > My question is should this be abstracted out into CMake as it should
> > handle cross platform build or should I use/write a macro to do that?
> >
> > If I have to manually intervene, could someone point me to an
> > example of how one should rename a given file from within a CMake
> > configuration file like CMakeLists.txt.
>
> If its a target (sounds like the case here) then you can use
> SET_TARGET_PROPERTIES. From the documentation of that command....
>
> "The PREFIX and SUFFIX properties override the default target
> name prefix (such as "lib") and suffix (such as ".so")"
For Java, you can use the following piece of code:
## The library name expected by the JNI relative to the system:
## MacOS : libLIBRARY.jnilib
## Windows: LIBRARY.dll
## Linux : libLIBRARY.so
##
## where LIBRARY is used in java to load the library:
## System.loadLibrary("LIBRARY");
IF(APPLE)
SET_TARGET_PROPERTIES(${SWIG_MODULE_<module_name>_REAL_NAME} PROPERTIES
PREFIX "lib" SUFFIX ".jnilib")
ELSEIF(WIN32)
SET_TARGET_PROPERTIES(${SWIG_MODULE_<module_name>_REAL_NAME} PROPERTIES
PREFIX "" SUFFIX ".dll")
ELSEIF(UNIX)
SET_TARGET_PROPERTIES(${SWIG_MODULE_<module_name>_REAL_NAME} PROPERTIES
PREFIX "lib" SUFFIX ".so")
ENDIF(APPLE)
For Python wrappers, there is no need to rename the target under OSX,
Linux, and Windows.
For Ruby, I have never tried!
--
Tristan Carel
Music with dinner is an insult both to the cook and the violinist.
http://www.tristancarel.com
More information about the CMake
mailing list