File: FindSMIME.cmake

package info (click to toggle)
evolution 3.30.5-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 118,136 kB
  • sloc: ansic: 485,682; xml: 5,159; python: 702; makefile: 565; sh: 294; perl: 169
file content (160 lines) | stat: -rw-r--r-- 5,580 bytes parent folder | download | duplicates (2)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# FindSMIME.cmake
#
# Searches for Mozilla's NSS and NSPR libraries, unless -DENABLE_SMIME=OFF is used
#
# The output is:
#    mozilla_nspr - if non-empty, then a pkg-config package name for nspr
#    mozilla_nss - if non-empty, then a pkg-config package name for nss
#    MANUAL_NSPR_INCLUDES - if non-empty, then contains manual nspr include directory, used for target_include_directories() and similar commands
#    MANUAL_NSPR_LIBS - if non-empty, then contains manual nspr libraries, used for target_link_libraries() and similar commands
#    MANUAL_NSS_INCLUDES - if non-empty, then contains manual nss include directory, used for target_include_directories() and similar commands
#    MANUAL_NSS_LIBS - if non-empty, then contains manual nss libraries, used for target_link_libraries() and similar commands
#    MOZILLA_NSS_LIB_DIR - a lib directory where Mozilla stores its libraries

include(CheckIncludeFiles)
include(CheckCSourceCompiles)
include(PrintableOptions)
include(PkgConfigEx)

add_printable_option(ENABLE_SMIME "Enable SMIME support through Mozilla nss" ON)
add_printable_variable_path(WITH_NSPR_INCLUDES "Prefix of Mozilla nspr4 includes" "")
add_printable_variable_path(WITH_NSPR_LIBS "Prefix of Mozilla nspr4 libs" "")
add_printable_variable_path(WITH_NSS_INCLUDES "Prefix of Mozilla nss3 includes" "")
add_printable_variable_path(WITH_NSS_LIBS "Prefix of Mozilla nss3 libs" "")

if(NOT ENABLE_SMIME)
	return()
endif(NOT ENABLE_SMIME)

set(mozilla_nspr "")
set(mozilla_nss "")
set(MOZILLA_NSS_LIB_DIR "")

# Use pkg-config when none is specified
if((WITH_NSPR_INCLUDES STREQUAL "") AND (WITH_NSPR_LIBS STREQUAL "") AND (WITH_NSS_INCLUDES STREQUAL "") AND (WITH_NSS_LIBS STREQUAL ""))
	foreach(pkg nspr mozilla-nspr firefox-nspr xulrunner-nspr seamonkey-nspr)
		pkg_check_exists(_have_pkg ${pkg})
		if(_have_pkg)
			set(mozilla_nspr ${pkg})
			break()
		endif(_have_pkg)
	endforeach(pkg)

	foreach(pkg nss mozilla-nss firefox-nss xulrunner-nss seamonkey-nss)
		pkg_check_exists(_have_pkg ${pkg})
		if(_have_pkg)
			set(mozilla_nss ${pkg})
			break()
		endif(_have_pkg)
	endforeach(pkg)

	if((NOT (mozilla_nspr STREQUAL "")) AND (NOT (mozilla_nss STREQUAL "")))
		pkg_check_variable(_nss_libdir ${mozilla_nss} libdir)

		set(MANUAL_NSPR_INCLUDES "")
		set(MANUAL_NSPR_LIBS "")
		set(MANUAL_NSS_INCLUDES "")
		set(MANUAL_NSS_LIBS "")
		set(MOZILLA_NSS_LIB_DIR "${_nss_libdir}/nss")
		return()
	endif((NOT (mozilla_nspr STREQUAL "")) AND (NOT (mozilla_nss STREQUAL "")))
endif()

# Manual search, even when pkg-config failed

# ******************
# Check for NSPR 4
# ******************

if(NOT (WITH_NSPR_INCLUDES STREQUAL ""))
	set(CMAKE_REQUIRED_INCLUDES ${WITH_NSPR_INCLUDES})
endif(NOT (WITH_NSPR_INCLUDES STREQUAL ""))

unset(_have_headers CACHE)

CHECK_INCLUDE_FILES("nspr.h;prio.h" _have_headers)

unset(CMAKE_REQUIRED_INCLUDES)

if(NOT _have_headers)
	message(FATAL_ERROR "NSPR headers not found. Use -DWITH_NSPR_INCLUDES=/path/to/nspr to specify the include dir of NSPR.")
endif(NOT _have_headers)

set(MANUAL_NSPR_INCLUDES "${WITH_NSPR_INCLUDES}")
string(STRIP ${MANUAL_NSPR_INCLUDES} MANUAL_NSPR_INCLUDES)

set(nsprlibs "-lplc4 -lplds4 -lnspr4")

set(CMAKE_REQUIRED_INCLUDES ${MANUAL_NSPR_INCLUDES})
set(CMAKE_REQUIRED_LIBRARIES ${nsprlibs})
unset(_nsprlibs_okay CACHE)
CHECK_C_SOURCE_COMPILES("#include <prinit.h>
			int main(void) { PR_Initialized(); return 0; }" _nsprlibs_okay)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_LIBRARIES)

if(NOT _nsprlibs_okay)
	message(FATAL_ERROR "NSPR libs not found. Use -DWITH_NSPR_LIBS=/path/to/libs to specify the libdir of NSPR")
endif(NOT _nsprlibs_okay)

set(MANUAL_NSPR_LIBS "")

if(NOT (WITH_NSPR_LIBS STREQUAL ""))
	set(MANUAL_NSPR_LIBS "-L${WITH_NSPR_LIBS}")
endif(NOT (WITH_NSPR_LIBS STREQUAL ""))

set(MANUAL_NSPR_LIBS "${MANUAL_NSPR_LIBS} ${nsprlibs}")
string(STRIP ${MANUAL_NSPR_LIBS} MANUAL_NSPR_LIBS)

# *****************
# Check for NSS 3
# *****************

if(NOT (WITH_NSS_INCLUDES STREQUAL ""))
	set(CMAKE_REQUIRED_INCLUDES ${WITH_NSS_INCLUDES})
endif(NOT (WITH_NSS_INCLUDES STREQUAL ""))

if(NOT (WITH_NSPR_INCLUDES STREQUAL ""))
	list(APPEND CMAKE_REQUIRED_INCLUDES ${WITH_NSPR_INCLUDES})
endif(NOT (WITH_NSPR_INCLUDES STREQUAL ""))

unset(_have_headers CACHE)

CHECK_INCLUDE_FILES("nss.h;ssl.h;smime.h" _have_headers)

unset(CMAKE_REQUIRED_INCLUDES)

if(NOT _have_headers)
	message(FATAL_ERROR "NSS headers not found. Use -DWITH_NSS_INCLUDES=/path/to/nss to specify the include dir of NSS.")
endif(NOT _have_headers)

set(MANUAL_NSS_INCLUDES "${WITH_NSS_INCLUDES}")
string(STRIP ${MANUAL_NSS_INCLUDES} MANUAL_NSS_INCLUDES)

set(nsslibs "-lssl3 -lsmime3 -lnss3")

set(CMAKE_REQUIRED_INCLUDES ${MANUAL_NSS_INCLUDES} ${MANUAL_NSPR_INCLUDES})
set(CMAKE_REQUIRED_LIBRARIES ${nsslibs} ${nsprlibs})
unset(_nsslibs_okay CACHE)
CHECK_C_SOURCE_COMPILES("#include <nss.h>
			int main(void) { NSS_Init(\"\"); return 0; }" _nsslibs_okay)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_LIBRARIES)

if(NOT _nsslibs_okay)
	message(FATAL_ERROR "NSS libs not found. Use -DWITH_NSS_LIBS=/path/to/libs to specify the libdir of NSS")
endif(NOT _nsslibs_okay)

set(MANUAL_NSS_LIBS "")

if(NOT (WITH_NSS_LIBS STREQUAL ""))
	set(MANUAL_NSS_LIBS "-L${WITH_NSS_LIBS}")
	set(MOZILLA_NSS_LIB_DIR "${WITH_NSS_LIBS}")
endif(NOT (WITH_NSS_LIBS STREQUAL ""))

set(MANUAL_NSS_LIBS "${MANUAL_NSS_LIBS} ${nsslibs} ${MANUAL_NSPR_LIBS}")
string(STRIP ${MANUAL_NSS_LIBS} MANUAL_NSS_LIBS)

if(MOZILLA_NSS_LIB_DIR STREQUAL "")
	set(MOZILLA_NSS_LIB_DIR "${LIB_INSTALL_DIR}")
endif(MOZILLA_NSS_LIB_DIR STREQUAL "")