mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-18 15:20:56 +03:00
cmake: allow tests with BUILD_STATIC_LIBS=OFF
Before this patch, the CMake build did not allow to disable static libssh2 library while also building tests. This patch removes this constraint, and makes this combination possible. In this case the 3 (at the moment) tests that require a static libssh2 library, are skipped from the build and test runs. Cherry-picked from #1036
This commit is contained in:
@@ -112,7 +112,7 @@ endif()
|
|||||||
option(BUILD_EXAMPLES "Build libssh2 examples" ON)
|
option(BUILD_EXAMPLES "Build libssh2 examples" ON)
|
||||||
option(BUILD_TESTING "Build libssh2 test suite" ON)
|
option(BUILD_TESTING "Build libssh2 test suite" ON)
|
||||||
|
|
||||||
if(NOT BUILD_STATIC_LIBS AND (NOT BUILD_SHARED_LIBS OR BUILD_TESTING))
|
if(NOT BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS)
|
||||||
set(BUILD_STATIC_LIBS ON)
|
set(BUILD_STATIC_LIBS ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -77,21 +77,29 @@ set(TESTS_WITH_LIB_STATIC
|
|||||||
)
|
)
|
||||||
|
|
||||||
foreach(test ${DOCKER_TESTS} ${STANDALONE_TESTS} ${SSHD_TESTS})
|
foreach(test ${DOCKER_TESTS} ${STANDALONE_TESTS} ${SSHD_TESTS})
|
||||||
|
if(NOT ";${TESTS_WITH_LIB_STATIC};" MATCHES ";${test};")
|
||||||
|
set(LIB_FOR_TESTS ${LIB_SELECTED})
|
||||||
|
elseif(TARGET ${LIB_STATIC})
|
||||||
|
set(LIB_FOR_TESTS ${LIB_STATIC})
|
||||||
|
else()
|
||||||
|
unset(LIB_FOR_TESTS)
|
||||||
|
message(STATUS "Skip test requiring static libssh2 lib: ${test}")
|
||||||
|
endif()
|
||||||
|
|
||||||
# We support the same target as both Docker and SSHD test. Build those just once.
|
# We support the same target as both Docker and SSHD test. Build those just once.
|
||||||
if(NOT TARGET ${test})
|
# Skip building tests that require the static lib when the static lib is disabled.
|
||||||
|
if(NOT TARGET ${test} AND LIB_FOR_TESTS)
|
||||||
add_executable(${test} ${test}.c)
|
add_executable(${test} ${test}.c)
|
||||||
target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}")
|
target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}")
|
||||||
target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include "${CRYPTO_BACKEND_INCLUDE_DIR}")
|
target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include "${CRYPTO_BACKEND_INCLUDE_DIR}")
|
||||||
set_target_properties(${test} PROPERTIES UNITY_BUILD false)
|
set_target_properties(${test} PROPERTIES UNITY_BUILD false)
|
||||||
|
|
||||||
# build a single test with gcov
|
# build a single test with gcov
|
||||||
if(GCOV_PATH AND test STREQUAL test_auth_keyboard_info_request)
|
if(GCOV_PATH AND test STREQUAL test_auth_keyboard_info_request AND TARGET ${LIB_STATIC})
|
||||||
target_compile_options(${test} BEFORE PRIVATE ${GCOV_OPTIONS})
|
target_compile_options(${test} BEFORE PRIVATE ${GCOV_OPTIONS})
|
||||||
target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES} gcov)
|
target_link_libraries(${test} runner ${LIB_FOR_TESTS} ${LIBRARIES} gcov)
|
||||||
elseif(";${TESTS_WITH_LIB_STATIC};" MATCHES ";${test};")
|
|
||||||
target_link_libraries(${test} runner ${LIB_STATIC} ${LIBRARIES})
|
|
||||||
else()
|
else()
|
||||||
target_link_libraries(${test} runner ${LIB_SELECTED} ${LIBRARIES})
|
target_link_libraries(${test} runner ${LIB_FOR_TESTS} ${LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(APPEND TEST_TARGETS ${test})
|
list(APPEND TEST_TARGETS ${test})
|
||||||
@@ -102,25 +110,33 @@ option(RUN_DOCKER_TESTS "Run tests requiring Docker" ON)
|
|||||||
|
|
||||||
if(RUN_DOCKER_TESTS)
|
if(RUN_DOCKER_TESTS)
|
||||||
foreach(test ${DOCKER_TESTS})
|
foreach(test ${DOCKER_TESTS})
|
||||||
|
if(TARGET ${test})
|
||||||
add_test(NAME ${test} COMMAND $<TARGET_FILE:${test}>)
|
add_test(NAME ${test} COMMAND $<TARGET_FILE:${test}>)
|
||||||
set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
foreach(test ${STANDALONE_TESTS})
|
foreach(test ${STANDALONE_TESTS})
|
||||||
|
if(TARGET ${test})
|
||||||
add_test(NAME ${test} COMMAND $<TARGET_FILE:${test}>)
|
add_test(NAME ${test} COMMAND $<TARGET_FILE:${test}>)
|
||||||
set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if(RUN_SSHD_TESTS AND SSHD_EXECUTABLE)
|
if(RUN_SSHD_TESTS AND SSHD_EXECUTABLE)
|
||||||
unset(sshd_test_targets)
|
unset(sshd_test_targets)
|
||||||
foreach(test ${SSHD_TESTS})
|
foreach(test ${SSHD_TESTS})
|
||||||
|
if(TARGET ${test})
|
||||||
set(sshd_test_targets "${sshd_test_targets} $<TARGET_FILE:${test}>")
|
set(sshd_test_targets "${sshd_test_targets} $<TARGET_FILE:${test}>")
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
if(sshd_test_targets)
|
||||||
add_test(NAME test_sshd COMMAND ${SH_EXECUTABLE} -c "${CMAKE_CURRENT_SOURCE_DIR}/test_sshd.test ${sshd_test_targets}")
|
add_test(NAME test_sshd COMMAND ${SH_EXECUTABLE} -c "${CMAKE_CURRENT_SOURCE_DIR}/test_sshd.test ${sshd_test_targets}")
|
||||||
set_property(TEST test_sshd APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
set_property(TEST test_sshd APPEND PROPERTY ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
set_property(TEST test_sshd APPEND PROPERTY ENVIRONMENT "SSHD=${SSHD_EXECUTABLE}")
|
set_property(TEST test_sshd APPEND PROPERTY ENVIRONMENT "SSHD=${SSHD_EXECUTABLE}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(RUN_DOCKER_TESTS)
|
if(RUN_DOCKER_TESTS)
|
||||||
|
|||||||
Reference in New Issue
Block a user