CMakeLists.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # This is a cmake script. Process it with the CMake gui or command line utility
  2. # to produce makefiles / Visual Studio project files on Mac OS X and Windows.
  3. #
  4. # To configure the build options either use the CMake gui, or run the command
  5. # line utility including the "-i" option.
  6. cmake_minimum_required(VERSION 3.0)
  7. cmake_policy(SET CMP0042 NEW)
  8. project(mosquitto)
  9. set (VERSION 2.0.13)
  10. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
  11. add_definitions (-DCMAKE -DVERSION=\"${VERSION}\")
  12. if (WIN32)
  13. add_definitions("-D_CRT_SECURE_NO_WARNINGS")
  14. add_definitions("-D_CRT_NONSTDC_NO_DEPRECATE")
  15. endif (WIN32)
  16. if(APPLE)
  17. set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -undefined dynamic_lookup")
  18. endif(APPLE)
  19. include(GNUInstallDirs)
  20. option(WITH_BUNDLED_DEPS "Build with bundled dependencies?" ON)
  21. option(WITH_TLS
  22. "Include SSL/TLS support?" ON)
  23. option(WITH_TLS_PSK
  24. "Include TLS-PSK support (requires WITH_TLS)?" ON)
  25. option(WITH_EC
  26. "Include Elliptic Curve support (requires WITH_TLS)?" ON)
  27. if (WITH_TLS)
  28. find_package(OpenSSL REQUIRED)
  29. add_definitions("-DWITH_TLS")
  30. if (WITH_TLS_PSK)
  31. add_definitions("-DWITH_TLS_PSK")
  32. endif (WITH_TLS_PSK)
  33. if (WITH_EC)
  34. add_definitions("-DWITH_EC")
  35. endif (WITH_EC)
  36. else (WITH_TLS)
  37. set (OPENSSL_INCLUDE_DIR "")
  38. endif (WITH_TLS)
  39. option(WITH_UNIX_SOCKETS "Include Unix Domain Socket support?" ON)
  40. if (WITH_UNIX_SOCKETS AND NOT WIN32)
  41. add_definitions("-DWITH_UNIX_SOCKETS")
  42. endif (WITH_UNIX_SOCKETS AND NOT WIN32)
  43. option(WITH_SOCKS "Include SOCKS5 support?" ON)
  44. if (WITH_SOCKS)
  45. add_definitions("-DWITH_SOCKS")
  46. endif (WITH_SOCKS)
  47. option(WITH_SRV "Include SRV lookup support?" OFF)
  48. option(WITH_STATIC_LIBRARIES "Build static versions of the libmosquitto/pp libraries?" OFF)
  49. option(WITH_PIC "Build the static library with PIC (Position Independent Code) enabled archives?" OFF)
  50. option(WITH_THREADING "Include client library threading support?" ON)
  51. if (WITH_THREADING)
  52. add_definitions("-DWITH_THREADING")
  53. if (WIN32)
  54. if (CMAKE_CL_64)
  55. set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x64\\pthreadVC2.lib)
  56. else (CMAKE_CL_64)
  57. set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x86\\pthreadVC2.lib)
  58. endif (CMAKE_CL_64)
  59. set (PTHREAD_INCLUDE_DIR C:\\pthreads\\Pre-built.2\\include)
  60. elseif (ANDROID)
  61. set (PTHREAD_LIBRARIES "")
  62. set (PTHREAD_INCLUDE_DIR "")
  63. else (WIN32)
  64. find_library(LIBPTHREAD pthread)
  65. if (LIBPTHREAD)
  66. set (PTHREAD_LIBRARIES pthread)
  67. else (LIBPTHREAD)
  68. set (PTHREAD_LIBRARIES "")
  69. endif()
  70. set (PTHREAD_INCLUDE_DIR "")
  71. endif (WIN32)
  72. else (WITH_THREADING)
  73. set (PTHREAD_LIBRARIES "")
  74. set (PTHREAD_INCLUDE_DIR "")
  75. endif (WITH_THREADING)
  76. option(WITH_DLT "Include DLT support?" OFF)
  77. message(STATUS "WITH_DLT = ${WITH_DLT}")
  78. if (WITH_DLT)
  79. #find_package(DLT REQUIRED)
  80. find_package(PkgConfig)
  81. pkg_check_modules(DLT "automotive-dlt >= 2.11")
  82. add_definitions("-DWITH_DLT")
  83. endif (WITH_DLT)
  84. option(WITH_CJSON "Build with cJSON support (required for dynamic security plugin and useful for mosquitto_sub)?" ON)
  85. if (WITH_CJSON)
  86. FIND_PACKAGE(cJSON)
  87. if (CJSON_FOUND)
  88. message(STATUS ${CJSON_FOUND})
  89. else (CJSON_FOUND)
  90. message(STATUS "Optional dependency cJSON not found. Some features will be disabled.")
  91. endif(CJSON_FOUND)
  92. endif()
  93. # ========================================
  94. # Include projects
  95. # ========================================
  96. option(WITH_CLIENTS "Build clients?" ON)
  97. option(WITH_BROKER "Build broker?" ON)
  98. option(WITH_APPS "Build apps?" ON)
  99. option(WITH_PLUGINS "Build plugins?" ON)
  100. option(DOCUMENTATION "Build documentation?" ON)
  101. add_subdirectory(lib)
  102. if (WITH_CLIENTS)
  103. add_subdirectory(client)
  104. endif (WITH_CLIENTS)
  105. if (WITH_BROKER)
  106. add_subdirectory(src)
  107. endif (WITH_BROKER)
  108. if (WITH_APPS)
  109. add_subdirectory(apps)
  110. endif (WITH_APPS)
  111. if (WITH_PLUGINS)
  112. add_subdirectory(plugins)
  113. endif (WITH_PLUGINS)
  114. if (DOCUMENTATION)
  115. add_subdirectory(man)
  116. endif (DOCUMENTATION)
  117. # ========================================
  118. # Install config file
  119. # ========================================
  120. if (WITH_BROKER)
  121. install(FILES mosquitto.conf aclfile.example pskfile.example pwfile.example DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/mosquitto")
  122. endif (WITH_BROKER)
  123. # ========================================
  124. # Install pkg-config files
  125. # ========================================
  126. configure_file(libmosquitto.pc.in libmosquitto.pc @ONLY)
  127. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquitto.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  128. configure_file(libmosquittopp.pc.in libmosquittopp.pc @ONLY)
  129. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquittopp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  130. # ========================================
  131. # Testing
  132. # ========================================
  133. enable_testing()