LwsCheckRequirements.cmake 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. MACRO(require_lws_config reqconfig _val result)
  8. if (DEFINED ${reqconfig})
  9. if (${reqconfig})
  10. set (rq 1)
  11. else()
  12. set (rq 0)
  13. endif()
  14. else()
  15. set(rq 0)
  16. endif()
  17. if (${_val} EQUAL ${rq})
  18. set(SAME 1)
  19. else()
  20. set(SAME 0)
  21. endif()
  22. if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME})
  23. if (${_val})
  24. message("${SAMP}: skipping as lws being built without ${reqconfig}")
  25. else()
  26. message("${SAMP}: skipping as lws built with ${reqconfig}")
  27. endif()
  28. set(${result} 0)
  29. else()
  30. if (LWS_WITH_MINIMAL_EXAMPLES)
  31. set(MET ${SAME})
  32. else()
  33. 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})
  34. if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig})
  35. set(HAS_${reqconfig} 0)
  36. else()
  37. set(HAS_${reqconfig} 1)
  38. endif()
  39. if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val}))
  40. set(MET 1)
  41. else()
  42. set(MET 0)
  43. endif()
  44. endif()
  45. if (NOT MET)
  46. if (${_val})
  47. message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}")
  48. else()
  49. message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project")
  50. endif()
  51. endif()
  52. endif()
  53. ENDMACRO()
  54. MACRO(require_pthreads result)
  55. CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
  56. if (NOT LWS_HAVE_PTHREAD_H)
  57. if (LWS_WITH_MINIMAL_EXAMPLES)
  58. set(${result} 0)
  59. message("${SAMP}: skipping as no pthreads")
  60. else()
  61. message(FATAL_ERROR "threading support requires pthreads")
  62. endif()
  63. else()
  64. if (WIN32)
  65. set(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})
  66. else()
  67. set(PTHREAD_LIB pthread)
  68. endif()
  69. endif()
  70. ENDMACRO()