summaryrefslogtreecommitdiffstats
path: root/exporters/cmake/OpenSSLConfig.cmake.in
blob: 606773ff2726e915ede8f8fae05924d438433bb4 (plain)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# Generated by OpenSSL
{-
   use lib catdir($config{sourcedir}, 'Configurations');
   use platform;
   use Data::Dumper;

   our %lib_info = (
       map { my %x = ();
             my $lib_static = platform->staticlib($_);
             my $lib_shared =
                 (platform->can("sharedlib_simple")
                  ? platform->sharedlib_simple($_)
                  : undef)
                 // platform->sharedlib($_);
             my $lib_shared_import = platform->sharedlib_import($_);
             $x{static} = $lib_static if $lib_static;
             $x{shared} = $lib_shared if $lib_shared;
             $x{shared_import} = $lib_shared_import if $lib_shared_import;
             %x ? ( $_ => \%x ) : () }
       grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
       @{$unified_info{libraries}}
   );
   our $no_static = !$disabled{shared} && !$lib_info{libcrypto}->{static};
   our $no_shared = $disabled{shared};

   # Unixifying of paths, because that's what CMake understands.
   # This assumes that the given path is absolute.
   sub unixify {
       use File::Spec;
       use File::Spec::Unix;

       my $path = shift;
       my $no_file = shift;
       (my $volume, $directories, $file) = File::Spec->splitpath($path, $no_file // ());
       $directories = File::Spec::Unix->catdir(File::Spec->splitdir($directories));

       # We know that $volume is ignored by File::Spec::Unix, so we handle it specially
       # according to the conventions of the platform.
       $volume =~ s|^(.*?):$|/$1| if $^O eq "vms"; # On VMS, DEV: -> /DEV

       return $volume . File::Spec::Unix->catpath('', $directories, $no_file ? () : $file);
   }
   ""
-}
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Avoid duplicate find_package()
set(_ossl_expected_targets OpenSSL::Crypto OpenSSL::SSL
    {- output_off() if $disabled{uplink}; "" -}OpenSSL::applink{- output_on() if $disabled{uplink}; "" -})
set(_ossl_defined_targets)
set(_ossl_undefined_targets)
foreach(t IN LISTS _ossl_expected_targets)
  if(TARGET "${t}")
    LIST(APPEND _ossl_defined_targets "${t}")
  else()
    LIST(APPEND _ossl_undefined_targets "${t}")
  endif()
endforeach()
message(DEBUG "_ossl_expected_targets = ${_ossl_expected_targets}")
message(DEBUG "_ossl_defined_targets = ${_ossl_defined_targets}")
message(DEBUG "_ossl_undefined_targets = ${_ossl_undefined_targets}")
if(NOT _ossl_undefined_targets)
  # All targets are defined, we're good, just undo everything and return
  unset(_ossl_expected_targets)
  unset(_ossl_defined_targets)
  unset(_ossl_undefined_targets)
  unset(CMAKE_IMPORT_FILE_VERSION)
  return()
endif()
if(_ossl_defined_targets)
  # We have a mix of defined and undefined targets.  This is hard to reconcile,
  # and probably the result of another config, or FindOpenSSL.cmake having been
  # called, or whatever.  Therefore, the best course of action is to quit with a
  # hard error.
  message(FATAL_ERROR "Some targets defined, others not:\nNot defined: ${_ossl_undefined_targets}\nDefined: ${_ossl_defined_targets}")
endif()
unset(_ossl_expected_targets)
unset(_ossl_defined_targets)
unset(_ossl_undefined_targets)

{-
  # It can be argued that 'cmake_path' would be the better choice here.  However,
  # cmake_path is relatively new, while get_filename_component has been around
  # since before CMake 3.0
-}
# Set up the import path, so all other import paths are made relative this file
get_filename_component(_ossl_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH)
{-
  # For each component in $OpenSSL::safe::installdata::CMAKECONFIGDIR_REL, have CMake
  # out the parent directory.
  my $d = unixify($OpenSSL::safe::installdata::CMAKECONFIGDIR_REL);
  $OUT = '';
  $OUT .= 'get_filename_component(_ossl_prefix "${_ossl_prefix}" PATH)' . "\n"
      foreach (split '/', $d);
-}
if(_ossl_prefix STREQUAL "/")
  set(_ossl_prefix "")
endif()

{- output_off() unless $disabled{shared}; "" -}
set(_ossl_use_static_libs True)
{- output_on() unless $disabled{shared}; "" -}
if(OPENSSL_USE_STATIC_LIBS)
  set(_ossl_use_static_libs True)
elseif(DEFINED OPENSSL_USE_STATIC_LIBS)
  # We know OPENSSL_USE_STATIC_LIBS is defined and False
  if(_ossl_use_static_libs)
    # OPENSSL_USE_STATIC_LIBS is explicitly false, indicating that shared libraries are
    # required.  However, _ossl_use_static_libs indicates that no shared libraries are
    # available.  The best course of action is to simply return and leave it to CMake to
    # use another OpenSSL config.
    unset(_ossl_use_static_libs)
    unset(CMAKE_IMPORT_FILE_VERSION)
    return()
  endif()
endif()

# Version, copied from what find_package() gives, for compatibility with FindOpenSSL.cmake
set(OPENSSL_VERSION "${OpenSSL_VERSION}")
set(OPENSSL_VERSION_MAJOR "${OpenSSL_VERSION_MAJOR}")
set(OPENSSL_VERSION_MINOR "${OpenSSL_VERSION_MINOR}")
set(OPENSSL_VERSION_FIX "${OpenSSL_VERSION_PATCH}")
set(OPENSSL_FOUND YES)

# Directories and names
set(OPENSSL_INCLUDE_DIR "${_ossl_prefix}/{- unixify($OpenSSL::safe::installdata::INCLUDEDIR_REL, 1); -}")
set(OPENSSL_LIBRARY_DIR "${_ossl_prefix}/{- unixify($OpenSSL::safe::installdata::LIBDIR_REL, 1); -}")
set(OPENSSL_ENGINES_DIR "${_ossl_prefix}/{- unixify($OpenSSL::safe::installdata::ENGINESDIR_REL, 1); -}")
set(OPENSSL_MODULES_DIR "${_ossl_prefix}/{- unixify($OpenSSL::safe::installdata::MODULESDIR_REL, 1); -}")
set(OPENSSL_RUNTIME_DIR "${_ossl_prefix}/{- unixify($OpenSSL::safe::installdata::BINDIR_REL, 1); -}")
{- output_off() if $disabled{uplink}; "" -}
set(OPENSSL_APPLINK_SOURCE "${_ossl_prefix}/{- unixify($OpenSSL::safe::installdata::APPLINKDIR_REL, 1); -}/applink.c")
{- output_on() if $disabled{uplink}; "" -}
set(OPENSSL_PROGRAM "${OPENSSL_RUNTIME_DIR}/{- platform->bin('openssl') -}")

# Set up the imported targets
if(_ossl_use_static_libs)
{- output_off() unless $no_static; "" -}
  # Static libraries are UNSUPPORTED in this configuration
{- output_on() unless $no_static; output_off() if $no_static; "" -}
  add_library(OpenSSL::Crypto STATIC IMPORTED)
  add_library(OpenSSL::SSL STATIC IMPORTED)

  set(OPENSSL_LIBCRYPTO_STATIC "${OPENSSL_LIBRARY_DIR}/{- $lib_info{libcrypto}->{static} -}")
  set(OPENSSL_LIBCRYPTO_DEPENDENCIES {- join(' ', @OpenSSL::safe::installdata::LDLIBS) -})
  set_target_properties(OpenSSL::Crypto PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    IMPORTED_LOCATION ${OPENSSL_LIBCRYPTO_STATIC})
  set_property(TARGET OpenSSL::Crypto
    PROPERTY INTERFACE_LINK_LIBRARIES ${OPENSSL_LIBCRYPTO_DEPENDENCIES})

  set(OPENSSL_LIBSSL_STATIC "${OPENSSL_LIBRARY_DIR}/{- $lib_info{libssl}->{static} -}")
  set(OPENSSL_LIBSSL_DEPENDENCIES OpenSSL::Crypto)
  set_target_properties(OpenSSL::SSL PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    IMPORTED_LOCATION ${OPENSSL_LIBSSL_STATIC})
  set_property(TARGET OpenSSL::SSL
    PROPERTY INTERFACE_LINK_LIBRARIES ${OPENSSL_LIBSSL_DEPENDENCIES})

  # Directories and names compatible with CMake's FindOpenSSL.cmake
  set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_LIBCRYPTO_STATIC})
  set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_LIBCRYPTO_DEPENDENCIES})
  set(OPENSSL_SSL_LIBRARY ${OPENSSL_LIBSSL_STATIC})
  set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_LIBSSL_DEPENDENCIES})
  set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_LIBSSL_DEPENDENCIES} ${OPENSSL_LIBCRYPTO_DEPENDENCIES})
{- output_on(); "" -}
else()
{- output_off() unless $no_shared; "" -}
  # Shared libraries are UNSUPPORTED in this configuration
{- output_on() unless $no_shared;
   output_off() if $no_shared; "" -}
  add_library(OpenSSL::Crypto SHARED IMPORTED)
  add_library(OpenSSL::SSL SHARED IMPORTED)
{- output_off() unless $lib_info{libcrypto}->{shared_import}; "" -}
  set(OPENSSL_LIBCRYPTO_SHARED "${OPENSSL_RUNTIME_DIR}/{- $lib_info{libcrypto}->{shared} -}")
  set(OPENSSL_LIBCRYPTO_IMPORT "${OPENSSL_LIBRARY_DIR}/{- $lib_info{libcrypto}->{shared_import} -}")
  set(OPENSSL_LIBCRYPTO_DEPENDENCIES {- join(' ', @LDLIBS) -})
  set_target_properties(OpenSSL::Crypto PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    IMPORTED_IMPLIB ${OPENSSL_LIBCRYPTO_IMPORT}
    IMPORTED_LOCATION ${OPENSSL_LIBCRYPTO_SHARED})
  set_property(TARGET OpenSSL::Crypto
    PROPERTY INTERFACE_LINK_LIBRARIES ${OPENSSL_LIBCRYPTO_DEPENDENCIES})

  set(OPENSSL_LIBSSL_SHARED "${OPENSSL_RUNTIME_DIR}/{- $lib_info{libssl}->{shared} -}")
  set(OPENSSL_LIBSSL_IMPORT "${OPENSSL_LIBRARY_DIR}/{- $lib_info{libssl}->{shared_import} -}")
  set(OPENSSL_LIBSSL_DEPENDENCIES OpenSSL::Crypto {- join(' ', @LDLIBS) -})
  set_target_properties(OpenSSL::SSL PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    IMPORTED_IMPLIB ${OPENSSL_LIBSSL_IMPORT}
    IMPORTED_LOCATION ${OPENSSL_LIBSSL_SHARED})
  set_property(TARGET OpenSSL::SSL
    PROPERTY INTERFACE_LINK_LIBRARIES ${OPENSSL_LIBSSL_DEPENDENCIES})

  # Directories and names compatible with CMake's FindOpenSSL.cmake
  set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_LIBCRYPTO_IMPORT})
  set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_LIBCRYPTO_DEPENDENCIES})
  set(OPENSSL_SSL_LIBRARY ${OPENSSL_LIBSSL_IMPORT})
  set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_LIBSSL_DEPENDENCIES})
  set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_LIBSSL_DEPENDENCIES} ${OPENSSL_LIBCRYPTO_DEPENDENCIES})
{- output_on() unless $lib_info{libcrypto}->{shared_import};
   output_off() if $lib_info{libcrypto}->{shared_import}; "" -}
  # Dependencies are assumed to be implied in the shared libraries
  set(OPENSSL_LIBCRYPTO_SHARED "${OPENSSL_LIBRARY_DIR}/{- $lib_info{libcrypto}->{shared} -}")
  set_target_properties(OpenSSL::Crypto PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    IMPORTED_LOCATION ${OPENSSL_LIBCRYPTO_SHARED})

  set(OPENSSL_LIBSSL_SHARED "${OPENSSL_LIBRARY_DIR}/{- $lib_info{libssl}->{shared} -}")
  set_target_properties(OpenSSL::SSL PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
    IMPORTED_LOCATION ${OPENSSL_LIBSSL_SHARED})

  # Directories and names compatible with CMake's FindOpenSSL.cmake
  set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_LIBCRYPTO_SHARED})
  set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
  set(OPENSSL_SSL_LIBRARY ${OPENSSL_LIBSSL_SHARED})
  set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY})
  set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARIES})
{- output_on() if $lib_info{libcrypto}->{shared_import}; "" -}
{- output_on() if $no_shared; "" -}
endif()

set_target_properties(OpenSSL::Crypto PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
set_target_properties(OpenSSL::SSL PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")

{- output_off() if $disabled{uplink}; "" -}
add_library(OpenSSL::applink INTERFACE IMPORTED)
set_property(TARGET OpenSSL::applink PROPERTY
  INTERFACE_SOURCES "${OPENSSL_APPLINK_SOURCE}")
{- output_on() if $disabled{uplink}; "" -}

unset(_ossl_prefix)
unset(_ossl_use_static_libs)