From 8d811913a52d51ade4b96674e02bb175cf2fc6e2 Mon Sep 17 00:00:00 2001 From: Castor215 <132155746+Castor215@users.noreply.github.com> Date: Thu, 2 Nov 2023 00:57:10 +0000 Subject: [PATCH] externals: allow user to use system cryptopp (#7105) --- externals/CMakeLists.txt | 16 ++++++--- .../cmake-modules/CitraHandleSystemLibs.cmake | 3 ++ externals/cmake-modules/Findcryptopp.cmake | 36 +++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 externals/cmake-modules/Findcryptopp.cmake diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 08aeffb7f..53dc89fdc 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -46,11 +46,17 @@ set(CATCH_INSTALL_EXTRAS OFF CACHE BOOL "") add_subdirectory(catch2) # Crypto++ -set(CRYPTOPP_BUILD_DOCUMENTATION OFF CACHE BOOL "") -set(CRYPTOPP_BUILD_TESTING OFF CACHE BOOL "") -set(CRYPTOPP_INSTALL OFF CACHE BOOL "") -set(CRYPTOPP_SOURCES "${CMAKE_SOURCE_DIR}/externals/cryptopp" CACHE STRING "") -add_subdirectory(cryptopp-cmake) +if(USE_SYSTEM_CRYPTOPP) + find_package(cryptopp REQUIRED) + add_library(cryptopp INTERFACE) + target_link_libraries(cryptopp INTERFACE cryptopp::cryptopp) +else() + set(CRYPTOPP_BUILD_DOCUMENTATION OFF CACHE BOOL "") + set(CRYPTOPP_BUILD_TESTING OFF CACHE BOOL "") + set(CRYPTOPP_INSTALL OFF CACHE BOOL "") + set(CRYPTOPP_SOURCES "${CMAKE_SOURCE_DIR}/externals/cryptopp" CACHE STRING "") + add_subdirectory(cryptopp-cmake) +endif() # dds-ktx add_library(dds-ktx INTERFACE) diff --git a/externals/cmake-modules/CitraHandleSystemLibs.cmake b/externals/cmake-modules/CitraHandleSystemLibs.cmake index 13efe7eef..ad341586f 100644 --- a/externals/cmake-modules/CitraHandleSystemLibs.cmake +++ b/externals/cmake-modules/CitraHandleSystemLibs.cmake @@ -20,6 +20,7 @@ option(USE_SYSTEM_FFMPEG_HEADERS "Use the system FFmpeg headers (instead of the option(USE_SYSTEM_GLSLANG "Use the system glslang and SPIR-V libraries (instead of the bundled ones)" OFF) option(USE_SYSTEM_ZSTD "Use the system Zstandard library (instead of the bundled one)" OFF) option(USE_SYSTEM_ENET "Use the system libenet (instead of the bundled one)" OFF) +option(USE_SYSTEM_CRYPTOPP "Use the system cryptopp (instead of the bundled one)" OFF) # Qt and MoltenVK are handled separately CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_SDL2 "Disable system SDL2" OFF "USE_SYSTEM_LIBS" OFF) @@ -39,6 +40,7 @@ CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FFMPEG_HEADERS "Disable system ffmpeg" OFF CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_GLSLANG "Disable system glslang" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ZSTD "Disable system Zstandard" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ENET "Disable system libenet" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CRYPTOPP "Disable system cryptopp" OFF "USE_SYSTEM_LIBS" OFF) set(LIB_VAR_LIST SDL2 @@ -58,6 +60,7 @@ set(LIB_VAR_LIST GLSLANG ZSTD ENET + CRYPTOPP ) # First, check that USE_SYSTEM_XXX is not used with USE_SYSTEM_LIBS diff --git a/externals/cmake-modules/Findcryptopp.cmake b/externals/cmake-modules/Findcryptopp.cmake new file mode 100644 index 000000000..eb17bed1d --- /dev/null +++ b/externals/cmake-modules/Findcryptopp.cmake @@ -0,0 +1,36 @@ +if(NOT CRYPTOPP_FOUND) + pkg_check_modules(CRYPTOPP_TMP libcrypto++) + + find_path(CRYPTOPP_INCLUDE_DIRS NAMES cryptlib.h + PATHS + ${CRYPTOPP_TMP_INCLUDE_DIRS} + /usr/include + /usr/include/crypto++ + /usr/local/include + /usr/local/include/crypto++ + ) + + find_library(CRYPTOPP_LIBRARY_DIRS NAMES crypto++ + PATHS + ${CRYPTOPP_TMP_LIBRARY_DIRS} + /usr/lib + /usr/locallib + ) + + if(CRYPTOPP_INCLUDE_DIRS AND CRYPTOPP_LIBRARY_DIRS) + set(CRYPTOPP_FOUND TRUE CACHE INTERNAL "Found cryptopp") + message(STATUS "Found cryptopp: ${CRYPTOPP_LIBRARY_DIRS}, ${CRYPTOPP_INCLUDE_DIRS}") + else() + set(CRYPTOPP_FOUND FALSE CACHE INTERNAL "Found cryptopp") + message(STATUS "Cryptopp not found.") + endif() +endif() + +if(CRYPTOPP_FOUND AND NOT TARGET cryptopp::cryptopp) + add_library(cryptopp::cryptopp UNKNOWN IMPORTED) + set_target_properties(cryptopp::cryptopp PROPERTIES + INCLUDE_DIRECTORIES ${CRYPTOPP_INCLUDE_DIRS} + INTERFACE_LINK_LIBRARIES ${CRYPTOPP_LIBRARY_DIRS} + IMPORTED_LOCATION ${CRYPTOPP_LIBRARY_DIRS} + ) +endif()