From 5c7b5af92a96484ec7d91101f50255d7ec3b2b84 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sun, 6 Sep 2020 11:46:25 +0100 Subject: [PATCH] cmake: disable export visibility when building lws static This is complicated by the fact extern on a function declaration implies visibility... we have to make LWS_EXTERN empty when building static. And, setting target_compile_definitions() doesn't work inside macros, so it has to be set explicitly for the plugins. Checking the symbol status needs nm -C -D as per https://stackoverflow.com/questions/37934388/symbol-visibility-not-working-as-expected after this patch, libwebsockets.a shows no symbols when checked like that and the static-linked minimal examples only show -U for their other dynamic imports. In a handful of cases we use LWS_EXTERN on extern data declarations, those then need to change to explicit extern. --- include/libwebsockets.h | 39 ++++++++--- .../libwebsockets/lws-secure-streams-client.h | 2 +- lib/CMakeLists.txt | 2 + lib/core-net/connect.c | 1 - lib/core-net/private-lib-core-net.h | 6 +- lib/core/private-lib-core.h | 38 +++++------ lib/event-libs/CMakeLists.txt | 1 + lib/misc/base64-decode.c | 3 +- lib/misc/dir.c | 1 - lib/misc/lejp.c | 1 - lib/misc/lws-ring.c | 1 - lib/misc/sha-1.c | 1 - lib/roles/h2/private-lib-roles-h2.h | 44 ++++++------- lib/tls/openssl/lws-genhash.c | 2 +- lib/tls/private-lib-tls.h | 21 +++--- lib/tls/private-network.h | 64 +++++++++---------- lwsws/CMakeLists.txt | 18 +++--- plugin-standalone/CMakeLists.txt | 1 + plugins/CMakeLists.txt | 44 ++++++++----- test-apps/CMakeLists.txt | 5 +- 20 files changed, 166 insertions(+), 129 deletions(-) diff --git a/include/libwebsockets.h b/include/libwebsockets.h index 85fd5ec60..e65f8d52f 100644 --- a/include/libwebsockets.h +++ b/include/libwebsockets.h @@ -93,7 +93,7 @@ typedef unsigned long long lws_intptr_t; #define LWS_WARN_DEPRECATED #define LWS_FORMAT(string_index) -#if !defined(LWS_EXTERN) +#if !defined(LWS_EXTERN) && defined(LWS_BUILDING_SHARED) #ifdef LWS_DLL #ifdef LWS_INTERNAL #define LWS_EXTERN extern __declspec(dllexport) @@ -103,6 +103,11 @@ typedef unsigned long long lws_intptr_t; #endif #endif +#if !defined(LWS_INTERNAL) && !defined(LWS_EXTERN) +#define LWS_EXTERN +#define LWS_VISIBLE +#endif + #define LWS_INVALID_FILE INVALID_HANDLE_VALUE #define LWS_SOCK_INVALID (INVALID_SOCKET) #define LWS_O_RDONLY _O_RDONLY @@ -150,7 +155,6 @@ typedef unsigned long long lws_intptr_t; #if defined(__FreeBSD__) #include #endif - #if defined(__GNUC__) /* warn_unused_result attribute only supported by GCC 3.4 or later */ @@ -160,25 +164,44 @@ typedef unsigned long long lws_intptr_t; #define LWS_WARN_UNUSED_RESULT #endif +#if defined(LWS_BUILDING_SHARED) +/* this is only set when we're building lws itself shared */ #define LWS_VISIBLE __attribute__((visibility("default"))) +#define LWS_EXTERN extern + +#else /* not shared */ +#if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__) +#define LWS_VISIBLE +#define LWS_EXTERN extern +#else +/* + * If we explicitly say hidden here, symbols exist as T but + * cannot be imported at link-time. + */ +#define LWS_VISIBLE +#define LWS_EXTERN +#endif + +#endif /* not shared */ + #define LWS_WARN_DEPRECATED __attribute__ ((deprecated)) #define LWS_FORMAT(string_index) __attribute__ ((format(printf, string_index, string_index+1))) -#else +#else /* not GNUC */ + #define LWS_VISIBLE #define LWS_WARN_UNUSED_RESULT #define LWS_WARN_DEPRECATED #define LWS_FORMAT(string_index) +#if !defined(LWS_EXTERN) +#define LWS_EXTERN extern #endif +#endif + #if defined(__ANDROID__) #include #include #endif - -#endif - -#ifndef LWS_EXTERN -#define LWS_EXTERN extern #endif #ifdef _WIN32 diff --git a/include/libwebsockets/lws-secure-streams-client.h b/include/libwebsockets/lws-secure-streams-client.h index 98747989e..035c7c3a1 100644 --- a/include/libwebsockets/lws-secure-streams-client.h +++ b/include/libwebsockets/lws-secure-streams-client.h @@ -157,7 +157,7 @@ lws_sspc_proxy_create(struct lws_context *context); LWS_VISIBLE LWS_EXTERN struct lws_context * lws_sspc_get_context(struct lws_sspc_handle *h); -LWS_VISIBLE LWS_EXTERN const struct lws_protocols lws_sspc_protocols[]; +LWS_VISIBLE extern const struct lws_protocols lws_sspc_protocols[2]; LWS_VISIBLE LWS_EXTERN const char * lws_sspc_rideshare(struct lws_sspc_handle *h); diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a93426e4b..dc9813145 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -154,6 +154,7 @@ if (LWS_WITH_STATIC) set_target_properties(websockets PROPERTIES LINKER_LANGUAGE C) list(APPEND LWS_LIBRARIES websockets) target_include_directories(websockets PRIVATE ${LWS_LIB_BUILD_INC_PATHS}) + target_compile_definitions(websockets PRIVATE LWS_BUILDING_STATIC) if (WIN32) # Windows uses the same .lib ending for static libraries and shared @@ -174,6 +175,7 @@ if (LWS_WITH_SHARED) set_target_properties(websockets_shared PROPERTIES LINKER_LANGUAGE C) list(APPEND LWS_LIBRARIES websockets_shared) target_include_directories(websockets_shared PRIVATE ${LWS_LIB_BUILD_INC_PATHS}) + target_compile_definitions(websockets_shared PRIVATE LWS_BUILDING_SHARED) # We want the shared lib to be named "libwebsockets" # not "libwebsocket_shared". diff --git a/lib/core-net/connect.c b/lib/core-net/connect.c index 937290ebf..72c613c14 100644 --- a/lib/core-net/connect.c +++ b/lib/core-net/connect.c @@ -22,7 +22,6 @@ * IN THE SOFTWARE. */ -#include #include "private-lib-core.h" struct lws * diff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h index ea785c509..b68dc6577 100644 --- a/lib/core-net/private-lib-core-net.h +++ b/lib/core-net/private-lib-core-net.h @@ -1086,11 +1086,11 @@ lws_change_pollfd(struct lws *wsi, int _and, int _or); #if defined(LWS_WITH_SERVER) int _lws_vhost_init_server(const struct lws_context_creation_info *info, struct lws_vhost *vhost); - LWS_EXTERN struct lws_vhost * +struct lws_vhost * lws_select_vhost(struct lws_context *context, int port, const char *servername); - LWS_EXTERN int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_parse_ws(struct lws *wsi, unsigned char **buf, size_t len); - LWS_EXTERN void +void lws_server_get_canonical_hostname(struct lws_context *context, const struct lws_context_creation_info *info); #else diff --git a/lib/core/private-lib-core.h b/lib/core/private-lib-core.h index 55d4aeab0..b313c6895 100644 --- a/lib/core/private-lib-core.h +++ b/lib/core/private-lib-core.h @@ -570,7 +570,7 @@ lws_vhost_destroy1(struct lws_vhost *vh); #if defined(LWS_PLAT_FREERTOS) -LWS_EXTERN int +int lws_find_string_in_file(const char *filename, const char *str, int stringlen); #endif @@ -587,22 +587,22 @@ struct lws_buflist { size_t pos; }; -LWS_EXTERN char * +char * lws_strdup(const char *s); -LWS_EXTERN int log_level; +extern int log_level; -LWS_EXTERN int +int lws_b64_selftest(void); #ifndef LWS_NO_DAEMONIZE - LWS_EXTERN pid_t get_daemonize_pid(); + pid_t get_daemonize_pid(); #else #define get_daemonize_pid() (0) #endif -LWS_EXTERN void lwsl_emit_stderr(int level, const char *line); +void lwsl_emit_stderr(int level, const char *line); #if !defined(LWS_WITH_TLS) #define LWS_SSL_ENABLED(context) (0) @@ -657,13 +657,13 @@ lws_vhost_unlock(struct lws_vhost *vhost) #define lws_pt_stats_unlock(_a) (void)(_a) #endif -LWS_EXTERN int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_ssl_pending_no_ssl(struct lws *wsi); int @@ -688,10 +688,10 @@ lws_find_mount(struct lws *wsi, const char *uri_ptr, int uri_len); /* * custom allocator */ -LWS_EXTERN void * +void * lws_realloc(void *ptr, size_t size, const char *reason); -LWS_EXTERN void * LWS_WARN_UNUSED_RESULT +void * LWS_WARN_UNUSED_RESULT lws_zalloc(size_t size, const char *reason); #ifdef LWS_PLAT_OPTEE @@ -716,17 +716,17 @@ lws_vfs_select_fops(const struct lws_plat_file_ops *fops, const char *vfs_path, /* lws_plat_ */ -LWS_EXTERN int +int lws_plat_context_early_init(void); -LWS_EXTERN void +void lws_plat_context_early_destroy(struct lws_context *context); -LWS_EXTERN void +void lws_plat_context_late_destroy(struct lws_context *context); -LWS_EXTERN int +int lws_plat_init(struct lws_context *context, const struct lws_context_creation_info *info); -LWS_EXTERN int +int lws_plat_drop_app_privileges(struct lws_context *context, int actually_drop); #if defined(LWS_WITH_UNIX_SOCK) && !defined(WIN32) @@ -740,11 +740,11 @@ lws_plat_ntpclient_config(struct lws_context *context); int lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len); -LWS_EXTERN int +int lws_check_byte_utf8(unsigned char state, unsigned char c); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len); -LWS_EXTERN int alloc_file(struct lws_context *context, const char *filename, +int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf, lws_filepos_t *amount); void lws_msleep(unsigned int); diff --git a/lib/event-libs/CMakeLists.txt b/lib/event-libs/CMakeLists.txt index d501bbcb3..3bb647652 100644 --- a/lib/event-libs/CMakeLists.txt +++ b/lib/event-libs/CMakeLists.txt @@ -42,6 +42,7 @@ macro(create_evlib_plugin PLUGIN_NAME MAIN_SRC PLUGIN_HDR EVLIB) target_link_libraries(websockets-${PLUGIN_NAME} websockets_shared ${EVLIB}) add_dependencies(websockets-${PLUGIN_NAME} websockets_shared) + target_compile_definitions(websockets-${PLUGIN_NAME} PRIVATE LWS_BUILDING_SHARED) target_include_directories(websockets-${PLUGIN_NAME} PRIVATE ${PLUGIN_INCLUDE} ${LWS_LIB_BUILD_INC_PATHS}) diff --git a/lib/misc/base64-decode.c b/lib/misc/base64-decode.c index 885ddaccc..a47743df7 100644 --- a/lib/misc/base64-decode.c +++ b/lib/misc/base64-decode.c @@ -36,11 +36,10 @@ * of libwebsockets */ -#include +#include "private-lib-core.h" #include #include -#include "private-lib-core.h" static const char encode_orig[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz0123456789+/"; diff --git a/lib/misc/dir.c b/lib/misc/dir.c index 1ebe96d48..6502d521e 100644 --- a/lib/misc/dir.c +++ b/lib/misc/dir.c @@ -29,7 +29,6 @@ #define _DARWIN_C_SOURCE #endif -#include #include "private-lib-core.h" #include #include diff --git a/lib/misc/lejp.c b/lib/misc/lejp.c index 8f7a0c095..49cb44768 100644 --- a/lib/misc/lejp.c +++ b/lib/misc/lejp.c @@ -22,7 +22,6 @@ * IN THE SOFTWARE. */ -#include #include "private-lib-core.h" #include #include diff --git a/lib/misc/lws-ring.c b/lib/misc/lws-ring.c index edc3691cc..e30183592 100644 --- a/lib/misc/lws-ring.c +++ b/lib/misc/lws-ring.c @@ -22,7 +22,6 @@ * IN THE SOFTWARE. */ -#include #include "private-lib-core.h" struct lws_ring * diff --git a/lib/misc/sha-1.c b/lib/misc/sha-1.c index 86d61f3d2..109bfdb8d 100644 --- a/lib/misc/sha-1.c +++ b/lib/misc/sha-1.c @@ -32,7 +32,6 @@ * implemented by Jun-ichiro itojun Itoh */ -#include #include "private-lib-core.h" #ifdef LWS_HAVE_SYS_TYPES_H diff --git a/lib/roles/h2/private-lib-roles-h2.h b/lib/roles/h2/private-lib-roles-h2.h index 454fe1b9e..9bce1d9c0 100644 --- a/lib/roles/h2/private-lib-roles-h2.h +++ b/lib/roles/h2/private-lib-roles-h2.h @@ -322,58 +322,58 @@ struct _lws_h2_related { int lws_h2_rst_stream(struct lws *wsi, uint32_t err, const char *reason); struct lws * lws_h2_get_nth_child(struct lws *wsi, int n); -LWS_EXTERN void lws_h2_init(struct lws *wsi); -LWS_EXTERN int +void lws_h2_init(struct lws *wsi); +int lws_h2_settings(struct lws *nwsi, struct http2_settings *settings, unsigned char *buf, int len); -LWS_EXTERN int +int lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, lws_filepos_t *inused); -LWS_EXTERN int +int lws_h2_do_pps_send(struct lws *wsi); -LWS_EXTERN int +int lws_h2_frame_write(struct lws *wsi, int type, int flags, unsigned int sid, unsigned int len, unsigned char *buf); -LWS_EXTERN struct lws * +struct lws * lws_wsi_mux_from_id(struct lws *wsi, unsigned int sid); -LWS_EXTERN int +int lws_hpack_interpret(struct lws *wsi, unsigned char c); -LWS_EXTERN int +int lws_add_http2_header_by_name(struct lws *wsi, const unsigned char *name, const unsigned char *value, int length, unsigned char **p, unsigned char *end); -LWS_EXTERN int +int lws_add_http2_header_by_token(struct lws *wsi, enum lws_token_indexes token, const unsigned char *value, int length, unsigned char **p, unsigned char *end); -LWS_EXTERN int +int lws_add_http2_header_status(struct lws *wsi, unsigned int code, unsigned char **p, unsigned char *end); -LWS_EXTERN void +void lws_hpack_destroy_dynamic_header(struct lws *wsi); -LWS_EXTERN int +int lws_hpack_dynamic_size(struct lws *wsi, int size); -LWS_EXTERN int +int lws_h2_goaway(struct lws *wsi, uint32_t err, const char *reason); -LWS_EXTERN int +int lws_h2_tx_cr_get(struct lws *wsi); -LWS_EXTERN void +void lws_h2_tx_cr_consume(struct lws *wsi, int consumed); -LWS_EXTERN int +int lws_hdr_extant(struct lws *wsi, enum lws_token_indexes h); -LWS_EXTERN void +void lws_pps_schedule(struct lws *wsi, struct lws_h2_protocol_send *pss); -LWS_EXTERN const struct http2_settings lws_h2_defaults; -LWS_EXTERN int +extern const struct http2_settings lws_h2_defaults; +int lws_h2_ws_handshake(struct lws *wsi); -LWS_EXTERN int lws_h2_issue_preface(struct lws *wsi); -LWS_EXTERN int +int lws_h2_issue_preface(struct lws *wsi); +int lws_h2_client_handshake(struct lws *wsi); -LWS_EXTERN struct lws * +struct lws * lws_wsi_h2_adopt(struct lws *parent_wsi, struct lws *wsi); int lws_handle_POLLOUT_event_h2(struct lws *wsi); diff --git a/lib/tls/openssl/lws-genhash.c b/lib/tls/openssl/lws-genhash.c index 7ff52186d..743643986 100644 --- a/lib/tls/openssl/lws-genhash.c +++ b/lib/tls/openssl/lws-genhash.c @@ -24,7 +24,7 @@ * lws_genhash provides a hash / hmac abstraction api in lws that works the * same whether you are using openssl or mbedtls hash functions underneath. */ -#include "libwebsockets.h" +#include #include /* * Care: many openssl apis return 1 for success. These are translated to the diff --git a/lib/tls/private-lib-tls.h b/lib/tls/private-lib-tls.h index 2be605222..ea7e06abc 100644 --- a/lib/tls/private-lib-tls.h +++ b/lib/tls/private-lib-tls.h @@ -134,9 +134,9 @@ typedef X509 lws_tls_x509; #include "private-network.h" #endif -LWS_EXTERN int +int lws_context_init_ssl_library(const struct lws_context_creation_info *info); -LWS_EXTERN void +void lws_context_deinit_ssl_library(struct lws_context *context); #define LWS_SSL_ENABLED(vh) (vh && vh->tls.use_ssl) @@ -147,25 +147,24 @@ struct lws_ec_valid_curves { const char *jwa_name; /* list terminates with NULL jwa_name */ }; -LWS_EXTERN enum lws_tls_extant +enum lws_tls_extant lws_tls_use_any_upgrade_check_extant(const char *name); -LWS_EXTERN int openssl_websocket_private_data_index; +extern int openssl_websocket_private_data_index; - -LWS_EXTERN void +void lws_tls_err_describe_clear(void); -LWS_EXTERN int +int lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type, union lws_tls_cert_info_results *buf, size_t len); -LWS_EXTERN int +int lws_tls_check_all_cert_lifetimes(struct lws_context *context); -LWS_EXTERN int +int lws_tls_alloc_pem_to_der_file(struct lws_context *context, const char *filename, const char *inbuf, lws_filepos_t inlen, uint8_t **buf, lws_filepos_t *amount); -LWS_EXTERN char * +char * lws_ssl_get_error_string(int status, int ret, char *buf, size_t len); int @@ -179,7 +178,7 @@ lws_gencrypto_destroy_elements(struct lws_gencrypto_keyelem *el, int m); struct lws_gencrypto_keyelem; struct lws_ec_curves; -LWS_EXTERN const struct lws_ec_curves lws_ec_curves[4]; +extern const struct lws_ec_curves lws_ec_curves[4]; const struct lws_ec_curves * lws_genec_curve(const struct lws_ec_curves *table, const char *name); LWS_VISIBLE void diff --git a/lib/tls/private-network.h b/lib/tls/private-network.h index 0dd3a838d..82444031e 100644 --- a/lib/tls/private-network.h +++ b/lib/tls/private-network.h @@ -78,52 +78,52 @@ struct lws_lws_tls { }; -LWS_EXTERN void +void lws_context_init_alpn(struct lws_vhost *vhost); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_ssl_pending(struct lws *wsi); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_server_socket_service_ssl(struct lws *new_wsi, lws_sockfd_type accept_fd, char is_pollin); -LWS_EXTERN int +int lws_ssl_close(struct lws *wsi); -LWS_EXTERN void +void lws_ssl_SSL_CTX_destroy(struct lws_vhost *vhost); -LWS_EXTERN void +void lws_ssl_context_destroy(struct lws_context *context); void __lws_ssl_remove_wsi_from_buffered_list(struct lws *wsi); LWS_VISIBLE void lws_ssl_remove_wsi_from_buffered_list(struct lws *wsi); -LWS_EXTERN int +int lws_ssl_client_bio_create(struct lws *wsi); -LWS_EXTERN int +int lws_ssl_client_connect1(struct lws *wsi, char *errbuf, int len); -LWS_EXTERN int +int lws_ssl_client_connect2(struct lws *wsi, char *errbuf, int len); -LWS_EXTERN int +int lws_tls_fake_POLLIN_for_buffered(struct lws_context_per_thread *pt); -LWS_EXTERN int +int lws_gate_accepts(struct lws_context *context, int on); -LWS_EXTERN void +void lws_ssl_bind_passphrase(lws_tls_ctx *ssl_ctx, int is_client, const struct lws_context_creation_info *info); -LWS_EXTERN void +void lws_ssl_info_callback(const lws_tls_conn *ssl, int where, int ret); -LWS_EXTERN int +int lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, const char *cert, const char *private_key, const char *mem_cert, size_t len_mem_cert, const char *mem_privkey, size_t mem_privkey_len); -LWS_EXTERN enum lws_tls_extant +enum lws_tls_extant lws_tls_generic_cert_checks(struct lws_vhost *vhost, const char *cert, const char *private_key); #if defined(LWS_WITH_SERVER) - LWS_EXTERN int + int lws_context_init_server_ssl(const struct lws_context_creation_info *info, struct lws_vhost *vhost); void @@ -133,35 +133,35 @@ lws_tls_generic_cert_checks(struct lws_vhost *vhost, const char *cert, #define lws_tls_acme_sni_cert_destroy(_a) #endif -LWS_EXTERN void +void lws_ssl_destroy(struct lws_vhost *vhost); /* * lws_tls_ abstract backend implementations */ -LWS_EXTERN int +int lws_tls_server_client_cert_verify_config(struct lws_vhost *vh); -LWS_EXTERN int +int lws_tls_server_vhost_backend_init(const struct lws_context_creation_info *info, struct lws_vhost *vhost, struct lws *wsi); -LWS_EXTERN int +int lws_tls_server_new_nonblocking(struct lws *wsi, lws_sockfd_type accept_fd); -LWS_EXTERN enum lws_ssl_capable_status +enum lws_ssl_capable_status lws_tls_server_accept(struct lws *wsi); -LWS_EXTERN enum lws_ssl_capable_status +enum lws_ssl_capable_status lws_tls_server_abort_connection(struct lws *wsi); -LWS_EXTERN enum lws_ssl_capable_status +enum lws_ssl_capable_status __lws_tls_shutdown(struct lws *wsi); -LWS_EXTERN enum lws_ssl_capable_status +enum lws_ssl_capable_status lws_tls_client_connect(struct lws *wsi, char *errbuf, int len); -LWS_EXTERN int +int lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len); -LWS_EXTERN int +int lws_tls_client_create_vhost_context(struct lws_vhost *vh, const struct lws_context_creation_info *info, const char *cipher_list, @@ -176,16 +176,16 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, unsigned int key_mem_len); -LWS_EXTERN lws_tls_ctx * +lws_tls_ctx * lws_tls_ctx_from_wsi(struct lws *wsi); -LWS_EXTERN int +int lws_ssl_get_error(struct lws *wsi, int n); -LWS_EXTERN int +int lws_context_init_client_ssl(const struct lws_context_creation_info *info, struct lws_vhost *vhost); -LWS_EXTERN void +void lws_ssl_info_callback(const lws_tls_conn *ssl, int where, int ret); int diff --git a/lwsws/CMakeLists.txt b/lwsws/CMakeLists.txt index 2febd3026..544667225 100644 --- a/lwsws/CMakeLists.txt +++ b/lwsws/CMakeLists.txt @@ -42,25 +42,27 @@ if (LWS_WITH_LWSWS) source_group("Headers Private" FILES ${LWSWS_HDR}) source_group("Sources" FILES ${LWSWS_SRCS}) - add_executable("lwsws" ${LWSWS_SRCS} ${LWSWS_HDR}) + add_executable(lwsws ${LWSWS_SRCS} ${LWSWS_HDR}) if (LWS_WITH_SHARED) - target_link_libraries("lwsws" websockets_shared ${LIB_LIST_AT_END}) - add_dependencies("lwsws" websockets_shared) + target_link_libraries(lwsws websockets_shared ${LIB_LIST_AT_END}) + add_dependencies(lwsws websockets_shared) else() - target_link_libraries("lwsws" websockets ${LIB_LIST_AT_END}) - add_dependencies("lwsws" websockets) + target_link_libraries(lwsws websockets ${LIB_LIST_AT_END}) + add_dependencies(lwsws websockets) endif() - target_include_directories("lwsws" PRIVATE "${LWS_LIB_INCLUDES}" ${LWS_LIB_BUILD_INC_PATHS}) - + target_include_directories(lwsws PRIVATE "${LWS_LIB_INCLUDES}" ${LWS_LIB_BUILD_INC_PATHS}) # Set test app specific defines. - set_property(TARGET "lwsws" + set_property(TARGET lwsws PROPERTY COMPILE_DEFINITIONS INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" ) install(TARGETS lwsws RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT lwsws ) + target_compile_definitions(lwsws PRIVATE LWS_BUILDING_SHARED) + + endif (LWS_WITH_LWSWS) diff --git a/plugin-standalone/CMakeLists.txt b/plugin-standalone/CMakeLists.txt index 39e8e5668..78ceb385d 100644 --- a/plugin-standalone/CMakeLists.txt +++ b/plugin-standalone/CMakeLists.txt @@ -57,6 +57,7 @@ set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}") source_group("Headers Private" FILES ${PLUGIN_HDR}) source_group("Sources" FILES ${PLUGIN_SRCS}) add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR}) +target_compile_definitions(${PLUGIN_NAME} PRIVATE LWS_BUILDING_SHARED) target_link_libraries(${PLUGIN_NAME} -lwebsockets ${LIBWEBSOCKETS_DEP_LIBS}) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 183c05a10..062992f16 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -58,31 +58,19 @@ if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED) source_group("Headers Private" FILES ${PLUGIN_HDR}) source_group("Sources" FILES ${PLUGIN_SRCS}) add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR}) - - foreach(libpath ${LWS_DEP_LIB_PATHS}) - target_link_directories(${TEST_NAME} ${libpath}) - endforeach() - target_link_libraries(${PLUGIN_NAME} websockets_shared) add_dependencies(${PLUGIN_NAME} websockets_shared) - target_include_directories(${PLUGIN_NAME} PRIVATE ${PLUGIN_INCLUDE} ${LWS_LIB_BUILD_INC_PATHS}) - - # Set test app specific defines. + # doesn't work inside macro :-O + # target_compile_definitions(${PLUGIN_NAME} PRIVATE LWS_BUILDING_SHARED) + target_include_directories(${PLUGIN_NAME} PRIVATE ${PLUGIN_INCLUDE} + ${LWS_LIB_BUILD_INC_PATHS}) set_property(TARGET ${PLUGIN_NAME} PROPERTY COMPILE_DEFINITIONS INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins" ) set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -# SET_TARGET_PROPERTIES(${PLUGIN_NAME} -# PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS}) - -# set_target_properties(${PLUGIN_NAME} -# PROPERTIES -# OUTPUT_NAME ${PLUGIN_NAME}) - list(APPEND PLUGINS_LIST ${PLUGIN_NAME}) endmacro() @@ -90,50 +78,73 @@ if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED) if (LWS_ROLE_WS) create_plugin(protocol_dumb_increment "" "protocol_dumb_increment.c" "" "") + target_compile_definitions(protocol_dumb_increment PRIVATE LWS_BUILDING_SHARED) + create_plugin(protocol_lws_mirror "" "protocol_lws_mirror.c" "" "") + target_compile_definitions(protocol_lws_mirror PRIVATE LWS_BUILDING_SHARED) + create_plugin(protocol_lws_status "" "protocol_lws_status.c" "" "") + target_compile_definitions(protocol_lws_status PRIVATE LWS_BUILDING_SHARED) + if (NOT WIN32) create_plugin(protocol_lws_raw_test "" "protocol_lws_raw_test.c" "" "") + target_compile_definitions(protocol_lws_raw_test PRIVATE LWS_BUILDING_SHARED) + if (UNIX AND LWS_HAVE_PTHREAD_H) create_plugin(protocol_deaddrop "" "deaddrop/protocol_lws_deaddrop.c" "" "") + target_compile_definitions(protocol_deaddrop PRIVATE LWS_BUILDING_SHARED) + endif() endif() if (LWS_WITH_SERVER_STATUS) create_plugin(protocol_lws_server_status "" "protocol_lws_server_status.c" "" "") + target_compile_definitions(protocol_lws_server_status PRIVATE LWS_BUILDING_SHARED) + endif() if (NOT LWS_WITHOUT_CLIENT) create_plugin(protocol_client_loopback_test "" "protocol_client_loopback_test.c" "" "") + target_compile_definitions(protocol_client_loopback_test PRIVATE LWS_BUILDING_SHARED) + endif() endif(LWS_ROLE_WS) create_plugin(protocol_post_demo "" "protocol_post_demo.c" "" "") + target_compile_definitions(protocol_post_demo PRIVATE LWS_BUILDING_SHARED) + if (LWS_ROLE_RAW_PROXY) create_plugin(protocol_lws_raw_proxy "" "raw-proxy/protocol_lws_raw_proxy.c" "" "") + target_compile_definitions(protocol_lws_raw_proxy PRIVATE LWS_BUILDING_SHARED) + endif() if (LWS_WITH_FTS) create_plugin(protocol_fulltext_demo "" "protocol_fulltext_demo.c" "" "") + target_compile_definitions(protocol_fulltext_demo PRIVATE LWS_BUILDING_SHARED) + endif() if (LWS_WITH_SSL) create_plugin(protocol_lws_ssh_base "ssh-base/include" "ssh-base/sshd.c;ssh-base/telnet.c;ssh-base/kex-25519.c" "ssh-base/crypto/chacha.c;ssh-base/crypto/ed25519.c;ssh-base/crypto/fe25519.c;ssh-base/crypto/ge25519.c;ssh-base/crypto/poly1305.c;ssh-base/crypto/sc25519.c;ssh-base/crypto/smult_curve25519_ref.c" "") + target_compile_definitions(protocol_lws_ssh_base PRIVATE LWS_BUILDING_SHARED) + create_plugin(protocol_lws_sshd_demo "ssh-base/include" "protocol_lws_sshd_demo.c" "" "") + target_compile_definitions(protocol_lws_sshd_demo PRIVATE LWS_BUILDING_SHARED) include_directories("${PROJECT_SOURCE_DIR}/plugins/ssh-base/include") endif() @@ -143,6 +154,7 @@ endif() if (LWS_WITH_ACME) create_plugin(protocol_lws_acme_client "" "acme-client/protocol_lws_acme_client.c" "" "") + target_compile_definitions(protocol_lws_acme_client PRIVATE LWS_BUILDING_SHARED) endif() endif(LWS_WITH_PLUGINS AND LWS_WITH_SHARED) diff --git a/test-apps/CMakeLists.txt b/test-apps/CMakeLists.txt index bd9c3b178..5892878c0 100644 --- a/test-apps/CMakeLists.txt +++ b/test-apps/CMakeLists.txt @@ -132,6 +132,7 @@ if ((LWS_ROLE_H1 OR LWS_ROLE_H2)) "" "" "") + target_compile_definitions(test-server PRIVATE LWS_BUILDING_SHARED) if (LWS_WITH_CGI AND LWS_WITH_TLS) create_test_app(test-sshd "test-sshd.c" @@ -141,7 +142,7 @@ if ((LWS_ROLE_H1 OR LWS_ROLE_H2)) "" "") target_include_directories(test-sshd PRIVATE "${PROJECT_SOURCE_DIR}/plugins/ssh-base/include") - + target_compile_definitions(test-sshd PRIVATE LWS_BUILDING_SHARED) endif() endif() @@ -157,6 +158,7 @@ if ((LWS_ROLE_H1 OR LWS_ROLE_H2)) "" "" "") + target_compile_definitions(test-server-extpoll PRIVATE LWS_BUILDING_SHARED) # Set defines for this executable only. set_property( TARGET test-server-extpoll @@ -180,6 +182,7 @@ if ((LWS_ROLE_H1 OR LWS_ROLE_H2)) "" "" "") + target_compile_definitions(test-lejp PRIVATE LWS_BUILDING_STATIC) endif() # Data files for running the test server.