-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
105 lines (92 loc) · 2.39 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Simple C library to let your networking app connect to a host running behind a SSH server.
#
# Copyright (c) Christian Beier <info@christianbeier.net>
#
# SPDX-License-Identifier: BSD-3-Clause
#
cmake_minimum_required(VERSION 3.10)
project(libsshtunnel VERSION 0.3.0 LANGUAGES C)
include(CheckIncludeFile)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(CMAKE_GENERATOR MATCHES "Unix Makefiles|Ninja")
# some LSP servers expect compile_commands.json in the project root
add_custom_target(
libsshtunnel-copy-compile-commands ALL
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_SOURCE_DIR}
)
endif(CMAKE_GENERATOR MATCHES "Unix Makefiles|Ninja")
#
# Dependencies
#
find_package(LibSSH2 REQUIRED)
check_include_file("threads.h" HAVE_THREADS_H)
if(HAVE_THREADS_H)
message(STATUS "Multithreading using C11 threads")
add_definitions(-DHAVE_THREADS_H)
else()
find_package(Threads REQUIRED)
if(CMAKE_USE_PTHREADS_INIT)
message(STATUS "Multithreading using pthreads")
endif()
if(CMAKE_USE_WIN32_THREADS_INIT)
message(STATUS "Multithreading Win32 threads")
endif()
endif()
#
# Sources
#
set(SOURCE_FILES
src/libsshtunnel.c
)
if(CMAKE_USE_PTHREADS_INIT)
set(SOURCE_FILES
${SOURCE_FILES}
src/c11threads.h
)
endif()
if(CMAKE_USE_WIN32_THREADS_INIT)
set(SOURCE_FILES
${SOURCE_FILES}
src/c11threads.h
src/c11threads_win32.c
)
endif()
set(HEADER_FILES
include/libsshtunnel.h
)
#
# Build config
#
if(UNIX)
add_definitions(-DUNIX)
endif(UNIX)
if(WIN32)
add_definitions(-DWIN32)
set(WS_LIBRARY ws2_32)
endif(WIN32)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${LIBSSH2_INCLUDE_DIR})
add_library(sshtunnel ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(sshtunnel PRIVATE ${LIBSSH2_LIBRARY} ${WS_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
#
# Test config
#
enable_testing()
add_executable(test-close-of-unused-tunnel
test/close-of-unused-tunnel.c
)
target_link_libraries(test-close-of-unused-tunnel sshtunnel)
add_test(NAME close-of-unused-tunnel COMMAND test-close-of-unused-tunnel)
#
# Install
#
# Install built targets
install(TARGETS sshtunnel
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
# Install headers
install(FILES ${HEADER_FILES} DESTINATION include)