Skip to content

Modernize FindBotan.cmake: Use Imported Targets and Remove Global Variables - #13620

Draft
aollier wants to merge 1 commit into
keepassxreboot:developfrom
aollier:FindBotan
Draft

Modernize FindBotan.cmake: Use Imported Targets and Remove Global Variables#13620
aollier wants to merge 1 commit into
keepassxreboot:developfrom
aollier:FindBotan

Conversation

@aollier

@aollier aollier commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Modernize FindBotan.cmake: Use Imported Targets and Improve Portability

This Pull Request refactors the FindBotan.cmake module to align with modern CMake best practices, as outlined in the official CMake documentation. The changes improve maintainability, portability, and cleanliness of the build system while ensuring backward compatibility with the rest of the project.


Key Improvements

  • Leverages PkgConfig for hints:
    Uses pkg_search_module to automatically detect Botan's include and library paths via PkgConfig. These paths are then passed as HINTS to find_path and find_library, ensuring robust detection without relying solely on PkgConfig.
    → Combines the efficiency of PkgConfig with the reliability of CMake's built-in commands.

  • Creates a modern imported target (Botan::botan):
    Replaces global variables (BOTAN_LIBRARY, BOTAN_INCLUDE_DIRS) with a modern imported target, following CMake’s recommended practices.
    → Enables clean integration with target_link_libraries() and prevents dependency leaks.

  • Manages Debug and Release configurations:
    Uses SelectLibraryConfigurations to handle separate Debug and Release builds of Botan (e.g., botan-3 vs. botand-3 on Windows).
    → Ensures correct linking for multi-configuration generators like MSVC.

  • Automatic version extraction:
    Extracts the Botan version from botan/build.h and validates it using find_package_handle_standard_args.
    → Ensures compatibility with the required Botan version.

  • Propagates platform-specific flags:
    Uses INTERFACE_LINK_OPTIONS to propagate platform-specific flags (e.g., -pthread, -fstack-protector) from PkgConfig to the imported target.
    → Ensures correct linking behavior without manual flag duplication.

  • Removes global include_directories:
    Replaces include_directories(SYSTEM ${BOTAN_INCLUDE_DIR}) with explicit dependencies via target_link_libraries(Botan::botan).
    → Prevents unnecessary inclusion of Botan headers and reduces global namespace pollution.

  • Replaces ${BOTAN_LIBRARIES} with Botan::botan:
    All occurrences of ${BOTAN_LIBRARIES} have been replaced with the imported target, in line with CMake’s dependency management recommendations.

  • Falls back gracefully:
    If PkgConfig is unavailable, find_path and find_library will still search standard system paths (e.g., /usr/include, /usr/lib).
    → No explicit fallback logic is needed, as the module already handles this case.


Impact on the Project

  • Compatibility: No changes are required in the rest of the codebase, except for replacing ${BOTAN_LIBRARIES} with Botan::botan (already done).
  • Portability: The module is now more robust and should work across all platforms (Linux, Windows, macOS), provided Botan is correctly installed.
  • Maintainability: The code is more readable and adheres to CMake best practices, making future updates easier.



Points to Verify or Improve for the Maintainer

  • Testing on Windows and macOS:
    The module has been tested on Ubuntu, but it is recommended to verify its behavior on Windows (via vcpkg or MSYS2) and macOS (via Homebrew).
    → If adjustments are needed for these platforms, I’m ready to implement them.

  • Version consistency check:
    If PkgConfig detects a version of Botan (e.g., 2.19.1), but find_path locates a build.h with a different version, consider adding a warning:

    if(PC_Botan_VERSION AND NOT PC_Botan_VERSION STREQUAL Botan_VERSION)
        message(WARNING "Version mismatch: PkgConfig found ${PC_Botan_VERSION}, but build.h reports ${Botan_VERSION}")
    endif()

    → Helps avoid inconsistencies between detected and actual versions.

  • Debugging messages:
    Adding a status message to indicate whether PkgConfig was used could help with debugging:

    if(PkgConfig_FOUND AND PC_Botan_FOUND)
       message(STATUS "Found Botan via PkgConfig: ${PC_Botan_VERSION}")
    else()
       message(STATUS "PkgConfig not found or Botan not detected via PkgConfig, falling back to find_path/find_library")
    endif()

    → Useful for troubleshooting but not mandatory.

Type of change

  • ✅ Refactor (significant modification to existing code)

@aollier

aollier commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

On Ubuntu, I have:

$ pkg-config --libs --cflags botan-3
-I/usr/include/botan-3 -lbotan-3 -fstack-protector -m64 -pthread

My change will add the -fstack-protector -m64 -pthread flags to the targets linked with Botan::botan, which is an improvement in and of itself. Executables should be more robust and more in line with the requirements of the botan library.

- Replace raw variables (BOTAN_LIBRARY, BOTAN_INCLUDE_DIRS) with an imported
target Botan::botan that carries include dirs, compile options, and link flags
- Remove global include_directories() in favor of explicit target_link_libraries()
- Rename internal variables from BOTAN_ to Botan_ for consistency
- Update the rest of the project to depend on Botan::botan instead of ${BOTAN_LIBRARIES}

Tested on Ubuntu; relying on GitHub CI to validate Windows and macOS builds.
@droidmonkey

droidmonkey commented Aug 25, 2026

Copy link
Copy Markdown
Member

Did you add compile flags?

@aollier

aollier commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

No I didn't add any compile flags. These flags are provided by the libbotan-3-dev package:

$ dpkg -L libbotan-3-dev | grep \.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/botan-3.pc
$ cat $(!!)
cat $(dpkg -L libbotan-3-dev | grep \.pc)
prefix=/usr/
exec_prefix=${prefix}
libdir=/usr/lib/x86_64-linux-gnu
includedir=${prefix}/include/botan-3

Name: Botan
Description: Crypto and TLS for Modern C++
Version: 3.10.0

Libs: -L${libdir} -lbotan-3 -fstack-protector -m64 -pthread
Libs.private: -lbz2 -llzma -lrt -lsqlite3 -ltspi -lz
Cflags: -I${includedir}

This means these flags are provided for Ubuntu. They may be different on Windows and MacOS.

@aollier

aollier commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

The flags are fetched from pkg-config and propagated to the imported target with this line:

https://github.com/aollier/keepassxc/blob/3ce88dbf1c626eb078d21dd8b47585aed565fd1b/cmake/FindBotan.cmake#L112

On Ubuntu, this results to the -fstack-protector -m64 -pthread flags.

@aollier

aollier commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

If your question was "Does your change add compile flags to the targets that link against Botan::botan ?", the answer is yes and it is the desired behaviour. These flags are supposed to be used by projects using this library.

@droidmonkey

Copy link
Copy Markdown
Member

I dont think that is appropriate at all. We do not want to inherit compile flags that are potentially different across distributions. The executable compile flags absolutely do not need to be the same as the libraries it loads. We already have a lot of security related flags set especially around memory layout and overwrite protection.

@aollier

aollier commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

The flags that pkg-config provides are not the ones used to compile the library (libbotan here). They are intended to be used by the target that links against.

Check the documentation of pkg-config:
https://www.freedesktop.org/wiki/Software/pkg-config/ and https://people.freedesktop.org/~dbn/pkg-config-guide.html#faq.

In particular:

The most important pkg-config metadata fields are Requires, Requires.private, Cflags, Libs and Libs.private. They will define the metadata used by external projects to compile and link with the library.

Theses flags are required to link against the libbotan, no matter which flags are used on the other hand by our executables. This information is provided by the maintainer of the application. It is absolutely not related with memory layout or security considerations and does not conflict with.

Providing compilation information (include directories with the -I flag, library paths with the -L flag, and library names with the -l flag and other link options) is the very reason pkg-config exists.

@aollier

aollier commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author
  1. -fstack-protector
    Enables protection against stack smashing. If libbotan-3 was compiled with this option, your program must also use it to avoid incompatibilities or undefined behavior (e.g., missing symbols or runtime conflicts).
  2. -m64
    Indicates that the library was compiled for a 64-bit architecture. If you do not specify this flag, your program might be compiled as 32-bit (depending on your compiler's default settings), which would make it impossible to link with libbotan-3.
  3. -pthread
    This flag is crucial if libbotan-3 uses thread-safe functions or depends on pthread (e.g., for internal locks, parallel operations, etc.). Without it, you risk linking errors (undefined reference) or crashes at runtime.

@aollier

aollier commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

I am wondering about this line:

if(WIN32 AND NOT MINGW)

Isn't meant to focus on MSVC? In this case, we can change it to:

if(MSVC)

which is more appropriate.

@droidmonkey

Copy link
Copy Markdown
Member

No that was for windows builds using vcpkg.

I disagree completely with the compiler flags. I think you misread the pkg_conf docs. It is saying those are the flags it used to build the library. Not what flags you need to use the library. Either way, we already set stack protection and the others. I do not want a vector where "random" compile flags are added to our builds.

@aollier

aollier commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

No I am absolutely sure about what I am saying. Here are some extracts of the documentation (https://people.freedesktop.org/~dbn/pkg-config-guide.html):

Importants words are bolded.

Concepts

The primary use of pkg-config is to provide the necessary details for compiling and linking a program to a library. This metadata is stored in pkg-config files. These files have the suffix .pc and reside in specific locations known to the pkg-config tool.

The most important pkg-config metadata fields are Requires, Requires.private, Cflags, Libs and Libs.private. They will define the metadata used by external projects to compile and link with the library.

The most important sentence is: They will define the metadata used by external projects to compile and link with the library. This is clear and non ambiguous.

As an exemple, with botan-3:

$ pkg-config --libs --cflags botan-3
-I/usr/include/botan-3 -lbotan-3 -fstack-protector -m64 -pthread

libbotan-3.so can't have been built with the -lbotan-3 flag, since it instructs to link with the libbotan-3. Here we can clearly see that it's a vicious cycle.

libbotan-3.so have been compiled with much more compiler flags. The other flags provided by pkg-config (-fstack-protector -m64 -pthread) are a subset of the ones used to compile this library. These are the ones needed for link editing that guarantees the compatibility and stability of the executable being linked to.

If pkg-config provided all the flags used for compilation, there would be many more, and more importantly, there would be no point in exposing them. What would be the benefit?
pkg-config, as explained in the Concepts section, is a way for a project to easily and efficiently determine which flags to use when linking to a library provided by an external entity.

I hope I've convinced you this time, otherwise what can we do to determine who is right?

@droidmonkey

Copy link
Copy Markdown
Member

Hmm fair enough, I was wrong. I still do not agree with auto adding compiler flags from an external source.

@aollier

aollier commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

I understand the desire to keep total control over compiler flags. However, discarding the Cflags provided by pkg-config creates a structural reliability risk that hardcoded paths or raw library linking cannot solve.

Here is why consuming the complete pkg-config interface is standard engineering practice for modern C/C++ targets:

  1. Public macros drive the API layout & ABI:
    A library's public headers often depend on specific preprocessor definitions defined in its .pc file (e.g., -D_FILE_OFFSET_BITS=64, -DFOO_ENABLE_THREADS, or ABI versioning flags). If downstream projects strip these flags, header structures may compile with different memory layouts or struct sizes between KeePassXC and the library itself. This leads to subtle One Definition Rule (ODR) violations and Undefined Behavior at runtime that no linker warning can catch.

  2. Contractual boundary:
    The downstream application cannot assume it knows better than the upstream library developer what definitions are required to consume their API. The .pc file is the official contract provided by the library maintainer. Ignoring it replaces an explicit contract with implicit assumptions.

  3. Isolation guarantees safety:
    By scope-limiting the flags using CMake's PRIVATE target properties:

    target_link_libraries(<keepassxc_target> PRIVATE Botan::botan)

These flags affect only the translation units that include this third-party dependency. They cannot bleed into the rest of KeePassXC's codebase or alter global optimization flags.

As a regular KeePassXC user myself, my goal is certainly not to break the application, but on the contrary to make its build system more reliable and future-proof.

If you are concerned about rogue flags in edge cases, we can explicitly print the imported flags during the CMake configuration step (message(STATUS ...)). This ensures 100% visibility while maintaining robust, specification-compliant builds.

Would you be open to reviewing the PR with target-scoped flags enabled and CMake status visibility?

@aollier

aollier commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

To move forward pragmatically, since the CI pipeline hasn't run yet, would you be open to letting the CI build and test this PR across all supported platforms (Linux, macOS, Windows)?

If you have a moment to build and run this branch locally, you can also verify firsthand that it causes no regressions or runtime instability.

Testing it in practice rather than in theory seems like the safest way to ensure that scoped pkg-config flags improve build reliability without introducing any side effects.

@aollier
aollier marked this pull request as draft September 1, 2026 21:39
@aollier

aollier commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Hello @droidmonkey, I marked this PR as draft since a build failed for an unknown and obscure reason and should be restarted.
When the build is restarted and successful, I will need to push another commit to link the targets to the imported Botan::botan library in PRIVATE, so as to contain (limit) the propagation of Botan::botan requirements.

Since I don't have Windows or MacOS at home, I'm not sure it will compile successfully on those systems. Hence separate commits, the first serving to verify that the compilation succeeds and the tests pass in the current configuration, the second serving to limit the scope of the imported library to the strict minimum necessary.

@droidmonkey

Copy link
Copy Markdown
Member

In all technicality you dont need to include Botan library everywhere. Every built executable includes keepassxc core which includes botan.

@aollier

aollier commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

The botan library is required to compile not only the final executables, but also the intermediate libraries themselves.

For exemple, if I remove the Botan::botan target from proxy/CMakeLists.txt, it doesn't compile:

====================[ Build | all | Debug ]=====================================
/snap/clion/489/bin/cmake/linux/x64/bin/cmake --build /home/adrien/projects/keepassxc/cmake-build-debug --target all -j 1
[10/59] Building CXX object src/proxy/CMakeFiles/proxy_alloc.dir/__/core/Alloc.cpp.o
FAILED: [code=1] src/proxy/CMakeFiles/proxy_alloc.dir/__/core/Alloc.cpp.o 
/usr/bin/c++ -DQT_CORE_LIB -DQT_NO_CAST_TO_ASCII -DQT_NO_DEPRECATED_WARNINGS -DQT_NO_EXCEPTIONS -DQT_STRICT_ITERATORS -I/home/adrien/projects/keepassxc/cmake-build-debug/src/proxy/proxy_alloc_autogen/include -I/home/adrien/projects/keepassxc/src -I/home/adrien/projects/keepassxc/cmake-build-debug/src -isystem /usr/include/minizip -isystem /usr/include/PCSC -isystem /usr/include/libusb-1.0 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -fno-common -fopenmp -Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long -Wformat=2 -Wmissing-format-attribute -fvisibility=hidden -fvisibility-inlines-hidden -Wshadow-compatible-local -Wshadow-local -Werror -Wno-deprecated-enum-enum-conversion -Wno-error=deprecated  -fstack-protector-strong -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Werror=format-security -Wcast-align -fsized-deallocation -Wno-deprecated-declarations -g -std=gnu++20 -fPIC -fdiagnostics-color=always -MD -MT src/proxy/CMakeFiles/proxy_alloc.dir/__/core/Alloc.cpp.o -MF src/proxy/CMakeFiles/proxy_alloc.dir/__/core/Alloc.cpp.o.d -o src/proxy/CMakeFiles/proxy_alloc.dir/__/core/Alloc.cpp.o -c /home/adrien/projects/keepassxc/src/core/Alloc.cpp
/home/adrien/projects/keepassxc/src/core/Alloc.cpp:19:10: fatal error: botan/mem_ops.h: Aucun fichier ou dossier de ce nom
   19 | #include <botan/mem_ops.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.

because the compiler does not find botan/mem_ops.h.

It was also necessary to add it for autotype and cli:

  • autotype without the Botan::botan target:
    ====================[ Build | all | Debug ]=====================================
    /snap/clion/489/bin/cmake/linux/x64/bin/cmake --build /home/adrien/projects/keepassxc/cmake-build-debug --target all -j 1
    [3/67] Building CXX object src/autotype/CMakeFiles/autotype.dir/autotype_autogen/mocs_compilation.cpp.o
    FAILED: [code=1] src/autotype/CMakeFiles/autotype.dir/autotype_autogen/mocs_compilation.cpp.o 
    /usr/bin/c++ -DQT_CORE_LIB -DQT_DBUS_LIB -DQT_GUI_LIB -DQT_NO_CAST_TO_ASCII -DQT_NO_DEPRECATED_WARNINGS -DQT_NO_EXCEPTIONS -DQT_STRICT_ITERATORS -DQT_WIDGETS_LIB -I/home/adrien/projects/keepassxc/cmake-build-debug/src/autotype/autotype_autogen/include -I/home/adrien/projects/keepassxc/src -I/home/adrien/projects/keepassxc/cmake-build-debug/src -I/home/adrien/projects/keepassxc/src/autotype -I/home/adrien/projects/keepassxc/cmake-build-debug/src/autotype -isystem /usr/include/minizip -isystem /usr/include/PCSC -isystem /usr/include/libusb-1.0 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt6/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt6/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtDBus -fno-common -fopenmp -Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long -Wformat=2 -Wmissing-format-attribute -fvisibility=hidden -fvisibility-inlines-hidden -Wshadow-compatible-local -Wshadow-local -Werror -Wno-deprecated-enum-enum-conversion -Wno-error=deprecated  -fstack-protector-strong -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Werror=format-security -Wcast-align -fsized-deallocation -Wno-deprecated-declarations -g -std=gnu++20 -fPIC -fdiagnostics-color=always -MD -MT src/autotype/CMakeFiles/autotype.dir/autotype_autogen/mocs_compilation.cpp.o -MF src/autotype/CMakeFiles/autotype.dir/autotype_autogen/mocs_compilation.cpp.o.d -o src/autotype/CMakeFiles/autotype.dir/autotype_autogen/mocs_compilation.cpp.o -c /home/adrien/projects/keepassxc/cmake-build-debug/src/autotype/autotype_autogen/mocs_compilation.cpp
    In file included from /home/adrien/projects/keepassxc/src/core/Database.h:33,
                     from /home/adrien/projects/keepassxc/cmake-build-debug/src/autotype/autotype_autogen/EWIEGA46WW/../../../../../src/autotype/AutoType.h:32,
                     from /home/adrien/projects/keepassxc/cmake-build-debug/src/autotype/autotype_autogen/EWIEGA46WW/moc_AutoType.cpp:9,
                     from /home/adrien/projects/keepassxc/cmake-build-debug/src/autotype/autotype_autogen/mocs_compilation.cpp:2:
    /home/adrien/projects/keepassxc/src/keys/PasswordKey.h:21:10: fatal error: botan/secmem.h: Aucun fichier ou dossier de ce nom
       21 | #include <botan/secmem.h>
          |          ^~~~~~~~~~~~~~~~
    compilation terminated.
    ninja: build stopped: subcommand failed.
    
    
  • cli without the Botan::botan target:
    ====================[ Build | all | Debug ]=====================================
    /snap/clion/489/bin/cmake/linux/x64/bin/cmake --build /home/adrien/projects/keepassxc/cmake-build-debug --target all -j 1
    [12/92] Building CXX object src/cli/CMakeFiles/cli.dir/Add.cpp.o
    FAILED: [code=1] src/cli/CMakeFiles/cli.dir/Add.cpp.o 
    /usr/bin/c++ -DQT_CORE_LIB -DQT_NO_CAST_TO_ASCII -DQT_NO_DEPRECATED_WARNINGS -DQT_NO_EXCEPTIONS -DQT_STRICT_ITERATORS -I/home/adrien/projects/keepassxc/cmake-build-debug/src/cli/cli_autogen/include -I/home/adrien/projects/keepassxc/src -I/home/adrien/projects/keepassxc/cmake-build-debug/src -I/home/adrien/projects/keepassxc/src/thirdparty/zxcvbn -isystem /usr/include/minizip -isystem /usr/include/PCSC -isystem /usr/include/libusb-1.0 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -fno-common -fopenmp -Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long -Wformat=2 -Wmissing-format-attribute -fvisibility=hidden -fvisibility-inlines-hidden -Wshadow-compatible-local -Wshadow-local -Werror -Wno-deprecated-enum-enum-conversion -Wno-error=deprecated  -fstack-protector-strong -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Werror=format-security -Wcast-align -fsized-deallocation -Wno-deprecated-declarations -g -std=gnu++20 -fPIC -fdiagnostics-color=always -MD -MT src/cli/CMakeFiles/cli.dir/Add.cpp.o -MF src/cli/CMakeFiles/cli.dir/Add.cpp.o.d -o src/cli/CMakeFiles/cli.dir/Add.cpp.o -c /home/adrien/projects/keepassxc/src/cli/Add.cpp
    In file included from /home/adrien/projects/keepassxc/src/core/Database.h:33,
                     from /home/adrien/projects/keepassxc/src/cli/Command.h:23,
                     from /home/adrien/projects/keepassxc/src/cli/DatabaseCommand.h:21,
                     from /home/adrien/projects/keepassxc/src/cli/Add.h:21,
                     from /home/adrien/projects/keepassxc/src/cli/Add.cpp:18:
    /home/adrien/projects/keepassxc/src/keys/PasswordKey.h:21:10: fatal error: botan/secmem.h: Aucun fichier ou dossier de ce nom
       21 | #include <botan/secmem.h>
          |          ^~~~~~~~~~~~~~~~
    compilation terminated.
    ninja: build stopped: subcommand failed.
    

As we can see, src/keys/PasswordKey.h is included indirectly from several libraries, but src/keys does not provide any target.
We could remove the Botan::botan explicit dependency for those libraries (autotype, cli) by providing a key library target which would have Botan::botan as a dependency. But as botan is required in a header, it would be a PUBLIC dependency.

For the others libraries, botan is a direct dependency:

$ git grep -l 'botan/' -- '*.h' '*.cpp'
src/browser/BrowserMessageBuilder.cpp
src/browser/BrowserPasskeys.cpp
src/browser/BrowserPasskeys.h
src/core/Alloc.cpp
src/crypto/Crypto.cpp
src/crypto/CryptoHash.cpp
src/crypto/Random.cpp
src/crypto/Random.h
src/crypto/SymmetricCipher.cpp
src/crypto/kdf/Argon2Kdf.cpp
src/fdosecrets/objects/SessionCipher.cpp
src/format/BitwardenReader.cpp
src/format/OpVaultReader.cpp
src/keeshare/KeeShareSettings.cpp
src/keeshare/ShareExport.cpp
src/keys/FileKey.h
src/keys/PasswordKey.h
src/keys/drivers/YubiKey.h
src/quickunlock/Polkit.cpp
src/sshagent/OpenSSHKey.cpp
src/sshagent/OpenSSHKeyGen.cpp
tests/TestBrowser.cpp
tests/TestPasskeys.cpp
tests/TestPasskeys.h
tests/TestSharing.cpp

@droidmonkey

Copy link
Copy Markdown
Member

That is because you removed the global include directory on line 485 in the main CMakeLists.txt

@aollier

aollier commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Yes, I know. The Botan include directory was always included, even when not needed, thereby polluting the global namespace.
This change allows it to be included only when necessary. That is one of the goals of these modifications.
As stated in the description, this change aligns with the modern CMake way of doing things.

@aollier

aollier commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

The current situation is completely contradictory: you tell me there's no need to include the library everywhere, yet on the other hand, the Botan include directory is present everywhere due to the global inclusion.

@droidmonkey

Copy link
Copy Markdown
Member

Having a search path set is very different from including a library in a build. Including excessive libraries tends to increase linker time because it has to deconflict symbols over and over again.

@aollier

aollier commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Since we are building a static library target (STATIC), CMake does not invoke the linker (ld / lld) or pass -l flags at this stage. It only runs the compiler with the necessary -I and -D flags to generate object files, then archives them (ar).

The binary library linking (-l) is automatically deferred by CMake to the final executable target that consumes the static library.

Therefore, using target_link_libraries(<keepassxc_static_target> PRIVATE PkgConfig::MY_LIB) on a static library target carries zero linker overhead during its build, while ensuring that all required include directories and preprocessor definitions are cleanly scoped to object compilation.

@aollier

aollier commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

I think there was a misunderstanding: I wasn't talking about adding new links to the Botan library throughout the project, but rather replacing the existing PUBLIC links with PRIVATE ones—except for keepassxc_core.
That would be done in a second commit.

@droidmonkey

Copy link
Copy Markdown
Member

Gotcha OK

@aollier

aollier commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Now that we finally understand each other, could you please rerun the failed build to ensure that all tests are passing at this stage? Once that's done, I'll push the second commit to make the links PUBLIC to PRIVATE. Thank you very much.

@aollier

aollier commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@droidmonkey Since I am modifying the cmake/FindBotan.cmake file, does that affect its license?

Here is a sample about the COPYING file:

Files: cmake/FindBotan.cmake
Copyright: none
License: LGPL-2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants