CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. cmake_minimum_required (VERSION 3.13)
  2. ### Basic compilation settings
  3. set (CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  4. include_directories (
  5. ${CMAKE_CURRENT_SOURCE_DIR}
  6. ${CMAKE_CURRENT_BINARY_DIR}
  7. )
  8. ### Compiler-specific flags
  9. if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
  10. add_compile_options ("-fvisibility=hidden")
  11. add_link_options ("-fvisibility=hidden")
  12. endif ()
  13. ### "Libraries"
  14. add_library (https MODULE
  15. lua/main.cpp
  16. )
  17. add_library (https-common STATIC
  18. common/HTTPS.cpp
  19. common/HTTPRequest.cpp
  20. common/HTTPSClient.cpp
  21. common/PlaintextConnection.cpp
  22. )
  23. add_library (https-curl STATIC EXCLUDE_FROM_ALL
  24. generic/CurlClient.cpp
  25. )
  26. add_library (https-openssl STATIC EXCLUDE_FROM_ALL
  27. generic/OpenSSLConnection.cpp
  28. )
  29. add_library (https-schannel STATIC EXCLUDE_FROM_ALL
  30. windows/SChannelConnection.cpp
  31. )
  32. add_library (https-nsurl STATIC EXCLUDE_FROM_ALL
  33. macos/NSURLClient.mm
  34. )
  35. add_library (https-android STATIC EXCLUDE_FROM_ALL
  36. android/AndroidClient.cpp
  37. )
  38. ### Flags
  39. if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  40. option (USE_CURL_BACKEND "Use the libcurl backend" ON)
  41. option (USE_OPENSSL_BACKEND "Use the openssl backend" ON)
  42. option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
  43. option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" OFF)
  44. option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF)
  45. option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
  46. elseif (WIN32)
  47. option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
  48. option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
  49. option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" ON)
  50. option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" OFF)
  51. option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF)
  52. option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" ON)
  53. elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
  54. option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
  55. option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
  56. option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
  57. option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" ON)
  58. option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF)
  59. option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
  60. elseif (ANDROID)
  61. option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
  62. option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
  63. option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
  64. option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" OFF)
  65. option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" ON)
  66. option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
  67. endif ()
  68. option (DEBUG_SCHANNEL "Enable debug output in schannel backend" OFF)
  69. set_target_properties(https PROPERTIES PREFIX "")
  70. ### Dependencies
  71. target_link_libraries (https https-common)
  72. find_package (Lua 5.1 REQUIRED)
  73. include_directories (${LUA_INCLUDE_DIR})
  74. target_link_libraries (https ${LUA_LIBRARIES})
  75. if (USE_CURL_BACKEND)
  76. set(HTTPS_BACKEND_CURL ON)
  77. find_package (CURL REQUIRED)
  78. include_directories (${CURL_INCLUDE_DIR})
  79. target_link_libraries (https https-curl ${CURL_LIBRARIES})
  80. endif ()
  81. if (USE_OPENSSL_BACKEND)
  82. set(HTTPS_BACKEND_OPENSSL ON)
  83. find_package (OpenSSL REQUIRED)
  84. include_directories (${OPENSSL_INCLUDE_DIR})
  85. target_link_libraries (https https-openssl ${OPENSSL_LIBRARIES})
  86. endif ()
  87. if (USE_SCHANNEL_BACKEND)
  88. set(HTTPS_BACKEND_SCHANNEL ON)
  89. target_link_libraries (https https-schannel ws2_32 secur32)
  90. endif ()
  91. if (USE_NSURL_BACKEND)
  92. set(HTTPS_BACKEND_NSURL ON)
  93. set_target_properties(
  94. https-nsurl
  95. PROPERTIES
  96. MACOSX_BUNDLE YES
  97. XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
  98. )
  99. target_link_libraries (https "-framework Foundation")
  100. target_link_libraries (https https-nsurl)
  101. endif ()
  102. if (USE_ANDROID_BACKEND)
  103. set(HTTPS_BACKEND_ANDROID ON)
  104. target_link_libraries (https https-android)
  105. message(STATUS "Ensure to add the Java files to your project too!")
  106. endif ()
  107. ### Generate config-generated.h
  108. add_compile_definitions(HTTPS_HAVE_CONFIG_GENERATED_H)
  109. configure_file (
  110. common/config-generated.h.in
  111. common/config-generated.h
  112. )