mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-31 00:03:08 +03:00
cmake: tidy-up foreach()
syntax
Use `IN LISTS` and `IN ITEMS`. This appears to be the preferred way within CMake's own source code and possibly improves readability. Fixup a side-effect of `IN LISTS`, where it retains empty values at the end of the list, as opposed to the syntax used before, which dropped it. In our case this happened with lines read from a text file via `file(READ)`. https://cmake.org/cmake/help/v3.7/command/foreach.html Closes #1180
This commit is contained in:
@ -65,7 +65,7 @@ function(check_function_exists_may_need_library function variable)
|
||||
check_function_exists(${function} ${variable})
|
||||
|
||||
if(NOT ${variable})
|
||||
foreach(lib ${ARGN})
|
||||
foreach(lib IN LISTS ARGN)
|
||||
string(TOUPPER ${lib} UP_LIB)
|
||||
# Use new variable to prevent cache from previous step shortcircuiting
|
||||
# new test
|
||||
|
@ -52,12 +52,11 @@ function(ADD_TARGET_TO_COPY_DEPENDENCIES)
|
||||
# parallel builds trying to kick off the commands at the same time
|
||||
add_custom_target(${COPY_TARGET})
|
||||
|
||||
foreach(target ${COPY_BEFORE_TARGETS})
|
||||
foreach(target IN LISTS COPY_BEFORE_TARGETS)
|
||||
add_dependencies(${target} ${COPY_TARGET})
|
||||
endforeach()
|
||||
|
||||
foreach(dependency ${COPY_DEPENDENCIES})
|
||||
|
||||
foreach(dependency IN LISTS COPY_DEPENDENCIES)
|
||||
add_custom_command(
|
||||
TARGET ${COPY_TARGET}
|
||||
DEPENDS ${dependency}
|
||||
@ -68,7 +67,5 @@ function(ADD_TARGET_TO_COPY_DEPENDENCIES)
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy ${dependency} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
|
||||
VERBATIM)
|
||||
|
||||
endforeach()
|
||||
|
||||
endfunction()
|
||||
|
@ -189,11 +189,11 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_I
|
||||
|
||||
unset(WPICKY)
|
||||
|
||||
foreach(_CCOPT ${WPICKY_ENABLE})
|
||||
foreach(_CCOPT IN LISTS WPICKY_ENABLE)
|
||||
set(WPICKY "${WPICKY} ${_CCOPT}")
|
||||
endforeach()
|
||||
|
||||
foreach(_CCOPT ${WPICKY_DETECT})
|
||||
foreach(_CCOPT IN LISTS WPICKY_DETECT)
|
||||
# surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
|
||||
# test result in.
|
||||
string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname)
|
||||
|
@ -45,7 +45,7 @@ transform_makefile_inc("Makefile.am" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cm
|
||||
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.am.cmake")
|
||||
set(EXAMPLES ${noinst_PROGRAMS})
|
||||
|
||||
foreach(example ${EXAMPLES})
|
||||
foreach(example IN LISTS EXAMPLES)
|
||||
add_executable(${example} "${example}.c")
|
||||
list(APPEND EXAMPLE_TARGETS ${example})
|
||||
# to find generated header
|
||||
|
@ -74,7 +74,7 @@ add_library(runner STATIC ${librunner_la_SOURCES})
|
||||
target_compile_definitions(runner PRIVATE "${CRYPTO_BACKEND_DEFINE}")
|
||||
target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" "../src" "../include" "${CRYPTO_BACKEND_INCLUDE_DIR}")
|
||||
|
||||
foreach(test ${DOCKER_TESTS} ${STANDALONE_TESTS} ${SSHD_TESTS})
|
||||
foreach(test IN LISTS DOCKER_TESTS STANDALONE_TESTS SSHD_TESTS)
|
||||
if(NOT ";${DOCKER_TESTS_STATIC};${STANDALONE_TESTS_STATIC};" MATCHES ";${test};")
|
||||
set(LIB_FOR_TESTS ${LIB_SELECTED})
|
||||
elseif(TARGET ${LIB_STATIC})
|
||||
@ -107,7 +107,7 @@ endforeach()
|
||||
option(RUN_DOCKER_TESTS "Run tests requiring Docker" ON)
|
||||
|
||||
if(RUN_DOCKER_TESTS)
|
||||
foreach(test ${DOCKER_TESTS})
|
||||
foreach(test IN LISTS DOCKER_TESTS)
|
||||
if(TARGET ${test})
|
||||
add_test(NAME ${test} COMMAND "$<TARGET_FILE:${test}>")
|
||||
set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
@ -115,7 +115,7 @@ if(RUN_DOCKER_TESTS)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
foreach(test ${STANDALONE_TESTS})
|
||||
foreach(test IN LISTS STANDALONE_TESTS)
|
||||
if(TARGET ${test})
|
||||
add_test(NAME ${test} COMMAND "$<TARGET_FILE:${test}>")
|
||||
set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
@ -124,7 +124,7 @@ endforeach()
|
||||
|
||||
if(RUN_SSHD_TESTS AND SSHD_EXECUTABLE)
|
||||
unset(sshd_test_targets)
|
||||
foreach(test ${SSHD_TESTS})
|
||||
foreach(test IN LISTS SSHD_TESTS)
|
||||
if(TARGET ${test})
|
||||
set(sshd_test_targets "${sshd_test_targets} $<TARGET_FILE:${test}>")
|
||||
endif()
|
||||
@ -141,7 +141,8 @@ if(RUN_DOCKER_TESTS)
|
||||
# CRYPT/MAC algo tests
|
||||
file(READ "test_read_algos.txt" ALGO_TESTS)
|
||||
string(REGEX REPLACE "\\\n" ";" ALGO_TESTS ${ALGO_TESTS})
|
||||
foreach(test ${ALGO_TESTS})
|
||||
foreach(test IN LISTS ALGO_TESTS)
|
||||
if(test)
|
||||
set(testname "test_read-${test}")
|
||||
add_test(NAME ${testname} COMMAND "$<TARGET_FILE:test_read>")
|
||||
set_property(TEST ${testname} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
@ -150,6 +151,7 @@ if(RUN_DOCKER_TESTS)
|
||||
else()
|
||||
set_property(TEST ${testname} APPEND PROPERTY ENVIRONMENT "FIXTURE_TEST_CRYPT=${test}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
@ -20,7 +20,7 @@ if(TEST_INTEGRATION_MODE STREQUAL "find_package" OR
|
||||
DOWNLOAD_EXTRACT_TIMESTAMP ON)
|
||||
endif()
|
||||
find_package(libssh2 REQUIRED CONFIG)
|
||||
foreach(result_var libssh2_FOUND libssh2_VERSION)
|
||||
foreach(result_var IN ITEMS libssh2_FOUND libssh2_VERSION)
|
||||
if(${result_var})
|
||||
message(STATUS "${result_var}: |${${result_var}}|")
|
||||
else()
|
||||
|
Reference in New Issue
Block a user