Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / cmake / modules / Findcryptopp.cmake
1 # Module for locating the Crypto++ encryption library.
2 #
3 # Customizable variables:
4 #   CRYPTOPP_ROOT_DIR
5 #     This variable points to the CryptoPP root directory. On Windows the
6 #     library location typically will have to be provided explicitly using the
7 #     -D command-line option. The directory should include the include/cryptopp,
8 #     lib and/or bin sub-directories.
9 #
10 # Read-only variables:
11 #   CRYPTOPP_FOUND
12 #     Indicates whether the library has been found.
13 #
14 #   CRYPTOPP_INCLUDE_DIRS
15 #     Points to the CryptoPP include directory.
16 #
17 #   CRYPTOPP_LIBRARIES
18 #     Points to the CryptoPP libraries that should be passed to
19 #     target_link_libararies.
20 #
21 #
22 # Copyright (c) 2012 Sergiu Dotenco
23 #
24 # Permission is hereby granted, free of charge, to any person obtaining a copy
25 # of this software and associated documentation files (the "Software"), to deal
26 # in the Software without restriction, including without limitation the rights
27 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28 # copies of the Software, and to permit persons to whom the Software is
29 # furnished to do so, subject to the following conditions:
30 #
31 # The above copyright notice and this permission notice shall be included in all
32 # copies or substantial portions of the Software.
33 #
34 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 # SOFTWARE.
41
42 INCLUDE (FindPackageHandleStandardArgs)
43
44 FIND_PATH (CRYPTOPP_ROOT_DIR
45   NAMES cryptopp/cryptlib.h include/cryptopp/cryptlib.h
46   PATHS ENV CRYPTOPPROOT
47   DOC "CryptoPP root directory")
48
49 # Re-use the previous path:
50 FIND_PATH (CRYPTOPP_INCLUDE_DIR
51   NAMES cryptopp/cryptlib.h
52   HINTS ${CRYPTOPP_ROOT_DIR}
53   PATH_SUFFIXES include
54   DOC "CryptoPP include directory")
55
56 FIND_LIBRARY (CRYPTOPP_LIBRARY_DEBUG
57   NAMES cryptlibd cryptoppd
58   HINTS ${CRYPTOPP_ROOT_DIR}
59   PATH_SUFFIXES lib
60   DOC "CryptoPP debug library")
61
62 FIND_LIBRARY (CRYPTOPP_LIBRARY_RELEASE
63   NAMES cryptlib cryptopp
64   HINTS ${CRYPTOPP_ROOT_DIR}
65   PATH_SUFFIXES lib
66   DOC "CryptoPP release library")
67
68 IF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE)
69   SET (CRYPTOPP_LIBRARY
70     optimized ${CRYPTOPP_LIBRARY_RELEASE}
71     debug ${CRYPTOPP_LIBRARY_DEBUG} CACHE DOC "CryptoPP library")
72 ELSEIF (CRYPTOPP_LIBRARY_RELEASE)
73   SET (CRYPTOPP_LIBRARY ${CRYPTOPP_LIBRARY_RELEASE} CACHE DOC
74     "CryptoPP library")
75 ENDIF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE)
76
77 IF (CRYPTOPP_INCLUDE_DIR)
78   SET (_CRYPTOPP_VERSION_HEADER ${CRYPTOPP_INCLUDE_DIR}/cryptopp/config.h)
79
80   IF (EXISTS ${_CRYPTOPP_VERSION_HEADER})
81     FILE (STRINGS ${_CRYPTOPP_VERSION_HEADER} _CRYPTOPP_VERSION_TMP REGEX
82       "^#define CRYPTOPP_VERSION[ \t]+[0-9]+$")
83
84     STRING (REGEX REPLACE
85       "^#define CRYPTOPP_VERSION[ \t]+([0-9]+)" "\\1" _CRYPTOPP_VERSION_TMP
86       ${_CRYPTOPP_VERSION_TMP})
87
88     STRING (REGEX REPLACE "([0-9]+)[0-9][0-9]" "\\1" CRYPTOPP_VERSION_MAJOR
89       ${_CRYPTOPP_VERSION_TMP})
90     STRING (REGEX REPLACE "[0-9]([0-9])[0-9]" "\\1" CRYPTOPP_VERSION_MINOR
91       ${_CRYPTOPP_VERSION_TMP})
92     STRING (REGEX REPLACE "[0-9][0-9]([0-9])" "\\1" CRYPTOPP_VERSION_PATCH
93       ${_CRYPTOPP_VERSION_TMP})
94
95     SET (CRYPTOPP_VERSION_COUNT 3)
96     SET (CRYPTOPP_VERSION
97       ${CRYPTOPP_VERSION_MAJOR}.${CRYPTOPP_VERSION_MINOR}.${CRYPTOPP_VERSION_PATCH})
98   ENDIF (EXISTS ${_CRYPTOPP_VERSION_HEADER})
99 ENDIF (CRYPTOPP_INCLUDE_DIR)
100
101 SET (CRYPTOPP_INCLUDE_DIRS ${CRYPTOPP_INCLUDE_DIR})
102 SET (CRYPTOPP_LIBRARIES ${CRYPTOPP_LIBRARY})
103
104 MARK_AS_ADVANCED (CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY CRYPTOPP_LIBRARY_DEBUG
105   CRYPTOPP_LIBRARY_RELEASE)
106
107 FIND_PACKAGE_HANDLE_STANDARD_ARGS (cryptopp REQUIRED_VARS CRYPTOPP_ROOT_DIR
108   CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY VERSION_VAR CRYPTOPP_VERSION)