Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. cmake_minimum_required(VERSION 2.4)
  2. if(COMMAND cmake_policy)
  3. if(POLICY CMP0026)
  4. cmake_policy(SET CMP0026 OLD)
  5. endif()
  6. endif()
  7. project(postsrsd C)
  8. include(CheckIncludeFile)
  9. option(GENERATE_SRS_SECRET "Generate a random SRS secret if none exists during install" ON)
  10. option(USE_APPARMOR "Enable AppArmor profile" OFF)
  11. option(USE_SELINUX "Enable SELinux policy module" OFF)
  12. set(CHROOT_DIR "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}" CACHE PATH "Chroot jail for daemon")
  13. set(SYSCONF_DIR "/etc" CACHE PATH "Global system configuration folder")
  14. set(SYSD_UNIT_DIR "${SYSCONF_DIR}/systemd/system" CACHE PATH "Systemd unit file folder")
  15. set(CONFIG_DIR "${SYSCONF_DIR}/default" CACHE PATH "Location of startup configuration file")
  16. set(DOC_DIR "share/doc/${PROJECT_NAME}" CACHE PATH "Path for documentation files")
  17. mark_as_advanced(CHROOT_DIR SYSCONF_DIR SYSD_UNIT_DIR CONFIG_DIR DOC_DIR)
  18. find_program(HELP2MAN help2man DOC "path to help2man executable")
  19. find_program(DD dd DOC "path to dd executable")
  20. find_program(BASE64 base64 DOC "path to base64 executable")
  21. find_program(OPENSSL openssl DOC "path to OpenSSL executable")
  22. find_program(INSSERV insserv DOC "path to insserv executable")
  23. find_program(CHKCONFIG chkconfig DOC "path to chkconfig executable")
  24. find_library(LIBSOCKET socket)
  25. find_library(LIBNSL nsl)
  26. if(BASE64)
  27. set(BASE64_ENCODE "${BASE64}")
  28. elseif(OPENSSL)
  29. set(BASE64_ENCODE "${OPENSSL} base64 -e")
  30. else()
  31. set(BASE64_ENCODE "")
  32. endif()
  33. check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
  34. if(HAVE_SYS_WAIT_H)
  35. add_definitions(-DHAVE_SYS_WAIT_H)
  36. endif()
  37. check_include_file(wait.h HAVE_WAIT_H)
  38. if(HAVE_WAIT_H)
  39. add_definitions(-DHAVE_WAIT_H)
  40. endif()
  41. check_include_file(sys/time.h HAVE_SYS_TIME_H)
  42. if(HAVE_SYS_TIME_H)
  43. add_definitions(-DHAVE_SYS_TIME_H)
  44. endif()
  45. check_include_file(time.h HAVE_TIME_H)
  46. if(HAVE_TIME_H)
  47. add_definitions(-DHAVE_TIME_H)
  48. endif()
  49. check_include_file(alloca.h HAVE_ALLOCA_H)
  50. if(HAVE_ALLOCA_H)
  51. add_definitions(-DHAVE_ALLOCA_H)
  52. endif()
  53. check_include_file(sys/types.h HAVE_SYS_TYPES_H)
  54. if(HAVE_SYS_TYPES_H)
  55. add_definitions(-DHAVE_SYS_TYPES_H)
  56. endif()
  57. if(NOT DEFINED INIT_FLAVOR)
  58. if(IS_DIRECTORY "${SYSD_UNIT_DIR}" AND EXISTS "/usr/lib/systemd/systemd")
  59. message(STATUS "Detected init flavor: systemd")
  60. set(INIT_FLAVOR "systemd" CACHE STRING "Init daemon of this system")
  61. elseif(IS_DIRECTORY "${SYSCONF_DIR}/init" AND EXISTS "/lib/init/upstart-job")
  62. message(STATUS "Detected init flavor: upstart")
  63. set(INIT_FLAVOR "upstart" CACHE STRING "Init daemon of this system")
  64. elseif(IS_DIRECTORY "${SYSCONF_DIR}/init.d" AND EXISTS "${SYSCONF_DIR}/init.d/functions")
  65. message(STATUS "Detected init flavor: sysv-redhat")
  66. set(INIT_FLAVOR "sysv-redhat" CACHE STRING "Init daemon of this system")
  67. elseif(IS_DIRECTORY "${SYSCONF_DIR}/init.d" AND EXISTS "/lib/lsb/init-functions")
  68. message(STATUS "Detected init flavor: sysv-lsb")
  69. set(INIT_FLAVOR "sysv-lsb" CACHE STRING "Init daemon of this system")
  70. else()
  71. message(STATUS "Detected init flavor: none")
  72. message(STATUS "System startup files will not be installed")
  73. set(INIT_FLAVOR "" CACHE STRING "Init daemon of this system")
  74. endif()
  75. endif()
  76. add_executable(${PROJECT_NAME} postsrsd.c sha1.c srs2.c)
  77. enable_testing()
  78. add_executable(${PROJECT_NAME}_tests tests.c sha1.c srs2.c)
  79. add_test(AllTests ${PROJECT_NAME}_tests)
  80. if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
  81. target_link_libraries(${PROJECT_NAME} ${LIBSOCKET} ${LIBNSL})
  82. target_link_libraries(${PROJECT_NAME}_tests ${LIBSOCKET} ${LIBNSL})
  83. endif()
  84. get_target_property(POSTSRSD ${PROJECT_NAME} LOCATION)
  85. get_filename_component(POSTSRSD ${POSTSRSD} NAME_WE)
  86. set(APPARMOR_PROFILE "${CMAKE_INSTALL_PREFIX}/sbin/${POSTSRSD}")
  87. string(REGEX REPLACE "^/+" "" APPARMOR_PROFILE "${APPARMOR_PROFILE}")
  88. string(REPLACE "/" "." APPARMOR_PROFILE "${APPARMOR_PROFILE}")
  89. configure_file(init/${PROJECT_NAME}.sysv-lsb.in ${PROJECT_NAME}.sysv-lsb @ONLY)
  90. configure_file(init/${PROJECT_NAME}.sysv-redhat.in ${PROJECT_NAME}.sysv-redhat @ONLY)
  91. configure_file(init/${PROJECT_NAME}.upstart.in ${PROJECT_NAME}.upstart @ONLY)
  92. configure_file(init/${PROJECT_NAME}.apparmor.in ${PROJECT_NAME}.apparmor @ONLY)
  93. configure_file(init/${PROJECT_NAME}.systemd.in ${PROJECT_NAME}.systemd @ONLY)
  94. configure_file(init/${PROJECT_NAME}.default.in ${PROJECT_NAME}.default @ONLY)
  95. configure_file(postinstall.cmake.in postinstall.cmake @ONLY)
  96. if(HELP2MAN)
  97. add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
  98. COMMAND ${HELP2MAN} ARGS -s8 -o${PROJECT_NAME}.8 -n "Postfix Sender Rewriting Scheme daemon" -N -h-h -v-v ${CMAKE_CURRENT_BINARY_DIR}/${POSTSRSD}
  99. VERBATIM
  100. )
  101. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.8 DESTINATION "share/man/man8")
  102. endif()
  103. if(USE_APPARMOR)
  104. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.apparmor DESTINATION "${SYSCONF_DIR}/apparmor.d" RENAME "${APPARMOR_PROFILE}")
  105. endif()
  106. if(USE_SELINUX)
  107. file(COPY selinux/${PROJECT_NAME}.te selinux/${PROJECT_NAME}.fc DESTINATION selinux)
  108. add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
  109. WORKING_DIRECTORY selinux
  110. COMMAND make -f /usr/share/selinux/devel/Makefile)
  111. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/selinux/${PROJECT_NAME}.pp
  112. DESTINATION /usr/share/selinux/packages/${PROJECT_NAME})
  113. endif()
  114. install(TARGETS ${PROJECT_NAME} DESTINATION "sbin")
  115. install(FILES README.md README_UPGRADE.md main.cf.ex DESTINATION "${DOC_DIR}")
  116. install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/postinstall.cmake")