I have a (simplified) CMAKE file like so:
cmake_minimum_required( VERSION 3.6 ) function(BUILD_SIMULINK model) set(OUTPUT_FILE ${model}.dll) set(SOURCE_FILE ${model}.slx) set(EXECUTE_COMMAND matlab -nojvm -nodisplay -nodesktop -nosplash -wait -r "rtwbuild(${model})" ) add_custom_target( ${model} ALL DEPENDS ${OUTPUT_FILE} ) add_custom_command( COMMAND ${EXECUTE_COMMAND} DEPENDS ${SOURCE_FILE} OUTPUT ${OUTPUT_FILE} ) install( TARGETS ${OUTPUT_FILE} DESTINATION lib ) endfunction(BUILD_SIMULINK) project(SimulinkBuild VERSION 1.0.0) build_simulink( model1 ) build_simulink( model2 ) build_simulink( model3 ) ... build_simulink( modeln ) # Arbitrarily large number of models My problem is that it takes several hours to do a clean build because I am calling one command at a time, using only one core at a time. I'd like to build my files in parallel, taking advantage of the multiple cores on my machine. How can we achieve executing parallel commands from cmake?
When I build I do this:
cmake .. cmake --build . --target install
makehas-joption for that case.cmake --buildto invoke the build too. I think I just passcmake --build . --target install --j4when using make. However, I'm using visual studio to test this right now which requires a/MPdirective in the command-line options. I'm hoping that there is a tool-independent way to do both./MPswitch, but I'm not using MSVC, I'm executing my own commands so this doesn't really work.cmake --build . --target install -- /mfor visual studio andcmake --build . --target install -- jfor make/ninja. This solves my issue. Though it would still be nice to have a generator-independant solution.