aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Norrbin <Johnex@users.noreply.github.com>2019-02-11 20:30:17 +0100
committerGitHub <noreply@github.com>2019-02-11 20:30:17 +0100
commit1dd2d050e106453eb887785c16fa82a1cff7efca (patch)
treec4da2ce66b25b770e6d2365e1b0ddba11205604a
parent535246269d4a7d8338320f8e6666ca887718c5d0 (diff)
downloadportable-1dd2d050e106453eb887785c16fa82a1cff7efca.tar.gz
portable-1dd2d050e106453eb887785c16fa82a1cff7efca.tar.bz2
portable-1dd2d050e106453eb887785c16fa82a1cff7efca.zip
Add LibreSSL CMake Find Module
CMake has the find_package function which tries to find the library install paths, and if found, gives the user some "interfaces" to use when including the library in their project. There was no LibreSSL module so i wrote one 👍. Placing this file in a new folder called CMake in the same folder as the root CMakeLists.txt file, and adding the following line to the top of it: set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}") Lets the user run the find_package like so: find_package(LibreSSL REQUIRED) If LibreSSL is installed and found, the user can then just include the library in their target like so: target_link_libraries(test LibreSSL::TLS) They are cascaded, TLS requires and sets SSL, which also requires and sets Crypto using INTERFACE_LINK_LIBRARIES. Instead of setting the CMAKE_MODULE_PATH like above, the file can be placed in the CMake modules folder. For linux CMake will look for LibreSSL in the default install location of "sudo make install", which was on Ubuntu /usr/local/ For Windows the user can set the paths to their library files and include folder manually using the CMake-GUI.
-rw-r--r--FindLibreSSL.cmake225
1 files changed, 225 insertions, 0 deletions
diff --git a/FindLibreSSL.cmake b/FindLibreSSL.cmake
new file mode 100644
index 0000000..d87b96e
--- /dev/null
+++ b/FindLibreSSL.cmake
@@ -0,0 +1,225 @@
1#[=======================================================================[
2
3Copyright (c) 2019 John Norrbin <jlnorrbin@johnex.se>
4
5Permission to use, copy, modify, and distribute this software for any
6purpose with or without fee is hereby granted, provided that the above
7copyright notice and this permission notice appear in all copies.
8
9THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17FindLibreSSL
18------------
19
20Find the LibreSSL encryption library.
21
22Optional Components
23^^^^^^^^^^^^^^^^^^^
24
25This module supports two optional components: SSL and TLS. Both
26components have associated imported targets, as described below.
27
28Imported Targets
29^^^^^^^^^^^^^^^^
30
31This module defines the following imported targets:
32
33LibreSSL::Crypto
34 The LibreSSL crypto library, if found.
35
36LibreSSL::SSL
37 The LibreSSL ssl library, if found. Requires and includes LibreSSL::Crypto automatically.
38
39LibreSSL::TLS
40 The LibreSSL tls library, if found. Requires and includes LibreSSL::SSL and LibreSSL::Crypto automatically.
41
42Result Variables
43^^^^^^^^^^^^^^^^
44
45This module will set the following variables in your project:
46
47LIBRESSL_FOUND
48 System has the LibreSSL library. If no components are requested it only requires the crypto library.
49LIBRESSL_INCLUDE_DIR
50 The LibreSSL include directory.
51LIBRESSL_CRYPTO_LIBRARY
52 The LibreSSL crypto library.
53LIBRESSL_SSL_LIBRARY
54 The LibreSSL SSL library.
55LIBRESSL_TLS_LIBRARY
56 The LibreSSL TLS library.
57LIBRESSL_LIBRARIES
58 All LibreSSL libraries.
59LIBRESSL_VERSION
60 This is set to $major.$minor.$revision (e.g. 2.6.8).
61
62Hints
63^^^^^
64
65Set LIBRESSL_ROOT_DIR to the root directory of an LibreSSL installation.
66
67]=======================================================================]
68
69# Set Hints
70set(_LIBRESSL_ROOT_HINTS
71 ${LIBRESSL_ROOT_DIR}
72 ENV LIBRESSL_ROOT_DIR
73)
74
75# Set Paths
76if (WIN32)
77 file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
78 set(_LIBRESSL_ROOT_PATHS
79 "${_programfiles}/LibreSSL"
80 )
81 unset(_programfiles)
82else()
83 set(_LIBRESSL_ROOT_PATHS
84 "/usr/local/"
85 )
86endif()
87
88# Combine
89set(_LIBRESSL_ROOT_HINTS_AND_PATHS
90 HINTS ${_LIBRESSL_ROOT_HINTS}
91 PATHS ${_LIBRESSL_ROOT_PATHS}
92)
93
94# Find Include Path
95find_path(LIBRESSL_INCLUDE_DIR
96 NAMES
97 tls.h
98 ${_LIBRESSL_ROOT_HINTS_AND_PATHS}
99 PATH_SUFFIXES
100 include
101)
102
103# Find Crypto Library
104find_library(LIBRESSL_CRYPTO_LIBRARY
105 NAMES
106 libcrypto
107 crypto
108 NAMES_PER_DIR
109 ${_LIBRESSL_ROOT_HINTS_AND_PATHS}
110 PATH_SUFFIXES
111 lib
112)
113
114# Find SSL Library
115find_library(LIBRESSL_SSL_LIBRARY
116 NAMES
117 libssl
118 ssl
119 NAMES_PER_DIR
120 ${_LIBRESSL_ROOT_HINTS_AND_PATHS}
121 PATH_SUFFIXES
122 lib
123)
124
125# Find TLS Library
126find_library(LIBRESSL_TLS_LIBRARY
127 NAMES
128 libtls
129 tls
130 NAMES_PER_DIR
131 ${_LIBRESSL_ROOT_HINTS_AND_PATHS}
132 PATH_SUFFIXES
133 lib
134)
135
136# Set Libraries
137set(LIBRESSL_LIBRARIES ${LIBRESSL_CRYPTO_LIBRARY} ${LIBRESSL_SSL_LIBRARY} ${LIBRESSL_TLS_LIBRARY})
138
139# Mark Variables As Advanced
140mark_as_advanced(LIBRESSL_INCLUDE_DIR LIBRESSL_LIBRARIES LIBRESSL_CRYPTO_LIBRARY LIBRESSL_SSL_LIBRARY LIBRESSL_TLS_LIBRARY)
141
142# Find Version File
143if(LIBRESSL_INCLUDE_DIR AND EXISTS "${LIBRESSL_INCLUDE_DIR}/openssl/opensslv.h")
144
145 # Get Version From File
146 file(STRINGS "${LIBRESSL_INCLUDE_DIR}/openssl/opensslv.h" OPENSSLV.H REGEX "#define LIBRESSL_VERSION_TEXT[ ]+\".*\"")
147
148 # Match Version String
149 string(REGEX REPLACE ".*\".*([0-9]+)\\.([0-9]+)\\.([0-9]+)\"" "\\1;\\2;\\3" LIBRESSL_VERSION_LIST "${OPENSSLV.H}")
150
151 # Split Parts
152 list(GET LIBRESSL_VERSION_LIST 0 LIBRESSL_VERSION_MAJOR)
153 list(GET LIBRESSL_VERSION_LIST 1 LIBRESSL_VERSION_MINOR)
154 list(GET LIBRESSL_VERSION_LIST 2 LIBRESSL_VERSION_REVISION)
155
156 # Set Version String
157 set(LIBRESSL_VERSION "${LIBRESSL_VERSION_MAJOR}.${LIBRESSL_VERSION_MINOR}.${LIBRESSL_VERSION_REVISION}")
158
159endif()
160
161# Set Find Package Arguments
162find_package_handle_standard_args(LibreSSL
163 REQUIRED_VARS
164 LIBRESSL_CRYPTO_LIBRARY
165 LIBRESSL_INCLUDE_DIR
166 VERSION_VAR
167 LIBRESSL_VERSION
168 HANDLE_COMPONENTS
169 FAIL_MESSAGE
170 "Could NOT find LibreSSL, try setting the path to LibreSSL using the LIBRESSL_ROOT_DIR environment variable"
171)
172
173# LibreSSL Found
174if(LIBRESSL_FOUND)
175
176 # Set LibreSSL::Crypto
177 if(NOT TARGET LibreSSL::Crypto AND EXISTS "${LIBRESSL_CRYPTO_LIBRARY}")
178
179 # Add Library
180 add_library(LibreSSL::Crypto UNKNOWN IMPORTED)
181
182 # Set Properties
183 set_target_properties(
184 LibreSSL::Crypto
185 PROPERTIES
186 INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}"
187 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
188 IMPORTED_LOCATION "${LIBRESSL_CRYPTO_LIBRARY}"
189 )
190
191 endif() # LibreSSL::Crypto
192
193 # Set LibreSSL::SSL
194 if(NOT TARGET LibreSSL::SSL AND EXISTS "${LIBRESSL_SSL_LIBRARY}")
195
196 # Add Library
197 add_library(LibreSSL::SSL UNKNOWN IMPORTED)
198
199 # Set Properties
200 set_target_properties(
201 LibreSSL::SSL
202 PROPERTIES
203 INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}"
204 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
205 IMPORTED_LOCATION "${LIBRESSL_SSL_LIBRARY}"
206 INTERFACE_LINK_LIBRARIES LibreSSL::Crypto
207 )
208
209 endif() # LibreSSL::SSL
210
211 # Set LibreSSL::TLS
212 if(NOT TARGET LibreSSL::TLS AND EXISTS "${LIBRESSL_TLS_LIBRARY}")
213 add_library(LibreSSL::TLS UNKNOWN IMPORTED)
214 set_target_properties(
215 LibreSSL::TLS
216 PROPERTIES
217 INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}"
218 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
219 IMPORTED_LOCATION "${LIBRESSL_TLS_LIBRARY}"
220 INTERFACE_LINK_LIBRARIES LibreSSL::SSL
221 )
222
223 endif() # LibreSSL::TLS
224
225endif(LIBRESSL_FOUND)