comparison OrthancFramework/Resources/CMake/OpenSslConfigurationStatic-3.0.cmake @ 4702:312e0e29de90 openssl-3.x

compilation using openssl-3.0.0-beta1
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Jun 2021 07:09:34 +0200
parents
children 2b3db9d08fe2
comparison
equal deleted inserted replaced
4701:68635d365a27 4702:312e0e29de90
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-2021 Osimis S.A., Belgium
5 #
6 # This program is free software: you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public License
8 # as published by the Free Software Foundation, either version 3 of
9 # the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this program. If not, see
18 # <http://www.gnu.org/licenses/>.
19
20
21 set(OPENSSL_VERSION_MAJOR 3)
22 set(OPENSSL_VERSION_MINOR 0)
23 set(OPENSSL_VERSION_PATCH 0)
24 set(OPENSSL_VERSION_PRE_RELEASE "-beta1")
25 set(OPENSSL_VERSION_FULL "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_PATCH}${OPENSSL_VERSION_PRE_RELEASE}")
26 SET(OPENSSL_SOURCES_DIR ${CMAKE_BINARY_DIR}/openssl-${OPENSSL_VERSION_FULL})
27 SET(OPENSSL_URL "http://orthanc.osimis.io/ThirdPartyDownloads/openssl-${OPENSSL_VERSION_FULL}.tar.gz")
28 SET(OPENSSL_MD5 "437b21bd0e09fbaa0a89151c6c0130a7")
29
30 if (IS_DIRECTORY "${OPENSSL_SOURCES_DIR}")
31 set(FirstRun OFF)
32 else()
33 set(FirstRun ON)
34 endif()
35
36 DownloadPackage(${OPENSSL_MD5} ${OPENSSL_URL} "${OPENSSL_SOURCES_DIR}")
37
38
39 if (FirstRun)
40 # Apply the patches
41 execute_process(
42 COMMAND ${PATCH_EXECUTABLE} -p0 -N -i
43 ${CMAKE_CURRENT_LIST_DIR}/../Patches/openssl-3.0.0-beta1.patch
44 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
45 RESULT_VARIABLE Failure
46 )
47
48 if (Failure)
49 message(FATAL_ERROR "Error while patching a file")
50 endif()
51
52 execute_process(
53 COMMAND ${PYTHON_EXECUTABLE}
54 ${CMAKE_CURRENT_LIST_DIR}/../Patches/OpenSSL-ConfigureHeaders.py
55 "${OPENSSL_SOURCES_DIR}"
56 RESULT_VARIABLE Failure
57 )
58
59 if (Failure)
60 message(FATAL_ERROR "Error while configuring the OpenSSL headers")
61 endif()
62
63 file(WRITE ${OPENSSL_SOURCES_DIR}/include/openssl/opensslv.h "")
64 file(WRITE ${OPENSSL_SOURCES_DIR}/include/crypto/bn_conf.h "")
65 file(WRITE ${OPENSSL_SOURCES_DIR}/include/crypto/dso_conf.h "")
66
67 file(WRITE ${OPENSSL_SOURCES_DIR}/crypto/buildinf.h "
68 #define DATE \"\"
69 #define PLATFORM \"\"
70 #define compiler_flags \"\"
71 ")
72
73 else()
74 message("The patches for OpenSSL have already been applied")
75 endif()
76
77
78 if (OPENSSL_VERSION_PRE_RELEASE STREQUAL "")
79 set(VERSION_VERSION_OFFSET 0)
80 else()
81 set(VERSION_VERSION_OFFSET 15)
82 endif()
83
84 math(EXPR OPENSSL_CONFIGURED_API "${OPENSSL_VERSION_MAJOR} * 10000 + ${OPENSSL_VERSION_MINOR} * 100 + ${OPENSSL_VERSION_PATCH}")
85
86 # This macro is normally defined in "opensslv.h.in"
87 math(EXPR OPENSSL_VERSION_NUMBER "(${OPENSSL_VERSION_MAJOR} << 28) + (${OPENSSL_VERSION_MINOR} << 20) + (${OPENSSL_VERSION_PATCH} << 4) + ${VERSION_VERSION_OFFSET}")
88
89 list(GET CMAKE_FIND_LIBRARY_SUFFIXES 0 OPENSSL_DSO_EXTENSION)
90
91 add_definitions(
92 -DOPENSSL_VERSION_MAJOR=${OPENSSL_VERSION_MAJOR}
93 -DOPENSSL_VERSION_MINOR=${OPENSSL_VERSION_MINOR}
94 -DOPENSSL_VERSION_PATCH=${OPENSSL_VERSION_PATCH}
95 -DOPENSSL_CONFIGURED_API=${OPENSSL_CONFIGURED_API}
96 -DOPENSSL_VERSION_NUMBER=${OPENSSL_VERSION_NUMBER}
97 -DOPENSSL_VERSION_PRE_RELEASE="${OPENSSL_VERSION_PRE_RELEASE}"
98 -DOPENSSL_VERSION_BUILD_METADATA=""
99 -DOPENSSL_VERSION_TEXT="OpenSSL ${OPENSSL_VERSION_FULL}"
100 -DOPENSSL_VERSION_STR="${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_PATCH}"
101 -DOPENSSL_FULL_VERSION_STR="${OPENSSL_VERSION_FULL}"
102 -DDSO_EXTENSION="${OPENSSL_DSO_EXTENSION}"
103
104 -DOPENSSLDIR="/usr/local/ssl"
105 -DMODULESDIR="" # TODO
106
107 -DOPENSSL_BUILDING_OPENSSL
108 -DOPENSSL_THREADS
109 -DOPENSSL_IA32_SSE2
110
111 -DOPENSSL_NO_AFALGENG
112 -DOPENSSL_NO_ASM
113 -DOPENSSL_NO_DEVCRYPTOENG
114 -DOPENSSL_NO_DYNAMIC_ENGINE
115 -DOPENSSL_NO_EC_NISTP_64_GCC_128
116 -DOPENSSL_NO_GOST
117 -DOPENSSL_NO_RFC3779
118 -DOPENSSL_NO_SCTP
119
120 -DOPENSSL_NO_KTLS # TODO ?
121 )
122
123
124 include_directories(
125 ${OPENSSL_SOURCES_DIR}
126 ${OPENSSL_SOURCES_DIR}/crypto/asn1
127 ${OPENSSL_SOURCES_DIR}/crypto/ec/curve448
128 ${OPENSSL_SOURCES_DIR}/crypto/ec/curve448/arch_32
129 ${OPENSSL_SOURCES_DIR}/crypto/evp
130 ${OPENSSL_SOURCES_DIR}/crypto/include
131 ${OPENSSL_SOURCES_DIR}/crypto/modes
132 ${OPENSSL_SOURCES_DIR}/include
133 ${OPENSSL_SOURCES_DIR}/providers/common/include
134 ${OPENSSL_SOURCES_DIR}/providers/implementations/include
135 )
136
137
138 set(OPENSSL_SOURCES_SUBDIRS
139 ## Assembly is disabled
140 # ${OPENSSL_SOURCES_DIR}/crypto/aes/asm
141 # ${OPENSSL_SOURCES_DIR}/crypto/bf/asm
142 # ${OPENSSL_SOURCES_DIR}/crypto/bn/asm
143 # ${OPENSSL_SOURCES_DIR}/crypto/camellia/asm
144 # ${OPENSSL_SOURCES_DIR}/crypto/cast/asm
145 # ${OPENSSL_SOURCES_DIR}/crypto/chacha/asm
146 # ${OPENSSL_SOURCES_DIR}/crypto/des/asm
147 # ${OPENSSL_SOURCES_DIR}/crypto/ec/asm
148 # ${OPENSSL_SOURCES_DIR}/crypto/md5/asm
149 # ${OPENSSL_SOURCES_DIR}/crypto/modes/asm
150 # ${OPENSSL_SOURCES_DIR}/crypto/poly1305/asm
151 # ${OPENSSL_SOURCES_DIR}/crypto/rc4/asm
152 # ${OPENSSL_SOURCES_DIR}/crypto/rc5/asm
153 # ${OPENSSL_SOURCES_DIR}/crypto/ripemd/asm
154 # ${OPENSSL_SOURCES_DIR}/crypto/sha/asm
155 # ${OPENSSL_SOURCES_DIR}/crypto/whrlpool/asm
156
157 ${OPENSSL_SOURCES_DIR}/crypto
158 ${OPENSSL_SOURCES_DIR}/crypto/aes
159 ${OPENSSL_SOURCES_DIR}/crypto/aria
160 ${OPENSSL_SOURCES_DIR}/crypto/asn1
161 ${OPENSSL_SOURCES_DIR}/crypto/async
162 ${OPENSSL_SOURCES_DIR}/crypto/async/arch
163 ${OPENSSL_SOURCES_DIR}/crypto/bf
164 ${OPENSSL_SOURCES_DIR}/crypto/bio
165 ${OPENSSL_SOURCES_DIR}/crypto/bn
166 ${OPENSSL_SOURCES_DIR}/crypto/buffer
167 ${OPENSSL_SOURCES_DIR}/crypto/camellia
168 ${OPENSSL_SOURCES_DIR}/crypto/cast
169 ${OPENSSL_SOURCES_DIR}/crypto/chacha
170 ${OPENSSL_SOURCES_DIR}/crypto/cmac
171 ${OPENSSL_SOURCES_DIR}/crypto/cmp
172 ${OPENSSL_SOURCES_DIR}/crypto/cms
173 ${OPENSSL_SOURCES_DIR}/crypto/comp
174 ${OPENSSL_SOURCES_DIR}/crypto/conf
175 ${OPENSSL_SOURCES_DIR}/crypto/crmf
176 ${OPENSSL_SOURCES_DIR}/crypto/ct
177 ${OPENSSL_SOURCES_DIR}/crypto/des
178 ${OPENSSL_SOURCES_DIR}/crypto/dh
179 ${OPENSSL_SOURCES_DIR}/crypto/dsa
180 ${OPENSSL_SOURCES_DIR}/crypto/dso
181 ${OPENSSL_SOURCES_DIR}/crypto/ec
182 ${OPENSSL_SOURCES_DIR}/crypto/ec/curve448
183 ${OPENSSL_SOURCES_DIR}/crypto/ec/curve448/arch_32
184 ${OPENSSL_SOURCES_DIR}/crypto/ec/curve448/arch_64
185 ${OPENSSL_SOURCES_DIR}/crypto/encode_decode
186 ${OPENSSL_SOURCES_DIR}/crypto/engine
187 ${OPENSSL_SOURCES_DIR}/crypto/err
188 ${OPENSSL_SOURCES_DIR}/crypto/ess
189 ${OPENSSL_SOURCES_DIR}/crypto/evp
190 ${OPENSSL_SOURCES_DIR}/crypto/ffc
191 ${OPENSSL_SOURCES_DIR}/crypto/hmac
192 ${OPENSSL_SOURCES_DIR}/crypto/http
193 ${OPENSSL_SOURCES_DIR}/crypto/idea
194 ${OPENSSL_SOURCES_DIR}/crypto/kdf
195 ${OPENSSL_SOURCES_DIR}/crypto/lhash
196 ${OPENSSL_SOURCES_DIR}/crypto/md2
197 ${OPENSSL_SOURCES_DIR}/crypto/md4
198 ${OPENSSL_SOURCES_DIR}/crypto/md5
199 ${OPENSSL_SOURCES_DIR}/crypto/mdc2
200 ${OPENSSL_SOURCES_DIR}/crypto/modes
201 ${OPENSSL_SOURCES_DIR}/crypto/objects
202 ${OPENSSL_SOURCES_DIR}/crypto/ocsp
203 ${OPENSSL_SOURCES_DIR}/crypto/pem
204 ${OPENSSL_SOURCES_DIR}/crypto/perlasm
205 ${OPENSSL_SOURCES_DIR}/crypto/pkcs12
206 ${OPENSSL_SOURCES_DIR}/crypto/pkcs7
207 ${OPENSSL_SOURCES_DIR}/crypto/poly1305
208 ${OPENSSL_SOURCES_DIR}/crypto/property
209 ${OPENSSL_SOURCES_DIR}/crypto/rand
210 ${OPENSSL_SOURCES_DIR}/crypto/rc2
211 ${OPENSSL_SOURCES_DIR}/crypto/rc4
212 ${OPENSSL_SOURCES_DIR}/crypto/rc5
213 ${OPENSSL_SOURCES_DIR}/crypto/ripemd
214 ${OPENSSL_SOURCES_DIR}/crypto/rsa
215 ${OPENSSL_SOURCES_DIR}/crypto/seed
216 ${OPENSSL_SOURCES_DIR}/crypto/sha
217 ${OPENSSL_SOURCES_DIR}/crypto/siphash
218 ${OPENSSL_SOURCES_DIR}/crypto/sm2
219 ${OPENSSL_SOURCES_DIR}/crypto/sm3
220 ${OPENSSL_SOURCES_DIR}/crypto/sm4
221 ${OPENSSL_SOURCES_DIR}/crypto/srp
222 ${OPENSSL_SOURCES_DIR}/crypto/stack
223 ${OPENSSL_SOURCES_DIR}/crypto/store
224 ${OPENSSL_SOURCES_DIR}/crypto/ts
225 ${OPENSSL_SOURCES_DIR}/crypto/txt_db
226 ${OPENSSL_SOURCES_DIR}/crypto/ui
227 ${OPENSSL_SOURCES_DIR}/crypto/whrlpool
228 ${OPENSSL_SOURCES_DIR}/crypto/x509
229
230 # ${OPENSSL_SOURCES_DIR}/providers/implementations/rands/seeding # OS-specific
231 ${OPENSSL_SOURCES_DIR}/providers
232 ${OPENSSL_SOURCES_DIR}/providers/common
233 ${OPENSSL_SOURCES_DIR}/providers/common/der
234 ${OPENSSL_SOURCES_DIR}/providers/implementations/asymciphers
235 ${OPENSSL_SOURCES_DIR}/providers/implementations/ciphers
236 ${OPENSSL_SOURCES_DIR}/providers/implementations/digests
237 ${OPENSSL_SOURCES_DIR}/providers/implementations/encode_decode
238 ${OPENSSL_SOURCES_DIR}/providers/implementations/exchange
239 ${OPENSSL_SOURCES_DIR}/providers/implementations/kdfs
240 ${OPENSSL_SOURCES_DIR}/providers/implementations/kem
241 ${OPENSSL_SOURCES_DIR}/providers/implementations/keymgmt
242 ${OPENSSL_SOURCES_DIR}/providers/implementations/macs
243 ${OPENSSL_SOURCES_DIR}/providers/implementations/rands
244 ${OPENSSL_SOURCES_DIR}/providers/implementations/signature
245 ${OPENSSL_SOURCES_DIR}/providers/implementations/storemgmt
246
247 ${OPENSSL_SOURCES_DIR}/ssl
248 ${OPENSSL_SOURCES_DIR}/ssl/record
249 ${OPENSSL_SOURCES_DIR}/ssl/statem
250 )
251
252 if (ENABLE_OPENSSL_ENGINES)
253 add_definitions(
254 #-DENGINESDIR="/usr/local/lib/engines-1.1" # On GNU/Linux
255 -DENGINESDIR="."
256 )
257
258 list(APPEND OPENSSL_SOURCES_SUBDIRS
259 ${OPENSSL_SOURCES_DIR}/engines
260 ${OPENSSL_SOURCES_DIR}/crypto/engine
261 )
262 else()
263 add_definitions(-DOPENSSL_NO_ENGINE)
264 endif()
265
266 list(APPEND OPENSSL_SOURCES_SUBDIRS
267 # EC, ECDH and ECDSA are necessary for PKCS11, and for contacting
268 # HTTPS servers that use TLS certificate encrypted with ECDSA
269 # (check the output of a recent version of the "sslscan"
270 # command). Until Orthanc <= 1.4.1, these features were only
271 # enabled if ENABLE_PKCS11 support was set to "ON".
272 # https://groups.google.com/d/msg/orthanc-users/2l-bhYIMEWg/oMmK33bYBgAJ
273 ${OPENSSL_SOURCES_DIR}/crypto/ec
274 ${OPENSSL_SOURCES_DIR}/crypto/ecdh
275 ${OPENSSL_SOURCES_DIR}/crypto/ecdsa
276 )
277
278 foreach(d ${OPENSSL_SOURCES_SUBDIRS})
279 AUX_SOURCE_DIRECTORY(${d} OPENSSL_SOURCES)
280 endforeach()
281
282
283 list(REMOVE_ITEM OPENSSL_SOURCES
284 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_nyi.c
285 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_unix.c
286 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_vms.c
287 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_win.c
288 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_win32.c
289 ${OPENSSL_SOURCES_DIR}/crypto/LPdir_wince.c
290 ${OPENSSL_SOURCES_DIR}/crypto/aes/aes_x86core.c
291 ${OPENSSL_SOURCES_DIR}/crypto/armcap.c
292 ${OPENSSL_SOURCES_DIR}/crypto/des/ncbc_enc.c
293 ${OPENSSL_SOURCES_DIR}/crypto/ec/ecp_nistp224.c
294 ${OPENSSL_SOURCES_DIR}/crypto/ec/ecp_nistp256.c
295 ${OPENSSL_SOURCES_DIR}/crypto/ec/ecp_nistp521.c
296 ${OPENSSL_SOURCES_DIR}/crypto/ec/ecp_nistz256.c
297 ${OPENSSL_SOURCES_DIR}/crypto/ec/ecp_nistz256_table.c
298 ${OPENSSL_SOURCES_DIR}/crypto/ec/ecp_s390x_nistp.c
299 ${OPENSSL_SOURCES_DIR}/crypto/ec/ecx_s390x.c
300 ${OPENSSL_SOURCES_DIR}/crypto/poly1305/poly1305_base2_44.c
301 ${OPENSSL_SOURCES_DIR}/crypto/ppccap.c
302 ${OPENSSL_SOURCES_DIR}/crypto/rsa/rsa_acvp_test_params.c
303 ${OPENSSL_SOURCES_DIR}/crypto/s390xcap.c
304 ${OPENSSL_SOURCES_DIR}/crypto/sparcv9cap.c
305 ${OPENSSL_SOURCES_DIR}/engines/e_devcrypto.c
306 ${OPENSSL_SOURCES_DIR}/engines/e_loader_attic.c
307 ${OPENSSL_SOURCES_DIR}/providers/common/securitycheck_fips.c
308 ${OPENSSL_SOURCES_DIR}/providers/implementations/macs/blake2_mac_impl.c
309
310 ${OPENSSL_SOURCES_DIR}/ssl/ktls.c # TODO ?
311 )
312
313
314 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
315 ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR
316 ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR
317 ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
318 list(APPEND OPENSSL_SOURCES
319 ${OPENSSL_SOURCES_DIR}/providers/implementations/rands/seeding/rand_unix.c
320 )
321 endif()
322
323
324 # Check out "${OPENSSL_SOURCES_DIR}/Configurations/README.md": "This
325 # is default if no option is specified, it works on any supported
326 # system." It is mandatory to define it as a macro, as it is used by
327 # all the source files that include OpenSSL (e.g. "Core/Toolbox.cpp"
328 # or curl)
329 add_definitions(-DTHIRTY_TWO_BIT)
330
331
332 if (NOT CMAKE_COMPILER_IS_GNUCXX OR
333 "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR
334 "${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
335 # Disable the use of a gcc extension, that is neither available on
336 # MinGW, nor on LSB
337 add_definitions(
338 -DOPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
339 )
340 endif()
341
342
343 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
344 set(OPENSSL_DEFINITIONS
345 "${OPENSSL_DEFINITIONS};OPENSSL_SYSNAME_WIN32;SO_WIN32;WIN32_LEAN_AND_MEAN;L_ENDIAN;NO_WINDOWS_BRAINDEATH")
346
347 if (ENABLE_OPENSSL_ENGINES)
348 link_libraries(crypt32)
349 endif()
350
351 add_definitions(
352 -DOPENSSL_RAND_SEED_OS # ${OPENSSL_SOURCES_DIR}/crypto/rand/rand_win.c
353 )
354
355 elseif ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
356 add_definitions(
357 # In order for "crypto/mem_sec.c" to compile on LSB
358 -DOPENSSL_NO_SECURE_MEMORY
359
360 # The "OPENSSL_RAND_SEED_OS" value implies a syscall() to
361 # "__NR_getrandom" (i.e. system call "getentropy(2)") in
362 # "rand_unix.c", which is not available in LSB.
363 -DOPENSSL_RAND_SEED_DEVRANDOM
364
365 # If "OPENSSL_NO_ERR" is not defined, the PostgreSQL plugin
366 # crashes with segmentation fault in function
367 # "build_SYS_str_reasons()", that is called from
368 # "OPENSSL_init_ssl()"
369 # https://bugs.orthanc-server.com/show_bug.cgi?id=193
370 -DOPENSSL_NO_ERR
371 )
372
373 else()
374 # Fixes error "OpenSSL error: error:2406C06E:random number
375 # generator:RAND_DRBG_instantiate:error retrieving entropy" that was
376 # present in Orthanc 1.6.0, if statically linking on Ubuntu 18.04
377 add_definitions(
378 -DOPENSSL_RAND_SEED_OS
379 )
380 endif()
381
382
383 set_source_files_properties(
384 ${OPENSSL_SOURCES}
385 PROPERTIES COMPILE_DEFINITIONS
386 "${OPENSSL_DEFINITIONS};DSO_NONE"
387 )