@@ -59,12 +59,21 @@ FetchContent_Declare(
59
59
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp/
60
60
GIT_TAG 28f93bdec6387d42332220afa9558060c8016795
61
61
GIT_PROGRESS NOT
62
+ FIND_PACKAGE_ARGS NAMES yaml-cpp
62
63
${FETCHCONTENT_QUIET} )
63
64
64
65
set (YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
65
66
66
67
FetchContent_MakeAvailable(yaml-cpp)
67
68
69
+ # Ensure yaml-cpp::yaml-cpp target exists (handle both system and FetchContent scenarios)
70
+ if (NOT TARGET yaml-cpp::yaml-cpp)
71
+ if (TARGET yaml-cpp)
72
+ # Create alias for system-installed yaml-cpp that provides 'yaml-cpp' target
73
+ add_library (yaml-cpp::yaml-cpp ALIAS yaml-cpp)
74
+ endif ()
75
+ endif ()
76
+
68
77
# ##############################################################################
69
78
# Docs
70
79
@@ -80,20 +89,30 @@ if(TUVX_ENABLE_BENCHMARK)
80
89
FetchContent_Declare(
81
90
googlebenchmark
82
91
GIT_REPOSITORY https://github.com/google/benchmark.git
83
- GIT_TAG v1.8.3)
92
+ GIT_TAG v1.8.3
93
+ FIND_PACKAGE_ARGS NAMES benchmark)
84
94
85
95
set (BENCHMARK_DOWNLOAD_DEPENDENCIES ON )
86
96
set (BENCHMARK_ENABLE_GTEST_TESTS OFF )
87
97
set (BENCHMARK_ENABLE_ASSEMBLY_TESTS OFF )
88
98
set (BENCHMARK_ENABLE_TESTING OFF )
89
99
FetchContent_MakeAvailable(googlebenchmark)
100
+
101
+ # Ensure benchmark::benchmark target exists (handle both system and FetchContent scenarios)
102
+ if (NOT TARGET benchmark::benchmark)
103
+ if (TARGET benchmark)
104
+ # Create alias for system-installed benchmark that provides 'benchmark' target
105
+ add_library (benchmark::benchmark ALIAS benchmark)
106
+ endif ()
107
+ endif ()
90
108
endif ()
91
109
92
110
if (TUVX_ENABLE_TESTS)
93
111
FetchContent_Declare(
94
112
googletest
95
113
GIT_REPOSITORY https://github.com/google/googletest.git
96
- GIT_TAG be03d00f5f0cc3a997d1a368bee8a1fe93651f48)
114
+ GIT_TAG be03d00f5f0cc3a997d1a368bee8a1fe93651f48
115
+ FIND_PACKAGE_ARGS NAMES GTest)
97
116
98
117
set (INSTALL_GTEST
99
118
OFF
@@ -104,9 +123,21 @@ if(TUVX_ENABLE_TESTS)
104
123
105
124
FetchContent_MakeAvailable(googletest)
106
125
107
- # don't run clang-tidy on google test
108
- set_target_properties (gtest PROPERTIES CXX_CLANG_TIDY "" )
109
- set_target_properties (gtest_main PROPERTIES CXX_CLANG_TIDY "" )
126
+ # Ensure GTest::gtest_main target exists (handle both system and FetchContent scenarios)
127
+ if (NOT TARGET GTest::gtest_main)
128
+ if (TARGET gtest_main)
129
+ # Create alias for system-installed gtest that provides 'gtest_main' target
130
+ add_library (GTest::gtest_main ALIAS gtest_main)
131
+ endif ()
132
+ endif ()
133
+
134
+ # don't run clang-tidy on google test (only when built from source)
135
+ if (TARGET gtest)
136
+ set_target_properties (gtest PROPERTIES CXX_CLANG_TIDY "" )
137
+ endif ()
138
+ if (TARGET gtest_main)
139
+ set_target_properties (gtest_main PROPERTIES CXX_CLANG_TIDY "" )
140
+ endif ()
110
141
endif ()
111
142
112
143
# ##############################################################################
0 commit comments