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 set(PTHREAD_LIB pthread) 79 endif() 80 endif() 81ENDMACRO() 82 83MACRO(sai_resource SR_NAME SR_AMOUNT SR_LEASE SR_SCOPE) 84 if (DEFINED ENV{SAI_OVN}) 85 86 site_name(HOST_NAME) 87 88 # 89 # Creates a "test" called res_${SR_SCOPE} that waits to be 90 # given a lease on ${SR_AMOUNT} of a resource ${SR_NAME}, for at 91 # most $SR_LEASE seconds, until the test dependent on it can 92 # proceed. 93 # 94 # We need to keep this sai-resource instance up for the 95 # duration of the actual test it is authorizing, when it 96 # is killed, the resource is then immediately released. 97 # 98 # The resource cookie has to be globally unique within the 99 # distributed builder sessions, so it includes the builder 100 # hostname and builder instance information 101 # 102 103 add_test(NAME st_res_${SR_SCOPE} COMMAND 104 ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh 105 res_${SR_SCOPE} 106 sai-resource ${SR_NAME} ${SR_AMOUNT} ${SR_LEASE} 107 ${HOST_NAME}-res_${SR_SCOPE}-$ENV{SAI_PROJECT}-$ENV{SAI_OVN}) 108 109 # allow it to wait for up to 100s for the resource lease 110 111 set_tests_properties(st_res_${SR_SCOPE} PROPERTIES 112 WORKING_DIRECTORY . 113 FIXTURES_SETUP res_sspcmin 114 TIMEOUT 100) 115 116 add_test(NAME ki_res_${SR_SCOPE} COMMAND 117 ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh 118 res_${SR_SCOPE} sai-resource ) 119 120 set_tests_properties(ki_res_${SR_SCOPE} PROPERTIES 121 FIXTURES_CLEANUP res_${SR_SCOPE}) 122 123 endif() 124ENDMACRO() 125 126