Error in condition check inside add_custom_command of CMAKE

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.

unit-testing
makefile
cmake
ctest
add-custom-command
asked on Stack Overflow Jul 7, 2020 by jailaxmi k • edited Jul 7, 2020 by jailaxmi k

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0