Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 8 additions & 6 deletions cmake/log-it-cppConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
20 changes: 20 additions & 0 deletions tests/dependency_reuse/build_tree/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
31 changes: 31 additions & 0 deletions tests/dependency_reuse/installed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions tests/dependency_reuse/installed/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <logit.hpp>

int main() {
LOGIT_FMT_INFO("dependency reuse {}", 42);
return 0;
}
Loading