From 9a769054fc03f02db75355f0850360a26fae7324 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 5 Sep 2024 23:18:47 -0400 Subject: [PATCH] cmake: always run the tests even when static libs are disabled The BUILD_STATIC_LIBS option is intended for the use case where users do not wish to build and install a static lib because it is not one of the artifacts they are interested in. The option should not be used to disable running the testsuite. Instead, when tests are enabled, define the target. Just don't export or install it. Build systems build lots of things that aren't deliverable artifacts, and this becomes just one more of them. (cherry-picked from PR https://github.com/libssh2/libssh2/pull/1450) Signed-off-by: Eli Schwartz --- src/CMakeLists.txt | 6 ++++-- tests/CMakeLists.txt | 8 ++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5bbed5e5..eb2fb7c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -97,8 +97,10 @@ if(WIN32 AND BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS AND endif() # we want it to be called libssh2 on all platforms -if(BUILD_STATIC_LIBS) - list(APPEND libssh2_export ${LIB_STATIC}) +if(BUILD_STATIC_LIBS OR BUILD_TESTING) + if(BUILD_STATIC_LIBS) + list(APPEND libssh2_export ${LIB_STATIC}) + endif() add_library(${LIB_STATIC} STATIC ${SOURCES}) target_compile_definitions(${LIB_STATIC} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) target_link_libraries(${LIB_STATIC} PRIVATE ${LIBRARIES}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 76eb78ef..a61ea5a3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -73,16 +73,12 @@ target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" . 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}") + set(LIB_FOR_TESTS ${LIB_STATIC}) endif() # We support the same target as both Docker and SSHD test. Build those just once. - # Skip building tests that require the static lib when the static lib is disabled. - if(NOT TARGET ${test} AND LIB_FOR_TESTS) + if(NOT TARGET ${test}) add_executable(${test} ${test}.c) target_compile_definitions(${test} PRIVATE "${CRYPTO_BACKEND_DEFINE}") target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../src" ../src ../include "${CRYPTO_BACKEND_INCLUDE_DIR}") -- 2.44.2