From 182f57e942df778238b9164397d33e600b488f6a Mon Sep 17 00:00:00 2001 From: tobim Date: Thu, 11 Aug 2022 02:03:07 +0200 Subject: [PATCH] pkgsStatic.c-ares: fix CMake shim (#185777) The handwritten CMake config file assumed a shared library build, which is not always the case. --- pkgs/development/libraries/c-ares/default.nix | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkgs/development/libraries/c-ares/default.nix b/pkgs/development/libraries/c-ares/default.nix index b133f9867d32..a5a41813bc3e 100644 --- a/pkgs/development/libraries/c-ares/default.nix +++ b/pkgs/development/libraries/c-ares/default.nix @@ -25,13 +25,17 @@ stdenv.mkDerivation rec { }; # Adapted from running a cmake build - passthru.cmake-config = writeTextDir "c-ares-config.cmake" + passthru.cmake-config = let + extension = if stdenv.hostPlatform.isStatic then ".a" else stdenv.hostPlatform.extensions.sharedLibrary; + buildType = if stdenv.hostPlatform.isStatic then "STATIC" else "SHARED"; + buildTypeLower = if stdenv.hostPlatform.isStatic then "static" else "shared"; + in writeTextDir "c-ares-config.cmake" '' set(c-ares_INCLUDE_DIR "${self}/include") set(c-ares_LIBRARY c-ares::cares) - add_library(c-ares::cares SHARED IMPORTED) + add_library(c-ares::cares ${buildType} IMPORTED) set_target_properties(c-ares::cares PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${self}/include" @@ -39,12 +43,12 @@ stdenv.mkDerivation rec { ) set_property(TARGET c-ares::cares APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(c-ares::cares PROPERTIES - IMPORTED_LOCATION_RELEASE "${self}/lib/libcares${stdenv.targetPlatform.extensions.sharedLibrary}" - IMPORTED_SONAME_RELEASE "libcares${stdenv.targetPlatform.extensions.sharedLibrary}" + IMPORTED_LOCATION_RELEASE "${self}/lib/libcares${extension}" + IMPORTED_SONAME_RELEASE "libcares${extension}" ) - add_library(c-ares::cares_shared INTERFACE IMPORTED) - set_target_properties(c-ares::cares_shared PROPERTIES INTERFACE_LINK_LIBRARIES "c-ares::cares") - set(c-ares_SHARED_LIBRARY c-ares::cares_shared) + add_library(c-ares::cares_${buildTypeLower} INTERFACE IMPORTED) + set_target_properties(c-ares::cares_${buildTypeLower} PROPERTIES INTERFACE_LINK_LIBRARIES "c-ares::cares") + set(c-ares_${buildType}_LIBRARY c-ares::cares_${buildTypeLower}) ''; }; in self