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