1- cmake_minimum_required (VERSION 3.0 )
1+ cmake_minimum_required (VERSION 3.13 )
22
3- set (HTTPS_SOURCES
3+ ### Basic compilation settings
4+ set (CMAKE_POSITION_INDEPENDENT_CODE TRUE )
5+ add_definitions (-DNOMINMAX )
6+
7+ include_directories (
8+ ${CMAKE_CURRENT_SOURCE_DIR}
9+ ${CMAKE_CURRENT_BINARY_DIR}
10+ )
11+
12+ ### Compiler-specific flags
13+ if (MSVC )
14+ set (DLLEXPORT "__declspec(dllexport)" )
15+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
16+ set (DLLEXPORT "__attribute__((visibility(\" default\" )))" )
17+ add_compile_options ("-fvisibility=hidden" )
18+ add_link_options ("-fvisibility=hidden" )
19+ endif ()
20+
21+ ### "Libraries"
22+ add_library (https MODULE
423 lua/main.cpp
24+ )
25+
26+ add_library (https-common STATIC
527 common/HTTPRequest.cpp
628 common/HTTPSClient.cpp
729 common/PlaintextConnection.cpp
830)
9- set (HTTPS_LINK_LIBRARIES)
10- set (HTTPS_INCLUDE_DIRECTORIES
11- ${CMAKE_CURRENT_SOURCE_DIR}
12- ${CMAKE_CURRENT_BINARY_DIR}
31+
32+ add_library (https-curl STATIC EXCLUDE_FROM_ALL
33+ generic/CurlClient.cpp
34+ )
35+
36+ add_library (https-openssl STATIC EXCLUDE_FROM_ALL
37+ generic/OpenSSLConnection.cpp
38+ )
39+
40+ add_library (https-schannel STATIC EXCLUDE_FROM_ALL
41+ windows/SChannelConnection.cpp
42+ )
43+
44+ add_library (https-nsurl STATIC EXCLUDE_FROM_ALL
45+ macos/NSURLClient.mm
46+ )
47+
48+ add_library (https-android STATIC EXCLUDE_FROM_ALL
49+ android /AndroidClient.cpp
1350)
1451
1552### Flags
@@ -21,7 +58,7 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
2158 option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF )
2259
2360 option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF )
24- elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
61+ elseif (WIN32 )
2562 option (USE_CURL_BACKEND "Use the libcurl backend" OFF )
2663 option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF )
2764 option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" ON )
@@ -48,57 +85,45 @@ elseif (ANDROID)
4885endif ()
4986option (DEBUG_SCHANNEL "Enable debug output in schannel backend" OFF )
5087
88+ set_target_properties (https PROPERTIES PREFIX "" )
89+
5190### Dependencies
91+ target_link_libraries (https https-common )
5292
5393find_package (Lua 5.1 REQUIRED )
54- list ( APPEND HTTPS_INCLUDE_DIRECTORIES ${LUA_INCLUDE_DIR} )
55- list ( APPEND HTTPS_LINK_LIBRARIES ${LUA_LIBRARIES} )
94+ include_directories ( ${LUA_INCLUDE_DIR} )
95+ target_link_libraries ( https ${LUA_LIBRARIES} )
5696
5797if (USE_CURL_BACKEND)
5898 find_package (CURL REQUIRED )
59- list (APPEND HTTPS_SOURCES generic/CurlClient.cpp)
60- list (APPEND HTTPS_INCLUDE_DIRECTORIES ${CURL_INCLUDE_DIR} )
61- list (APPEND HTTPS_LINK_LIBRARIES ${CURL_LIBRARIES} )
99+ include_directories (${CURL_INCLUDE_DIR} )
100+ target_link_libraries (https https-curl ${CURL_LIBRARIES} )
62101endif ()
63102
64103if (USE_OPENSSL_BACKEND)
65104 find_package (OpenSSL REQUIRED )
66- list (APPEND HTTPS_SOURCES generic/OpenSSLConnection.cpp)
67- list (APPEND HTTPS_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR} )
68- list (APPEND HTTPS_LINK_LIBRARIES ${OPENSSL_LIBRARIES} )
105+ include_directories (${OPENSSL_INCLUDE_DIR} )
106+ target_link_libraries (https https-openssl ${OPENSSL_LIBRARIES} )
69107endif ()
70108
71109if (USE_SCHANNEL_BACKEND)
72- list (APPEND HTTPS_SOURCES windows/SChannelConnection.cpp)
73- list (APPEND HTTPS_LINK_LIBRARIES ws2_32 secur32)
110+ target_link_libraries (https https-schannel ws2_32 secur32 )
74111endif ()
75112
76113if (USE_NSURL_BACKEND)
77- list (APPEND HTTPS_SOURCES macos/NSURLClient.mm)
114+ set_target_properties (
115+ https-nsurl
116+ PROPERTIES
117+ MACOSX_BUNDLE YES
118+ XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
119+ )
120+ target_link_libraries (https "-framework Foundation" )
121+ target_link_libraries (https https-nsurl )
78122endif ()
79123
80124if (USE_ANDROID_BACKEND)
81- list (APPEND HTTPS_SOURCES android /AndroidClient.cpp)
82- endif ()
83-
84- ### Main library
85- add_library (https MODULE ${HTTPS_SOURCES} )
86-
87- ### Target options
88- target_include_directories (https PRIVATE ${HTTPS_INCLUDE_DIRECTORIES} )
89- target_compile_definitions (https PRIVATE NOMINMAX )
90- target_link_libraries (https ${HTTPS_LINK_LIBRARIES} )
91- set_target_properties (https PROPERTIES
92- POSITION_INDEPENDENT_CODE ON
93- CXX_VISIBILITY_PRESET hidden
94- PREFIX ""
95- )
96-
97- ### Compiler-specific flags
98- if (MSVC )
99- set (DLLEXPORT "__declspec(dllexport)" )
100- elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
101- set (DLLEXPORT "__attribute__((visibility(\" default\" )))" )
125+ target_link_libraries (https https-android )
126+ message (STATUS "Ensure to add the Java files to your project too!" )
102127endif ()
103128
104129### Generate config.h
0 commit comments