Skip to content

Commit

Permalink
Updates for system packaging
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jagerman committed Jul 13, 2024
1 parent bb4dd3a commit 0d63899
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 13 deletions.
35 changes: 30 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,7 +55,6 @@ add_subdirectory(src/ethyl-keccak)

add_library(
${PROJECT_NAME}
${headers}
${sources}
)

Expand All @@ -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")

Expand All @@ -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
)
Expand Down Expand Up @@ -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()
12 changes: 11 additions & 1 deletion cmake/StandardSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
6 changes: 3 additions & 3 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

#
Expand All @@ -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()

#
Expand All @@ -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}")

Expand Down
9 changes: 6 additions & 3 deletions include/ethyl/provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
#pragma once

#include <forward_list>
#include <functional>
#include <string>
#include <string_view>
#include <optional>
#include <queue>
#include <chrono>
#include <mutex>

#include <cpr/cprtypes.h>
#include <cpr/session.h>
#include <nlohmann/json_fwd.hpp>

#include "transaction.hpp"
#include "logs.hpp"

using namespace std::literals;

namespace cpr {
class Session;
}

namespace ethyl
{

Expand All @@ -32,7 +35,7 @@ struct FeeData {

struct Client {
std::string name;
cpr::Url url;
std::string url;
};

struct HeightInfo {
Expand Down
13 changes: 13 additions & 0 deletions libethyl.pc.in
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion src/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"}});
Expand Down

0 comments on commit 0d63899

Please sign in to comment.