Skip to content

Commit 0406774

Browse files
committed
CMakeLists.txt: add run-version* targets
Generate run-version-<test> target for each test from run_tests, make it a dependency of run-version target. and, if run_add_version_dep vesioble is set to ON (the default), set "run-version" as a dependency of the "run" target. Signed-off-by: Eugene Syromiatnikov <[email protected]>
1 parent c1b4d8f commit 0406774

File tree

1 file changed

+80
-31
lines changed

1 file changed

+80
-31
lines changed

source/CMakeLists.txt

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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
222227
set(run_evp_fetch_pqs
223228
evp_fetch "" "" "-q"
@@ -300,6 +305,14 @@ 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+
303316
# Generate search path for later DLL copying
304317
if (WIN32)
305318
set(dll_search_dirs)
@@ -309,6 +322,66 @@ if (WIN32)
309322
endforeach()
310323
endif()
311324

325+
#
326+
# gen_run_target(<cmd> <test> [VAR <var>] [NAME <name>])
327+
#
328+
# Generates a target that runs <cmd> and depends on target <test> and sets
329+
# <var> to the target's name.
330+
#
331+
function(gen_run_taget _CMD _TEST)
332+
include(CMakeParseArguments)
333+
334+
set(_Options "")
335+
set(_OneValueArgs VAR NAME)
336+
set(_MultiValueArgs "")
337+
cmake_parse_arguments(GEN_RUN_TARGET
338+
"${_Options}"
339+
"${_OneValueArgs}"
340+
"${_MultiValueArgs}"
341+
${ARGN}
342+
)
343+
344+
string(REGEX REPLACE " *" ";" cmd "${_CMD}")
345+
string(REGEX REPLACE "[^0-9A-Za-z]" "-" cmd_target_name "${cmd}")
346+
# A hack for lesser OSes that cannot normally distinguish lower-
347+
# and uppercase letters.
348+
if (WIN32 OR APPLE)
349+
string(REGEX REPLACE "[A-Z]" "\\0_" cmd_target_name
350+
"${cmd_target_name}")
351+
endif()
352+
if (NOT GEN_RUN_TARGET_NAME)
353+
set(GEN_RUN_TARGET_NAME "run-${cmd_target_name}")
354+
endif()
355+
string(REPLACE ";" " " cmd_desc "${cmd}")
356+
357+
358+
add_custom_target("${GEN_RUN_TARGET_NAME}"
359+
COMMAND ${cmd}
360+
DEPENDS "${_TEST}"
361+
COMMENT "Run ${cmd_desc}"
362+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
363+
USES_TERMINAL)
364+
365+
# A dirty hack to copy the dependent DLLs into the build directory so they
366+
# get picked up before the ones in the system directory or wherever.
367+
if(WIN32)
368+
if (NOT TARGET "${_TEST}-copy-dlls")
369+
add_custom_target("${_TEST}-copy-dlls"
370+
COMMAND ${CMAKE_COMMAND}
371+
-D TARGET_FILE=$<TARGET_FILE:${_TEST}>
372+
-D TARGET_DIR=$<TARGET_FILE_DIR:${_TEST}>
373+
-D "SEARCH_PATH=${dll_search_dirs}"
374+
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/copy_reqs.cmake"
375+
COMMENT "Copying DLLs for ${_TEST}")
376+
endif()
377+
add_dependencies("${GEN_RUN_TARGET_NAME}" "${_TEST}-copy-dlls")
378+
endif()
379+
380+
if (GEN_RUN_TARGET_VAR)
381+
set("${GEN_RUN_TARGET_VAR}" "${GEN_RUN_TARGET_NAME}" PARENT_SCOPE)
382+
endif()
383+
endfunction()
384+
312385
# run targets generation
313386
foreach(test IN LISTS run_tests)
314387
set(cmds "${test}")
@@ -358,37 +431,13 @@ foreach(test IN LISTS run_tests)
358431
endforeach()
359432
set(cmds ${new_cmds})
360433

434+
# Run targets
361435
foreach(cmd IN LISTS cmds)
362-
string(REGEX REPLACE " *" ";" cmd "${cmd}")
363-
string(REGEX REPLACE "[^0-9A-Za-z]" "-" cmd_target_name "${cmd}")
364-
# A hack for lesser OSes that cannot normally distinguish lower-
365-
# and uppercase letters.
366-
if (WIN32 OR APPLE)
367-
string(REGEX REPLACE "[A-Z]" "\\0_" cmd_target_name
368-
"${cmd_target_name}")
369-
endif()
370-
string(REPLACE ";" " " cmd_desc "${cmd}")
371-
add_custom_target("run-${cmd_target_name}"
372-
COMMAND ${cmd}
373-
DEPENDS "${test}"
374-
COMMENT "Run ${cmd_desc}"
375-
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
376-
USES_TERMINAL)
377-
add_dependencies(run "run-${cmd_target_name}")
378-
379-
# A dirty hack to copy the dependent DLLs into the build directory so they
380-
# get picked up before the ones in the system directory or wherever.
381-
if(WIN32)
382-
if (NOT TARGET "${test}-copy-dlls")
383-
add_custom_target("${test}-copy-dlls"
384-
COMMAND ${CMAKE_COMMAND}
385-
-D TARGET_FILE=$<TARGET_FILE:${test}>
386-
-D TARGET_DIR=$<TARGET_FILE_DIR:${test}>
387-
-D "SEARCH_PATH=${dll_search_dirs}"
388-
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/copy_reqs.cmake"
389-
COMMENT "Copying DLLs for ${test}")
390-
endif()
391-
add_dependencies("${run-${cmd_target_name}}" "${test}-copy-dlls")
392-
endif()
436+
gen_run_taget("${cmd}" "${test}" VAR run_target_name)
437+
add_dependencies(run "${run_target_name}")
393438
endforeach()
439+
440+
# Per-test version taget
441+
gen_run_taget("${test} -V" "${test}" NAME "run-version-${test}")
442+
add_dependencies(run-version "run-version-${test}")
394443
endforeach()

0 commit comments

Comments
 (0)