1project(lws-minimal-http-server-eventlib-foreign) 2cmake_minimum_required(VERSION 2.8) 3include(CheckCSourceCompiles) 4 5set(SAMP lws-minimal-http-server-eventlib-foreign) 6set(SRCS minimal-http-server-eventlib-foreign.c) 7 8 9# If we are being built as part of lws, confirm current build config supports 10# reqconfig, else skip building ourselves. 11# 12# If we are being built externally, confirm installed lws was configured to 13# support reqconfig, else error out with a helpful message about the problem. 14# 15MACRO(require_lws_config reqconfig _val result) 16 17 if (DEFINED ${reqconfig}) 18 if (${reqconfig}) 19 set (rq 1) 20 else() 21 set (rq 0) 22 endif() 23 else() 24 set(rq 0) 25 endif() 26 27 if (${_val} EQUAL ${rq}) 28 set(SAME 1) 29 else() 30 set(SAME 0) 31 endif() 32 33 if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) 34 if (${_val}) 35 message("${SAMP}: skipping as lws being built without ${reqconfig}") 36 else() 37 message("${SAMP}: skipping as lws built with ${reqconfig}") 38 endif() 39 set(${result} 0) 40 else() 41 if (LWS_WITH_MINIMAL_EXAMPLES) 42 set(MET ${SAME}) 43 else() 44 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}) 45 if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) 46 set(HAS_${reqconfig} 0) 47 else() 48 set(HAS_${reqconfig} 1) 49 endif() 50 if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) 51 set(MET 1) 52 else() 53 set(MET 0) 54 endif() 55 endif() 56 if (NOT MET) 57 if (${_val}) 58 message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") 59 else() 60 message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") 61 endif() 62 endif() 63 endif() 64ENDMACRO() 65 66set(requirements 1) 67require_lws_config(LWS_ROLE_H1 1 requirements) 68require_lws_config(LWS_WITH_SERVER 1 requirements) 69 70 71 72CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_LIBUV)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBUV) 73CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_LIBEVENT)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBEVENT) 74CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_LIBEV)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBEV) 75CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_GLIB)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_GLIB) 76 77 78if (LWS_WITH_LIBUV) 79 set(extralibs ${extralibs} uv) 80endif() 81if (LWS_WITH_LIBEVENT) 82 set(extralibs ${extralibs} event) 83endif() 84if (LWS_WITH_LIBEV) 85 set(extralibs ${extralibs} ev) 86endif() 87if (LWS_WITH_GLIB) 88 set(LWS_GLIB_INCLUDE_DIRS CACHE PATH "Path to the glib include directory") 89 set(LWS_GLIB_LIBRARIES CACHE PATH "Path to the glib library") 90 include (FindPkgConfig) 91 if (NOT GLIB_FOUND) 92 find_path(GLIB_INCLUDE_DIRS NAMES glib-2.0/glib.h) 93 find_library(GLIB_LIBRARIES NAMES glib-2.0) 94 if(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES) 95 set(GLIB_FOUND 1) 96 endif() 97 if (GLIB_INCLUDE_DIRS) 98 set(GLIB_INCLUDE_DIRS "${GLIB_INCLUDE_DIRS}/glib-2.0") 99 endif() 100 endif() 101 PKG_SEARCH_MODULE(LWS_GLIB2 glib-2.0) 102 if (LWS_GLIB2_FOUND) 103 list(APPEND GLIB_INCLUDE_DIRS "${LWS_GLIB2_INCLUDE_DIRS}") 104 endif() 105 message("glib include dir: ${GLIB_INCLUDE_DIRS}") 106 message("glib libraries: ${GLIB_LIBRARIES}") 107 include_directories("${GLIB_INCLUDE_DIRS}") 108 set(extralibs ${extralibs} ${GLIB_LIBRARIES}) 109endif() 110 111message("Extra libs: ${extralibs}") 112 113if (NOT LWS_WITH_LIBUV AND NOT LWS_WITH_LIBEVENT AND NOT LWS_WITH_LIBEV AND NOT LWS_WITH_GLIB) 114 set(requirements 0) 115endif() 116 117if (requirements) 118 add_executable(${SAMP} ${SRCS}) 119 120 if (websockets_shared) 121 target_link_libraries(${SAMP} websockets_shared ${extralibs}) 122 add_dependencies(${SAMP} websockets_shared) 123 else() 124 target_link_libraries(${SAMP} websockets ${extralibs}) 125 endif() 126endif() 127