From e4a3e8c4d42e860d49356b1c26fd0890e7bf72f1 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 17 Mar 2018 06:43:12 +0800 Subject: [PATCH] LWS_WITH_MINIMAL_EXAMPLES: default-off build all minimal samples after lws for QA This adds an lws cmake option that builds all the minimal examples as part of lws, it's useful for QA. It adds a macro to examples that depend on a particular lws configuration to understand they should just null out their project definition in builds where the lws configuration requirement is not met, and we are building as part of lws. It also adapts all the example library additions to select the just-built-but-not-yet-installed library in the case it is built as part of lws. If built standalone, it now uses the cmake platform-abstracted way to add the library requirement too. --- .travis.yml | 10 +-- CMakeLists.txt | 43 +++++++-- cmake/lws_config.h.in | 5 ++ minimal-examples/README.md | 20 +++-- .../minimal-ws-proxy/CMakeLists.txt | 76 ++++++++++++++-- .../minimal-ws-proxy/protocol_lws_minimal.c | 8 +- .../minimal-http-client/CMakeLists.txt | 74 +++++++++++++-- .../minimal-http-server-libuv/CMakeLists.txt | 78 +++++++++++++--- .../CMakeLists.txt | 74 +++++++++++++-- .../minimal-http-server-smp/CMakeLists.txt | 89 ++++++++++++++++-- .../minimal-http-server-smp.c | 1 + .../minimal-http-server/CMakeLists.txt | 74 +++++++++++++-- .../minimal-ws-client-rx/CMakeLists.txt | 74 +++++++++++++-- .../minimal-ws-client-tx/CMakeLists.txt | 88 ++++++++++++++++-- .../minimal-ws-client-tx/minimal-ws-client.c | 3 +- .../minimal-ws-broker/CMakeLists.txt | 75 ++++++++++++++-- .../minimal-ws-broker/protocol_lws_minimal.c | 2 +- .../minimal-ws-server-pmd-bulk/CMakeLists.txt | 81 ++++++++++++++--- .../minimal-ws-server-pmd/CMakeLists.txt | 83 ++++++++++++++--- .../protocol_lws_minimal.c | 4 +- .../minimal-ws-server-ring/CMakeLists.txt | 75 ++++++++++++++-- .../protocol_lws_minimal.c | 2 +- .../minimal-ws-server-threads/CMakeLists.txt | 90 +++++++++++++++++-- .../minimal-ws-server.c | 1 + .../protocol_lws_minimal.c | 2 +- .../minimal-ws-server/CMakeLists.txt | 75 ++++++++++++++-- .../minimal-ws-server/protocol_lws_minimal.c | 4 +- 27 files changed, 1079 insertions(+), 132 deletions(-) diff --git a/.travis.yml b/.travis.yml index d833f8ad..e89f39db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,11 +4,11 @@ env: global: - secure: "KhAdQ9ja+LBObWNQTYO7Df5J4DyOih6S+eerDMu8UPSO+CoWV2pWoQzbOfocjyOscGOwC+2PrrHDNZyGfqkCLDXg1BxynXPCFerHC1yc2IajvKpGXmAAygNIvp4KACDfGv/dkXrViqIzr/CdcNaU4vIMHSVb5xkeLi0W1dPnQOI=" matrix: - - LWS_METHOD=lwsws CMAKE_ARGS="-DLWS_WITH_LWSWS=ON -DLWS_WITH_HTTP2=1 -DLWS_WITH_ACME=1" - - LWS_METHOD=default - - LWS_METHOD=noserver CMAKE_ARGS="-DLWS_WITHOUT_SERVER=ON" - - LWS_METHOD=noclient CMAKE_ARGS="-DLWS_WITHOUT_CLIENT=ON" - - LWS_METHOD=noext CMAKE_ARGS="-DLWS_WITHOUT_EXTENSIONS=ON" + - LWS_METHOD=lwsws CMAKE_ARGS="-DLWS_WITH_LWSWS=ON -DLWS_WITH_HTTP2=1 -DLWS_WITH_ACME=1 -DLWS_WITH_MINIMAL_EXAMPLES=1" + - LWS_METHOD=default CMAKE_ARGS="-DLWS_WITH_MINIMAL_EXAMPLES=1" + - LWS_METHOD=noserver CMAKE_ARGS="-DLWS_WITHOUT_SERVER=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" + - LWS_METHOD=noclient CMAKE_ARGS="-DLWS_WITHOUT_CLIENT=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" + - LWS_METHOD=noext CMAKE_ARGS="-DLWS_WITHOUT_EXTENSIONS=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" - LWS_METHOD=libev CMAKE_ARGS="-DLWS_WITH_LIBEV=ON" - LWS_METHOD=noipv6 CMAKE_ARGS="-DLWS_IPV6=OFF" - LWS_METHOD=nossl CMAKE_ARGS="-DLWS_WITH_SSL=OFF" diff --git a/CMakeLists.txt b/CMakeLists.txt index 6648ac1f..db2ea780 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,6 +101,7 @@ option(LWS_WITH_SELFTESTS "Selftests run at context creation" OFF) option(LWS_WITH_GCOV "Build with gcc gcov coverage instrumentation" OFF) option(LWS_WITH_EXPORT_LWSTARGETS "Export libwebsockets CMake targets. Disable if they conflict with an outer cmake project." ON) option(LWS_REPRODUCIBLE "Build libwebsockets reproducible. It removes the build user and hostname from the build" ON) +option(LWS_WITH_MINIMAL_EXAMPLES "Also build the normally standalone minimal examples, for QA" OFF) # # End of user settings # @@ -123,7 +124,6 @@ if(LWS_WITH_DISTRO_RECOMMENDED) set(LWS_WITHOUT_EXTENSIONS 0) endif() - if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type") endif() @@ -196,6 +196,10 @@ if(GIT_EXECUTABLE) message("Git commit hash: ${LWS_BUILD_HASH}") endif() +if (LWS_WITH_HTTP2 AND LWS_WITHOUT_SERVER) + message(FATAL_ERROR "HTTP2 can only be used with server at the moment") +endif() + if (LWS_WITH_LWSWS) message(STATUS "LWS_WITH_LWSWS --> Enabling LWS_WITH_PLUGINS and LWS_WITH_LIBUV") set(LWS_WITH_PLUGINS 1) @@ -814,7 +818,7 @@ if (NOT LWS_WITHOUT_BUILTIN_SHA1) lib/misc/sha-1.c) endif() -if (LWS_WITH_HTTP2) +if (LWS_WITH_HTTP2 AND NOT LWS_WITHOUT_SERVER) list(APPEND SOURCES lib/http2/http2.c lib/http2/hpack.c @@ -1532,7 +1536,7 @@ if (NOT LWS_WITHOUT_TESTAPPS) "" "") endif() - if (UNIX AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND LWS_HAVE_PTHREAD_H) + if (UNIX AND NOT LWS_WITHOUT_SERVER AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND LWS_HAVE_PTHREAD_H) create_test_app(test-server-pthreads "test-apps/test-server-pthreads.c" "test-apps/test-server-http.c" @@ -1662,20 +1666,20 @@ if (NOT LWS_WITHOUT_TESTAPPS) # # test-fraggle # - if (NOT LWS_WITHOUT_TEST_FRAGGLE) + if (NOT LWS_WITHOUT_TEST_FRAGGLE AND NOT LWS_WITHOUT_SERVER) create_test_app(test-fraggle "test-apps/test-fraggle.c" "" "" "" "" "") endif() # # test-ping # - if (NOT LWS_WITHOUT_TEST_PING) + if (NOT LWS_WITHOUT_TEST_PING AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_CLIENT) create_test_app(test-ping "test-apps/test-ping.c" "" "" "" "" "") endif() # # test-echo # - if (NOT LWS_WITHOUT_TEST_ECHO) + if (NOT LWS_WITHOUT_TEST_ECHO AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_CLIENT) create_test_app(test-echo "test-apps/test-echo.c" "" "" "" "" "") endif() @@ -2157,5 +2161,32 @@ if (LWS_WITH_SHARED) set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library") endif() +if (LWS_WITH_MINIMAL_EXAMPLES) + MACRO(SUBDIRLIST result curdir) + FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) + SET(dirlist "") + + FOREACH(child ${children}) + IF(IS_DIRECTORY ${curdir}/${child}) + LIST(APPEND dirlist ${child}) + ENDIF() + ENDFOREACH() + + SET(${result} ${dirlist}) + ENDMACRO() + + SUBDIRLIST(SUBDIRS "${PROJECT_SOURCE_DIR}/minimal-examples") + FOREACH(subdir ${SUBDIRS}) + + SUBDIRLIST(SUBDIRS2 "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}") + FOREACH(subdir2 ${SUBDIRS2}) + if (EXISTS "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}/CMakeLists.txt") + message("Processing ${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}") + add_subdirectory("${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}") + endif() + ENDFOREACH() + ENDFOREACH() +ENDIF() + # This must always be last! include(CPack) diff --git a/cmake/lws_config.h.in b/cmake/lws_config.h.in index a77fa173..64904e8e 100644 --- a/cmake/lws_config.h.in +++ b/cmake/lws_config.h.in @@ -47,6 +47,11 @@ /* Turn off websocket extensions */ #cmakedefine LWS_NO_EXTENSIONS +#cmakedefine LWS_WITHOUT_EXTENSIONS + +/* notice if client or server gone */ +#cmakedefine LWS_WITHOUT_SERVER +#cmakedefine LWS_WITHOUT_CLIENT /* Enable libev io loop */ #cmakedefine LWS_WITH_LIBEV diff --git a/minimal-examples/README.md b/minimal-examples/README.md index 003a8008..e4fc7515 100644 --- a/minimal-examples/README.md +++ b/minimal-examples/README.md @@ -8,9 +8,11 @@ client-server|Minimal examples providing client and server connections simultane ## FAQ -### What should I look at first +### Getting started -Build and install lws itself first, these examples all want to link to it. Then +Build and install lws itself first (note that after installing lws on \*nix, you need to run `ldconfig` one time so the OS can learn about the new library. Lws installs in `/usr/local` by default, Debian / Ubuntu ldconfig knows to look there already, but Fedora / CentOS need you to add the line `/usr/local/lib` to `/etc/ld.so.conf` and run ldconfig) + +Then start with the simplest: `http-server/minimal-http-server` @@ -37,7 +39,7 @@ You will notice a lot of the main C code is the same boilerplate repeated for each example. The actual interesting part is in the protocol callback only. -Lws provides a generic lightweight server app called 'lwsws' that +Lws provides (-DLWS_WITH_LWSWS=1) a generic lightweight server app called 'lwsws' that can be configured by JSON. Combined with your protocol as a plugin, it means you don't actually have to make a special server "app" part, you can just use lwsws and pass per-vhost configuration @@ -46,9 +48,14 @@ an existing app you are bolting lws on to, then you don't care about this for that particular case). Because lwsws has no dependency on whatever your plugin does, it -can mix and match different protocols without needing any code +can mix and match different protocols randomly without needing any code changes. It reduces the size of the task to just writing the -code you care about in your protocol handler. +code you care about in your protocol handler, and nothing else to write +or maintain. + +Lwsws supports advanced features like reload, where it starts a new server +instance with changed config or different plugins, while keeping the old +instance around until the last connection to it closes. ### I get why there is a pss, but why is there a vhd? @@ -67,7 +74,8 @@ provides a different vhd specific to the protocol instance on that vhost. For example many of the samples keep a linked-list head to a list of live pss in the vhd... that means it's cleanly a list of pss opened **on that vhost**. If another vhost has the protocol -enabled, connections to that will point to a different vhd. +enabled, connections to that will point to a different vhd, and the +linked-list head on that vhd will only list connections to his vhost. The example "ws-server/minimal-ws-server-threads" demonstrates how to deliver external configuration data to a specific vhost + protocol diff --git a/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt b/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt index 3ec2949e..006d260e 100644 --- a/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt +++ b/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt @@ -1,11 +1,77 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-proxy) set(SRCS minimal-ws-proxy.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c b/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c index 08ab0584..983c526f 100644 --- a/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c +++ b/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c @@ -89,7 +89,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, lws_get_protocol(wsi)); const struct msg *pmsg; struct msg amsg; - int n, m; + int m; switch (reason) { @@ -142,7 +142,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len, LWS_WRITE_TEXT); if (m < (int)pmsg->len) { - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } @@ -181,8 +181,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, if (!vhd->pss_list) break; - n = (int)lws_ring_get_count_free_elements(vhd->ring); - if (!n) { + if (!lws_ring_get_count_free_elements(vhd->ring)) { lwsl_user("dropping!\n"); break; } @@ -210,7 +209,6 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, ppss, vhd->pss_list) { lws_callback_on_writable((*ppss)->wsi); } lws_end_foreach_llp(ppss, pss_list); - break; case LWS_CALLBACK_CLIENT_CLOSED: diff --git a/minimal-examples/http-client/minimal-http-client/CMakeLists.txt b/minimal-examples/http-client/minimal-http-client/CMakeLists.txt index 5d6d2649..511362ed 100644 --- a/minimal-examples/http-client/minimal-http-client/CMakeLists.txt +++ b/minimal-examples/http-client/minimal-http-client/CMakeLists.txt @@ -1,12 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-http-client) set(SRCS minimal-http-client.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt index 8168b245..3a2a0e5a 100644 --- a/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt @@ -4,16 +4,74 @@ include(CheckSymbolExists) set(SAMP lws-minimal-http-server-libuv) set(SRCS minimal-http-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -CHECK_SYMBOL_EXISTS(LWS_WITH_LIBUV libwebsockets.h HAS_LIBUV) -if (HAS_LIBUV) -else() - message(FATAL_ERROR "lws must have been built with LWS_WITH_LIBUV") -endif() + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITH_LIBUV 1 requirements) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt index 5077704a..5684ff2f 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt @@ -1,12 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-http-server-multivhost) set(SRCS minimal-http-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt index 8dcdc847..59f49b75 100644 --- a/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt @@ -1,18 +1,89 @@ cmake_minimum_required(VERSION 2.8) include(CheckIncludeFile) +include(CheckSymbolExists) set(SAMP lws-minimal-http-server-smp) set(SRCS minimal-http-server-smp.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +MACRO(require_pthreads result) + CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) + if (NOT LWS_HAVE_PTHREAD_H) + if (LWS_WITH_MINIMAL_EXAMPLES) + set(result 0) + else() + message(FATAL_ERROR "threading support requires pthreads") + endif() + endif() +ENDMACRO() -CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) -if (NOT LWS_HAVE_PTHREAD_H) - message(FATAL_ERROR "smp support requires pthreads") -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets -lpthread) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_pthreads(requirements) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared pthread) + add_dependencies(${SAMP} websockets_shared pthread) + else() + target_link_libraries(${SAMP} websockets pthread) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c index 86bbb1ad..417afb6f 100644 --- a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c +++ b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c @@ -21,6 +21,7 @@ #include #include #include +#include #define COUNT_THREADS 8 diff --git a/minimal-examples/http-server/minimal-http-server/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server/CMakeLists.txt index f054a4e1..457e817a 100644 --- a/minimal-examples/http-server/minimal-http-server/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server/CMakeLists.txt @@ -1,12 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-http-server) set(SRCS minimal-http-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt b/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt index 659779b6..22f69014 100644 --- a/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt +++ b/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt @@ -1,12 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-client-rx) set(SRCS minimal-ws-client.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt b/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt index 69d5be4d..156d7c35 100644 --- a/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt +++ b/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt @@ -1,18 +1,88 @@ cmake_minimum_required(VERSION 2.8) include(CheckIncludeFile) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-client-tx) set(SRCS minimal-ws-client.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +MACRO(require_pthreads result) + CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) + if (NOT LWS_HAVE_PTHREAD_H) + if (LWS_WITH_MINIMAL_EXAMPLES) + set(result 0) + else() + message(FATAL_ERROR "threading support requires pthreads") + endif() + endif() +ENDMACRO() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) -if (NOT LWS_HAVE_PTHREAD_H) - message(FATAL_ERROR "threading support requires pthreads") -endif() + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets -pthread) + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_pthreads(requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared pthread) + add_dependencies(${SAMP} websockets_shared pthread) + else() + target_link_libraries(${SAMP} websockets pthread) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c index b5540fb1..4a925416 100644 --- a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c +++ b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c @@ -21,6 +21,7 @@ #include #include #include +#include static int interrupted; @@ -217,7 +218,7 @@ init_fail: LWS_WRITE_TEXT); if (m < (int)pmsg->len) { pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock */ - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt index fc84b871..8ad44309 100644 --- a/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt @@ -1,11 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-broker) set(SRCS minimal-ws-broker.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c index b53184fb..b2efc6cb 100644 --- a/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c @@ -136,7 +136,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len, LWS_WRITE_TEXT); if (m < (int)pmsg->len) { - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt index f872dd90..36af4b78 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt @@ -1,20 +1,77 @@ cmake_minimum_required(VERSION 2.8.9) -include(CheckFunctionExists) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server-pmd-bulk) set(SRCS minimal-ws-server-pmd-bulk.c) -set(CMAKE_REQUIRED_LIBRARIES websockets) +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -CHECK_FUNCTION_EXISTS(lws_extension_callback_pm_deflate HAVE_PMD) -if (HAVE_PMD) -else() - message(FATAL_ERROR "LWS need to have been built for extensions") -endif() + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt index 72ffa07c..8b9721b1 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt @@ -1,20 +1,77 @@ cmake_minimum_required(VERSION 2.8.9) -include(CheckFunctionExists) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server-pmd) set(SRCS minimal-ws-server-pmd.c) -set(CMAKE_REQUIRED_LIBRARIES websockets) +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -CHECK_FUNCTION_EXISTS(lws_extension_callback_pm_deflate HAVE_PMD) -if (HAVE_PMD) -else() - message(FATAL_ERROR "LWS needs to have been built for extensions") + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() endif() - -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() - -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c index 70ccefe6..b9ec3305 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c @@ -69,7 +69,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, (struct per_vhost_data__minimal *) lws_protocol_vh_priv_get(lws_get_vhost(wsi), lws_get_protocol(wsi)); - int n, m; + int m; switch (reason) { case LWS_CALLBACK_PROTOCOL_INIT: @@ -111,7 +111,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, vhd->amsg.payload + LWS_PRE, vhd->amsg.len, LWS_WRITE_TEXT); if (m < (int)vhd->amsg.len) { - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt index 3bfdc5ff..04e9d5bd 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt @@ -1,11 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server-ring) set(SRCS minimal-ws-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c index f61c1414..cdf1216e 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c @@ -112,7 +112,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len, LWS_WRITE_TEXT); if (m < (int)pmsg->len) { - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt index 0849c579..8b147749 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt @@ -1,17 +1,89 @@ cmake_minimum_required(VERSION 2.8) include(CheckIncludeFile) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server-threads) set(SRCS minimal-ws-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +MACRO(require_pthreads result) + CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) + if (NOT LWS_HAVE_PTHREAD_H) + if (LWS_WITH_MINIMAL_EXAMPLES) + set(result 0) + else() + message(FATAL_ERROR "threading support requires pthreads") + endif() + endif() +ENDMACRO() -CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) -if (NOT LWS_HAVE_PTHREAD_H) - message(FATAL_ERROR "threading support requires pthreads") -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets -pthread) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_pthreads(requirements) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c index 90773454..c4f36574 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c @@ -21,6 +21,7 @@ #include #include #include +#include #define LWS_PLUGIN_STATIC #include "protocol_lws_minimal.c" diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c index 6bfddeda..12129629 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c @@ -228,7 +228,7 @@ init_fail: LWS_WRITE_TEXT); if (m < (int)pmsg->len) { pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ - lwsl_err("ERROR %d writing to di socket\n", n); + lwsl_err("ERROR %d writing to ws socket\n", m); return -1; } diff --git a/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt index 8dd86a04..6ec72fe9 100644 --- a/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt @@ -1,11 +1,76 @@ cmake_minimum_required(VERSION 2.8) +include(CheckSymbolExists) set(SAMP lws-minimal-ws-server) set(SRCS minimal-ws-server.c) -if (UNIX) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" ) -endif() +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) -add_executable(${SAMP} ${SRCS}) -target_link_libraries(${SAMP} -lwebsockets) + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) + if (NOT DEFINED HAS) + set(HAS 0) + endif() + if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() \ No newline at end of file diff --git a/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c index 63200a93..bc161a87 100644 --- a/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c @@ -69,7 +69,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, (struct per_vhost_data__minimal *) lws_protocol_vh_priv_get(lws_get_vhost(wsi), lws_get_protocol(wsi)); - int n, m; + int m; switch (reason) { case LWS_CALLBACK_PROTOCOL_INIT: @@ -111,7 +111,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, m = lws_write(wsi, vhd->amsg.payload + LWS_PRE, vhd->amsg.len, LWS_WRITE_TEXT); if (m < (int)vhd->amsg.len) { - lwsl_err("ERROR %d writing to ws\n", n); + lwsl_err("ERROR %d writing to ws\n", m); return -1; }