[Cmake] Using CMake to build MEX files for Matlab

gareth.jones at stud.man.ac.uk gareth.jones at stud.man.ac.uk
Wed Jan 8 11:17:13 EST 2003


Andy,

Thank you for the suggestion, but I don't think it solves the problem
because it still leaves the MEX linker arguments being passed to
non-MEX share libraries.  I think this is a more general problem than
just for MEX files because any time one builds more than one shared
library in a directory one may want to pass seperate linker arguments,
perhaps to set the versioning for the symbols or for some other
reason.

Also, the reason for preferring changing the _LIBRARY_SUFFIX and
_PREFIX is that adding the custom command means that MEX file does not
get deleted by "make clean" -- adding another custom command for the
"clean" target doesn't seem to solve this.  (I'm not sure about what
happens when installing because I've not got that far yet.)

I would be interested to know the easy way with CMake 1.6 because that
is what I am using.  Creating a MEX file is sufficiently involved that
it makes sense to use a macro, which I believe are not supported in
previous versions of CMake.

Gareth Jones

Andy Cedilnik <andy.cedilnik at kitware.com> writes:

> If everything else fails, you can always do this:
[use ADD_CUSTOM_COMMAND to copy libfoo.so to foo.mex]
> This should work on all platforms.
> Starting with CMake 1.6, there are easier way of doing that, but I would
> start with this.
...
>> It is possible to build MEX files (at least on linux) by setting
>> CMAKE_SHARED_LIBRARY_SUFFIX and _PREFIX to "" and ".mexglx", but this
>> causes problems if other, ordinary, libraries are build in the same
>> CMakeLists.txt.  I know that it is possible to use ADD_CUSTOM_COMMAND
>> to copy the library but this does not seem particularly elegant and it
>> prevents both libfoo.so and foo.mex being built in the same directory.
>>
>> I've used CMAKE_SHARED_LINKER_FLAGS to add the MEX specific linker
>> flags but again this is bad because it is used by all shared objects
>> (and doubly bad because the MEX flags get added to the variable so if
>> two MEX files are compiled then the linker presumably gets the options
>> twice).
>>
>> In summary, what I want is a way to specify the precise output name
>> for a single library target, and to specify link options on a
>> per-target basis rather than globally.  Is there any way to do this in
>> CMake as it stands?  



More information about the CMake mailing list