From c83d14a54a39e36e6de55b098a36a8951bbabf53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= Date: Tue, 11 Jan 2022 14:01:57 +0100 Subject: [PATCH] Use directly pkg-config target PkgConfig cmake module can provide target itself. Use that instead of preparing its own. Add dependency to built libraries if libuv was found, it would propagate to uvw installation. It would still require find_package(libuv) on downstream builds. --- CMakeLists.txt | 7 ++----- src/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47cb0f94..f06f40de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,12 +109,9 @@ function(use_libuv) else(libuv_FOUND) find_package(PkgConfig QUIET) if (PkgConfig_FOUND) - pkg_check_modules(libuv libuv>=${LIBUV_VERSION}) + pkg_check_modules(libuv IMPORTED_TARGET libuv>=${LIBUV_VERSION}) if (libuv_FOUND) - add_library(uv INTERFACE) - target_include_directories(uv PUBLIC ${libuv_INCLUDE_DIRS}) - target_link_libraries(uv INTERFACE ${libuv_LDFLAGS} ${libuv_LIBRARIES}) - add_library(uv::uv-shared ALIAS uv) + add_library(uv::uv-shared ALIAS PkgConfig::libuv) set(FETCH_LIBUV_DEFAULT OFF) message(STATUS "libuv ${libuv_VERSION} found via pkg-config") endif(libuv_FOUND) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e949e47..584abfcb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,14 +65,14 @@ if (BUILD_UVW_SHARED_LIB) add_library(uvw SHARED) add_library(uvw::uvw-shared ALIAS uvw) # If libuv is not fetched by ourselves, it's the caller's responsibility to make sure of the linkage. - if(FETCH_LIBUV) + if(FETCH_LIBUV OR libuv_FOUND) target_link_libraries(uvw PUBLIC uv::uv-shared) endif() else() add_library(uvw STATIC) add_library(uvw::uvw-static ALIAS uvw) # If libuv is not fetched by ourselves, it's the caller's responsibility to make sure of the linkage. - if(FETCH_LIBUV) + if(FETCH_LIBUV OR libuv_FOUND) target_link_libraries(uvw PUBLIC uv::uv-static) endif() endif()