You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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