@@ -218,6 +218,11 @@ set(run_tests evp_fetch
218218              x509storeissuer
219219              CACHE  STRING  "List of tests to run" )
220220
221+ set (run_add_version_dep
222+     ON 
223+     CACHE  BOOL  "Whether to print version information on run "  +
224+                "(call all the tests with -V option before the main run)" )
225+ 
221226# Per-test options, the format: test option values 
222227set (run_evp_fetch_pqs
223228    evp_fetch ""  ""  "-q" 
@@ -300,6 +305,15 @@ add_custom_target(run
300305                  COMMENT  "Run perf tests" 
301306                  WORKING_DIRECTORY  "${CMAKE_CURRENT_BINARY_DIR} " )
302307
308+ # Version target 
309+ add_custom_target (run-version 
310+                   COMMENT  "Get version information for perf tests" 
311+                   WORKING_DIRECTORY  "${CMAKE_CURRENT_BINARY_DIR} " )
312+ if  (run_add_version_dep)
313+     add_dependencies (run run-version )
314+ endif ()
315+ 
316+ 
303317if (WIN32 )
304318    # Prepare the PATH value for the generated batch files on Windows 
305319    get_target_property (crypto_path OpenSSL::Crypto IMPORTED_LOCATION )
@@ -309,6 +323,75 @@ if(WIN32)
309323    set (win32_path "${crypto_path} ;${ssl_path} ;%PATH%" )
310324endif ()
311325
326+ # 
327+ # gen_run_target(<cmd> <test> [VAR <var>] [NAME <name>]) 
328+ # 
329+ # Generates a target that runs <cmd> and depends on target <test> and sets 
330+ # <var> to the target's name. 
331+ # 
332+ function (gen_run_taget _CMD _TEST)
333+     include (CMakeParseArguments)
334+ 
335+     set (_Options "" )
336+     set (_OneValueArgs VAR NAME )
337+     set (_MultiValueArgs "" )
338+     cmake_parse_arguments (GEN_RUN_TARGET
339+         "${_Options} " 
340+         "${_OneValueArgs} " 
341+         "${_MultiValueArgs} " 
342+         ${ARGN} 
343+     )
344+ 
345+     # 
346+     # In order to execute the command on Windows, we need 
347+     # to add OPENSSL_ROOT_DIR to PATH variable so runtime 
348+     # linker can find OpenSSL 's .dll files.  Adjusting PATH on Windows 
349+     # requires us to generate a .bat file with two commands: 
350+     #    set PATH=c:\...\OPENSSL_ROOT_DIR;%PATH% 
351+     #    command_to_exec with_options 
352+     # 
353+     string (REGEX  REPLACE "  *"  ";"  cmd "${_CMD} " )
354+     string (REGEX  REPLACE "[^0-9A-Za-z]"  "-"  cmd_target_name "${cmd} " )
355+     # A hack for lesser OSes that cannot normally distinguish lower- 
356+     # and uppercase letters. 
357+     if  (WIN32  OR  APPLE )
358+         string (REGEX  REPLACE "[A-Z]"  "\\ 0_"  cmd_target_name
359+                "${cmd_target_name} " )
360+     endif ()
361+     if  (NOT  GEN_RUN_TARGET_NAME)
362+         set (GEN_RUN_TARGET_NAME "run-${cmd_target_name} " )
363+     endif ()
364+     string (REPLACE ";"  " "  cmd_desc "${cmd} " )
365+ 
366+ 
367+     if (WIN32 )
368+         # 
369+         # generate .bat file and target to execute it. 
370+         # 
371+         file (GENERATE OUTPUT  "${cmd_target_name} .bat" 
372+              CONTENT  "set PATH=${win32_path} \n ${_CMD} " 
373+              NEWLINE_STYLE  WIN32 )
374+         add_custom_target ("${GEN_RUN_TARGET_NAME} " 
375+                           COMMAND  "${cmd_target_name} .bat" 
376+                           DEPENDS  "${_TEST} " 
377+                           COMMENT  "Run ${cmd_desc} " 
378+                           WORKING_DIRECTORY  "${CMAKE_CURRENT_BINARY_DIR} " 
379+                           USES_TERMINAL )
380+     else ()
381+         add_custom_target ("${GEN_RUN_TARGET_NAME} " 
382+                           COMMAND  ${cmd} 
383+                           DEPENDS  "${_TEST} " 
384+                           COMMENT  "Run ${cmd_desc} " 
385+                           WORKING_DIRECTORY  "${CMAKE_CURRENT_BINARY_DIR} " 
386+                           USES_TERMINAL )
387+     endif ()
388+ 
389+     if  (GEN_RUN_TARGET_VAR)
390+         set ("${GEN_RUN_TARGET_VAR} "  "${GEN_RUN_TARGET_NAME} "  PARENT_SCOPE)
391+     endif ()
392+ endfunction ()
393+ 
394+ # run targets generation 
312395foreach (test  IN LISTS run_tests)
313396    set (cmds "${test} " )
314397
@@ -357,48 +440,13 @@ foreach(test IN LISTS run_tests)
357440    endforeach ()
358441    set (cmds ${new_cmds} )
359442
443+     # Run target 
360444    foreach (cmd IN LISTS cmds)
361-         # 
362-         # In order to execute the command on Windows, we need 
363-         # to add OPENSSL_ROOT_DIR to PATH variable so runtime 
364-         # linker can find OpenSSL 's .dll files.  Adjusting PATH on Windows 
365-         # requires us to generate a .bat file with two commands: 
366-         #    set PATH=c:\...\OPENSSL_ROOT_DIR;%PATH% 
367-         #    command_to_exec with_options 
368-         # 
369-         # raw_cmd variable keeps the command to execute 
370-         # 
371-         set (raw_cmd "${cmd} " )
372-         string (REGEX  REPLACE "  *"  ";"  cmd "${cmd} " )
373-         string (REGEX  REPLACE "[^0-9A-Za-z]"  "-"  cmd_target_name "${cmd} " )
374-         # A hack for lesser OSes that cannot normally distinguish lower- 
375-         # and uppercase letters. 
376-         if  (WIN32  OR  APPLE )
377-             string (REGEX  REPLACE "[A-Z]"  "\\ 0_"  cmd_target_name
378-                    "${cmd_target_name} " )
379-         endif ()
380-         string (REPLACE ";"  " "  cmd_desc "${cmd} " )
381-         if (WIN32 )
382-             # 
383-             # generate .bat file and target to execute it. 
384-             # 
385-             file (GENERATE OUTPUT  "${cmd_target_name} .bat" 
386-                  CONTENT  "set PATH=${win32_path} \n ${raw_cmd} " 
387-                  NEWLINE_STYLE  WIN32 )
388-             add_custom_target ("run-${cmd_target_name} " 
389-                               COMMAND  "${cmd_target_name} .bat" 
390-                               DEPENDS  "${test} " 
391-                               COMMENT  "Run ${cmd_desc} " 
392-                               WORKING_DIRECTORY  "${CMAKE_CURRENT_BINARY_DIR} " 
393-                               USES_TERMINAL )
394-         else ()
395-             add_custom_target ("run-${cmd_target_name} " 
396-                               COMMAND  ${cmd} 
397-                               DEPENDS  "${test} " 
398-                               COMMENT  "Run ${cmd_desc} " 
399-                               WORKING_DIRECTORY  "${CMAKE_CURRENT_BINARY_DIR} " 
400-                               USES_TERMINAL )
401-         endif ()
402-         add_dependencies (run "run-${cmd_target_name} " )
445+         gen_run_taget("${cmd} "  "${test} "  VAR run_target_name)
446+         add_dependencies (run "${run_target_name} " )
403447    endforeach ()
448+ 
449+     # Per-test version taget 
450+     gen_run_taget("${test}  -V"  "${test} "  NAME  "run-version-${test} " )
451+     add_dependencies (run-version  "run-version-${test} " )
404452endforeach ()
0 commit comments