11#[=============================================================================[
22# FindSendmail
33
4- Find the `sendmail` program.
4+ This module finds mailer program for PHP and sets sensible defaults based on the
5+ target system. On Windows, PHP has built-in mailer (sendmail.c), on *nix systems
6+ either `sendmail` is used if found, or a general default value is set to
7+ `/usr/sbin/sendmail`.
58
69## Result variables
710
8- * `Sendmail_FOUND` - Whether sendmail has been found.
11+ * `Sendmail_FOUND` - Whether mailer has been found.
12+ * `PROG_SENDMAIL` - Path to the sendmail executable program, either found by
13+ the module or set to a sensible default value.
914
1015## Cache variables
1116
12- * `Sendmail_EXECUTABLE` - Path to the sendmail executable, if found.
13- * `PROG_SENDMAIL` - Path to the sendmail program.
17+ * `Sendmail_EXECUTABLE` - Path to the sendmail executable program, if found.
1418#]=============================================================================]
1519
1620include (FeatureSummary)
@@ -23,29 +27,40 @@ set_package_properties(
2327 DESCRIPTION "Mail Transport Agent"
2428)
2529
26- find_program (
27- Sendmail_EXECUTABLE
28- NAMES sendmail
29- DOC "The path to the sendmail executable"
30- )
30+ set (_reason)
3131
32- if (Sendmail_EXECUTABLE)
33- set (_sendmail ${Sendmail_EXECUTABLE} )
32+ if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
33+ set (_sendmailIsBuiltInMsg "PHP built-in mailer (Windows)" )
34+ set (_sendmailRequiredVars _sendmailIsBuiltInMsg)
3435else ()
35- set (_sendmail "/usr/sbin/sendmail" )
36- endif ()
36+ find_program (
37+ Sendmail_EXECUTABLE
38+ NAMES sendmail
39+ DOC "The path to the sendmail executable"
40+ )
41+ mark_as_advanced (Sendmail_EXECUTABLE)
3742
38- # TODO: Should this be result variable?
39- set (PROG_SENDMAIL "${_sendmail} " CACHE INTERNAL "Path to sendmail executable" )
43+ set (_sendmailRequiredVars Sendmail_EXECUTABLE)
4044
41- mark_as_advanced (Sendmail_EXECUTABLE)
45+ if (Sendmail_EXECUTABLE)
46+ set (PROG_SENDMAIL ${Sendmail_EXECUTABLE} )
47+ else ()
48+ set (PROG_SENDMAIL "/usr/sbin/sendmail" )
49+ endif ()
50+
51+ set (
52+ _reason
53+ "sendmail not found. Default set to ${PROG_SENDMAIL} .
54+ It can be overridden with 'sendmail_path' php.ini directive."
55+ )
56+ endif ()
4257
4358find_package_handle_standard_args(
4459 Sendmail
45- REQUIRED_VARS Sendmail_EXECUTABLE
46- REASON_FAILURE_MESSAGE
47- "sendmail not found, setting default to ${_sendmail} .
48- It can be overridden in php.ini with sendmail_path directive."
60+ REQUIRED_VARS ${_sendmailRequiredVars}
61+ REASON_FAILURE_MESSAGE "${_reason} "
4962)
5063
51- unset (_sendmail)
64+ unset (_reason)
65+ unset (_sendmailIsBuiltInMsg)
66+ unset (_sendmailRequiredVars)
0 commit comments