On 26.07.2014 12:18, Ramón Casero Cañas wrote:

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.


Try using full paths for the OUTPUTs in the custom command and the DEPENDS in your custom target (e.g. "${CMAKE_CURRENT_BINARY_DIR}/run_vmu2png.sh"). The custom commands will keep rerunning when the actual outputs do not coincide with the declared outputs.

Nils
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to