From 5711b4916a887ac3dea5640217a32b897cb54a66 Mon Sep 17 00:00:00 2001 From: Guilherme Janczak Date: Fri, 27 May 2022 03:32:35 +0000 Subject: [PATCH] add pkg-config definitions pkg-config makes curlcpp easy to use with non-CMake build systems like the .cmake files make it easy to use with CMake. Done with a lot of help from @eli-schwartz. --- CMakeLists.txt | 20 ++++++++++++++++++-- CMakeScripts/JoinPaths.cmake | 23 +++++++++++++++++++++++ src/curlcpp.pc.in | 12 ++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 CMakeScripts/JoinPaths.cmake create mode 100644 src/curlcpp.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c8e21e..ff1dc9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,15 @@ cmake_minimum_required(VERSION 3.11...3.15) # Setting up project -project(curlcpp LANGUAGES CXX) +project(curlcpp + VERSION 1.4 + DESCRIPTION "An object oriented C++ wrapper for CURL (libcurl)" + HOMEPAGE_URL "https://github.com/JosephP91/curlcpp/" + LANGUAGES CXX) + +# For the pkg-config file. Please read https://github.com/jtojnar/cmake-snips +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeScripts") +include(JoinPaths) include(GNUInstallDirs) @@ -48,4 +56,12 @@ include(CMakePackageConfigHelpers) configure_package_config_file(CMake/curlcppConfig.cmake.in "${PROJECT_BINARY_DIR}/curlcppConfig.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/curlcpp") -install(FILES ${PROJECT_BINARY_DIR}/curlcppConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/curlcpp) \ No newline at end of file +install(FILES ${PROJECT_BINARY_DIR}/curlcppConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/curlcpp) + +join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") +join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") +configure_file("${PROJECT_SOURCE_DIR}/src/curlcpp.pc.in" + "${PROJECT_BINARY_DIR}/src/curlcpp.pc" + @ONLY) +install(FILES "${PROJECT_BINARY_DIR}/src/curlcpp.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") diff --git a/CMakeScripts/JoinPaths.cmake b/CMakeScripts/JoinPaths.cmake new file mode 100644 index 0000000..c68d91b --- /dev/null +++ b/CMakeScripts/JoinPaths.cmake @@ -0,0 +1,23 @@ +# This module provides function for joining paths +# known from most languages +# +# SPDX-License-Identifier: (MIT OR CC0-1.0) +# Copyright 2020 Jan Tojnar +# https://github.com/jtojnar/cmake-snips +# +# Modelled after Python’s os.path.join +# https://docs.python.org/3.7/library/os.path.html#os.path.join +# Windows not supported +function(join_paths joined_path first_path_segment) + set(temp_path "${first_path_segment}") + foreach(current_segment IN LISTS ARGN) + if(NOT ("${current_segment}" STREQUAL "")) + if(IS_ABSOLUTE "${current_segment}") + set(temp_path "${current_segment}") + else() + set(temp_path "${temp_path}/${current_segment}") + endif() + endif() + endforeach() + set(${joined_path} "${temp_path}" PARENT_SCOPE) +endfunction() diff --git a/src/curlcpp.pc.in b/src/curlcpp.pc.in new file mode 100644 index 0000000..2637c2e --- /dev/null +++ b/src/curlcpp.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +includedir=@includedir_for_pc_file@ +libdir=@libdir_for_pc_file@ + +Name: @PROJECT_NAME@ +Description: @CMAKE_PROJECT_DESCRIPTION@ +URL: @CMAKE_PROJECT_HOMEPAGE_URL@ +Version: @PROJECT_VERSION@ +Requires: libcurl >= @CURL_MIN_VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} -lcurlcpp