diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1012ddf..612f0ba 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -225,6 +225,7 @@ include_directories(
   ${LIBSSH_PRIVATE_INCLUDE_DIRS}
 )
 
+if (NOT WITH_STATIC_LIB)
 add_library(${LIBSSH_SHARED_LIBRARY} SHARED ${libssh_SRCS})
 
 target_link_libraries(${LIBSSH_SHARED_LIBRARY} ${LIBSSH_LINK_LIBRARIES})
@@ -259,6 +260,7 @@ install(
   ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
   COMPONENT libraries
 )
+endif()
 
 if (WITH_STATIC_LIB)
   add_library(${LIBSSH_STATIC_LIBRARY} STATIC ${libssh_SRCS})
