1cmake_minimum_required(VERSION 2.8) 2include(CheckCSourceCompiles) 3 4set(SAMP lws-minimal-secure-streams-avs) 5 6# If we are being built as part of lws, confirm current build config supports 7# reqconfig, else skip building ourselves. 8# 9# If we are being built externally, confirm installed lws was configured to 10# support reqconfig, else error out with a helpful message about the problem. 11# 12MACRO(require_lws_config reqconfig _val result) 13 14 if (DEFINED ${reqconfig}) 15 if (${reqconfig}) 16 set (rq 1) 17 else() 18 set (rq 0) 19 endif() 20 else() 21 set(rq 0) 22 endif() 23 24 if (${_val} EQUAL ${rq}) 25 set(SAME 1) 26 else() 27 set(SAME 0) 28 endif() 29 30 if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) 31 if (${_val}) 32 message("${SAMP}: skipping as lws being built without ${reqconfig}") 33 else() 34 message("${SAMP}: skipping as lws built with ${reqconfig}") 35 endif() 36 set(${result} 0) 37 else() 38 if (LWS_WITH_MINIMAL_EXAMPLES) 39 set(MET ${SAME}) 40 else() 41 CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) 42 if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) 43 set(HAS_${reqconfig} 0) 44 else() 45 set(HAS_${reqconfig} 1) 46 endif() 47 if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) 48 set(MET 1) 49 else() 50 set(MET 0) 51 endif() 52 endif() 53 if (NOT MET) 54 if (${_val}) 55 message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") 56 else() 57 message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") 58 endif() 59 endif() 60 endif() 61ENDMACRO() 62 63 64set(requirements 1) 65require_lws_config(LWS_ROLE_H1 1 requirements) 66require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) 67require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) 68 69if (requirements) 70 add_executable(${SAMP} main.c avs.c) 71 72 if (websockets_shared) 73 target_link_libraries(${SAMP} websockets_shared) 74 add_dependencies(${SAMP} websockets_shared) 75 else() 76 target_link_libraries(${SAMP} websockets) 77 endif() 78 79 if (LWS_WITH_SECURE_STREAMS_PROXY_API) 80 add_compile_options(-DLWS_SS_USE_SSPC) 81 82 add_executable(${SAMP}-client main-client.c avs.c) 83 if (websockets_shared) 84 target_link_libraries(${SAMP}-client websockets_shared) 85 add_dependencies(${SAMP}-client websockets_shared) 86 else() 87 target_link_libraries(${SAMP}-client websockets) 88 endif() 89 endif() 90 91endif() 92