(Note that I changed my answer after studying the problem due to Florian's comment. More about editing below)
The execute_process documentation clearly states that it does not use an intermediate shell, so redirection operators do not work there.
But this is not the case for add_custom_command . The redirection should work there as expected. [EDIT] The reason this sometimes doesnβt work is because of some unsuccessful combination of the CMake generator, the VERBATIM and (space) a space between > and the file name.
It turned out that if you make sure that between > and the name of the file with which it works in most cases, there is a space even with VERBATIM :
add_custom_command(OUTPUT ${some-file} COMMAND cmake --version > ${some-file} VERBATIM
A note on an alternative solution: I used to think that add_custom_command , just like execute_process does not use an intermediate shell, so I suggested calling a CMake script that contains the execute_process command, which launches a valid command, redirecting its output using the OUTPUT_FILE option.
If for some reason the solution above is still not suitable for you, try an alternative solution using ExecuteProcessWrapper.cmake
tamas.kenez
source share