1project(lws-minimal-gtk) 2cmake_minimum_required(VERSION 2.8) 3include(CheckCSourceCompiles) 4 5set(SAMP lws-minimal-gtk) 6set(SRCS main.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) 69require_lws_config(LWS_WITH_GLIB 1 requirements) 70require_lws_config(LWS_WITH_GTK 1 requirements) 71 72if (requirements) 73 74# gtk pieces 75 76 include (FindPkgConfig) 77 78 set(LWS_GTK_INCLUDE_DIRS CACHE PATH "Path to the gtk include directory") 79 set(LWS_GTK_LIBRARIES CACHE PATH "Path to the gtk library") 80 PKG_SEARCH_MODULE(LWS_GTK2 gtk+-3.0) 81 if (LWS_GTK2_FOUND) 82 list(APPEND LWS_GTK_INCLUDE_DIRS "${LWS_GTK2_INCLUDE_DIRS}") 83 list(APPEND LWS_GTK_LIBRARIES "${LWS_GTK2_LIBRARIES}") 84 endif() 85 message("gtk include dir: ${LWS_GTK_INCLUDE_DIRS}") 86 message("gtk libraries: ${LWS_GTK_LIBRARIES}") 87 include_directories("${LWS_GTK_INCLUDE_DIRS}") 88 set(extralibs ${extralibs} ${LWS_GTK_LIBRARIES}) 89 90 91 92 message("Extra libs: ${extralibs}") 93 94 add_executable(${SAMP} ${SRCS}) 95 96 if (websockets_shared) 97 target_link_libraries(${SAMP} websockets_shared ${extralibs}) 98 add_dependencies(${SAMP} websockets_shared) 99 else() 100 target_link_libraries(${SAMP} websockets ${extralibs}) 101 endif() 102endif() 103