|
1 |
| -################################################################################ |
2 |
| -# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY # |
3 |
| -# Please refer to the README for information about making permanent changes. # |
4 |
| -################################################################################ |
5 |
| - |
6 |
| -if (NOT MSVC) |
7 |
| -find_package(PkgConfig REQUIRED) |
8 |
| -pkg_check_modules(PC_SODIUM "libsodium") |
9 |
| -if (PC_SODIUM_FOUND) |
10 |
| - set(pkg_config_names_private "${pkg_config_names_private} libsodium") |
11 |
| -endif() |
12 |
| -if (NOT PC_SODIUM_FOUND) |
13 |
| - pkg_check_modules(PC_SODIUM "sodium") |
14 |
| - if (PC_SODIUM_FOUND) |
15 |
| - set(pkg_config_names_private "${pkg_config_names_private} sodium") |
16 |
| - endif() |
17 |
| -endif (NOT PC_SODIUM_FOUND) |
18 |
| -if (PC_SODIUM_FOUND) |
19 |
| - set(SODIUM_INCLUDE_HINTS ${PC_SODIUM_INCLUDE_DIRS} ${PC_SODIUM_INCLUDE_DIRS}/*) |
20 |
| - set(SODIUM_LIBRARY_HINTS ${PC_SODIUM_LIBRARY_DIRS} ${PC_SODIUM_LIBRARY_DIRS}/*) |
| 1 | +# From https://github.com/aminya/libsodium/blob/patch-1/contrib/Findsodium.cmake |
| 2 | + |
| 3 | +# Written in 2016 by Henrik Steffen Gaßmann <[email protected]> |
| 4 | +# |
| 5 | +# To the extent possible under law, the author(s) have dedicated all copyright |
| 6 | +# and related and neighboring rights to this software to the public domain |
| 7 | +# worldwide. This software is distributed without any warranty. |
| 8 | +# |
| 9 | +# You should have received a copy of the CC0 Public Domain Dedication along with |
| 10 | +# this software. If not, see |
| 11 | +# |
| 12 | +# http://creativecommons.org/publicdomain/zero/1.0/ |
| 13 | +# |
| 14 | +# ############################################################################## |
| 15 | +# Tries to find the local libsodium installation. |
| 16 | +# |
| 17 | +# On Windows the sodium_DIR environment variable is used as a default hint which |
| 18 | +# can be overridden by setting the corresponding cmake variable. |
| 19 | +# |
| 20 | +# Once done the following variables will be defined: |
| 21 | +# |
| 22 | +# sodium_FOUND sodium_INCLUDE_DIR sodium_LIBRARY_DEBUG sodium_LIBRARY_RELEASE |
| 23 | +# sodium_VERSION_STRING |
| 24 | +# |
| 25 | +# Furthermore an imported "sodium" target is created. |
| 26 | +# |
| 27 | + |
| 28 | +if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 29 | + set(_GCC_COMPATIBLE 1) |
| 30 | +endif() |
| 31 | + |
| 32 | +# static library option |
| 33 | +if(NOT DEFINED sodium_USE_STATIC_LIBS) |
| 34 | + option(sodium_USE_STATIC_LIBS "enable to statically link against sodium" OFF) |
| 35 | +endif() |
| 36 | +if(NOT (sodium_USE_STATIC_LIBS EQUAL sodium_USE_STATIC_LIBS_LAST)) |
| 37 | + unset(sodium_LIBRARY CACHE) |
| 38 | + unset(sodium_LIBRARY_DEBUG CACHE) |
| 39 | + unset(sodium_LIBRARY_RELEASE CACHE) |
| 40 | + unset(sodium_DLL_DEBUG CACHE) |
| 41 | + unset(sodium_DLL_RELEASE CACHE) |
| 42 | + set(sodium_USE_STATIC_LIBS_LAST |
| 43 | + ${sodium_USE_STATIC_LIBS} |
| 44 | + CACHE INTERNAL "internal change tracking variable") |
| 45 | +endif() |
| 46 | + |
| 47 | +# ############################################################################## |
| 48 | +# UNIX |
| 49 | +if(UNIX) |
| 50 | + # import pkg-config |
| 51 | + find_package(PkgConfig QUIET) |
| 52 | + if(PKG_CONFIG_FOUND) |
| 53 | + pkg_check_modules(sodium_PKG QUIET libsodium) |
| 54 | + endif() |
| 55 | + |
| 56 | + if(sodium_USE_STATIC_LIBS) |
| 57 | + if(sodium_PKG_STATIC_LIBRARIES) |
| 58 | + foreach(_libname ${sodium_PKG_STATIC_LIBRARIES}) |
| 59 | + if(NOT _libname MATCHES "^lib.*\\.a$") # ignore strings already ending |
| 60 | + # with .a |
| 61 | + list(INSERT sodium_PKG_STATIC_LIBRARIES 0 "lib${_libname}.a") |
| 62 | + endif() |
| 63 | + endforeach() |
| 64 | + list(REMOVE_DUPLICATES sodium_PKG_STATIC_LIBRARIES) |
| 65 | + else() |
| 66 | + # if pkgconfig for libsodium doesn't provide static lib info, then |
| 67 | + # override PKG_STATIC here.. |
| 68 | + set(sodium_PKG_STATIC_LIBRARIES libsodium.a) |
| 69 | + endif() |
| 70 | + |
| 71 | + set(XPREFIX sodium_PKG_STATIC) |
| 72 | + else() |
| 73 | + if(sodium_PKG_LIBRARIES STREQUAL "") |
| 74 | + set(sodium_PKG_LIBRARIES sodium) |
| 75 | + endif() |
| 76 | + |
| 77 | + set(XPREFIX sodium_PKG) |
| 78 | + endif() |
| 79 | + |
| 80 | + find_path(sodium_INCLUDE_DIR sodium.h HINTS ${${XPREFIX}_INCLUDE_DIRS}) |
| 81 | + find_library(sodium_LIBRARY_DEBUG |
| 82 | + NAMES ${${XPREFIX}_LIBRARIES} |
| 83 | + HINTS ${${XPREFIX}_LIBRARY_DIRS}) |
| 84 | + find_library(sodium_LIBRARY_RELEASE |
| 85 | + NAMES ${${XPREFIX}_LIBRARIES} |
| 86 | + HINTS ${${XPREFIX}_LIBRARY_DIRS}) |
| 87 | + |
| 88 | + # ############################################################################ |
| 89 | + # Windows |
| 90 | +elseif(WIN32) |
| 91 | + set(sodium_DIR "$ENV{sodium_DIR}" CACHE FILEPATH "sodium install directory") |
| 92 | + mark_as_advanced(sodium_DIR) |
| 93 | + |
| 94 | + find_path(sodium_INCLUDE_DIR sodium.h |
| 95 | + HINTS ${sodium_DIR} |
| 96 | + PATH_SUFFIXES include) |
| 97 | + |
| 98 | + if(MSVC) |
| 99 | + # detect target architecture |
| 100 | + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/arch.c" [=[ |
| 101 | + #if defined _M_IX86 |
| 102 | + #error ARCH_VALUE x86_32 |
| 103 | + #elif defined _M_X64 |
| 104 | + #error ARCH_VALUE x86_64 |
| 105 | + #endif |
| 106 | + #error ARCH_VALUE unknown |
| 107 | + ]=]) |
| 108 | + try_compile(_UNUSED_VAR "${CMAKE_CURRENT_BINARY_DIR}" |
| 109 | + "${CMAKE_CURRENT_BINARY_DIR}/arch.c" |
| 110 | + OUTPUT_VARIABLE _COMPILATION_LOG) |
| 111 | + string(REGEX |
| 112 | + REPLACE ".*ARCH_VALUE ([a-zA-Z0-9_]+).*" |
| 113 | + "\\1" |
| 114 | + _TARGET_ARCH |
| 115 | + "${_COMPILATION_LOG}") |
| 116 | + |
| 117 | + # construct library path |
| 118 | + if(_TARGET_ARCH STREQUAL "x86_32") |
| 119 | + string(APPEND _PLATFORM_PATH "Win32") |
| 120 | + elseif(_TARGET_ARCH STREQUAL "x86_64") |
| 121 | + string(APPEND _PLATFORM_PATH "x64") |
| 122 | + else() |
| 123 | + message( |
| 124 | + FATAL_ERROR |
| 125 | + "the ${_TARGET_ARCH} architecture is not supported by Findsodium.cmake." |
| 126 | + ) |
| 127 | + endif() |
| 128 | + string(APPEND _PLATFORM_PATH "/$$CONFIG$$") |
| 129 | + |
| 130 | + if(MSVC_VERSION LESS 1900) |
| 131 | + math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 60") |
| 132 | + else() |
| 133 | + math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 50") |
| 134 | + endif() |
| 135 | + string(APPEND _PLATFORM_PATH "/v${_VS_VERSION}") |
| 136 | + |
| 137 | + if(sodium_USE_STATIC_LIBS) |
| 138 | + string(APPEND _PLATFORM_PATH "/static") |
| 139 | + else() |
| 140 | + string(APPEND _PLATFORM_PATH "/dynamic") |
| 141 | + endif() |
| 142 | + |
| 143 | + string(REPLACE "$$CONFIG$$" |
| 144 | + "Debug" |
| 145 | + _DEBUG_PATH_SUFFIX |
| 146 | + "${_PLATFORM_PATH}") |
| 147 | + string(REPLACE "$$CONFIG$$" |
| 148 | + "Release" |
| 149 | + _RELEASE_PATH_SUFFIX |
| 150 | + "${_PLATFORM_PATH}") |
| 151 | + |
| 152 | + find_library(sodium_LIBRARY_DEBUG libsodium.lib |
| 153 | + HINTS ${sodium_DIR} |
| 154 | + PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX}) |
| 155 | + find_library(sodium_LIBRARY_RELEASE libsodium.lib |
| 156 | + HINTS ${sodium_DIR} |
| 157 | + PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX}) |
| 158 | + if(NOT sodium_USE_STATIC_LIBS) |
| 159 | + set(CMAKE_FIND_LIBRARY_SUFFIXES_BCK ${CMAKE_FIND_LIBRARY_SUFFIXES}) |
| 160 | + set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll") |
| 161 | + find_library(sodium_DLL_DEBUG libsodium |
| 162 | + HINTS ${sodium_DIR} |
| 163 | + PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX}) |
| 164 | + find_library(sodium_DLL_RELEASE libsodium |
| 165 | + HINTS ${sodium_DIR} |
| 166 | + PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX}) |
| 167 | + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BCK}) |
| 168 | + endif() |
| 169 | + |
| 170 | + elseif(_GCC_COMPATIBLE) |
| 171 | + if(sodium_USE_STATIC_LIBS) |
| 172 | + find_library(sodium_LIBRARY_DEBUG libsodium.a |
| 173 | + HINTS ${sodium_DIR} |
| 174 | + PATH_SUFFIXES lib) |
| 175 | + find_library(sodium_LIBRARY_RELEASE libsodium.a |
| 176 | + HINTS ${sodium_DIR} |
| 177 | + PATH_SUFFIXES lib) |
| 178 | + else() |
| 179 | + find_library(sodium_LIBRARY_DEBUG libsodium.dll.a |
| 180 | + HINTS ${sodium_DIR} |
| 181 | + PATH_SUFFIXES lib) |
| 182 | + find_library(sodium_LIBRARY_RELEASE libsodium.dll.a |
| 183 | + HINTS ${sodium_DIR} |
| 184 | + PATH_SUFFIXES lib) |
| 185 | + |
| 186 | + file(GLOB _DLL |
| 187 | + LIST_DIRECTORIES false |
| 188 | + RELATIVE "${sodium_DIR}/bin" |
| 189 | + "${sodium_DIR}/bin/libsodium*.dll") |
| 190 | + find_library(sodium_DLL_DEBUG ${_DLL} libsodium |
| 191 | + HINTS ${sodium_DIR} |
| 192 | + PATH_SUFFIXES bin) |
| 193 | + find_library(sodium_DLL_RELEASE ${_DLL} libsodium |
| 194 | + HINTS ${sodium_DIR} |
| 195 | + PATH_SUFFIXES bin) |
| 196 | + endif() |
| 197 | + else() |
| 198 | + message(FATAL_ERROR "this platform is not supported by FindSodium.cmake") |
| 199 | + endif() |
| 200 | + |
| 201 | + # ############################################################################ |
| 202 | + # unsupported |
21 | 203 | else()
|
22 |
| - set(pkg_config_libs_private "${pkg_config_libs_private} -lsodium") |
| 204 | + message(FATAL_ERROR "this platform is not supported by FindSodium.cmake") |
23 | 205 | endif()
|
24 |
| -endif (NOT MSVC) |
25 | 206 |
|
26 |
| -# some libraries install the headers is a subdirectory of the include dir |
27 |
| -# returned by pkg-config, so use a wildcard match to improve chances of finding |
28 |
| -# headers and libraries. |
29 |
| -find_path( |
30 |
| - SODIUM_INCLUDE_DIRS |
31 |
| - NAMES sodium.h |
32 |
| - HINTS ${SODIUM_INCLUDE_HINTS} |
33 |
| -) |
| 207 | +# ############################################################################## |
| 208 | +# common stuff |
34 | 209 |
|
35 |
| -find_library( |
36 |
| - SODIUM_LIBRARIES |
37 |
| - NAMES libsodium sodium |
38 |
| - HINTS ${SODIUM_LIBRARY_HINTS} |
39 |
| -) |
| 210 | +# extract sodium version |
| 211 | +if(sodium_INCLUDE_DIR) |
| 212 | + set(_VERSION_HEADER "${sodium_INCLUDE_DIR}/sodium/version.h") |
| 213 | + if(EXISTS "${_VERSION_HEADER}") |
| 214 | + file(READ "${_VERSION_HEADER}" _VERSION_HEADER_CONTENT) |
| 215 | + string( |
| 216 | + REGEX |
| 217 | + REPLACE |
| 218 | + ".*define[ \t]+SODIUM_VERSION_STRING[^\"]+\"([^\"]+)\".*" |
| 219 | + "\\1" |
| 220 | + sodium_VERSION_STRING |
| 221 | + "${_VERSION_HEADER_CONTENT}") |
| 222 | + set(sodium_VERSION_STRING "${sodium_VERSION_STRING}") |
| 223 | + endif() |
| 224 | +endif() |
40 | 225 |
|
| 226 | +# communicate results |
41 | 227 | include(FindPackageHandleStandardArgs)
|
42 |
| -find_package_handle_standard_args(sodium DEFAULT_MSG SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS) |
43 |
| -mark_as_advanced(SODIUM_FOUND SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS) |
| 228 | +find_package_handle_standard_args(sodium |
| 229 | + REQUIRED_VARS |
| 230 | + sodium_LIBRARY_RELEASE |
| 231 | + sodium_LIBRARY_DEBUG |
| 232 | + sodium_INCLUDE_DIR |
| 233 | + VERSION_VAR |
| 234 | + sodium_VERSION_STRING) |
| 235 | +if (NOT sodium_FOUND) |
| 236 | + return() |
| 237 | +endif() |
44 | 238 |
|
45 |
| -################################################################################ |
46 |
| -# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY # |
47 |
| -# Please refer to the README for information about making permanent changes. # |
48 |
| -################################################################################ |
| 239 | +# mark file paths as advanced |
| 240 | +mark_as_advanced(sodium_INCLUDE_DIR) |
| 241 | +mark_as_advanced(sodium_LIBRARY_DEBUG) |
| 242 | +mark_as_advanced(sodium_LIBRARY_RELEASE) |
| 243 | +if(WIN32) |
| 244 | + mark_as_advanced(sodium_DLL_DEBUG) |
| 245 | + mark_as_advanced(sodium_DLL_RELEASE) |
| 246 | +endif() |
| 247 | + |
| 248 | +# create imported target |
| 249 | +if(sodium_USE_STATIC_LIBS) |
| 250 | + set(_LIB_TYPE STATIC) |
| 251 | +else() |
| 252 | + set(_LIB_TYPE SHARED) |
| 253 | +endif() |
| 254 | +add_library(sodium ${_LIB_TYPE} IMPORTED) |
| 255 | + |
| 256 | +set_target_properties(sodium |
| 257 | + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES |
| 258 | + "${sodium_INCLUDE_DIR}" |
| 259 | + IMPORTED_LINK_INTERFACE_LANGUAGES |
| 260 | + "C") |
| 261 | + |
| 262 | +if(sodium_USE_STATIC_LIBS) |
| 263 | + set_target_properties(sodium |
| 264 | + PROPERTIES INTERFACE_COMPILE_DEFINITIONS |
| 265 | + "SODIUM_STATIC" |
| 266 | + IMPORTED_LOCATION |
| 267 | + "${sodium_LIBRARY_RELEASE}" |
| 268 | + IMPORTED_LOCATION_DEBUG |
| 269 | + "${sodium_LIBRARY_DEBUG}") |
| 270 | +else() |
| 271 | + if(UNIX) |
| 272 | + set_target_properties(sodium |
| 273 | + PROPERTIES IMPORTED_LOCATION |
| 274 | + "${sodium_LIBRARY_RELEASE}" |
| 275 | + IMPORTED_LOCATION_DEBUG |
| 276 | + "${sodium_LIBRARY_DEBUG}") |
| 277 | + elseif(WIN32) |
| 278 | + set_target_properties(sodium |
| 279 | + PROPERTIES IMPORTED_IMPLIB |
| 280 | + "${sodium_LIBRARY_RELEASE}" |
| 281 | + IMPORTED_IMPLIB_DEBUG |
| 282 | + "${sodium_LIBRARY_DEBUG}") |
| 283 | + if(NOT (sodium_DLL_DEBUG MATCHES ".*-NOTFOUND")) |
| 284 | + set_target_properties(sodium |
| 285 | + PROPERTIES IMPORTED_LOCATION_DEBUG |
| 286 | + "${sodium_DLL_DEBUG}") |
| 287 | + endif() |
| 288 | + if(NOT (sodium_DLL_RELEASE MATCHES ".*-NOTFOUND")) |
| 289 | + set_target_properties(sodium |
| 290 | + PROPERTIES IMPORTED_LOCATION_RELWITHDEBINFO |
| 291 | + "${sodium_DLL_RELEASE}" |
| 292 | + IMPORTED_LOCATION_MINSIZEREL |
| 293 | + "${sodium_DLL_RELEASE}" |
| 294 | + IMPORTED_LOCATION_RELEASE |
| 295 | + "${sodium_DLL_RELEASE}") |
| 296 | + endif() |
| 297 | + endif() |
| 298 | +endif() |
0 commit comments