From 047a45bd2e3bda3456c1365115d67847d43dd9f1 Mon Sep 17 00:00:00 2001 From: Michael Jurkoic Date: Sun, 28 Apr 2024 09:56:06 -0500 Subject: Configure for Linux builds - Use vcpkg for most dependency management. - Manually include uuid_v4. - Update README with prerequisites and build instructions. - Support subproject and standalone builds. --- .gitignore | 5 ++++- CMakeLists.txt | 56 +++++++++++++++++---------------------------------- CMakePresets.json | 8 ++++---- README.md | 20 +++++++++++++----- include/nostr.hpp | 7 +++++-- src/nostr_service.cpp | 9 --------- 6 files changed, 46 insertions(+), 59 deletions(-) diff --git a/.gitignore b/.gitignore index efb998a..6623964 100644 --- a/.gitignore +++ b/.gitignore @@ -40,8 +40,11 @@ build/ # CMake outputs _deps/ CMakeFiles/ +out/ Makefile CTestTestfile.cmake CMakeCache.txt cmake_install.cmake -OpenSSL-prefix + +# vcpkg +vcpkg_installed/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 208265a..4c521c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.19) cmake_policy(SET CMP0135 NEW) -project(NostrSDK VERSION 0.0.1) +project(NostrSDK VERSION 0.1.0) include(ExternalProject) include(FetchContent) @@ -9,8 +9,6 @@ include(FetchContent) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/_deps) - get_directory_property(HAS_PARENT PARENT_DIRECTORY) if(HAS_PARENT) message(STATUS "Configuring as a subproject.") @@ -20,52 +18,36 @@ if(HAS_PARENT) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../out/${CMAKE_BUILD_TYPE}/lib/) set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/../env/) - set(Boost_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../env/boost/include) + if(DEFINED ENV{WORKSPACE}) + list(APPEND CMAKE_PREFIX_PATH $ENV{WORKSPACE}/env) + else() + list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/../env) + endif() else() message(STATUS "Configuring as a standalone project.") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/bin/) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/lib/) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/lib/) - - set(OPENSSL_INCLUDE_DIR ${OPENSSL_ROOT_DIR}/include/) - set(OPENSSL_LIBRARIES ${OPENSSL_ROOT_DIR}/lib/) -endif() - -if(DEFINED ENV{WORKSPACE}) - list(APPEND CMAKE_PREFIX_PATH $ENV{WORKSPACE}/env) -else() - list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/../env) endif() -#======== Find unmanaged dependencies ========# +#======== Find dependencies ========# +find_package(nlohmann_json CONFIG REQUIRED) find_package(OpenSSL REQUIRED) -find_package(Boost REQUIRED COMPONENTS filesystem system thread regex) +find_package(plog CONFIG REQUIRED) +find_package(websocketpp CONFIG REQUIRED) -#======== Fetch header-only dependencies ========# -FetchContent_Declare( - nlohmann_json - URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz - URL_HASH SHA256=d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d - USES_TERMINAL_DOWNLOAD TRUE -) -FetchContent_Declare( - plog - URL https://github.com/SergiusTheBest/plog/archive/refs/tags/1.1.10.tar.gz - USES_TERMINAL_DOWNLOAD TRUE -) -FetchContent_Declare( - websocketpp - GIT_REPOSITORY git@github.com:zaphoyd/websocketpp.git - GIT_TAG 0.8.2 -) +#======== Configure uuid_v4 ========# FetchContent_Declare( uuid_v4 - URL https://github.com/crashoz/uuid_v4/archive/refs/tags/v1.0.0.tar.gz - USES_TERMINAL_DOWNLOAD TRUE + GIT_REPOSITORY git@github.com:crashoz/uuid_v4.git + GIT_TAG v1.0.0 ) +FetchContent_Populate(uuid_v4) +set(uuid_v4_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/_deps/uuid_v4-src/) -FetchContent_MakeAvailable(nlohmann_json plog uuid_v4 websocketpp) +find_path(uuid_v4_INCLUDE_DIR uuid_v4.h) +include_directories(${uuid_v4_INCLUDE_DIR}) #======== Build the project ========# set(INCLUDE_DIR ./include) @@ -93,7 +75,6 @@ target_link_libraries(NostrSDK PRIVATE OpenSSL::SSL OpenSSL::Crypto plog::plog - uuid_v4::uuid_v4 websocketpp::websocketpp ) set_target_properties(NostrSDK PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES) @@ -124,7 +105,6 @@ target_link_libraries(NostrSDKTest PRIVATE GTest::gtest_main NostrSDK plog::plog - uuid_v4::uuid_v4 websocketpp::websocketpp ) set_target_properties(NostrSDKTest PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES) diff --git a/CMakePresets.json b/CMakePresets.json index 8c57178..3e327f5 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,12 +2,12 @@ "version": 2, "configurePresets": [ { - "name": "default", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build", + "name": "linux", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build/linux", "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" } } ] - } \ No newline at end of file + } diff --git a/README.md b/README.md index 07ef788..b38e83f 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,21 @@ C++ System Development Kit for Nostr ### Prerequisites -- CMake 3.14 or later +This project uses CMake as its build system, and vcpkg as its dependency manager. Thus, to build the SDK, you will need the following: + +- CMake 3.19 or later - C++17 compiler -- OpenSSL 1.1.1 or later -- Boost 1.85 or later +- vcpkg + +### Build Targets + +The SDK aims to support Linux, Windows, and macOS build targets. CMake presets are provided for each target. + +#### Linux -### Standalone Build +To build the SDK on Linux, run the following commands from the project root: -When building this library as a standalone project, the `Boost_INCLUDE_DIR` and `OPENSSL_ROOT_DIR` variables must be set at the CMake configuration step. +```bash +cmake --preset=linux . +cmake --build ./build/linux +``` diff --git a/include/nostr.hpp b/include/nostr.hpp index d6d5de1..dab4d71 100644 --- a/include/nostr.hpp +++ b/include/nostr.hpp @@ -1,18 +1,21 @@ #pragma once +#include #include #include #include #include +#include #include +#include #include #include - -#include +#include #include #include #include +#include #include "client/web_socket_client.hpp" diff --git a/src/nostr_service.cpp b/src/nostr_service.cpp index de40180..f8565cc 100644 --- a/src/nostr_service.cpp +++ b/src/nostr_service.cpp @@ -1,12 +1,3 @@ -#include - -#include -#include -#include -#include -#include -#include - #include "nostr.hpp" #include "client/web_socket_client.hpp" -- cgit