I am trying to copy the generated *.y
output (plane luma values, no header info) to text file using the add_custom_command
CMake command. How can I add the copy
command in add_custom_command
?
I want to redirect the generated *.y
output to text file. But the >
redirection was not running directly in CMake without add_custom_command
, so I tried to use add_custom_command
. Here I thought to use copy
instead of >
,
but still in both cases I am not able to redirect or copy the *.y
output to *.txt
file.
macro(COMPARE file function type type_out)
get_filename_component(main_base_name ${file} NAME_WE)
set(main_base_name_mangled ${main_base_name}_${function}_${type_out})
# file generated by simulation
set(output_file ${function}_${type_out}_0_opt.y)
# reference file generated by generator
set(reference_file ${function}_${type_out}_0_ref.y)
set(output_file_txt ${function}_${type_out}_0_opt.txt)
set(reference_file_txt ${function}_${type_out}_0_ref.txt)
add_custom_target(compare_${main_base_name_mangled}
COMMAND cmp ${reference_file} ${output_file}
COMMENT "Comparing ${reference_file} ${output_file}")
add_dependencies(compare_${main_base_name_mangled}
simulate_${main_base_name_mangled})
add_test(NAME Compare_${main_base_name_mangled}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}
--target compare_${main_base_name_mangled})
# add dependency to compile first
set_tests_properties(Compare_${main_base_name_mangled}
PROPERTIES REQUIRED_FILES ${reference_file})
set_tests_properties(Compare_${main_base_name_mangled}
PROPERTIES REQUIRED_FILES ${output_file})
# test Compare_X depends on Simulate_X
set_tests_properties(Compare_${main_base_name_mangled}
PROPERTIES DEPENDS Simulate_${base_name_mangled})
#Here I have added my code to redirect my *.y output to *.txt file
add_custom_command(
OUTPUT ${output_file}
${CMAKE_COMMAND} -E copy ${output_file} ${output_file_txt}
MAIN_DEPENDENCY ${output_file}
COMMENT "Redirecting ${output_file} to ${output_file_txt}")
add_custom_command(
OUTPUT ${reference_file}
${CMAKE_COMMAND} -E copy ${reference_file} ${reference_file_txt}
MAIN_DEPENDENCY ${reference_file}
COMMENT "Redirecting ${reference_file} to ${reference_file_txt}")
endmacro()
After running this code, I want to generate two text files, which is still not possible with above CMake changes.