0

I am trying to write unit test cases using CMAKE ctest .

I want to do unit test on my custom add and inverse function.

The difference between add and inverse test cases

  1. add is using two inputs where as inverse is using single input
  2. Address of the first input for both the test case is different

snippshort of my cmake file is showed below :

  add_custom_command(
    OUTPUT ${output_file_y} ${output_file_txt}
    COMMAND ${MY_EXECUTABLE}
    ARGS
     -lh ${bin_file} 0x10000000
     if((${function} STREQUAL "add"))
      -lh ${input_file0} 0x10100000
      -lh ${input_file1} 0x10200000 
     elseif((${function} STREQUAL "inverse"))
      -lh ${input_file0} 0x10c00000
     endif()
      ${options} 
     -outfile ${output_file_y}
     > ${output_file_txt}
    MAIN_DEPENDENCY ${bin_file}
    DEPENDS ${map_file} ${input_file0}
    COMMENT "Executing ${base_name_mangled}"
  )

After doing this I got below Error:

/bin/sh: 1: Syntax error: "(" unexpected ninja: build stopped:

subcommand failed.

Temporary Fixed:

if((${function} STREQUAL "add"))      
      add_custom_command(
        OUTPUT ${output_file_y} ${output_file_txt}
        COMMAND ${MY_EXECUTABLE}
        ARGS
         -lh ${bin_file} 0x10000000
         -lh ${input_file0} 0x10100000
         -lh ${input_file1} 0x10200000 
          ${options} 
         -outfile ${output_file_y}
         > ${output_file_txt}
        MAIN_DEPENDENCY ${bin_file}
        DEPENDS ${map_file} ${input_file0}
        COMMENT "Executing ${base_name_mangled}"
      )
elseif((${function} STREQUAL "inverse"))
      add_custom_command(
        OUTPUT ${output_file_y} ${output_file_txt}
        COMMAND ${MY_EXECUTABLE}
        ARGS
         -lh ${bin_file} 0x10000000
         -lh ${input_file0} 0x10c00000
          ${options} 
         -outfile ${output_file_y}
         > ${output_file_txt}
        MAIN_DEPENDENCY ${bin_file}
        DEPENDS ${map_file} ${input_file0}
        COMMENT "Executing ${base_name_mangled}"
      )
endif()

But in temporary Fixed,it has more copy & paste code .I want to avoid this and combine both the add_custom_command together.

Is there any way to do so.

jailaxmi k
  • 89
  • 3
  • 11
  • In CMake you cannot use commands inside other command's arguments. See the duplicate question about conditional command's arguments. – Tsyvarev Jul 07 '20 at 13:16
  • I have checked the link of earlier question which is answered. But my query is that can I use some thing like this outside add_custom_command command : if((${function} STREQUAL "add")) set(INPUT_LIST -lh ${input_file0} 0x10100000 -lh ${input_file1} 0x10200000 ) elseif((${function} STREQUAL "inverse")) set(INPUT_LIST -lh ${input_file0} 0x10c00000)) endif() – jailaxmi k Jul 07 '20 at 13:28
  • Yes, you may use this approach. It is described in the second snipped in the duplicate question (not in the answer to it!). – Tsyvarev Jul 07 '20 at 13:31

0 Answers0