FindCryptoPP.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. INCLUDE (FindPackageHandleStandardArgs)
  42. FIND_PATH (CRYPTOPP_ROOT_DIR
  43. NAMES cryptopp/cryptlib.h include/cryptopp/cryptlib.h
  44. PATHS ENV CRYPTOPPROOT
  45. DOC "CryptoPP root directory")
  46. # Re-use the previous path:
  47. FIND_PATH (CRYPTOPP_INCLUDE_DIR
  48. NAMES cryptopp/cryptlib.h
  49. HINTS ${CRYPTOPP_ROOT_DIR}
  50. PATH_SUFFIXES include
  51. DOC "CryptoPP include directory")
  52. FIND_LIBRARY (CRYPTOPP_LIBRARY_DEBUG
  53. NAMES cryptlibd cryptoppd
  54. HINTS ${CRYPTOPP_ROOT_DIR}
  55. PATH_SUFFIXES lib
  56. DOC "CryptoPP debug library")
  57. FIND_LIBRARY (CRYPTOPP_LIBRARY_RELEASE
  58. NAMES cryptlib cryptopp
  59. HINTS ${CRYPTOPP_ROOT_DIR}
  60. PATH_SUFFIXES lib
  61. DOC "CryptoPP release library")
  62. IF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE)
  63. SET (CRYPTOPP_LIBRARY
  64. optimized ${CRYPTOPP_LIBRARY_RELEASE}
  65. debug ${CRYPTOPP_LIBRARY_DEBUG} CACHE DOC "CryptoPP library")
  66. ELSEIF (CRYPTOPP_LIBRARY_RELEASE)
  67. SET (CRYPTOPP_LIBRARY ${CRYPTOPP_LIBRARY_RELEASE} CACHE DOC
  68. "CryptoPP library")
  69. ENDIF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE)
  70. IF (CRYPTOPP_INCLUDE_DIR)
  71. SET (_CRYPTOPP_VERSION_HEADER ${CRYPTOPP_INCLUDE_DIR}/cryptopp/config.h)
  72. IF (EXISTS ${_CRYPTOPP_VERSION_HEADER})
  73. FILE (STRINGS ${_CRYPTOPP_VERSION_HEADER} _CRYPTOPP_VERSION_TMP REGEX
  74. "^#define CRYPTOPP_VERSION[ \t]+[0-9]+$")
  75. STRING (REGEX REPLACE
  76. "^#define CRYPTOPP_VERSION[ \t]+([0-9]+)" "\\1" _CRYPTOPP_VERSION_TMP
  77. ${_CRYPTOPP_VERSION_TMP})
  78. STRING (REGEX REPLACE "([0-9]+)[0-9][0-9]" "\\1" CRYPTOPP_VERSION_MAJOR
  79. ${_CRYPTOPP_VERSION_TMP})
  80. STRING (REGEX REPLACE "[0-9]([0-9])[0-9]" "\\1" CRYPTOPP_VERSION_MINOR
  81. ${_CRYPTOPP_VERSION_TMP})
  82. STRING (REGEX REPLACE "[0-9][0-9]([0-9])" "\\1" CRYPTOPP_VERSION_PATCH
  83. ${_CRYPTOPP_VERSION_TMP})
  84. SET (CRYPTOPP_VERSION_COUNT 3)
  85. SET (CRYPTOPP_VERSION
  86. ${CRYPTOPP_VERSION_MAJOR}.${CRYPTOPP_VERSION_MINOR}.${CRYPTOPP_VERSION_PATCH})
  87. ENDIF (EXISTS ${_CRYPTOPP_VERSION_HEADER})
  88. ENDIF (CRYPTOPP_INCLUDE_DIR)
  89. SET (CRYPTOPP_INCLUDE_DIRS ${CRYPTOPP_INCLUDE_DIR})
  90. SET (CRYPTOPP_LIBRARIES ${CRYPTOPP_LIBRARY})
  91. MARK_AS_ADVANCED (CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY CRYPTOPP_LIBRARY_DEBUG
  92. CRYPTOPP_LIBRARY_RELEASE)
  93. FIND_PACKAGE_HANDLE_STANDARD_ARGS (CryptoPP REQUIRED_VARS
  94. CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY VERSION_VAR CRYPTOPP_VERSION)