forked from roehling/postsrsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
140 lines (122 loc) · 5.61 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
cmake_minimum_required(VERSION 3.0)
project(postsrsd VERSION 1.11 LANGUAGES C)
include(CheckIncludeFile)
include(CheckTypeSize)
include(TestBigEndian)
include(CTest)
option(GENERATE_SRS_SECRET "Generate a random SRS secret if none exists during install" ON)
option(USE_APPARMOR "Enable AppArmor profile" OFF)
option(USE_SELINUX "Enable SELinux policy module" OFF)
set(CHROOT_DIR "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}" CACHE PATH "Chroot jail for daemon")
set(SYSCONF_DIR "/etc" CACHE PATH "Global system configuration folder")
set(SYSD_UNIT_DIR "${SYSCONF_DIR}/systemd/system" CACHE PATH "Systemd unit file folder")
set(CONFIG_DIR "${SYSCONF_DIR}/default" CACHE PATH "Location of startup configuration file")
set(DOC_DIR "share/doc/${PROJECT_NAME}" CACHE PATH "Path for documentation files")
mark_as_advanced(CHROOT_DIR SYSCONF_DIR SYSD_UNIT_DIR CONFIG_DIR DOC_DIR)
find_program(HELP2MAN help2man DOC "path to help2man executable")
find_program(DD dd DOC "path to dd executable")
find_program(BASE64 base64 DOC "path to base64 executable")
find_program(OPENSSL openssl DOC "path to OpenSSL executable")
find_program(INSSERV insserv DOC "path to insserv executable")
find_program(CHKCONFIG chkconfig DOC "path to chkconfig executable")
find_program(SYSTEMCTL systemctl DOC "path to systemctl executable")
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
find_library(LIBSOCKET socket)
find_library(LIBNSL nsl)
endif()
if(BASE64)
set(BASE64_ENCODE "${BASE64}")
elseif(OPENSSL)
set(BASE64_ENCODE "${OPENSSL} base64 -e")
else()
set(BASE64_ENCODE "")
endif()
check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
if(HAVE_SYS_WAIT_H)
add_definitions(-DHAVE_SYS_WAIT_H)
endif()
check_include_file(wait.h HAVE_WAIT_H)
if(HAVE_WAIT_H)
add_definitions(-DHAVE_WAIT_H)
endif()
check_include_file(sys/time.h HAVE_SYS_TIME_H)
if(HAVE_SYS_TIME_H)
add_definitions(-DHAVE_SYS_TIME_H)
endif()
check_include_file(time.h HAVE_TIME_H)
if(HAVE_TIME_H)
add_definitions(-DHAVE_TIME_H)
endif()
check_include_file(alloca.h HAVE_ALLOCA_H)
if(HAVE_ALLOCA_H)
add_definitions(-DHAVE_ALLOCA_H)
endif()
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
if(HAVE_SYS_TYPES_H)
add_definitions(-DHAVE_SYS_TYPES_H)
endif()
test_big_endian(WORDS_BIGENDIAN)
if(WORDS_BIGENDIAN)
add_definitions(-DWORDS_BIGENDIAN)
endif()
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
add_definitions(-DSIZEOF_UNSIGNED_LONG=${SIZEOF_UNSIGNED_LONG})
if(NOT DEFINED INIT_FLAVOR)
if(SYSTEMCTL)
message(STATUS "Detected init flavor: systemd")
set(INIT_FLAVOR "systemd" CACHE STRING "Init daemon of this system")
elseif(IS_DIRECTORY "${SYSCONF_DIR}/init.d" AND EXISTS "${SYSCONF_DIR}/init.d/functions")
message(STATUS "Detected init flavor: sysv-redhat")
set(INIT_FLAVOR "sysv-redhat" CACHE STRING "Init daemon of this system")
elseif(IS_DIRECTORY "${SYSCONF_DIR}/init.d" AND EXISTS "/lib/lsb/init-functions")
message(STATUS "Detected init flavor: sysv-lsb")
set(INIT_FLAVOR "sysv-lsb" CACHE STRING "Init daemon of this system")
else()
message(STATUS "Detected init flavor: none")
message(STATUS "System startup files will not be installed")
set(INIT_FLAVOR "" CACHE STRING "Init daemon of this system")
endif()
endif()
add_definitions(-DPOSTSRSD_VERSION=\"${PROJECT_VERSION}\")
add_executable(${PROJECT_NAME} postsrsd.c sha1.c srs2.c)
if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
target_link_libraries(${PROJECT_NAME} ${LIBSOCKET} ${LIBNSL})
target_link_libraries(${PROJECT_NAME}_tests ${LIBSOCKET} ${LIBNSL})
endif()
set(POSTSRSD "${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}")
set(APPARMOR_PROFILE "${CMAKE_INSTALL_PREFIX}/sbin/${POSTSRSD}")
string(REGEX REPLACE "^/+" "" APPARMOR_PROFILE "${APPARMOR_PROFILE}")
string(REPLACE "/" "." APPARMOR_PROFILE "${APPARMOR_PROFILE}")
configure_file(init/${PROJECT_NAME}.sysv-lsb.in ${PROJECT_NAME}.sysv-lsb @ONLY)
configure_file(init/${PROJECT_NAME}.sysv-redhat.in ${PROJECT_NAME}.sysv-redhat @ONLY)
configure_file(init/${PROJECT_NAME}.apparmor.in ${PROJECT_NAME}.apparmor @ONLY)
configure_file(init/${PROJECT_NAME}.systemd.in ${PROJECT_NAME}.systemd @ONLY)
configure_file(init/${PROJECT_NAME}.default.in ${PROJECT_NAME}.default @ONLY)
configure_file(init/${PROJECT_NAME}-systemd-launcher.in ${PROJECT_NAME}-systemd-launcher @ONLY)
configure_file(postinstall.cmake.in postinstall.cmake @ONLY)
if(BUILD_TESTING)
add_executable(${PROJECT_NAME}_tests tests.c sha1.c srs2.c)
add_test(NAME AllTests COMMAND ${PROJECT_NAME}_tests)
endif()
if(HELP2MAN)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${HELP2MAN} ARGS -s8 -o${PROJECT_NAME}.8 -n "Postfix Sender Rewriting Scheme daemon" -N -h-h -v-v ${CMAKE_CURRENT_BINARY_DIR}/${POSTSRSD}
VERBATIM
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.8 DESTINATION "share/man/man8")
endif()
if(USE_APPARMOR)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.apparmor DESTINATION "${SYSCONF_DIR}/apparmor.d" RENAME "${APPARMOR_PROFILE}")
endif()
if(USE_SELINUX)
file(COPY selinux/${PROJECT_NAME}.te selinux/${PROJECT_NAME}.fc DESTINATION selinux)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
WORKING_DIRECTORY selinux
COMMAND make -f /usr/share/selinux/devel/Makefile)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/selinux/${PROJECT_NAME}.pp
DESTINATION /usr/share/selinux/packages/${PROJECT_NAME})
endif()
install(TARGETS ${PROJECT_NAME} DESTINATION "sbin")
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-systemd-launcher DESTINATION "share/${PROJECT_NAME}")
install(FILES README.md README_UPGRADE.md main.cf.ex DESTINATION "${DOC_DIR}")
install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/postinstall.cmake")