From: Sun Yuechi Date: Fri, 29 May 2026 10:19:18 +0000 (+0800) Subject: cmake/AddCephTest: use namespaced Catch2 imported targets X-Git-Tag: v21.0.1~27^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F69165%2Fhead;p=ceph.git cmake/AddCephTest: use namespaced Catch2 imported targets AddCephTest.cmake links the bare target names Catch2 / Catch2WithMain. With WITH_SYSTEM_CATCH2=ON, CPM resolves Catch2 via find_package(), which only exports the namespaced IMPORTED targets Catch2::Catch2 / Catch2::Catch2WithMain. CMake then treats the bare names as plain library names and the link fails with -lCatch2WithMain, since the physical library is named libCatch2Main (OUTPUT_NAME "Catch2Main"). Use the namespaced names. Catch2 exports them as ALIASes in the bundled (CPM subproject) build too, so the default path keeps working. Signed-off-by: Sun Yuechi --- diff --git a/cmake/modules/AddCephTest.cmake b/cmake/modules/AddCephTest.cmake index cd8cc90676b..83f442aec19 100644 --- a/cmake/modules/AddCephTest.cmake +++ b/cmake/modules/AddCephTest.cmake @@ -183,9 +183,9 @@ if(DEFINED catch2_opt_EXTRA_INCS) endif() if(${catch2_opt_NO_CATCH2_MAIN}) - LIST(APPEND tl_libs Catch2) + LIST(APPEND tl_libs Catch2::Catch2) else() - LIST(APPEND tl_libs Catch2WithMain) + LIST(APPEND tl_libs Catch2::Catch2WithMain) endif() target_link_libraries(unittest_${test_name}