CMakeLists.txt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. if (LOVR)
  14. set(LUA_LIBRARIES ${LOVR_LUA})
  15. else()
  16. ### Dependencies
  17. find_package (LuaJIT)
  18. if (LUAJIT_FOUND)
  19. set(LUA_INCLUDE_DIR ${LUAJIT_INCLUDE_DIR})
  20. set(LUA_LIBRARIES ${LUAJIT_LIBRARY})
  21. else ()
  22. find_package (Lua 5.1 REQUIRED)
  23. endif ()
  24. include_directories (${LUA_INCLUDE_DIR})
  25. endif ()
  26. ### "Libraries"
  27. add_library (https MODULE
  28. lua/main.cpp
  29. )
  30. add_library (https-common STATIC
  31. common/HTTPS.cpp
  32. common/HTTPRequest.cpp
  33. common/HTTPSClient.cpp
  34. common/PlaintextConnection.cpp
  35. common/LibraryLoader.cpp
  36. )
  37. add_library (https-curl STATIC EXCLUDE_FROM_ALL
  38. generic/CurlClient.cpp
  39. )
  40. add_library (https-openssl STATIC EXCLUDE_FROM_ALL
  41. generic/OpenSSLConnection.cpp
  42. )
  43. add_library (https-schannel STATIC EXCLUDE_FROM_ALL
  44. windows/SChannelConnection.cpp
  45. )
  46. add_library (https-nsurl STATIC EXCLUDE_FROM_ALL
  47. apple/NSURLClient.mm
  48. )
  49. add_library (https-android STATIC EXCLUDE_FROM_ALL
  50. android/AndroidClient.cpp
  51. )
  52. add_library (https-wininet STATIC EXCLUDE_FROM_ALL
  53. windows/WinINetClient.cpp
  54. )
  55. ### Flags
  56. if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  57. option (USE_CURL_BACKEND "Use the libcurl backend" ON)
  58. option (USE_OPENSSL_BACKEND "Use the openssl backend" ON)
  59. option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
  60. option (USE_NSURL_BACKEND "Use the NSUrl backend (apple-only)" OFF)
  61. option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF)
  62. option (USE_WININET_BACKEND "Use the WinINet backend (windows-only)" OFF)
  63. option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
  64. elseif (WIN32)
  65. option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
  66. option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
  67. option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" ON)
  68. option (USE_NSURL_BACKEND "Use the NSUrl backend (apple-only)" OFF)
  69. option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF)
  70. if (CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
  71. option (USE_WININET_BACKEND "Use the WinINet backend (windows-only)" OFF)
  72. else ()
  73. option (USE_WININET_BACKEND "Use the WinINet backend (windows-only)" ON)
  74. endif ()
  75. option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" ON)
  76. # Windows needs to link with Lua libraries
  77. target_link_libraries(https ${LUA_LIBRARIES})
  78. elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
  79. option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
  80. option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
  81. option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
  82. option (USE_NSURL_BACKEND "Use the NSUrl backend (apple-only)" ON)
  83. option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF)
  84. option (USE_WININET_BACKEND "Use the WinINet backend (windows-only)" OFF)
  85. option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
  86. if (NOT IOS)
  87. # macOS needs -undefined dynamic_lookup
  88. target_link_options(https PRIVATE -undefined dynamic_lookup)
  89. else ()
  90. target_link_libraries(https ${LUA_LIBRARIES})
  91. endif ()
  92. elseif (ANDROID)
  93. option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
  94. option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
  95. option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
  96. option (USE_NSURL_BACKEND "Use the NSUrl backend (apple-only)" OFF)
  97. option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" ON)
  98. option (USE_WININET_BACKEND "Use the WinINet backend (windows-only)" OFF)
  99. option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
  100. # Android needs to link with Lua libraries
  101. target_link_libraries(https ${LUA_LIBRARIES})
  102. endif ()
  103. option (DEBUG_SCHANNEL "Enable debug output in schannel backend" OFF)
  104. set_target_properties(https PROPERTIES PREFIX "")
  105. target_link_libraries (https https-common)
  106. if (USE_CURL_BACKEND)
  107. set(HTTPS_BACKEND_CURL ON)
  108. find_package (CURL REQUIRED)
  109. include_directories (${CURL_INCLUDE_DIRS})
  110. target_link_libraries (https https-curl)
  111. endif ()
  112. if (USE_OPENSSL_BACKEND)
  113. set(HTTPS_BACKEND_OPENSSL ON)
  114. find_package (OpenSSL REQUIRED)
  115. include_directories (${OPENSSL_INCLUDE_DIR})
  116. target_link_libraries (https https-openssl)
  117. endif ()
  118. if (USE_SCHANNEL_BACKEND)
  119. set(HTTPS_BACKEND_SCHANNEL ON)
  120. target_link_libraries (https https-schannel ws2_32 secur32)
  121. endif ()
  122. if (USE_NSURL_BACKEND)
  123. set(HTTPS_BACKEND_NSURL ON)
  124. set_target_properties(
  125. https-nsurl
  126. PROPERTIES
  127. MACOSX_BUNDLE YES
  128. XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
  129. )
  130. target_link_libraries (https "-framework Foundation")
  131. target_link_libraries (https https-nsurl)
  132. endif ()
  133. if (USE_ANDROID_BACKEND)
  134. set(HTTPS_BACKEND_ANDROID ON)
  135. target_link_libraries (https https-android)
  136. message(STATUS "Ensure to add the Java files to your project too!")
  137. endif ()
  138. if (USE_WININET_BACKEND)
  139. set(HTTPS_BACKEND_WININET ON)
  140. target_link_libraries (https https-wininet wininet)
  141. endif ()
  142. if (USE_WINSOCK)
  143. set(HTTPS_USE_WINSOCK ON)
  144. endif ()
  145. ### Generate config-generated.h
  146. add_compile_definitions(HTTPS_HAVE_CONFIG_GENERATED_H)
  147. configure_file (
  148. common/config-generated.h.in
  149. common/config-generated.h
  150. )
  151. ### Install target
  152. install(TARGETS https DESTINATION .)