diff --git a/configure.py b/configure.py index 68dadb02df9..3a407e86edb 100755 --- a/configure.py +++ b/configure.py @@ -527,6 +527,11 @@ def process_command_line(args): build_group.add_option('--without-pkg-config', dest='with_pkg_config', action='store_false', help=optparse.SUPPRESS_HELP) + build_group.add_option('--with-cmake-config', action='store_true', default=True, + help=optparse.SUPPRESS_HELP) + build_group.add_option('--without-cmake-config', dest='with_cmake_config', action='store_false', + help=optparse.SUPPRESS_HELP) + docs_group = optparse.OptionGroup(parser, 'Documentation Options') docs_group.add_option('--with-documentation', action='store_true', @@ -2299,6 +2304,9 @@ def test_exe_extra_ldflags(): if options.with_pkg_config: variables['botan_pkgconfig'] = os.path.join(build_paths.build_dir, 'botan-%d.pc' % (Version.major())) + if options.with_cmake_config: + variables['botan_cmake_config'] = os.path.join(build_paths.build_dir, 'cmake', 'botan-config.cmake') + variables['botan_cmake_version_config'] = os.path.join(build_paths.build_dir, 'cmake', 'botan-config-version.cmake') # The name is always set because Windows build needs it variables['static_lib_name'] = '%s%s.%s' % (variables['lib_prefix'], variables['libname'], @@ -3346,9 +3354,10 @@ def in_build_module_info(p): write_template(in_build_dir('build.h'), in_build_data('buildh.in')) write_template(in_build_dir('botan.doxy'), in_build_data('botan.doxy.in')) - robust_makedirs(in_build_dir("cmake")) - write_template(in_build_dir('cmake/botan-config.cmake'), in_build_data('botan-config.cmake.in')) - write_template(in_build_dir('cmake/botan-config-version.cmake'), in_build_data('botan-config-version.cmake.in')) + if options.with_cmake_config: + robust_makedirs(in_build_dir("cmake")) + write_template(in_build_dir('cmake/botan-config.cmake'), in_build_data('botan-config.cmake.in')) + write_template(in_build_dir('cmake/botan-config-version.cmake'), in_build_data('botan-config-version.cmake.in')) if 'botan_pkgconfig' in template_vars: write_template(template_vars['botan_pkgconfig'], in_build_data('botan.pc.in')) diff --git a/doc/building.rst b/doc/building.rst index ef08c1a56ce..0be5b8b9633 100644 --- a/doc/building.rst +++ b/doc/building.rst @@ -540,6 +540,21 @@ is less of a problem - only the developer needs to worry about it. As long as they can remember where they installed Botan, they just have to set the appropriate flags in their Makefile/project file. +CMake +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Starting in Botan 3.3.0 we provide a ``botan-config.cmake`` module to +discover the installed library binaries and headers. This hooks into +CMake's ``find_package()`` and comes with common features like version +detection. Also, library consumers may specify which botan modules they +require in ``find_package()``. + +Examples:: + + find_package(Botan 3.3.0) + find_package(Botan 3.3.0 COMPONENTS rsa ecdsa tls13) + find_package(Botan 3.3.0 OPTIONAL_COMPONENTS tls13_pqc) + Language Wrappers ---------------------------------------- diff --git a/doc/packaging.rst b/doc/packaging.rst index 3d3c13840fc..26327674cd0 100644 --- a/doc/packaging.rst +++ b/doc/packaging.rst @@ -34,6 +34,19 @@ releases and packages. Any value set with ``--distribution-info`` flag will be included in the version string, and can read through the ``BOTAN_DISTRIBUTION_INFO`` macro. +CMake Integration +----------------- + +Starting in Botan 3.3.0, we ship ``botan-config.cmake`` files. While this config +file is somewhat relocatable, it assumes the default installation directory +structure as generated by ``make install``. If your distribution changes the +directory layout of the installed files you might want to either adapt the final +``botan-config.cmake`` file accordingly or leave it out entirely using +``--without-cmake-config``. + +Please don't hesitate to give your feedback on this new feature by opening a +ticket on the upstream GitHub. + Minimize Distribution Patches ------------------------------ diff --git a/src/scripts/ci_check_install.py b/src/scripts/ci_check_install.py index 21ff4d4701e..5b4ec18f189 100755 --- a/src/scripts/ci_check_install.py +++ b/src/scripts/ci_check_install.py @@ -134,7 +134,8 @@ def main(args=None): if not verify_library(build_config): return 1 - if not verify_cmake_package(build_config): + has_cmake = 'botan_cmake_config' in build_config and 'botan_cmake_version_config' in build_config + if has_cmake and not verify_cmake_package(build_config): return 1 return 0 diff --git a/src/scripts/install.py b/src/scripts/install.py index 81ba766f951..b88276fffdb 100755 --- a/src/scripts/install.py +++ b/src/scripts/install.py @@ -210,12 +210,13 @@ def copy_executable(src, dst): copy_file(cfg['botan_pkgconfig'], prepend_destdir(os.path.join(pkgconfig_dir, os.path.basename(cfg['botan_pkgconfig'])))) - cmake_dir = os.path.join(prefix, lib_dir, cmake_dir, 'Botan-%s' % cfg["version"]) - makedirs(prepend_destdir(cmake_dir)) - copy_file('build/cmake/botan-config.cmake', - prepend_destdir(os.path.join(cmake_dir, 'botan-config.cmake'))) - copy_file('build/cmake/botan-config-version.cmake', - prepend_destdir(os.path.join(cmake_dir, 'botan-config-version.cmake'))) + if 'botan_cmake_config' in cfg and 'botan_cmake_version_config' in cfg: + cmake_dir = os.path.join(prefix, lib_dir, cmake_dir, 'Botan-%s' % cfg["version"]) + makedirs(prepend_destdir(cmake_dir)) + copy_file(cfg['botan_cmake_config'], + prepend_destdir(os.path.join(cmake_dir, os.path.basename(cfg['botan_cmake_config'])))) + copy_file(cfg['botan_cmake_version_config'], + prepend_destdir(os.path.join(cmake_dir, os.path.basename(cfg['botan_cmake_version_config'])))) if 'ffi' in cfg['mod_list'] and cfg['build_shared_lib'] is True and cfg['install_python_module'] is True: for ver in cfg['python_version'].split(','):