1 add_library (CRYPTOPP::CRYPTOPP
6 set (CRYPTOPP_SEARCH_PREFIXES "cryptopp" "crypto++")
8 if (NOT CRYPTOPP_INCLUDE_PREFIX)
9 unset (CRYPT_SEARCH CACHE)
10 check_include_file_cxx (cryptlib.h CRYPT_SEARCH)
13 set (CRYPTOPP_INCLUDE_PREFIX "" CACHE STRING "cryptopp include prefix" FORCE)
15 foreach (PREFIX ${CRYPTOPP_SEARCH_PREFIXES})
16 unset (CRYPT_SEARCH CACHE)
17 check_include_file_cxx (${PREFIX}/cryptlib.h CRYPT_SEARCH)
20 message (STATUS "cryptopp prefix found: ${PREFIX}")
21 set (CRYPTOPP_INCLUDE_PREFIX ${PREFIX} CACHE STRING "cryptopp include prefix" FORCE)
28 if (NOT CRYPTOPP_INCLUDE_PREFIX)
29 MESSAGE (FATAL_ERROR "cryptlib.h not found")
33 if (NOT CRYPTOPP_LIBRARY_DEBUG)
34 unset (CRYPTOPP_LIBRARY_DEBUG CACHE)
36 find_library (CRYPTOPP_LIBRARY_DEBUG
37 NAMES crypto++d cryptlibd cryptoppd
38 PATHS ${CRYPTOPP_LIB_SEARCH_PATH}
41 if (CRYPTOPP_LIBRARY_DEBUG)
42 message (STATUS "Found debug-libcrypto++ in ${CRYPTOPP_LIBRARY_DEBUG}")
46 if (CRYPTOPP_LIBRARY_DEBUG)
47 set_property (TARGET CRYPTOPP::CRYPTOPP
48 PROPERTY IMPORTED_LOCATION_DEBUG ${CRYPTOPP_LIBRARY_DEBUG}
51 set (CRYPTO_COMPLETE FALSE)
54 if (NOT CRYPTOPP_LIBRARY_RELEASE)
55 unset (CRYPTOPP_LIBRARY_RELEASE CACHE)
57 find_library (CRYPTOPP_LIBRARY_RELEASE
58 NAMES crypto++ cryptlib cryptopp
59 PATHS ${CRYPTOPP_LIB_SEARCH_PATH}
62 if (CRYPTOPP_LIBRARY_RELEASE)
63 message (STATUS "Found release-libcrypto++ in ${CRYPTOPP_LIBRARY_RELEASE}")
65 endif (NOT CRYPTOPP_LIBRARY_RELEASE)
67 if (CRYPTOPP_LIBRARY_RELEASE)
68 set_property (TARGET CRYPTOPP::CRYPTOPP
69 PROPERTY IMPORTED_LOCATION_RELEASE ${CRYPTOPP_LIBRARY_RELEASE}
72 set (CRYPTO_COMPLETE FALSE)
75 if (NOT CRYPTOPP_LIBRARY)
76 unset (CRYPTOPP_LIBRARY CACHE)
78 find_library (CRYPTOPP_LIBRARY
79 NAMES crypto++ cryptlib cryptopp
80 PATHS ${CRYPTOPP_LIB_SEARCH_PATH}
84 message (STATUS "Found libcrypto++ in ${CRYPTOPP_LIBRARY}")
89 set_property (TARGET CRYPTOPP::CRYPTOPP
90 PROPERTY IMPORTED_LOCATION ${CRYPTOPP_LIBRARY}
93 set (CRYPTO_COMPLETE FALSE)
97 if (NOT CRYPTOPP_CONFIG_SEARCH)
98 unset (CRYPTOPP_CONFIG_SEARCH CACHE)
100 check_include_file_cxx (${CRYPTOPP_INCLUDE_PREFIX}/config.h
101 CRYPTOPP_CONFIG_SEARCH
105 if (NOT CRYPTOPP_CONFIG_FILE)
106 if (CRYPTOPP_CONFIG_SEARCH)
107 if (CRYPTOPP_INCLUDE_DIR)
108 set (CRYPTOPP_CONFIG_FILE ${CRYPTOPP_INCLUDE_DIR}/${CRYPTOPP_INCLUDE_PREFIX}/config.h
109 CACHE FILEPATH "cryptopp config.h" FORCE
112 set_target_properties (CRYPTOPP::CRYPTOPP PROPERTIES
113 INTERFACE_INCLUDE_DIRECTORIES "${CRYPTOPP_INCLUDE_DIR}"
116 set (CRYPTOPP_CONFIG_FILE ${CRYPTOPP_INCLUDE_PREFIX}/config.h
117 CACHE FILEPATH "cryptopp config.h" FORCE
121 unset(CRYPTOPP_CONFIG_SEARCH)
124 unset (CMAKE_REQUIRED_INCLUDES)
127 if (NOT CRYPTOPP_CONFIG_FILE)
128 MESSAGE (FATAL_ERROR "crypto++ config.h not found")
131 if (NOT CRYPTOPP_VERSION)# AND CRYPTO_COMPLETE)
132 set (CMAKE_CONFIGURABLE_FILE_CONTENT
133 "#include <${CRYPTOPP_CONFIG_FILE}>\n
136 printf (\"%d\", CRYPTOPP_VERSION);\n
140 configure_file ("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
141 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckCryptoppVersion.cxx" @ONLY IMMEDIATE
147 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckCryptoppVersion.cxx
148 RUN_OUTPUT_VARIABLE CRYPTOPP_VERSION
151 string (REGEX REPLACE "([0-9])([0-9])([0-9])" "\\1.\\2.\\3" CRYPTOPP_VERSION "${CRYPTOPP_VERSION}")
153 if (${CRYPTOPP_VERSION} VERSION_LESS ${MIN_CRYPTOPP_VERSION})
154 message (FATAL_ERROR "crypto++ version ${CRYPTOPP_VERSION} is too old")
156 MESSAGE (STATUS "crypto++ version ${CRYPTOPP_VERSION} -- OK")
157 set (CRYPTOPP_CONFIG_FILE ${CRYPTOPP_CONFIG_FILE} CACHE STRING "Path to config.h of crypto-lib" FORCE)
158 set (CRYPTOPP_VERSION ${CRYPTOPP_VERSION} CACHE STRING "Version of cryptopp" FORCE)