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