I generating profaw
file with compiler option. If I run the executable, the executable will generate every time profraw
file. I wanted to automate this process
This way it perfectly works for executing twice the executable automatically.
add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo " 2. Execution of: ${EXECUTABLE_NAME}"
COMMAND $<TARGET_FILE:${EXECUTABLE_NAME}>
COMMAND ${CMAKE_COMMAND} -E sleep 1
COMMAND ${CMAKE_COMMAND} -E echo " 2. Execution of: ${EXECUTABLE_NAME}"
COMMAND $<TARGET_FILE:${EXECUTABLE_NAME}>
COMMAND ${CMAKE_COMMAND} -E sleep 1)
However I wanted to do run arbitrary number of times the executable so I wrote this command. However there’s 2 problems
- The command executing always twice as much the given number. For example I set SET_PROFRAW_COUNT to 5 so it will execute 10 times
- Generated profraw files are highly corrupted and non-functional
set(SET_PROFRAW_COUNT 5)
#Geneate the string for number of times executing the command
math(EXPR SET_PROFRAW_COUNT "${SET_PROFRAW_COUNT} -1") ##This is required because foreach executing 0-5 5th inclusive
set(COMMAND_LIST "")
foreach (i RANGE ${SET_PROFRAW_COUNT})
LIST(APPEND COMMAND_LIST
COMMAND ${CMAKE_COMMAND} -E echo " ${i}. Execution of: ${EXECUTABLE_NAME}"
COMMAND $<TARGET_FILE:${EXECUTABLE_NAME}>
COMMAND ${CMAKE_COMMAND} -E sleep 1)
endforeach ()
add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD ${COMMAND_LIST}