geom_gate userland utility improvements
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

433 lines
14 KiB

  1. # Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
  2. #
  3. # Redistribution and use in source and binary forms,
  4. # with or without modification, are permitted provided
  5. # that the following conditions are met:
  6. #
  7. # Redistributions of source code must retain the above
  8. # copyright notice, this list of conditions and the
  9. # following disclaimer.
  10. #
  11. # Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following
  13. # disclaimer in the documentation and/or other materials
  14. # provided with the distribution.
  15. #
  16. # Neither the name of the copyright holder nor the names
  17. # of any other contributors may be used to endorse or
  18. # promote products derived from this software without
  19. # specific prior written permission.
  20. #
  21. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  22. # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  23. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  24. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  26. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  29. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  33. # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  34. # OF SUCH DAMAGE.
  35. include(CheckFunctionExists)
  36. include(CheckSymbolExists)
  37. include(CheckFunctionExistsMayNeedLibrary)
  38. include(CheckIncludeFiles)
  39. include(CheckTypeSize)
  40. include(CheckSymbolExists)
  41. include(CheckNonblockingSocketSupport)
  42. include(SocketLibraries)
  43. ## Cryptography backend choice
  44. set(CRYPTO_BACKEND
  45. ""
  46. CACHE
  47. STRING
  48. "The backend to use for cryptography: OpenSSL, Libgcrypt or WinCNG, mbedTLS
  49. or empty to try any available")
  50. # If the crypto backend was given, rather than searching for the first
  51. # we are able to find, the find_package commands must abort configuration
  52. # and report to the user.
  53. if(CRYPTO_BACKEND)
  54. set(SPECIFIC_CRYPTO_REQUIREMENT REQUIRED)
  55. endif()
  56. if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
  57. find_package(OpenSSL ${SPECIFIC_CRYPTO_REQUIREMENT})
  58. if(OPENSSL_FOUND)
  59. set(CRYPTO_BACKEND "OpenSSL")
  60. set(CRYPTO_SOURCES openssl.c openssl.h)
  61. list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_OPENSSL)
  62. list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
  63. list(APPEND LIBRARIES ${OPENSSL_LIBRARIES})
  64. list(APPEND PC_REQUIRES_PRIVATE libssl libcrypto)
  65. if (WIN32)
  66. # Statically linking to OpenSSL requires crypt32 for some Windows APIs.
  67. # This should really be handled by FindOpenSSL.cmake.
  68. list(APPEND LIBRARIES crypt32)
  69. list(APPEND PC_LIBS -lcrypt32)
  70. find_file(DLL_LIBEAY32
  71. NAMES libeay32.dll crypto.dll libcrypto-1_1.dll libcrypto-1_1-x64.dll
  72. HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS}
  73. PATH_SUFFIXES bin)
  74. if (NOT DLL_LIBEAY32)
  75. message(WARNING
  76. "Unable to find OpenSSL crypto (aka libeay32) DLL, executables may not run")
  77. endif()
  78. find_file(DLL_SSLEAY32
  79. NAMES ssleay32.dll ssl.dll libssl-1_1.dll libssl-1_1-x64.dll
  80. HINTS ${_OPENSSL_ROOT_HINTS} PATHS ${_OPENSSL_ROOT_PATHS}
  81. PATH_SUFFIXES bin)
  82. if (NOT DLL_SSLEAY32)
  83. message(WARNING
  84. "Unable to find OpenSSL ssl (aka ssleay32) DLL, executables may not run")
  85. endif()
  86. if(DLL_LIBEAY32 AND DLL_SSLEAY32)
  87. list(APPEND _RUNTIME_DEPENDENCIES ${DLL_LIBEAY32} ${DLL_SSLEAY32})
  88. endif()
  89. endif()
  90. # Not all OpenSSL have AES-CTR functions.
  91. set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  92. set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
  93. check_function_exists(EVP_aes_128_ctr HAVE_EVP_AES_128_CTR)
  94. set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
  95. endif()
  96. endif()
  97. if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND)
  98. find_package(Libgcrypt ${SPECIFIC_CRYPTO_REQUIREMENT})
  99. if(LIBGCRYPT_FOUND)
  100. set(CRYPTO_BACKEND "Libgcrypt")
  101. set(CRYPTO_SOURCES libgcrypt.c libgcrypt.h)
  102. list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_LIBGCRYPT)
  103. list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${LIBGCRYPT_INCLUDE_DIRS})
  104. list(APPEND LIBRARIES ${LIBGCRYPT_LIBRARIES})
  105. list(APPEND PC_LIBS -lgcrypt)
  106. endif()
  107. endif()
  108. if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
  109. # The check actually compiles the header. This requires windows.h.
  110. check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H)
  111. if(HAVE_BCRYPT_H)
  112. set(CRYPTO_BACKEND "WinCNG")
  113. set(CRYPTO_SOURCES wincng.c wincng.h)
  114. list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_WINCNG)
  115. set(HAVE_LIBCRYPT32 TRUE)
  116. list(APPEND LIBRARIES bcrypt)
  117. list(APPEND PC_LIBS -lbcrypt)
  118. check_include_files(ntdef.h HAVE_NTDEF_H)
  119. check_include_files(ntstatus.h HAVE_NTSTATUS_H)
  120. # Reading keys from files is optional and depends on Wincrypt
  121. check_include_files("windows.h;wincrypt.h" HAVE_WINCRYPT_H)
  122. if(HAVE_WINCRYPT_H)
  123. list(APPEND LIBRARIES crypt32)
  124. list(APPEND PC_LIBS -lcrypt32)
  125. endif()
  126. elseif(${SPECIFIC_CRYPTO_REQUIREMENT} STREQUAL ${REQUIRED})
  127. message(FATAL_ERROR "WinCNG not available")
  128. endif()
  129. endif()
  130. if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND)
  131. find_package(mbedTLS ${SPECIFIC_CRYPTO_REQUIREMENT})
  132. if(MBEDTLS_FOUND)
  133. set(CRYPTO_BACKEND "mbedTLS")
  134. set(CRYPTO_SOURCES mbedtls.c mbedtls.h)
  135. list(APPEND PRIVATE_COMPILE_DEFINITIONS LIBSSH2_MBEDTLS)
  136. list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${MBEDTLS_INCLUDE_DIR})
  137. list(APPEND LIBRARIES ${MBEDTLS_LIBRARIES})
  138. list(APPEND PC_LIBS -lmbedcrypto)
  139. link_directories(${MBEDTLS_LIBRARY_DIR})
  140. endif()
  141. endif()
  142. if(NOT CRYPTO_BACKEND)
  143. message(FATAL_ERROR "No suitable cryptography backend found.")
  144. endif()
  145. ## Library definition
  146. include(GNUInstallDirs)
  147. set(SOURCES
  148. ${CRYPTO_SOURCES}
  149. agent.c
  150. blf.h
  151. bcrypt_pbkdf.c
  152. blowfish.c
  153. channel.c
  154. channel.h
  155. comp.c
  156. comp.h
  157. crypt.c
  158. crypto.h
  159. global.c
  160. hostkey.c
  161. keepalive.c
  162. kex.c
  163. knownhost.c
  164. libssh2_priv.h
  165. mac.c
  166. mac.h
  167. misc.c
  168. misc.h
  169. packet.c
  170. packet.h
  171. pem.c
  172. publickey.c
  173. scp.c
  174. session.c
  175. session.h
  176. sftp.c
  177. sftp.h
  178. transport.c
  179. transport.h
  180. userauth.c
  181. userauth.h
  182. version.c)
  183. if(WIN32)
  184. list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/win32/libssh2.rc)
  185. endif()
  186. add_library(libssh2 ${SOURCES})
  187. # we want it to be called libssh2 on all platforms
  188. set_target_properties(libssh2 PROPERTIES PREFIX "")
  189. target_compile_definitions(libssh2 PRIVATE ${PRIVATE_COMPILE_DEFINITIONS})
  190. target_include_directories(libssh2
  191. PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${PRIVATE_INCLUDE_DIRECTORIES}
  192. PUBLIC
  193. $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
  194. $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>)
  195. ## Options
  196. option(CLEAR_MEMORY "Enable clearing of memory before being freed" ON)
  197. if(CLEAR_MEMORY)
  198. add_definitions(-DLIBSSH2_CLEAR_MEMORY)
  199. endif(CLEAR_MEMORY)
  200. add_feature_info("Shared library" BUILD_SHARED_LIBS
  201. "creating libssh2 as a shared library (.so/.dll)")
  202. option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression")
  203. add_feature_info(Compression ENABLE_ZLIB_COMPRESSION
  204. "using zlib for compression")
  205. if(ENABLE_ZLIB_COMPRESSION)
  206. find_package(ZLIB REQUIRED)
  207. target_include_directories(libssh2 PRIVATE ${ZLIB_INCLUDE_DIRS})
  208. list(APPEND LIBRARIES ${ZLIB_LIBRARIES})
  209. list(APPEND PC_REQUIRES_PRIVATE zlib)
  210. if(ZLIB_FOUND)
  211. target_compile_definitions(libssh2 PRIVATE LIBSSH2_HAVE_ZLIB=1)
  212. endif()
  213. endif()
  214. option(ENABLE_CRYPT_NONE "Permit \"none\" cipher -- NOT RECOMMENDED")
  215. add_feature_info("\"none\" cipher" ENABLE_CRYPT_NONE "")
  216. if(ENABLE_CRYPT_NONE)
  217. target_compile_definitions(libssh2 PRIVATE LIBSSH2_CRYPT_NONE=1)
  218. endif()
  219. option(ENABLE_MAC_NONE "Permit \"none\" MAC -- NOT RECOMMMENDED")
  220. add_feature_info("\"none\" MAC" ENABLE_MAC_NONE "")
  221. if(ENABLE_MAC_NONE)
  222. target_compile_definitions(libssh2 PRIVATE LIBSSH2_MAC_NONE=1)
  223. endif()
  224. option(ENABLE_GEX_NEW
  225. "Enable diffie-hellman-group-exchange-sha1 method" ON)
  226. add_feature_info("diffie-hellman-group-exchange-sha1" ENABLE_GEX_NEW
  227. "\"new\" diffie-hellman-group-exchange-sha1 method")
  228. if(ENABLE_GEX_NEW)
  229. target_compile_definitions(libssh2 PRIVATE LIBSSH2_DH_GEX_NEW=1)
  230. endif()
  231. # Enable debugging logging by default if the user configured a debug build
  232. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  233. set(DEBUG_LOGGING_DEFAULT ON)
  234. else()
  235. set(DEBUG_LOGGING_DEFAULT OFF)
  236. endif()
  237. option(ENABLE_DEBUG_LOGGING "log execution with debug trace"
  238. ${DEBUG_LOGGING_DEFAULT})
  239. add_feature_info(Logging ENABLE_DEBUG_LOGGING
  240. "Logging of execution with debug trace")
  241. if(ENABLE_DEBUG_LOGGING)
  242. target_compile_definitions(libssh2 PRIVATE LIBSSH2DEBUG)
  243. endif()
  244. ## Platform checks
  245. check_include_files(unistd.h HAVE_UNISTD_H)
  246. check_include_files(inttypes.h HAVE_INTTYPES_H)
  247. check_include_files(stdlib.h HAVE_STDLIB_H)
  248. check_include_files(sys/select.h HAVE_SYS_SELECT_H)
  249. check_include_files(sys/uio.h HAVE_SYS_UIO_H)
  250. check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
  251. check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H)
  252. check_include_files(sys/time.h HAVE_SYS_TIME_H)
  253. check_include_files(sys/un.h HAVE_SYS_UN_H)
  254. check_include_files(windows.h HAVE_WINDOWS_H)
  255. check_include_files(ws2tcpip.h HAVE_WS2TCPIP_H)
  256. check_include_files(winsock2.h HAVE_WINSOCK2_H)
  257. check_type_size("long long" LONGLONG)
  258. if(HAVE_SYS_TIME_H)
  259. check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
  260. else()
  261. check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
  262. endif()
  263. if(HAVE_STDLIB_H)
  264. check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
  265. else()
  266. check_function_exists(strtoll HAVE_STRTOLL)
  267. endif()
  268. if (NOT HAVE_STRTOLL)
  269. # Try _strtoi64 if strtoll isn't available
  270. check_symbol_exists(_strtoi64 stdlib.h HAVE_STRTOI64)
  271. endif()
  272. check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
  273. check_symbol_exists(memset_s string.h HAVE_MEMSET_S)
  274. if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR
  275. ${CMAKE_SYSTEM_NAME} STREQUAL "Interix")
  276. # poll() does not work on these platforms
  277. #
  278. # Interix: "does provide poll(), but the implementing developer must
  279. # have been in a bad mood, because poll() only works on the /proc
  280. # filesystem here"
  281. #
  282. # Mac OS X's poll has funny behaviors, like:
  283. # not being able to do poll on no filedescriptors (10.3?)
  284. # not being able to poll on some files (like anything in /dev)
  285. # not having reliable timeout support
  286. # inconsistent return of POLLHUP where other implementations give POLLIN
  287. message("poll use is disabled on this platform")
  288. else()
  289. check_function_exists(poll HAVE_POLL)
  290. endif()
  291. append_needed_socket_libraries(LIBRARIES)
  292. # Non-blocking socket support tests. Must be after library tests to
  293. # link correctly
  294. set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  295. set(CMAKE_REQUIRED_LIBRARIES ${LIBRARIES})
  296. check_nonblocking_socket_support()
  297. set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
  298. configure_file(
  299. ${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in
  300. ${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h)
  301. # to find generated header
  302. target_include_directories(libssh2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
  303. # Check for the OS.
  304. # Daniel's note: this should not be necessary and we need to work to
  305. # get this removed.
  306. if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  307. target_compile_definitions(libssh2 PRIVATE LIBSSH2_WIN32)
  308. elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
  309. target_compile_definitions(libssh2 PRIVATE LIBSSH2_DARWIN)
  310. endif()
  311. if(MSVC)
  312. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od")
  313. set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG")
  314. endif()
  315. if(CMAKE_VERSION VERSION_LESS "2.8.12")
  316. # Fall back to over-linking dependencies
  317. target_link_libraries(libssh2 ${LIBRARIES})
  318. else()
  319. target_link_libraries(libssh2 PRIVATE ${LIBRARIES})
  320. endif()
  321. ## Installation
  322. install(FILES
  323. ${PROJECT_SOURCE_DIR}/include/libssh2.h
  324. ${PROJECT_SOURCE_DIR}/include/libssh2_publickey.h
  325. ${PROJECT_SOURCE_DIR}/include/libssh2_sftp.h
  326. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  327. install(TARGETS libssh2
  328. EXPORT Libssh2Config
  329. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  330. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  331. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
  332. if(BUILD_SHARED_LIBS)
  333. list(APPEND _RUNTIME_DEPENDENCIES $<TARGET_FILE:libssh2>)
  334. endif()
  335. set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL
  336. "Files that must be in the same directory as the executables at runtime.")
  337. # Package config
  338. ## During package installation, install Libssh2Config.cmake
  339. install(EXPORT Libssh2Config
  340. NAMESPACE Libssh2::
  341. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2)
  342. ## During build, register directly from build tree
  343. # create Libssh2Config.cmake
  344. export(TARGETS libssh2 NAMESPACE Libssh2:: FILE Libssh2Config.cmake)
  345. export(PACKAGE Libssh2) # register it
  346. ## Export a .pc file for client projects not using CMaek
  347. if(PC_REQUIRES_PRIVATE)
  348. string(REPLACE ";" "," PC_REQUIRES_PRIVATE "${PC_REQUIRES_PRIVATE}")
  349. endif()
  350. if(PC_LIBS)
  351. string(REPLACE ";" " " PC_LIBS "${PC_LIBS}")
  352. endif()
  353. configure_file(libssh2.pc.in libssh2.pc @ONLY)
  354. install(
  355. FILES ${CMAKE_CURRENT_BINARY_DIR}/libssh2.pc
  356. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  357. ## Versioning
  358. set_target_properties(libssh2 PROPERTIES
  359. SOVERSION 1
  360. VERSION 1.0.1)
  361. include(CMakePackageConfigHelpers)
  362. write_basic_package_version_file(
  363. ${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake
  364. VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}"
  365. COMPATIBILITY SameMajorVersion)
  366. install(
  367. FILES ${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake
  368. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2)