From cf3022a8441e7d711a4e12740e2a81e2e3d32e60 Mon Sep 17 00:00:00 2001 From: Tom Birdsong Date: Wed, 24 Jun 2026 12:08:17 -0400 Subject: [PATCH] Module template: Install complete CMake export interface Fixes module template so that new projects generate a viable C++ development package. Previous behavior: Creating a new Holoscan Module from template and then running default "./holohub package" commands would generate an incomplete C++ development package missing libraries and CMake import rules Updated: "./holohub package" installs binary operator libraries and CMake development files (*-config.cmake, *-targets.cmake) into the Debian package for distribution and reuse. Assisted-by: Claude:claude-opus-4.8 Signed-off-by: Tom Birdsong --- modules/template/hooks/post_gen_project.py | 7 ++++++- .../{{cookiecutter.operator_slug}}/CMakeLists.txt | 8 ++++++++ .../pkg/{{cookiecutter.module_repo_name}}/CMakeLists.txt | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/template/hooks/post_gen_project.py b/modules/template/hooks/post_gen_project.py index bdf3d7067e..c955bf1956 100644 --- a/modules/template/hooks/post_gen_project.py +++ b/modules/template/hooks/post_gen_project.py @@ -89,7 +89,11 @@ def remove_empty_dirs(root: str = ".") -> None: # Copy CMake helpers from the HoloHub clone so the module builds standalone: # - HoloHubConfigHelpers.cmake: add_holohub_application/operator/package gating -# - holohub_configure_deb.cmake: deb packaging helper used by the root CMakeLists +# - holohub_configure_deb.cmake: deb packaging helper used by the root +# CMakeLists. Brings a companion asset: +# - Config.cmake.in: package-config template the helper feeds to +# configure_package_config_file() when EXPORT_NAME is set, so +# downstream find_package() resolves the exported targets # - pybind11_add_holohub_module.cmake: fetches pybind11 at the HSDK-pinned # version + ABI-aligned target. Brings two companion assets: # - pybind11/__init__.py: per-operator __init__ template configured by @@ -102,6 +106,7 @@ def remove_empty_dirs(root: str = ".") -> None: for _rel in ( ("cmake", "HoloHubConfigHelpers.cmake"), ("cmake", "modules", "holohub_configure_deb.cmake"), + ("cmake", "modules", "Config.cmake.in"), ("cmake", "pybind11_add_holohub_module.cmake"), ): _src = _holohub_root.joinpath(*_rel) diff --git a/modules/template/{{cookiecutter.module_repo_name}}/operators/{{cookiecutter.operator_slug}}/CMakeLists.txt b/modules/template/{{cookiecutter.module_repo_name}}/operators/{{cookiecutter.operator_slug}}/CMakeLists.txt index 293724e275..7599caa9c5 100644 --- a/modules/template/{{cookiecutter.module_repo_name}}/operators/{{cookiecutter.operator_slug}}/CMakeLists.txt +++ b/modules/template/{{cookiecutter.module_repo_name}}/operators/{{cookiecutter.operator_slug}}/CMakeLists.txt @@ -12,6 +12,14 @@ target_link_libraries({{ cookiecutter.operator_slug }} PRIVATE holoscan::core) install(FILES {{ cookiecutter.operator_slug }}.hpp DESTINATION include/{{ cookiecutter.operator_slug }}) +# Add the operator to an export set. The package layer installs the set and +# generates the CMake config — see holohub_configure_deb(... EXPORT_NAME ...) in +# pkg/{{ cookiecutter.module_repo_name }}/CMakeLists.txt — so downstream projects +# can find_package({{ cookiecutter.module_repo_name }}) and link +# holoscan::{{ cookiecutter.operator_slug }}. +install(TARGETS {{ cookiecutter.operator_slug }} + EXPORT holoscan_{{ cookiecutter.module_slug }}_targets) + add_subdirectory(python) {% else %}# Pure Python operator — copy source into the Python package tree. configure_file( diff --git a/modules/template/{{cookiecutter.module_repo_name}}/pkg/{{cookiecutter.module_repo_name}}/CMakeLists.txt b/modules/template/{{cookiecutter.module_repo_name}}/pkg/{{cookiecutter.module_repo_name}}/CMakeLists.txt index fe9241b924..9404c65ddf 100644 --- a/modules/template/{{cookiecutter.module_repo_name}}/pkg/{{cookiecutter.module_repo_name}}/CMakeLists.txt +++ b/modules/template/{{cookiecutter.module_repo_name}}/pkg/{{cookiecutter.module_repo_name}}/CMakeLists.txt @@ -12,4 +12,5 @@ holohub_configure_deb( VENDOR "{% if cookiecutter.affiliation %}{{ cookiecutter.affiliation }}{% else %}NVIDIA{% endif %}" CONTACT "{{ cookiecutter.contact_email }}" DEPENDS "holoscan (>= {{ cookiecutter.holoscan_version }})" + EXPORT_NAME "holoscan_{{ cookiecutter.module_slug }}_targets" )