comparison OrthancFramework/Resources/CMake/OpenSslConfigurationStatic-1.1.1.cmake @ 4904:f2e78f7164d6

reintroduction of OpenSslConfigurationStatic-1.1.1.cmake for orthanc-gcp
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Feb 2022 09:34:36 +0100
parents
children 0ea402b4d901
comparison
equal deleted inserted replaced
4902:df86d2505df8 4904:f2e78f7164d6
1 # Orthanc - A Lightweight, RESTful DICOM Store
2 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3 # Department, University Hospital of Liege, Belgium
4 # Copyright (C) 2017-2022 Osimis S.A., Belgium
5 # Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
6 #
7 # This program is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public License
9 # as published by the Free Software Foundation, either version 3 of
10 # the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program. If not, see
19 # <http://www.gnu.org/licenses/>.
20
21
22 SET(OPENSSL_SOURCES_DIR ${CMAKE_BINARY_DIR}/openssl-1.1.1k)
23 SET(OPENSSL_URL "http://orthanc.osimis.io/ThirdPartyDownloads/openssl-1.1.1k.tar.gz")
24 SET(OPENSSL_MD5 "c4e7d95f782b08116afa27b30393dd27")
25
26 if (IS_DIRECTORY "${OPENSSL_SOURCES_DIR}")
27 set(FirstRun OFF)
28 else()
29 set(FirstRun ON)
30 endif()
31
32 DownloadPackage(${OPENSSL_MD5} ${OPENSSL_URL} "${OPENSSL_SOURCES_DIR}")
33
34 if (FirstRun)
35 file(WRITE ${OPENSSL_SOURCES_DIR}/crypto/buildinf.h "
36 #define DATE \"\"
37 #define PLATFORM \"\"
38 #define compiler_flags \"\"
39 ")
40 file(WRITE ${OPENSSL_SOURCES_DIR}/crypto/bn_conf.h "")
41 file(WRITE ${OPENSSL_SOURCES_DIR}/crypto/dso_conf.h "")
42
43 configure_file(
44 ${CMAKE_CURRENT_LIST_DIR}/../Patches/openssl-1.1.1-conf.h.in
45 ${OPENSSL_SOURCES_DIR}/include/openssl/opensslconf.h
46 )
47
48 # Apply the patches
49 execute_process(
50 COMMAND ${PATCH_EXECUTABLE} -p0 -N -i
51 ${CMAKE_CURRENT_LIST_DIR}/../Patches/openssl-1.1.1k.patch
52 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
53 RESULT_VARIABLE Failure
54 )
55
56 if (Failure)
57 message(FATAL_ERROR "Error while patching a file")
58 endif()
59
60 file(RENAME
61 ${OPENSSL_SOURCES_DIR}/include/openssl/e_os2.h
62 ${OPENSSL_SOURCES_DIR}/include/openssl/e_os2_source.h)
63
64 # The following patch of "e_os2.h" prevents from building OpenSSL
65 # as a DLL under Windows. Otherwise, symbols have inconsistent
66 # linkage if ${OPENSSL_SOURCES} is used to create a DLL (notably
67 # if building an Orthanc plugin such as PostgreSQL or MySQL).
68 file(WRITE ${OPENSSL_SOURCES_DIR}/include/openssl/e_os2.h "
69 #include \"e_os2_source.h\"
70 #if defined(_WIN32)
71 # undef OPENSSL_EXPORT
72 # undef OPENSSL_IMPORT
73 # undef OPENSSL_EXTERN
74 # undef OPENSSL_GLOBAL
75 # define OPENSSL_EXPORT
76 # define OPENSSL_IMPORT
77 # define OPENSSL_EXTERN extern
78 # define OPENSSL_GLOBAL
79 #endif
80 ")
81
82 else()
83 message("The patches for OpenSSL have already been applied")
84 endif()
85
86 add_definitions(
87 -DOPENSSL_THREADS
88 -DOPENSSL_IA32_SSE2
89 -DOPENSSL_NO_ASM
90 -DOPENSSL_NO_DYNAMIC_ENGINE
91 -DOPENSSL_NO_DEVCRYPTOENG
92
93 -DOPENSSL_NO_BF
94 -DOPENSSL_NO_CAMELLIA
95 -DOPENSSL_NO_CAST
96 -DOPENSSL_NO_EC_NISTP_64_GCC_128
97 -DOPENSSL_NO_GMP
98 -DOPENSSL_NO_GOST
99 -DOPENSSL_NO_HW
100 -DOPENSSL_NO_JPAKE
101 -DOPENSSL_NO_IDEA
102 -DOPENSSL_NO_KRB5
103 -DOPENSSL_NO_MD2
104 -DOPENSSL_NO_MDC2
105 #-DOPENSSL_NO_MD4 # MD4 is necessary for MariaDB/MySQL client
106 -DOPENSSL_NO_RC2
107 -DOPENSSL_NO_RC4
108 -DOPENSSL_NO_RC5
109 -DOPENSSL_NO_RFC3779
110 -DOPENSSL_NO_SCTP
111 -DOPENSSL_NO_STORE
112 -DOPENSSL_NO_SEED
113 -DOPENSSL_NO_WHIRLPOOL
114 -DOPENSSL_NO_RIPEMD
115 -DOPENSSL_NO_AFALGENG
116
117 -DOPENSSLDIR="/usr/local/ssl"
118 )
119
120
121 include_directories(
122 ${OPENSSL_SOURCES_DIR}
123 ${OPENSSL_SOURCES_DIR}/crypto
124 ${OPENSSL_SOURCES_DIR}/crypto/asn1
125 ${OPENSSL_SOURCES_DIR}/crypto/ec/curve448
126 ${OPENSSL_SOURCES_DIR}/crypto/ec/curve448/arch_32
127 ${OPENSSL_SOURCES_DIR}/crypto/evp
128 ${OPENSSL_SOURCES_DIR}/crypto/include
129 ${OPENSSL_SOURCES_DIR}/crypto/modes
130 ${OPENSSL_SOURCES_DIR}/include
131 )
132
133
134 set(OPENSSL_SOURCES_SUBDIRS
135 ${OPENSSL_SOURCES_DIR}/crypto
136 ${OPENSSL_SOURCES_DIR}/crypto/aes
137 ${OPENSSL_SOURCES_DIR}/crypto/aria
138 ${OPENSSL_SOURCES_DIR}/crypto/asn1
139 ${OPENSSL_SOURCES_DIR}/crypto/async
140 ${OPENSSL_SOURCES_DIR}/crypto/async/arch
141 ${OPENSSL_SOURCES_DIR}/crypto/bio
142 ${OPENSSL_SOURCES_DIR}/crypto/blake2
143 ${OPENSSL_SOURCES_DIR}/crypto/bn
144 ${OPENSSL_SOURCES_DIR}/crypto/buffer
145 ${OPENSSL_SOURCES_DIR}/crypto/chacha
146 ${OPENSSL_SOURCES_DIR}/crypto/cmac
147 ${OPENSSL_SOURCES_DIR}/crypto/cms
148 ${OPENSSL_SOURCES_DIR}/crypto/comp
149 ${OPENSSL_SOURCES_DIR}/crypto/conf
150 ${OPENSSL_SOURCES_DIR}/crypto/ct
151 ${OPENSSL_SOURCES_DIR}/crypto/des
152 ${OPENSSL_SOURCES_DIR}/crypto/dh
153 ${OPENSSL_SOURCES_DIR}/crypto/dsa
154 ${OPENSSL_SOURCES_DIR}/crypto/dso
155 ${OPENSSL_SOURCES_DIR}/crypto/ec
156 ${OPENSSL_SOURCES_DIR}/crypto/ec/curve448
157 ${OPENSSL_SOURCES_DIR}/crypto/ec/curve448/arch_32
158 ${OPENSSL_SOURCES_DIR}/crypto/err
159 ${OPENSSL_SOURCES_DIR}/crypto/evp
160 ${OPENSSL_SOURCES_DIR}/crypto/hmac
161 ${OPENSSL_SOURCES_DIR}/crypto/kdf
162 ${OPENSSL_SOURCES_DIR}/crypto/lhash
163 ${OPENSSL_SOURCES_DIR}/crypto/md4
164 ${OPENSSL_SOURCES_DIR}/crypto/md5
165 ${OPENSSL_SOURCES_DIR}/crypto/modes
166 ${OPENSSL_SOURCES_DIR}/crypto/objects
167 ${OPENSSL_SOURCES_DIR}/crypto/ocsp
168 ${OPENSSL_SOURCES_DIR}/crypto/pem
169 ${OPENSSL_SOURCES_DIR}/crypto/pkcs12
170 ${OPENSSL_SOURCES_DIR}/crypto/pkcs7
171 ${OPENSSL_SOURCES_DIR}/crypto/poly1305
172 ${OPENSSL_SOURCES_DIR}/crypto/pqueue
173 ${OPENSSL_SOURCES_DIR}/crypto/rand
174 ${OPENSSL_SOURCES_DIR}/crypto/ripemd
175 ${OPENSSL_SOURCES_DIR}/crypto/rsa
176 ${OPENSSL_SOURCES_DIR}/crypto/sha
177 ${OPENSSL_SOURCES_DIR}/crypto/siphash
178 ${OPENSSL_SOURCES_DIR}/crypto/sm2
179 ${OPENSSL_SOURCES_DIR}/crypto/sm3
180 ${OPENSSL_SOURCES_DIR}/crypto/sm4
181 ${OPENSSL_SOURCES_DIR}/crypto/srp
182 ${OPENSSL_SOURCES_DIR}/crypto/stack
183 ${OPENSSL_SOURCES_DIR}/crypto/store
184 ${OPENSSL_SOURCES_DIR}/crypto/ts
185 ${OPENSSL_SOURCES_DIR}/crypto/txt_db
186 ${OPENSSL_SOURCES_DIR}/crypto/ui
187 ${OPENSSL_SOURCES_DIR}/crypto/x509
188 ${OPENSSL_SOURCES_DIR}/crypto/x509v3
189 ${OPENSSL_SOURCES_DIR}/ssl
190 ${OPENSSL_SOURCES_DIR}/ssl/record
191 ${OPENSSL_SOURCES_DIR}/ssl/statem
192 )
193
194 if (ENABLE_OPENSSL_ENGINES)
195 add_definitions(
196 #-DENGINESDIR="/usr/local/lib/engines-1.1" # On GNU/Linux
197 -DENGINESDIR="."
198 )
199
200 list(APPEND OPENSSL_SOURCES_SUBDIRS
201 ${OPENSSL_SOURCES_DIR}/engines
202 ${OPENSSL_SOURCES_DIR}/crypto/engine
203 )
204 else()
205 add_definitions(-DOPENSSL_NO_ENGINE)
206 endif()
207
208 list(APPEND OPENSSL_SOURCES_SUBDIRS
209 # EC, ECDH and ECDSA are necessary for PKCS11, and for contacting
210 # HTTPS servers that use TLS certificate encrypted with ECDSA
211 # (check the output of a recent version of the "sslscan"
212 # command). Until Orthanc <= 1.4.1, these features were only
213 # enabled if ENABLE_PKCS11 support was set to "ON".
214 # https://groups.google.com/d/msg/orthanc-users/2l-bhYIMEWg/oMmK33bYBgAJ
215 ${OPENSSL_SOURCES_DIR}/crypto/ec
216 ${OPENSSL_SOURCES_DIR}/crypto/ecdh
217 ${OPENSSL_SOURCES_DIR}/crypto/ecdsa
218 )
219
220 foreach(d ${OPENSSL_SOURCES_SUBDIRS})
221 AUX_SOURCE_DIRECTORY(${d} OPENSSL_SOURCES)
222 endforeach()
223
224 list(REMOVE_ITEM OPENSSL_SOURCES
225 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_nyi.c
226 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_unix.c
227 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_vms.c
228 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_win.c
229 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_win32.c
230 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_wince.c
231 ${OPENSSL_SOURCES_DIR}/crypto/aes/aes_x86core.c
232 ${OPENSSL_SOURCES_DIR}/crypto/armcap.c
233 ${OPENSSL_SOURCES_DIR}/crypto/bio/bss_dgram.c
234 ${OPENSSL_SOURCES_DIR}/crypto/des/ncbc_enc.c
235 ${OPENSSL_SOURCES_DIR}/crypto/ec/ecp_nistz256.c
236 ${OPENSSL_SOURCES_DIR}/crypto/ec/ecp_nistz256_table.c
237 ${OPENSSL_SOURCES_DIR}/crypto/engine/eng_devcrypto.c
238 ${OPENSSL_SOURCES_DIR}/crypto/poly1305/poly1305_base2_44.c # Cannot be compiled with MinGW
239 ${OPENSSL_SOURCES_DIR}/crypto/poly1305/poly1305_ieee754.c # Cannot be compiled with MinGW
240 ${OPENSSL_SOURCES_DIR}/crypto/ppccap.c
241 ${OPENSSL_SOURCES_DIR}/crypto/s390xcap.c
242 ${OPENSSL_SOURCES_DIR}/crypto/sparcv9cap.c
243 ${OPENSSL_SOURCES_DIR}/engines/e_afalg.c # Cannot be compiled with MinGW
244 )
245
246 # Check out "${OPENSSL_SOURCES_DIR}/Configurations/README": "This is
247 # default if no option is specified, it works on any supported
248 # system." It is mandatory to define it as a macro, as it is used by
249 # all the source files that include OpenSSL (e.g. "Core/Toolbox.cpp"
250 # or curl)
251 add_definitions(-DTHIRTY_TWO_BIT)
252
253
254 if (NOT CMAKE_COMPILER_IS_GNUCXX OR
255 "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR
256 "${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
257 # Disable the use of a gcc extension, that is neither available on
258 # MinGW, nor on LSB
259 add_definitions(
260 -DOPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
261 )
262 endif()
263
264
265 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
266 set(OPENSSL_DEFINITIONS
267 "${OPENSSL_DEFINITIONS};OPENSSL_SYSNAME_WIN32;SO_WIN32;WIN32_LEAN_AND_MEAN;L_ENDIAN;NO_WINDOWS_BRAINDEATH")
268
269 if (ENABLE_OPENSSL_ENGINES)
270 link_libraries(crypt32)
271 endif()
272
273 add_definitions(
274 -DOPENSSL_RAND_SEED_OS # ${OPENSSL_SOURCES_DIR}/crypto/rand/rand_win.c
275 )
276
277 elseif ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
278 add_definitions(
279 # In order for "crypto/mem_sec.c" to compile on LSB
280 -DOPENSSL_NO_SECURE_MEMORY
281
282 # The "OPENSSL_RAND_SEED_OS" value implies a syscall() to
283 # "__NR_getrandom" (i.e. system call "getentropy(2)") in
284 # "rand_unix.c", which is not available in LSB.
285 -DOPENSSL_RAND_SEED_DEVRANDOM
286
287 # If "OPENSSL_NO_ERR" is not defined, the PostgreSQL plugin
288 # crashes with segmentation fault in function
289 # "build_SYS_str_reasons()", that is called from
290 # "OPENSSL_init_ssl()"
291 # https://bugs.orthanc-server.com/show_bug.cgi?id=193
292 -DOPENSSL_NO_ERR
293 )
294
295 else()
296 # Fixes error "OpenSSL error: error:2406C06E:random number
297 # generator:RAND_DRBG_instantiate:error retrieving entropy" that was
298 # present in Orthanc 1.6.0, if statically linking on Ubuntu 18.04
299 add_definitions(
300 -DOPENSSL_RAND_SEED_OS
301 )
302 endif()
303
304
305 set_source_files_properties(
306 ${OPENSSL_SOURCES}
307 PROPERTIES COMPILE_DEFINITIONS
308 "${OPENSSL_DEFINITIONS};DSO_NONE"
309 )