aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cynapses.org>2010-09-06 14:54:16 +0200
committerAndreas Schneider <asn@cynapses.org>2010-09-06 15:17:03 +0200
commitfbe102bada583f308450c27e256053b51643a532 (patch)
treea855a670d43df50647b5f90a89e15c093f26793f
parent2cca490076841b431d7a83d020d90e1ad00bbca5 (diff)
downloadlibssh-fbe102bada583f308450c27e256053b51643a532.tar.gz
libssh-fbe102bada583f308450c27e256053b51643a532.tar.xz
libssh-fbe102bada583f308450c27e256053b51643a532.zip
threads: Build a libssh threading library.
-rw-r--r--ConfigureChecks.cmake2
-rw-r--r--include/libssh/threads.h6
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/threads/CMakeLists.txt109
-rw-r--r--src/threads/native.c4
-rw-r--r--src/threads/pthread.c3
-rw-r--r--tests/CMakeLists.txt8
7 files changed, 129 insertions, 6 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index d6f67df7..fc17f61d 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -128,8 +128,6 @@ endif (Z_LIBRARY)
if (CMAKE_HAVE_THREADS_LIBRARY)
if (CMAKE_HAVE_PTHREADS_CREATE OR CMAKE_HAVE_PTHREAD_CREATE)
set(HAVE_PTHREAD 1)
-
- set(LIBSSH_REQUIRED_LIBRARIES ${LIBSSH_REQUIRED_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif (CMAKE_HAVE_PTHREADS_CREATE OR CMAKE_HAVE_PTHREAD_CREATE)
endif (CMAKE_HAVE_THREADS_LIBRARY)
diff --git a/include/libssh/threads.h b/include/libssh/threads.h
index d83e4219..78149d90 100644
--- a/include/libssh/threads.h
+++ b/include/libssh/threads.h
@@ -22,10 +22,10 @@
#ifndef THREADS_H_
#define THREADS_H_
+#include <libssh/libssh.h>
#include <libssh/callbacks.h>
-int ssh_threads_init(void);
-void ssh_threads_finalize(void);
-
+LIBSSH_API int ssh_threads_init(void);
+LIBSSH_API void ssh_threads_finalize(void);
#endif /* THREADS_H_ */
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b158ae6c..8f20c7b8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -202,3 +202,6 @@ if (WITH_STATIC_LIB)
)
endif (WITH_STATIC_LIB)
+if (CMAKE_HAVE_THREADS_LIBRARY)
+ add_subdirectory(threads)
+endif (CMAKE_HAVE_THREADS_LIBRARY)
diff --git a/src/threads/CMakeLists.txt b/src/threads/CMakeLists.txt
new file mode 100644
index 00000000..1cf3d7b1
--- /dev/null
+++ b/src/threads/CMakeLists.txt
@@ -0,0 +1,109 @@
+project(libssh-threads C)
+
+set(LIBSSH_THREADS_PUBLIC_INCLUDE_DIRS
+ ${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}
+ CACHE INTERNAL "libssh public include directories"
+)
+
+set(LIBSSH_PRIVATE_INCLUDE_DIRS
+ ${CMAKE_BINARY_DIR}
+)
+
+set(LIBSSH_THREADS_SHARED_LIBRARY
+ ssh_threads_shared
+ CACHE INTERNAL "libssh threads shared library"
+)
+
+if (WITH_STATIC_LIB)
+ set(LIBSSH_THREADS_STATIC_LIBRARY
+ ssh_threads_static
+ CACHE INTERNAL "libssh threads static library"
+ )
+endif (WITH_STATIC_LIB)
+
+set(LIBSSH_THREADS_LINK_LIBRARIES
+ ${LIBSSH_LINK_LIBRARIES}
+)
+
+set(LIBSSH_THREADS_LINK_LIBRARIES
+ ${LIBSSH_THREADS_LINK_LIBRARIES}
+ CACHE INTERNAL "libssh threads link libraries"
+)
+
+set(libssh_threads_SRCS
+ native.c
+)
+
+# build and link pthread
+if (CMAKE_HAVE_PTHREADS_CREATE OR CMAKE_HAVE_PTHREAD_CREATE)
+ set(libssh_threads_SRCS
+ ${libssh_threads_SRCS}
+ pthread.c
+ )
+
+ set(LIBSSH_THREADS_LINK_LIBRARIES
+ ${LIBSSH_THREADS_LINK_LIBRARIES}
+ ${CMAKE_THREAD_LIBS_INIT}
+ )
+endif (CMAKE_HAVE_PTHREADS_CREATE OR CMAKE_HAVE_PTHREAD_CREATE)
+
+include_directories(
+ ${LIBSSH_THREADS_PUBLIC_INCLUDE_DIRS}
+ ${LIBSSH_THREADS_PRIVATE_INCLUDE_DIRS}
+)
+
+add_library(${LIBSSH_THREADS_SHARED_LIBRARY} SHARED ${libssh_threads_SRCS})
+
+target_link_libraries(${LIBSSH_THREADS_SHARED_LIBRARY} ${LIBSSH_THREADS_LINK_LIBRARIES})
+
+set_target_properties(
+ ${LIBSSH_THREADS_SHARED_LIBRARY}
+ PROPERTIES
+ VERSION
+ ${LIBRARY_VERSION}
+ SOVERSION
+ ${LIBRARY_SOVERSION}
+ OUTPUT_NAME
+ ssh_threads
+ DEFINE_SYMBOL
+ LIBSSH_EXPORTS
+)
+
+if (WITH_VISIBILITY_HIDDEN)
+ set_target_properties(${LIBSSH_THREADS_SHARED_LIBRARY} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
+endif (WITH_VISIBILITY_HIDDEN)
+
+install(
+ TARGETS
+ ${LIBSSH_THREADS_SHARED_LIBRARY}
+ RUNTIME DESTINATION ${BIN_INSTALL_DIR}
+ LIBRARY DESTINATION ${LIB_INSTALL_DIR}
+ ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
+ COMPONENT libraries
+)
+
+if (WITH_STATIC_LIB)
+ add_library(${LIBSSH_THREADS_STATIC_LIBRARY} STATIC ${libssh_threads_SRCS})
+
+ set_target_properties(
+ ${LIBSSH_THREADS_STATIC_LIBRARY}
+ PROPERTIES
+ VERSION
+ ${LIBRARY_VERSION}
+ SOVERSION
+ ${LIBRARY_SOVERSION}
+ COMPILE_FLAGS
+ "-DLIBSSH_STATIC"
+ )
+
+ install(
+ TARGETS
+ ${LIBSSH_THREADS_STATIC_LIBRARY}
+ DESTINATION
+ ${LIB_INSTALL_DIR}
+ COMPONENT
+ libraries
+ )
+endif (WITH_STATIC_LIB)
diff --git a/src/threads/native.c b/src/threads/native.c
new file mode 100644
index 00000000..c65c18e4
--- /dev/null
+++ b/src/threads/native.c
@@ -0,0 +1,4 @@
+#include "config.h"
+#include <libssh/callbacks.h>
+
+struct ssh_threads_callbacks_struct ssh_pthread_callbacks;
diff --git a/src/threads/pthread.c b/src/threads/pthread.c
index 2f62ad3c..35589cc7 100644
--- a/src/threads/pthread.c
+++ b/src/threads/pthread.c
@@ -20,10 +20,12 @@
*/
#include "config.h"
+#include <libssh/callbacks.h>
#ifdef HAVE_PTHREAD
#include <errno.h>
+#include <stdlib.h>
#include <pthread.h>
/** @brief Defines the needed callbacks for pthread. Use this if your
@@ -81,4 +83,5 @@ static struct ssh_threads_callbacks_struct name= \
}
SSH_THREADS_PTHREAD(ssh_pthread_user_callbacks);
+
#endif /* HAVE_PTHREAD */
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 64811e29..8d1cb1e0 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -16,7 +16,13 @@ include_directories(
# create test library
add_library(${TORTURE_LIBRARY} SHARED torture.c cmdline.c)
-target_link_libraries(${TORTURE_LIBRARY} ${CHECK_LIBRARIES} ${LIBSSH_STATIC_LIBRARY} ${LIBSSH_LINK_LIBRARIES} ${ARGP_LIBRARIES})
+target_link_libraries(${TORTURE_LIBRARY}
+ ${CHECK_LIBRARIES}
+ ${LIBSSH_STATIC_LIBRARY}
+ ${LIBSSH_THREADS_STATIC_LIBRARY}
+ ${LIBSSH_LINK_LIBRARIES}
+ ${ARGP_LIBRARIES}
+)
set(TEST_TARGET_LIBRARIES ${SUPPORT_LIBRARY} ${LIBSSH_LINK_LIBRARIES})