-
Notifications
You must be signed in to change notification settings - Fork 55
/
CMakeLists.txt
98 lines (85 loc) · 4.13 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
# MIT License
#
# Copyright (c) 2015-2023 The ViaDuck Project
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
cmake_minimum_required(VERSION 3.12...3.27)
project(openssl-cmake)
set(BUILD_OPENSSL OFF CACHE BOOL "Automated OpenSSL building")
set(OPENSSL_BUILD_VERSION OFF CACHE STRING "OpenSSL version to build")
set(OPENSSL_USE_STATIC_LIBS OFF CACHE STRING "OpenSSL static libs are preferred over shared libs")
set(OPENSSL_INSTALL_MAN OFF CACHE STRING "Install man pages?")
set(OPENSSL_MODULES "no-cast no-md2 no-md4 no-mdc2 no-rc4 no-rc5 no-engine no-idea no-mdc2 no-rc5 no-camellia no-ssl3 no-heartbeats no-gost no-deprecated no-capieng no-comp no-dtls no-psk no-srp no-dso no-dsa no-rc2 no-des" CACHE STRING "OpenSSL configure options")
set(OPENSSL_RPATH "" CACHE STRING "RPath to set during build")
set(CROSS_ANDROID OFF CACHE BOOL "Cross-compiling for Android?")
set(CROSS OFF CACHE BOOL "Cross-compiling?")
set(CROSS_TARGET OFF CACHE STRING "Cross-compilation target")
set(SYSTEM_OPENSSL OFF CACHE STRING "Use system-provided openssl libraries (instead of prebuilts or building)")
# allow including our modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# mimic system ssl and crypto targets
add_library(ssl INTERFACE)
add_library(crypto INTERFACE)
if (SYSTEM_OPENSSL)
# use system provided openssl
find_package(OpenSSL REQUIRED)
# link fake targets
target_link_libraries(ssl INTERFACE OpenSSL::SSL)
target_link_libraries(crypto INTERFACE OpenSSL::Crypto)
add_custom_target(openssl)
else()
# build our own or use prebuilts
# set up prefix
if (BUILD_OPENSSL)
set(OPENSSL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/openssl-build/)
else()
set(OPENSSL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/openssl-prefix/src/openssl)
endif()
# predict byproduct names and include directory
include(ByproductsOpenSSL)
GetOpenSSLByproducts(${OPENSSL_PREFIX} OPENSSL_BYPRODUCTS OPENSSL_INCLUDE_DIR)
# set up openssl target
if (BUILD_OPENSSL)
include(BuildOpenSSL)
else()
include(PrebuiltOpenSSL)
endif()
# add imported targets to common target
add_dependencies(ssl_static_lib openssl)
add_dependencies(ssl_shared_lib openssl)
add_dependencies(crypto_static_lib openssl)
add_dependencies(crypto_shared_lib openssl)
if (OPENSSL_USE_STATIC_LIBS)
target_link_libraries(ssl INTERFACE ssl_static_lib)
target_link_libraries(crypto INTERFACE crypto_static_lib)
else()
target_link_libraries(ssl INTERFACE ssl_shared_lib)
target_link_libraries(crypto INTERFACE crypto_shared_lib)
endif()
# set include locations
target_include_directories(ssl BEFORE INTERFACE $<BUILD_INTERFACE:${OPENSSL_INCLUDE_DIR}>)
target_include_directories(crypto BEFORE INTERFACE $<BUILD_INTERFACE:${OPENSSL_INCLUDE_DIR}>)
install(DIRECTORY ${OPENSSL_PREFIX}/usr/local/bin/ TYPE BIN)
install(DIRECTORY ${OPENSSL_PREFIX}/usr/local/include/ TYPE INCLUDE)
install(DIRECTORY ${OPENSSL_PREFIX}/usr/local/lib/ TYPE LIB)
if (OPENSSL_INSTALL_MAN)
install(DIRECTORY ${OPENSSL_PREFIX}/usr/local/share/ TYPE DATA)
endif()
endif()