CMakeLists.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #*******************************************************************************
  2. # Copyright (c) 2015, 2020 logi.cals GmbH and others
  3. #
  4. # All rights reserved. This program and the accompanying materials
  5. # are made available under the terms of the Eclipse Public License v2.0
  6. # and Eclipse Distribution License v1.0 which accompany this distribution.
  7. #
  8. # The Eclipse Public License is available at
  9. # https://www.eclipse.org/legal/epl-2.0/
  10. # and the Eclipse Distribution License is available at
  11. # http://www.eclipse.org/org/documents/edl-v10.php.
  12. #
  13. # Contributors:
  14. # Rainer Poisel - initial version
  15. # Genis Riera Perez - Add support for building debian package
  16. #*******************************************************************************/
  17. # Note: on OS X you should install XCode and the associated command-line tools
  18. CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
  19. PROJECT("Eclipse Paho C" C)
  20. MESSAGE(STATUS "CMake version: " ${CMAKE_VERSION})
  21. MESSAGE(STATUS "CMake system name: " ${CMAKE_SYSTEM_NAME})
  22. SET(CMAKE_SCRIPTS "${CMAKE_SOURCE_DIR}/cmake")
  23. SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
  24. ## build settings
  25. file(READ version.major PAHO_VERSION_MAJOR)
  26. file(READ version.minor PAHO_VERSION_MINOR)
  27. file(READ version.patch PAHO_VERSION_PATCH)
  28. SET(CLIENT_VERSION ${PAHO_VERSION_MAJOR}.${PAHO_VERSION_MINOR}.${PAHO_VERSION_PATCH})
  29. INCLUDE(GNUInstallDirs)
  30. STRING(TIMESTAMP BUILD_TIMESTAMP UTC)
  31. MESSAGE(STATUS "Timestamp is ${BUILD_TIMESTAMP}")
  32. IF(WIN32)
  33. ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN)
  34. ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
  35. ADD_DEFINITIONS(-DOSX)
  36. ENDIF()
  37. ## build options
  38. SET(PAHO_WITH_SSL FALSE CACHE BOOL "Flag that defines whether to build ssl-enabled binaries too. ")
  39. SET(PAHO_BUILD_SHARED TRUE CACHE BOOL "Build shared library")
  40. SET(PAHO_BUILD_STATIC FALSE CACHE BOOL "Build static library")
  41. SET(PAHO_BUILD_DOCUMENTATION FALSE CACHE BOOL "Create and install the HTML based API documentation (requires Doxygen)")
  42. SET(PAHO_BUILD_SAMPLES FALSE CACHE BOOL "Build sample programs")
  43. SET(PAHO_BUILD_DEB_PACKAGE FALSE CACHE BOOL "Build debian package")
  44. SET(PAHO_ENABLE_TESTING TRUE CACHE BOOL "Build tests and run")
  45. SET(PAHO_ENABLE_CPACK TRUE CACHE BOOL "Enable CPack")
  46. SET(PAHO_HIGH_PERFORMANCE FALSE CACHE BOOL "Disable tracing and heap tracking")
  47. SET(PAHO_USE_SELECT FALSE CACHE BOOL "Revert to select system call instead of poll")
  48. IF (PAHO_HIGH_PERFORMANCE)
  49. ADD_DEFINITIONS(-DHIGH_PERFORMANCE=1)
  50. ENDIF()
  51. IF (PAHO_USE_SELECT)
  52. ADD_DEFINITIONS(-DUSE_SELECT=1)
  53. ENDIF()
  54. IF (NOT PAHO_BUILD_SHARED AND NOT PAHO_BUILD_STATIC)
  55. MESSAGE(FATAL_ERROR "You must set either PAHO_BUILD_SHARED, PAHO_BUILD_STATIC, or both")
  56. ENDIF()
  57. IF(PAHO_BUILD_DEB_PACKAGE)
  58. set(CMAKE_INSTALL_DOCDIR share/doc/libpaho-mqtt)
  59. set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
  60. set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY ">=")
  61. ENDIF()
  62. ADD_SUBDIRECTORY(src)
  63. IF(PAHO_BUILD_SAMPLES)
  64. ADD_SUBDIRECTORY(src/samples)
  65. ENDIF()
  66. IF(PAHO_BUILD_DOCUMENTATION)
  67. ADD_SUBDIRECTORY(doc)
  68. ENDIF()
  69. IF (PAHO_ENABLE_CPACK)
  70. ### packaging settings
  71. FILE(GLOB samples "src/samples/*.c")
  72. INSTALL(FILES ${samples} DESTINATION ${CMAKE_INSTALL_DOCDIR}/samples)
  73. SET(CPACK_PACKAGE_VENDOR "Eclipse Paho")
  74. SET(CPACK_PACKAGE_NAME "Eclipse-Paho-MQTT-C")
  75. INSTALL(FILES CONTRIBUTING.md epl-v20 edl-v10 README.md notice.html DESTINATION ${CMAKE_INSTALL_DOCDIR})
  76. IF (WIN32)
  77. SET(CPACK_GENERATOR "ZIP")
  78. ELSEIF(PAHO_BUILD_DEB_PACKAGE)
  79. INSTALL(FILES CONTRIBUTING.md epl-v20 edl-v10 README.md notice.html DESTINATION ${CMAKE_INSTALL_DOCDIR})
  80. SET(CPACK_GENERATOR "DEB")
  81. CONFIGURE_FILE(${CMAKE_SCRIPTS}/CPackDebConfig.cmake.in
  82. ${CMAKE_BINARY_DIR}/CPackDebConfig.cmake @ONLY)
  83. SET(CPACK_PROJECT_CONFIG_FILE ${CMAKE_BINARY_DIR}/CPackDebConfig.cmake)
  84. ELSE()
  85. SET(CPACK_GENERATOR "TGZ")
  86. ENDIF()
  87. ELSE()
  88. FILE(GLOB samples "src/samples/*.c")
  89. INSTALL(FILES ${samples} DESTINATION ${CMAKE_INSTALL_DOCDIR})
  90. ENDIF()
  91. SET(CPACK_PACKAGE_VERSION_MAJOR ${PAHO_VERSION_MAJOR})
  92. SET(CPACK_PACKAGE_VERSION_MINOR ${PAHO_VERSION_MINOR})
  93. SET(CPACK_PACKAGE_VERSION_PATCH ${PAHO_VERSION_PATCH})
  94. INCLUDE(CPack)
  95. IF(PAHO_ENABLE_TESTING)
  96. ENABLE_TESTING()
  97. INCLUDE_DIRECTORIES(test src)
  98. ADD_SUBDIRECTORY(test)
  99. ELSE()
  100. INCLUDE_DIRECTORIES(src)
  101. ENDIF()