From 0d63899fd211fc6fdb3ed34bd16d2c74841497da Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 12 Jul 2024 19:37:23 -0300 Subject: [PATCH] Updates for system packaging - Don't add headers to `add_library`; it's completely unnecessary and compilation should be able to find the headers if things are set up properly already. - Add a comment about version bump policy - Add ethyl_VERSION_SO to install a versioned shared lib - Remove cpr from include headers. Having them there means cpr becomes a build-time dependency for ethyl-using projects instead of just a build-time dependency of ethyl itself. - Remove cpr from public linkage - Add ethyl_INSTALL option that installs libs/headers - Exclude external submodules from "all" target - Add pkg-config file --- CMakeLists.txt | 35 ++++++++++++++++++++++++++++++----- cmake/StandardSettings.cmake | 12 +++++++++++- external/CMakeLists.txt | 6 +++--- include/ethyl/provider.hpp | 9 ++++++--- libethyl.pc.in | 13 +++++++++++++ src/provider.cpp | 2 +- 6 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 libethyl.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 46d69dd..1b24dda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Project details # +# When bumping the version, bump the 3rd version for source-only changes (i.e. no API changes in +# headers), and the 2nd version if anything in the headers change. project( ethyl VERSION 0.1.0 @@ -53,7 +55,6 @@ add_subdirectory(src/ethyl-keccak) add_library( ${PROJECT_NAME} - ${headers} ${sources} ) @@ -71,8 +72,14 @@ set_target_properties( PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE}" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}" ) +if(${PROJECT_NAME}_VERSION_SO) + set_target_properties( + ${PROJECT_NAME} + PROPERTIES + SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) +endif() + message(STATUS "Added all header and implementation files.\n") @@ -93,13 +100,13 @@ verbose_message("Applied compiler warnings.\n") target_link_libraries( ${PROJECT_NAME} PUBLIC - cpr::cpr - secp256k1 nlohmann_json::nlohmann_json oxenc::oxenc + secp256k1 + PRIVATE + cpr::cpr oxen::logging ethyl-keccak - PRIVATE gmp gmpxx ) @@ -137,3 +144,21 @@ configure_file( message(STATUS "Finished building requirements for installing the package.\n") +if(${PROJECT_NAME}_INSTALL) + include(GNUInstallDirs) + + install( + DIRECTORY include/ethyl + TYPE INCLUDE + FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h") + + install( + TARGETS ${PROJECT_NAME} + EXPORT ethylConfig + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + configure_file(libethyl.pc.in libethyl.pc @ONLY) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/libethyl.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +endif() diff --git a/cmake/StandardSettings.cmake b/cmake/StandardSettings.cmake index 24b6bed..865fb8a 100644 --- a/cmake/StandardSettings.cmake +++ b/cmake/StandardSettings.cmake @@ -11,7 +11,8 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(BUILD_SHARED_LIBS "Build libraries as shared libraries" ON) -Include(FetchContent) +# This is mainly useful for system packaging to create libquic.so.x.y instead of just libquic.so: +option(${PROJECT_NAME}_VERSION_SO "Add the project major/minor version into the shared library filename" OFF) # # Unit testing @@ -63,3 +64,12 @@ if(${PROJECT_NAME}_ENABLE_ASAN) add_compile_options(-fsanitize=address) add_link_options(-fsanitize=address) endif() + + +if (${PROJECT_NAME}_IS_TOPLEVEL_PROJECT OR BUILD_SHARED_LIBS) + set(${PROJECT_NAME}_INSTALL_DEFAULT ON) +else() + set(${PROJECT_NAME}_INSTALL_DEFAULT OFF) +endif() +option(${PROJECT_NAME}_INSTALL "Add libraries/headers to cmake install target; defaults to ON if BUILD_SHARED_LIBS is enabled or we are the top-level project" + ${${PROJECT_NAME}_IS_TOPLEVEL_PROJECT}) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index c7a9375..3ab0e14 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -14,7 +14,7 @@ set(BUILD_SHARED_LIBS OFF) # if(NOT TARGET cpr::cpr) set(CPR_USE_SYSTEM_CURL ON CACHE BOOL "") - add_subdirectory(cpr) + add_subdirectory(cpr EXCLUDE_FROM_ALL) endif() # @@ -33,7 +33,7 @@ system_or_submodule(SECP256K1 secp256k1 libsecp256k1 secp256k1) # Catch2 # if(NOT TARGET Catch2) - add_subdirectory(Catch2) + add_subdirectory(Catch2 EXCLUDE_FROM_ALL) endif() # @@ -44,7 +44,7 @@ if(NOT TARGET oxenc::oxenc) endif() if(NOT TARGET oxen::logging) - add_subdirectory(oxen-logging) + add_subdirectory(oxen-logging EXCLUDE_FROM_ALL) endif() oxen_logging_add_source_dir("${PROJECT_SOURCE_DIR}") diff --git a/include/ethyl/provider.hpp b/include/ethyl/provider.hpp index 09c14a8..600a4cd 100644 --- a/include/ethyl/provider.hpp +++ b/include/ethyl/provider.hpp @@ -2,6 +2,7 @@ #pragma once #include +#include #include #include #include @@ -9,8 +10,6 @@ #include #include -#include -#include #include #include "transaction.hpp" @@ -18,6 +17,10 @@ using namespace std::literals; +namespace cpr { +class Session; +} + namespace ethyl { @@ -32,7 +35,7 @@ struct FeeData { struct Client { std::string name; - cpr::Url url; + std::string url; }; struct HeightInfo { diff --git a/libethyl.pc.in b/libethyl.pc.in new file mode 100644 index 0000000..6e663b6 --- /dev/null +++ b/libethyl.pc.in @@ -0,0 +1,13 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: libethyl +Description: Ethereum RPC provider communication library for C++ +Version: @PROJECT_VERSION@ + +Libs: -L${libdir} -lethyl +Libs.private: @PRIVATE_LIBS@ +Requires: liboxenc nlohmann_json +Cflags: -I${includedir} diff --git a/src/provider.cpp b/src/provider.cpp index 1d7e229..fcb1516 100644 --- a/src/provider.cpp +++ b/src/provider.cpp @@ -207,7 +207,7 @@ void Provider::makeJsonRpcRequest(std::string_view method, cb(std::nullopt); return; } - auto url = clients[client_index].url.str(); + auto url = clients[client_index].url; auto session = get_client_session(url); session->SetBody(body); session->SetHeader({{"Content-Type", "application/json"}});