1# If we are being built as part of lws, confirm current build config supports 2# reqconfig, else skip building ourselves. 3# 4# If we are being built externally, confirm installed lws was configured to 5# support reqconfig, else error out with a helpful message about the problem. 6# 7 8include(CheckIncludeFile) 9 10MACRO(require_lws_config reqconfig _val result) 11 12 if (DEFINED ${reqconfig}) 13 if (${reqconfig}) 14 set (rq 1) 15 else() 16 set (rq 0) 17 endif() 18 else() 19 set(rq 0) 20 endif() 21 22 if (${_val} EQUAL ${rq}) 23 set(SAME 1) 24 else() 25 set(SAME 0) 26 endif() 27 28 string(COMPARE EQUAL "${result}" requirements _cmp) 29 30 # we go in the first clause if in-tree 31 if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) 32 if (${_val}) 33 message("${SAMP}: skipping as lws being built without ${reqconfig}") 34 else() 35 message("${SAMP}: skipping as lws built with ${reqconfig}") 36 endif() 37 set(${result} 0) 38 else() 39 if (LWS_WITH_MINIMAL_EXAMPLES) 40 set(MET ${SAME}) 41 else() 42 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}) 43 if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) 44 set(HAS_${reqconfig} 0) 45 else() 46 set(HAS_${reqconfig} 1) 47 endif() 48 if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) 49 set(MET 1) 50 else() 51 set(MET 0) 52 endif() 53 endif() 54 if (NOT MET AND _cmp) 55 if (${_val}) 56 message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") 57 else() 58 message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") 59 endif() 60 endif() 61 62 endif() 63ENDMACRO() 64 65MACRO(require_pthreads result) 66 CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) 67 if (NOT LWS_HAVE_PTHREAD_H) 68 if (LWS_WITH_MINIMAL_EXAMPLES) 69 set(${result} 0) 70 message("${SAMP}: skipping as no pthreads") 71 else() 72 message(FATAL_ERROR "threading support requires pthreads") 73 endif() 74 else() 75 if (WIN32) 76 set(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES}) 77 else() 78 if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "QNX") 79 set(PTHREAD_LIB pthread) 80 endif() 81 endif() 82 endif() 83ENDMACRO() 84 85MACRO(sai_resource SR_NAME SR_AMOUNT SR_LEASE SR_SCOPE) 86 if (DEFINED ENV{SAI_OVN}) 87 88 site_name(HOST_NAME) 89 90 # 91 # Creates a "test" called res_${SR_SCOPE} that waits to be 92 # given a lease on ${SR_AMOUNT} of a resource ${SR_NAME}, for at 93 # most $SR_LEASE seconds, until the test dependent on it can 94 # proceed. 95 # 96 # We need to keep this sai-resource instance up for the 97 # duration of the actual test it is authorizing, when it 98 # is killed, the resource is then immediately released. 99 # 100 # The resource cookie has to be globally unique within the 101 # distributed builder sessions, so it includes the builder 102 # hostname and builder instance information 103 # 104 105 add_test(NAME st_res_${SR_SCOPE} COMMAND 106 ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh 107 res_${SR_SCOPE} 108 sai-resource ${SR_NAME} ${SR_AMOUNT} ${SR_LEASE} 109 ${HOST_NAME}-res_${SR_SCOPE}-$ENV{SAI_PROJECT}-$ENV{SAI_OVN}) 110 111 # allow it to wait for up to 100s for the resource lease 112 113 set_tests_properties(st_res_${SR_SCOPE} PROPERTIES 114 WORKING_DIRECTORY . 115 FIXTURES_SETUP res_sspcmin 116 TIMEOUT 100) 117 118 add_test(NAME ki_res_${SR_SCOPE} COMMAND 119 ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh 120 res_${SR_SCOPE} sai-resource ) 121 122 set_tests_properties(ki_res_${SR_SCOPE} PROPERTIES 123 FIXTURES_CLEANUP res_${SR_SCOPE}) 124 125 endif() 126ENDMACRO() 127 128