![](/img/trans.png)
[英]add_custom_command depending on another add_custom_command
[英]add_custom_command for copy *.y to *.txt file
我試圖使用add_custom_command
CMake命令將生成的*.y
輸出(平面亮度值,無標題信息)復制到文本文件。 如何在add_custom_command
添加copy
命令?
我想將生成的*.y
輸出重定向到文本文件。 但是>
重定向沒有add_custom_command
不能直接在CMake中運行,所以我嘗試使用add_custom_command
。 在這里,我想使用copy
而不是>
,但是在兩種情況下,我仍然無法將*.y
輸出重定向或復制到*.txt
文件。
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()
運行此代碼后,我想生成兩個文本文件,上述CMake更改仍然無法實現。
您的add_custom_command
調用中的OUTPUT
指令應指定由定制命令生成的文件(即輸出文件),而不是輸入文件。 這是代碼中的固定代碼段:
# Here I have added my code to redirect my *.y output to *.txt file
add_custom_command(
OUTPUT ${output_file_txt}
${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_txt}
${CMAKE_COMMAND} -E copy ${reference_file} ${reference_file_txt}
MAIN_DEPENDENCY ${reference_file}
COMMENT "Redirecting ${reference_file} to ${reference_file_txt}")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.