[CMake] add_custom_target: Compiling a Matlab function into a binary with mcc

Ramón Casero Cañas rcasero at gmail.com
Sat Jul 26 06:18:42 EDT 2014


Dear all,

I have a Matlab function vmu2png.m (this is the source code), and I'd like
to compile it into an executable/binary using a CMake project (cmake
2.8.11.2 on linux).

To compile the function, I need to run Matlab's mcc program, e.g. "mcc
-m vmu2png.m" from CMake. This will produce two files: run_vmu2png.sh and
vmu2png.

So far, I have managed to do it with add_custom_command() and
add_custom_target(), but this makes the function compile every time I use
"make", regardless of whether vmu2png.m has been modified.

My code is

  # vmu2png
  add_custom_command(
    OUTPUT  run_vmu2png.sh vmu2png
    COMMAND ${MATLAB_ROOT}/bin/mcc
    ARGS    -m vmu2png.m
    DEPENDS vmu2png.m
    COMMENT "Compiling vmu2png.m into a binary"
    )
  add_custom_target(do_vmu2png ALL
    DEPENDS run_vmu2png.sh vmu2png
    SOURCES vmu2png.m
    )

If I remove ALL from add_custom_target(), then this compilation never
happens.

Is there a way to integrate this kind of compilation nicely with CMake?
That is, I'd like it to happen only when run_vmu2png.sh or vmu2png are
missing, or when the source file has been modified.

Best regards,

Ramon.



-- 
Dr. Ramón Casero Cañas

Institute of Biomedical Engineering
Department of Engineering Science, University of Oxford
Old Road Campus Research Building, Headington
Oxford
OX3 7DQ
UK

tlf         +44 (0) 1865 617716
twitter   @Ramon_Casero
web      http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140726/aaa30594/attachment.html>


More information about the CMake mailing list