[CMake] Cmake + Matlab mex

Brad King brad.king at kitware.com
Mon Oct 16 19:00:53 EDT 2006


Wojciech Jarosz wrote:
> I saw a couple questions regarding this in the archives from a few
> years, but no answers.
> 
> I am using CMake for my project, and would now like to write a matlab
> mex function which would use my C/C++ code base. I'd like to have the
> CMake infrastructure figure out the correct -I,-L,-l flags to pass to
> the mex compiler so everything compiles/links correctly. Has anyone done
> this before? I'm primarily using Linux.

FIND_PACKAGE(Matlab)
INCLUDE_DIRECTORIES(${MATLAB_INCLUDE_DIR})
ADD_LIBRARY(mymex MODULE mymex.c)
TARGET_LINK_LIBRARIES(mymex ${MATLAB_LIBRARIES})

See also "bin/cmake --help-module FindMatlab".

It looks like the matlab module is a bit out of date so let us know if
you have problems.

-Brad


More information about the CMake mailing list