add_custom_command用于复制 *.y to *.txt文件



我正在尝试使用add_custom_command CMAKE命令将生成的*.y输出(平面Luma值,无标头信息(复制为文本文件。如何在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}")

相关内容

  • 没有找到相关文章

最新更新