diff --git a/CMakeLists.txt b/CMakeLists.txt index 84de141764..7ddabfaf65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -476,13 +476,12 @@ endif() # Find Botan find_package(Botan REQUIRED) -if(BOTAN_VERSION VERSION_GREATER_EQUAL "3.0.0") +if(Botan_VERSION VERSION_GREATER_EQUAL "3.0.0") set(WITH_BOTAN3 TRUE) -elseif(BOTAN_VERSION VERSION_LESS "2.19.1") +elseif(Botan_VERSION VERSION_LESS "2.19.1") # Check for minimum Botan version - message(FATAL_ERROR "Botan 2.19.1 or higher is required") + message(FATAL_ERROR "Botan 2.19.1 or higher is required") endif() -include_directories(SYSTEM ${BOTAN_INCLUDE_DIR}) # Find zlib find_package(ZLIB REQUIRED) diff --git a/COPYING b/COPYING index a00aaf28c3..c0f5d4eb66 100644 --- a/COPYING +++ b/COPYING @@ -43,7 +43,7 @@ Copyright: 2012 - 2015, Lars Bilke License: BSD-3-clause Files: cmake/FindBotan.cmake -Copyright: none +Copyright: 2026, Adrien Ollier License: LGPL-2.1 Files: cmake/GenerateProductVersion.cmake diff --git a/INSTALL.md b/INSTALL.md index 4eb2665a4c..74afa4d1c9 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -16,7 +16,7 @@ The following build tools must exist within your PATH: The following minimum versions of libraries must exist: * qt (>= 5.12.0) -* botan (>= 2.12.0 or >= 3.0.0) +* botan (>= 2.19.1 or >= 3.0.0) * zlib (>= 1.2.0) * Besides a working C++ toolchain, KeePassXC also has a number of direct build and runtime dependencies. For detailed information about how to install them, please refer to the GitHub wiki: diff --git a/cmake/FindBotan.cmake b/cmake/FindBotan.cmake index dfa415c1d0..86e9397296 100644 --- a/cmake/FindBotan.cmake +++ b/cmake/FindBotan.cmake @@ -1,65 +1,134 @@ -# - Find botan -# Find the botan cryptographic library +# Copyright (C) 2026 Adrien Ollier # -# This module defines the following variables: -# BOTAN_FOUND - True if library and include directory are found -# If set to TRUE, the following are also defined: -# BOTAN_INCLUDE_DIRS - The directory where to find the header file -# BOTAN_LIBRARIES - Where to find the library files +# This file is part of KeePassXC (https://github.com/keepassxreboot/keepassxc). # -# This file is in the public domain (https://github.com/vistle/vistle/blob/master/cmake/Modules/FindBOTAN.cmake) +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this file; if not, contact the Free Software Foundation +# at licensing@fsf.org or write to the Free Software Foundation, Inc., +# 31 Milk Street, # 960789, Boston, MA 02196 USA. -include(FindPackageHandleStandardArgs) -set(BOTAN_VERSIONS botan-3 botan-2) -set(BOTAN_NAMES botan-3 botan-2 botan) -set(BOTAN_NAMES_DEBUG botand-3 botand-2 botand botan botan-3) +#[=======================================================================[.rst: +FindBotan +--------- + +Finds the botan cryptographic library + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``Botan::botan`` + The Botan library + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``Botan_FOUND`` + Boolean indicating whether Botan was found. +``Botan_VERSION`` + The version of the Botan library which was found. +``Botan_LIBRARY`` + The path to the Botan library + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Botan_INCLUDE_DIR`` + The directory containing ``botan/build.h``. +``Botan_LIBRARY_DEBUG`` + The debug version of the Botan library, if present +``Botan_LIBRARY_RELEASE`` + The release version of the Botan library + +#]=======================================================================] + +find_package(PkgConfig QUIET) +if(PkgConfig_FOUND) + pkg_search_module(PC_Botan QUIET botan-3 botan-2>=2.19.1 libbotan-2>=2.19.1 botan>=2.19.1) +endif() find_path( - BOTAN_INCLUDE_DIR + Botan_INCLUDE_DIR NAMES botan/build.h - PATH_SUFFIXES ${BOTAN_VERSIONS} + HINTS ${PC_Botan_INCLUDE_DIRS} + PATH_SUFFIXES botan-3 botan-2 DOC "The Botan include directory") -if(BOTAN_INCLUDE_DIR) - file(READ "${BOTAN_INCLUDE_DIR}/botan/build.h" build) + +if(Botan_INCLUDE_DIR) + file(READ "${Botan_INCLUDE_DIR}/botan/build.h" build) string(REGEX MATCH "BOTAN_VERSION_MAJOR ([0-9]*)" _ ${build}) - set(BOTAN_VERSION_MAJOR ${CMAKE_MATCH_1}) + set(Botan_VERSION_MAJOR ${CMAKE_MATCH_1}) string(REGEX MATCH "BOTAN_VERSION_MINOR ([0-9]*)" _ ${build}) - set(BOTAN_VERSION_MINOR ${CMAKE_MATCH_1}) + set(Botan_VERSION_MINOR ${CMAKE_MATCH_1}) string(REGEX MATCH "BOTAN_VERSION_PATCH ([0-9]*)" _ ${build}) - set(BOTAN_VERSION_PATCH ${CMAKE_MATCH_1}) - set(BOTAN_VERSION "${BOTAN_VERSION_MAJOR}.${BOTAN_VERSION_MINOR}.${BOTAN_VERSION_PATCH}") + set(Botan_VERSION_PATCH ${CMAKE_MATCH_1}) + set(Botan_VERSION "${Botan_VERSION_MAJOR}.${Botan_VERSION_MINOR}.${Botan_VERSION_PATCH}") endif() find_library( - BOTAN_LIBRARY - NAMES ${BOTAN_NAMES} + Botan_LIBRARY_RELEASE + NAMES botan-3 botan-2 botan + HINTS ${PC_Botan_LIBRARY_DIRS} PATH_SUFFIXES release/lib lib DOC "The Botan (release) library") + if(WIN32 AND NOT MINGW) find_library( - BOTAN_LIBRARY_DEBUG - NAMES ${BOTAN_NAMES_DEBUG} + Botan_LIBRARY_DEBUG + NAMES botand-3 botand-2 botand botan botan-3 + HINTS ${PC_Botan_LIBRARY_DIRS} PATH_SUFFIXES debug/lib lib DOC "The Botan debug library") - find_package_handle_standard_args( - Botan - REQUIRED_VARS BOTAN_LIBRARY BOTAN_LIBRARY_DEBUG BOTAN_INCLUDE_DIR - VERSION_VAR BOTAN_VERSION) -else() - find_package_handle_standard_args( - Botan - REQUIRED_VARS BOTAN_LIBRARY BOTAN_INCLUDE_DIR - VERSION_VAR BOTAN_VERSION) endif() -if(BOTAN_FOUND) - set(BOTAN_INCLUDE_DIRS ${BOTAN_INCLUDE_DIR}) - if(WIN32 AND NOT MINGW) - set(BOTAN_LIBRARIES optimized ${BOTAN_LIBRARY} debug ${BOTAN_LIBRARY_DEBUG}) - else() - set(BOTAN_LIBRARIES ${BOTAN_LIBRARY}) +include(SelectLibraryConfigurations) +select_library_configurations(Botan) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + Botan + REQUIRED_VARS Botan_LIBRARY Botan_INCLUDE_DIR + VERSION_VAR Botan_VERSION) + +if(Botan_FOUND) + if(NOT TARGET Botan::botan) + add_library(Botan::botan UNKNOWN IMPORTED) + endif() + if(Botan_LIBRARY_RELEASE) + set_property(TARGET Botan::botan APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE + ) + set_target_properties(Botan::botan PROPERTIES + IMPORTED_LOCATION ${Botan_LIBRARY_RELEASE} + IMPORTED_LOCATION_RELEASE ${Botan_LIBRARY_RELEASE}) + endif() + if(Botan_LIBRARY_DEBUG) + set_property(TARGET Botan::botan APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG + ) + set_target_properties(Botan::botan PROPERTIES + IMPORTED_LOCATION_DEBUG ${Botan_LIBRARY_DEBUG}) endif() + set_target_properties(Botan::botan PROPERTIES + INTERFACE_LINK_OPTIONS "${PC_Botan_LDFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Botan_INCLUDE_DIR}" + ) endif() -mark_as_advanced(BOTAN_INCLUDE_DIR BOTAN_LIBRARY BOTAN_LIBRARY_DEBUG) +mark_as_advanced(Botan_INCLUDE_DIR Botan_LIBRARY_RELEASE Botan_LIBRARY_DEBUG) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3956de2d33..cef407d5dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -352,11 +352,12 @@ find_package(Qt6 REQUIRED COMPONENTS SvgWidgets) # Core Library Definition add_library(keepassxc_core STATIC ${core_SOURCES}) target_compile_definitions(keepassxc_core PRIVATE KPXC_BUILDING_CORE) -target_link_libraries(keepassxc_core - ${qrcode_LIB} +target_link_libraries(keepassxc_core + PUBLIC Qt6::Core Qt6::Concurrent - ${BOTAN_LIBRARIES} + Botan::botan + ${qrcode_LIB} ${PCSC_LIBRARIES} ${ZXCVBN_LIBRARIES} ${ZLIB_LIBRARIES} @@ -367,6 +368,7 @@ target_link_libraries(keepassxc_core add_library(keepassxc_gui STATIC ${gui_SOURCES}) target_compile_definitions(keepassxc_gui PRIVATE KPXC_BUILDING_CORE) target_link_libraries(keepassxc_gui + PUBLIC keepassxc_core Qt6::Network Qt6::SvgWidgets @@ -378,27 +380,27 @@ target_link_libraries(keepassxc_gui ${sshagent_LIB}) if(APPLE) - target_link_libraries(keepassxc_gui "-framework Foundation -framework AppKit -framework Carbon -framework Security -framework LocalAuthentication -framework ScreenCaptureKit") + target_link_libraries(keepassxc_gui PUBLIC "-framework Foundation -framework AppKit -framework Carbon -framework Security -framework LocalAuthentication -framework ScreenCaptureKit") if(Qt6MacExtras_FOUND) - target_link_libraries(keepassxc_gui Qt6::MacExtras) + target_link_libraries(keepassxc_gui PRIVATE Qt6::MacExtras) endif() endif() if(HAIKU) - target_link_libraries(keepassxc_gui network) + target_link_libraries(keepassxc_gui PRIVATE network) endif() if(UNIX AND NOT APPLE) - target_link_libraries(keepassxc_core Qt6::DBus ${LIBUSB_LIBRARIES}) + target_link_libraries(keepassxc_core PUBLIC Qt6::DBus PRIVATE ${LIBUSB_LIBRARIES}) if("${CMAKE_SYSTEM}" MATCHES "Linux") - target_link_libraries(keepassxc_core ${KEYUTILS_LIBRARIES}) + target_link_libraries(keepassxc_core PRIVATE ${KEYUTILS_LIBRARIES}) endif() if(WITH_X11) - target_link_libraries(keepassxc_gui X11) + target_link_libraries(keepassxc_gui PRIVATE X11) endif() endif() if(WIN32) - target_link_libraries(keepassxc_gui Wtsapi32.lib Ws2_32.lib) + target_link_libraries(keepassxc_gui PRIVATE Wtsapi32.lib Ws2_32.lib) if (WINSDK) - target_link_libraries(keepassxc_gui WindowsApp.lib) + target_link_libraries(keepassxc_gui PRIVATE WindowsApp.lib) endif() endif() diff --git a/src/autotype/CMakeLists.txt b/src/autotype/CMakeLists.txt index 77f75cb819..d97e7be4d9 100644 --- a/src/autotype/CMakeLists.txt +++ b/src/autotype/CMakeLists.txt @@ -38,13 +38,15 @@ elseif(WIN32) endif() add_library(autotype STATIC ${autotype_SOURCES}) -target_link_libraries(autotype Qt6::Core Qt6::Widgets) +target_link_libraries(autotype + PUBLIC Qt6::Core Qt6::Widgets + PRIVATE Botan::botan) if(UNIX AND NOT APPLE AND NOT HAIKU) - target_link_libraries(autotype Qt6::DBus PkgConfig::Xkbcommon) + target_link_libraries(autotype PRIVATE Qt6::DBus PkgConfig::Xkbcommon) if(WITH_X11) - target_link_libraries(autotype ${X11_X11_LIB} ${X11_Xi_LIB} ${X11_XTest_LIB}) + target_link_libraries(autotype PRIVATE ${X11_X11_LIB} ${X11_Xi_LIB} ${X11_XTest_LIB}) endif() elseif(APPLE) - target_link_libraries(autotype "-framework Foundation" "-framework AppKit" "-framework Carbon" "-framework ScreenCaptureKit") + target_link_libraries(autotype PUBLIC "-framework Foundation" "-framework AppKit" "-framework Carbon" "-framework ScreenCaptureKit") endif() diff --git a/src/browser/CMakeLists.txt b/src/browser/CMakeLists.txt index 7bfd2e047b..bc044f9cb5 100644 --- a/src/browser/CMakeLists.txt +++ b/src/browser/CMakeLists.txt @@ -37,5 +37,6 @@ if(KPXC_FEATURE_BROWSER) PasskeyUtils.cpp) add_library(browser STATIC ${browser_SOURCES}) - target_link_libraries(browser Qt6::Core Qt6::Concurrent Qt6::Widgets Qt6::Network ${BOTAN_LIBRARIES}) + target_link_libraries(browser + PUBLIC Qt6::Core Qt6::Concurrent Qt6::Widgets Qt6::Network Botan::botan) endif() diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 455e6e7af4..f7e2395e11 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -62,7 +62,7 @@ endif() # cli library add_library(cli STATIC ${cli_SOURCES}) target_link_libraries(cli - PRIVATE ${ZXCVBN_LIBRARIES} text_stream + PRIVATE ${ZXCVBN_LIBRARIES} Botan::botan text_stream PUBLIC Qt6::Core) add_executable(keepassxc-cli keepassxc-cli.cpp) diff --git a/src/fdosecrets/CMakeLists.txt b/src/fdosecrets/CMakeLists.txt index 27ecb06809..15a81fcc2b 100644 --- a/src/fdosecrets/CMakeLists.txt +++ b/src/fdosecrets/CMakeLists.txt @@ -30,5 +30,7 @@ if(KPXC_FEATURE_FDOSECRETS) objects/Prompt.cpp dbus/DBusTypes.cpp ) - target_link_libraries(fdosecrets Qt6::Core Qt6::Widgets Qt6::DBus ${BOTAN_LIBRARIES}) + target_link_libraries(fdosecrets + PUBLIC Qt6::Core Qt6::Widgets Qt6::DBus + PRIVATE Botan::botan) endif() diff --git a/src/keeshare/CMakeLists.txt b/src/keeshare/CMakeLists.txt index 5da855b501..0768576c87 100644 --- a/src/keeshare/CMakeLists.txt +++ b/src/keeshare/CMakeLists.txt @@ -27,5 +27,8 @@ set(keeshare_SOURCES ) add_library(keeshare STATIC ${keeshare_SOURCES}) -target_link_libraries(keeshare PUBLIC Qt6::Core Qt6::Widgets ${BOTAN_LIBRARIES} ${ZLIB_LIBRARIES} PRIVATE ${MINIZIP_LIBRARIES}) +target_link_libraries(keeshare + PUBLIC Qt6::Core Qt6::Widgets + PRIVATE Botan::botan ${MINIZIP_LIBRARIES} ${ZLIB_LIBRARIES}) + include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/proxy/CMakeLists.txt b/src/proxy/CMakeLists.txt index b71311470f..33b7556ab1 100644 --- a/src/proxy/CMakeLists.txt +++ b/src/proxy/CMakeLists.txt @@ -21,7 +21,9 @@ if(KPXC_FEATURE_BROWSER) # Alloc must be defined in a static library to prevent clashing with clang ASAN definitions add_library(proxy_alloc STATIC ../core/Alloc.cpp) - target_link_libraries(proxy_alloc PRIVATE Qt6::Core ${BOTAN_LIBRARIES}) + target_link_libraries(proxy_alloc + PUBLIC Qt6::Core + PRIVATE Botan::botan) add_executable(keepassxc-proxy ${proxy_SOURCES}) target_link_libraries(keepassxc-proxy proxy_alloc Qt6::Core Qt6::Network) diff --git a/src/sshagent/CMakeLists.txt b/src/sshagent/CMakeLists.txt index 759d1ea9ea..254db812a5 100644 --- a/src/sshagent/CMakeLists.txt +++ b/src/sshagent/CMakeLists.txt @@ -29,5 +29,7 @@ if(KPXC_FEATURE_SSHAGENT) ) add_library(sshagent STATIC ${sshagent_SOURCES}) - target_link_libraries(sshagent Qt6::Core Qt6::Widgets Qt6::Network ${BOTAN_LIBRARIES}) + target_link_libraries(sshagent + PUBLIC Qt6::Core Qt6::Widgets Qt6::Network + PRIVATE Botan::botan) endif()