From 86d6752481387e7de90b909b62f7561ed89de6a7 Mon Sep 17 00:00:00 2001 From: Aster Seker Date: Tue, 8 Sep 2026 13:03:20 +0300 Subject: [PATCH 1/2] fix(packaging): reuse provided dependency targets Skip dependency discovery when parent or consumer projects already provide the exported targets, while retaining the TimeShield 1.0.6 requirement for discovery. --- CMakeLists.txt | 6 ++++-- cmake/log-it-cppConfig.cmake.in | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ecf3bd..24dfd96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,8 +37,10 @@ if(LOGIT_WITH_MDBX AND CMAKE_CXX_STANDARD LESS 17) endif() # Dependency: TimeShield -find_package(TimeShield 1.0.6 QUIET CONFIG) -if(NOT TimeShield_FOUND) +if(NOT TARGET time_shield::time_shield) + find_package(TimeShield 1.0.6 QUIET CONFIG) +endif() +if(NOT TARGET time_shield::time_shield) if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/time-shield-cpp/CMakeLists.txt") add_subdirectory(external/time-shield-cpp) else() diff --git a/cmake/log-it-cppConfig.cmake.in b/cmake/log-it-cppConfig.cmake.in index 3f2c8e7..a832da1 100644 --- a/cmake/log-it-cppConfig.cmake.in +++ b/cmake/log-it-cppConfig.cmake.in @@ -1,25 +1,27 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) -find_dependency(TimeShield) +if(NOT TARGET time_shield::time_shield) + find_dependency(TimeShield 1.0.6 CONFIG) +endif() -if(@LOGIT_WITH_FMT@) +if(@LOGIT_WITH_FMT@ AND NOT TARGET fmt::fmt) find_dependency(fmt CONFIG) endif() -if(@LOGIT_WITH_OTLP@) +if(@LOGIT_WITH_OTLP@ AND NOT TARGET kurlyk) find_dependency(kurlyk CONFIG) endif() -if(@LOGIT_WITH_GZIP@) +if(@LOGIT_WITH_GZIP@ AND NOT TARGET ZLIB::ZLIB) find_dependency(ZLIB) endif() -if(@LOGIT_WITH_ZSTD@) +if(@LOGIT_WITH_ZSTD@ AND NOT TARGET ZSTD::ZSTD) find_dependency(ZSTD) endif() -if(@LOGIT_WITH_MDBX@) +if(@LOGIT_WITH_MDBX@ AND NOT TARGET mdbx_containers::mdbx_containers) find_dependency(mdbx_containers CONFIG) endif() From 7ceb5676f3ee40ad70e64325ae0e9c7ae2a3e607 Mon Sep 17 00:00:00 2001 From: Aster Seker Date: Tue, 8 Sep 2026 21:40:25 +0300 Subject: [PATCH 2/2] test(packaging): cover dependency target reuse Exercise build-tree TimeShield reuse and installed-package reuse of parent-provided TimeShield and fmt targets with package discovery disabled. Run the focused integration scenarios in the Linux C++17 CI job so regressions cannot pass through the normal package consumer flow unnoticed. --- .github/workflows/ci.yml | 17 ++++++++++ .../build_tree/CMakeLists.txt | 20 ++++++++++++ .../dependency_reuse/installed/CMakeLists.txt | 31 +++++++++++++++++++ tests/dependency_reuse/installed/main.cpp | 6 ++++ 4 files changed, 74 insertions(+) create mode 100644 tests/dependency_reuse/build_tree/CMakeLists.txt create mode 100644 tests/dependency_reuse/installed/CMakeLists.txt create mode 100644 tests/dependency_reuse/installed/main.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 859798b..66ef781 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,23 @@ jobs: - name: Build fmt-enabled consumer project if: matrix.std == 17 run: cmake --build build-fmt-consumer + - name: Configure build-tree dependency reuse + if: matrix.std == 17 + run: >- + cmake -S tests/dependency_reuse/build_tree -B build-timeshield-reuse + -DLOGIT_SOURCE_DIR=${{ github.workspace }} + -DCMAKE_DISABLE_FIND_PACKAGE_TimeShield=TRUE + - name: Configure installed dependency reuse + if: matrix.std == 17 + run: >- + cmake -S tests/dependency_reuse/installed -B build-installed-reuse + -DLOGIT_SOURCE_DIR=${{ github.workspace }} + -DCMAKE_PREFIX_PATH=${{ github.workspace }}/install-fmt-package + -DCMAKE_DISABLE_FIND_PACKAGE_TimeShield=TRUE + -DCMAKE_DISABLE_FIND_PACKAGE_fmt=TRUE + - name: Build installed dependency reuse + if: matrix.std == 17 + run: cmake --build build-installed-reuse - name: Configure Prometheus server package if: matrix.std == 17 run: cmake -S . -B build-prometheus-package -DLOGIT_CPP_BUILD_TESTS=OFF -DLOGIT_WITH_PROMETHEUS_SERVER=ON -DLOGIT_WITH_SYSLOG=OFF -DLOGIT_WITH_WIN_EVENT_LOG=OFF diff --git a/tests/dependency_reuse/build_tree/CMakeLists.txt b/tests/dependency_reuse/build_tree/CMakeLists.txt new file mode 100644 index 0000000..1950f7d --- /dev/null +++ b/tests/dependency_reuse/build_tree/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.18) +project(parent_provided_timeshield LANGUAGES CXX) + +if(NOT DEFINED LOGIT_SOURCE_DIR) + message(FATAL_ERROR "LOGIT_SOURCE_DIR must point to the LogIt++ checkout") +endif() +if(NOT CMAKE_DISABLE_FIND_PACKAGE_TimeShield) + message(FATAL_ERROR "The test must disable TimeShield package discovery") +endif() + +# Model a parent project that has already provided TimeShield. The test invokes +# CMake with CMAKE_DISABLE_FIND_PACKAGE_TimeShield=TRUE so a regression that +# probes the package before checking the target cannot fall back silently. +add_library(time_shield::time_shield INTERFACE IMPORTED GLOBAL) + +add_subdirectory("${LOGIT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/log-it-cpp") + +if(NOT TARGET log-it-cpp::log-it-cpp) + message(FATAL_ERROR "LogIt++ target was not created") +endif() diff --git a/tests/dependency_reuse/installed/CMakeLists.txt b/tests/dependency_reuse/installed/CMakeLists.txt new file mode 100644 index 0000000..07485ce --- /dev/null +++ b/tests/dependency_reuse/installed/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.18) +project(installed_dependency_reuse LANGUAGES CXX) + +if(NOT DEFINED LOGIT_SOURCE_DIR) + message(FATAL_ERROR "LOGIT_SOURCE_DIR must point to the LogIt++ checkout") +endif() +if(NOT CMAKE_DISABLE_FIND_PACKAGE_TimeShield OR + NOT CMAKE_DISABLE_FIND_PACKAGE_fmt) + message(FATAL_ERROR "The test must disable TimeShield and fmt package discovery") +endif() + +# Both targets model dependencies supplied by the parent project. Discovery is +# disabled by the invoking test so the installed package must reuse these +# targets instead of calling find_dependency(). +add_library(time_shield::time_shield INTERFACE IMPORTED GLOBAL) +set_target_properties(time_shield::time_shield PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LOGIT_SOURCE_DIR}/external/time-shield-cpp/include" +) + +add_library(fmt::fmt INTERFACE IMPORTED GLOBAL) +set_target_properties(fmt::fmt PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LOGIT_SOURCE_DIR}/external/fmt/include" +) + +find_package(log-it-cpp CONFIG REQUIRED) + +add_executable(installed_dependency_reuse main.cpp) +target_link_libraries(installed_dependency_reuse PRIVATE log-it-cpp::log-it-cpp) +if(MSVC) + target_compile_options(installed_dependency_reuse PRIVATE /utf-8) +endif() diff --git a/tests/dependency_reuse/installed/main.cpp b/tests/dependency_reuse/installed/main.cpp new file mode 100644 index 0000000..2bd2ef7 --- /dev/null +++ b/tests/dependency_reuse/installed/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + LOGIT_FMT_INFO("dependency reuse {}", 42); + return 0; +}