diff --git a/CMakeLists.txt b/CMakeLists.txt index 7767e915..5e25695c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,24 @@ set(LIBPOWERLOADER_SRCS src/uploader/oci_upload.cpp ) +set(LIBPOWERLOADER_HEADERS + include/context.hpp + include/curl.hpp + include/download_target.hpp + include/downloader.hpp + include/enums.hpp + include/errors.hpp + include/fastest_mirror.hpp + include/fileio.hpp + include/mirror.hpp + include/url.hpp + include/result.hpp + include/target.hpp + include/utils.hpp + include/zck.hpp +) + + add_executable(powerloader src/cli/main.cpp) @@ -46,12 +64,18 @@ endif() add_library(libpowerloader ${LIBPOWERLOADER_SRCS} ) +set_target_properties(libpowerloader + PROPERTIES PREFIX "" +) target_include_directories(powerloader PUBLIC include ${CURL_INCLUDE_DIRS} ${ZCK_INCLUDE_DIRS} ) + +set_target_properties(powerloader PROPERTIES PUBLIC_HEADER "${LIBPOWERLOADER_HEADERS}") + if (DEV) add_executable(dpowerloader src/main.cpp) target_link_libraries(dpowerloader libpowerloader) @@ -82,6 +106,19 @@ target_link_libraries(libpowerloader ${YAML_CPP_LIBRARIES}) target_link_libraries(powerloader libpowerloader CLI11::CLI11) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +set(LIBMAMBA_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for libmambaConfig.cmake") + +install(TARGETS powerloader libpowerloader + EXPORT ${PROJECT_NAME}-targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/powerloader +) + option(ENABLE_TESTS "Enable tests" ON) option(ENABLE_PYTHON "Enable python bindings" ON) diff --git a/include/context.hpp b/include/context.hpp index b21fd123..cb3d478c 100644 --- a/include/context.hpp +++ b/include/context.hpp @@ -5,7 +5,6 @@ #include <chrono> #include <map> #include <filesystem> -namespace fs = std::filesystem; #include <spdlog/spdlog.h> #ifdef WITH_ZCHUNK @@ -18,6 +17,8 @@ extern "C" namespace powerloader { + namespace fs = std::filesystem; + struct Mirror; class Context diff --git a/include/download_target.hpp b/include/download_target.hpp index b68634c2..a35518c0 100644 --- a/include/download_target.hpp +++ b/include/download_target.hpp @@ -17,6 +17,15 @@ extern "C" namespace powerloader { + /** Called when a transfer is done (use transfer status to check + * if successful or failed). + * @param clientp Pointer to user data. + * @param status Transfer status + * @param msg Error message or NULL. + * @return See LrCbReturnCode codes + */ + typedef CbReturnCode (*EndCb)(TransferStatus status, const std::string& msg, void* clientp); + class DownloadTarget { public: @@ -123,6 +132,7 @@ namespace powerloader std::function<int(curl_off_t, curl_off_t)> progress_callback; + EndCb endcb = nullptr; void* cbdata = nullptr; diff --git a/include/downloader.hpp b/include/downloader.hpp index 28b5cbe0..b457cf81 100644 --- a/include/downloader.hpp +++ b/include/downloader.hpp @@ -16,7 +16,6 @@ extern "C" #include <fcntl.h> } -namespace fs = std::filesystem; #include "context.hpp" #include "curl.hpp" @@ -32,6 +31,8 @@ namespace fs = std::filesystem; namespace powerloader { + namespace fs = std::filesystem; + class Downloader { public: diff --git a/include/enums.hpp b/include/enums.hpp index 4c926b37..97539e68 100644 --- a/include/enums.hpp +++ b/include/enums.hpp @@ -85,13 +85,4 @@ namespace powerloader ChecksumType type; std::string checksum; }; - - /** Called when a transfer is done (use transfer status to check - * if successful or failed). - * @param clientp Pointer to user data. - * @param status Transfer status - * @param msg Error message or NULL. - * @return See LrCbReturnCode codes - */ - typedef CbReturnCode (*EndCb)(TransferStatus status, const std::string& msg, void* clientp); } diff --git a/include/fileio.hpp b/include/fileio.hpp index 2ca6543e..60f0dfc0 100644 --- a/include/fileio.hpp +++ b/include/fileio.hpp @@ -1,3 +1,5 @@ +#pragma once + #include <filesystem> #include <spdlog/spdlog.h> @@ -10,10 +12,11 @@ #include <windows.h> #endif -namespace fs = std::filesystem; namespace powerloader { + namespace fs = std::filesystem; + class FileIO { private: diff --git a/include/target.hpp b/include/target.hpp index c9573df3..b3cbc893 100644 --- a/include/target.hpp +++ b/include/target.hpp @@ -5,8 +5,6 @@ #include <fstream> #include <set> -namespace fs = std::filesystem; - #include "curl.hpp" #include "download_target.hpp" #include "enums.hpp" @@ -15,6 +13,8 @@ namespace fs = std::filesystem; namespace powerloader { + namespace fs = std::filesystem; + class Target { public: diff --git a/include/url.hpp b/include/url.hpp index 3868ce03..00d42f16 100644 --- a/include/url.hpp +++ b/include/url.hpp @@ -4,8 +4,8 @@ // // The full license is in the file LICENSE, distributed with this software. -#ifndef MAMBA_CORE_URL_HPP -#define MAMBA_CORE_URL_HPP +#ifndef POWERLOADER_URL_HPP +#define POWERLOADER_URL_HPP extern "C" { diff --git a/include/utils.hpp b/include/utils.hpp index dd11507a..20ceddb2 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -10,8 +10,6 @@ #include <string_view> #include <cctype> -namespace fs = std::filesystem; - extern "C" { #include <openssl/evp.h> @@ -19,6 +17,8 @@ extern "C" namespace powerloader { + namespace fs = std::filesystem; + inline bool is_sig_interrupted() { return false; diff --git a/src/target.cpp b/src/target.cpp index 5fbe378c..8ae3cc4c 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -51,6 +51,8 @@ namespace powerloader CbReturnCode Target::call_endcallback(TransferStatus status) { + reset_file(status); + EndCb end_cb = override_endcb ? override_endcb : target->endcb; void* cb_data = override_endcb ? override_endcb_data : target->cbdata; CbReturnCode rc = CbReturnCode::kOK; @@ -66,9 +68,6 @@ namespace powerloader spdlog::error("End-Callback returned an error"); } } - - reset_file(status); - return rc; }