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