Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 1 | From 7e1ae687916fd5878ee755afbdea6b10494e0b92 Mon Sep 17 00:00:00 2001 |
| 2 | From: Alexey Firago <alexey_firago@mentor.com> |
| 3 | Date: Wed, 26 Jul 2017 23:21:25 +0300 |
| 4 | Subject: [PATCH] cmake: Install libcares.pc |
| 5 | |
| 6 | Prepare and install libcares.pc file during cmake build, so libraries |
| 7 | using pkg-config to find libcares will not fail. |
| 8 | |
| 9 | Signed-off-by: Alexey Firago <alexey_firago@mentor.com> |
| 10 | --- |
| 11 | CMakeLists.txt | 21 +++++++++++++++++++++ |
| 12 | libcares.pc.cmakein | 20 ++++++++++++++++++++ |
| 13 | 2 files changed, 41 insertions(+) |
| 14 | create mode 100644 libcares.pc.cmakein |
| 15 | |
| 16 | diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 17 | index 364b6c7..0016b67 100644 |
| 18 | --- a/CMakeLists.txt |
| 19 | +++ b/CMakeLists.txt |
| 20 | @@ -173,21 +173,29 @@ ADD_DEFINITIONS(${SYSFLAGS}) |
| 21 | |
| 22 | |
| 23 | # Tell C-Ares about libraries to depend on |
| 24 | +# Also pass these libraries to pkg-config file |
| 25 | +SET(CARES_PRIVATE_LIBS_LIST) |
| 26 | IF (HAVE_LIBRESOLV) |
| 27 | LIST (APPEND CARES_DEPENDENT_LIBS resolv) |
| 28 | + LIST (APPEND CARES_PRIVATE_LIBS_LIST "-lresolv") |
| 29 | ENDIF () |
| 30 | IF (HAVE_LIBNSL) |
| 31 | LIST (APPEND CARES_DEPENDENT_LIBS nsl) |
| 32 | + LIST (APPEND CARES_PRIVATE_LIBS_LIST "-lnsl") |
| 33 | ENDIF () |
| 34 | IF (HAVE_LIBSOCKET) |
| 35 | LIST (APPEND CARES_DEPENDENT_LIBS socket) |
| 36 | + LIST (APPEND CARES_PRIVATE_LIBS_LIST "-lsocket") |
| 37 | ENDIF () |
| 38 | IF (HAVE_LIBRT) |
| 39 | LIST (APPEND CARES_DEPENDENT_LIBS rt) |
| 40 | + LIST (APPEND CARES_PRIVATE_LIBS_LIST "-lrt") |
| 41 | ENDIF () |
| 42 | IF (WIN32) |
| 43 | LIST (APPEND CARES_DEPENDENT_LIBS ws2_32) |
| 44 | + LIST (APPEND CARES_PRIVATE_LIBS_LIST "-lws2_32") |
| 45 | ENDIF () |
| 46 | +string (REPLACE ";" " " CARES_PRIVATE_LIBS "${CARES_PRIVATE_LIBS_LIST}") |
| 47 | |
| 48 | |
| 49 | # When checking for symbols, we need to make sure we set the proper |
| 50 | @@ -489,6 +497,13 @@ CONFIGURE_FILE (ares_build.h.cmake ${PROJECT_BINARY_DIR}/ares_build.h) |
| 51 | # Write ares_config.h configuration file. This is used only for the build. |
| 52 | CONFIGURE_FILE (ares_config.h.cmake ${PROJECT_BINARY_DIR}/ares_config.h) |
| 53 | |
| 54 | +# Pass required CFLAGS to pkg-config in case of static library |
| 55 | +IF (CARES_STATIC) |
| 56 | + SET (CPPFLAG_CARES_STATICLIB "-DCARES_STATICLIB") |
| 57 | +ENDIF() |
| 58 | + |
| 59 | +# Write ares_config.h configuration file. This is used only for the build. |
| 60 | +CONFIGURE_FILE (libcares.pc.cmakein ${PROJECT_BINARY_DIR}/libcares.pc @ONLY) |
| 61 | |
| 62 | # TRANSFORM_MAKEFILE_INC |
| 63 | # |
| 64 | @@ -625,6 +640,12 @@ IF (CARES_INSTALL) |
| 65 | INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" DESTINATION ${CMAKECONFIG_INSTALL_DIR}) |
| 66 | ENDIF () |
| 67 | |
| 68 | +# pkg-config file |
| 69 | +IF (CARES_INSTALL) |
| 70 | + SET (PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 71 | + INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcares.pc" DESTINATION ${PKGCONFIG_INSTALL_DIR}) |
| 72 | +ENDIF () |
| 73 | + |
| 74 | # Legacy chain-building variables (provided for compatibility with old code). |
| 75 | # Don't use these, external code should be updated to refer to the aliases directly (e.g., Cares::cares). |
| 76 | SET (CARES_FOUND 1 CACHE INTERNAL "CARES LIBRARY FOUND") |
| 77 | diff --git a/libcares.pc.cmakein b/libcares.pc.cmakein |
| 78 | new file mode 100644 |
| 79 | index 0000000..f29fede |
| 80 | --- /dev/null |
| 81 | +++ b/libcares.pc.cmakein |
| 82 | @@ -0,0 +1,20 @@ |
| 83 | +#*************************************************************************** |
| 84 | +# Project ___ __ _ _ __ ___ ___ |
| 85 | +# / __|____ / _` | '__/ _ \/ __| |
| 86 | +# | (_|_____| (_| | | | __/\__ \ |
| 87 | +# \___| \__,_|_| \___||___/ |
| 88 | +# |
| 89 | +prefix=@CMAKE_INSTALL_PREFIX@ |
| 90 | +exec_prefix=@CMAKE_INSTALL_PREFIX@ |
| 91 | +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ |
| 92 | +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ |
| 93 | + |
| 94 | +Name: c-ares |
| 95 | +URL: http://daniel.haxx.se/projects/c-ares/ |
| 96 | +Description: asynchronous DNS lookup library |
| 97 | +Version: @VERSION@ |
| 98 | +Requires: |
| 99 | +Requires.private: |
| 100 | +Cflags: -I${includedir} @CPPFLAG_CARES_STATICLIB@ |
| 101 | +Libs: -L${libdir} -lcares |
| 102 | +Libs.private: @CARES_PRIVATE_LIBS@ |
| 103 | -- |
| 104 | 2.7.4 |
| 105 | |