mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
b81f7025c9
Replaces custom logging system with spdlog-based oxen logging. This commit mainly replaces the backend logging with the spdlog-based system, but doesn't (yet) convert all the existing LogWarn, etc. to use the new format-based logging. New logging statements will look like: llarp::log::warning(cat, "blah: {}", val); where `cat` should be set up in each .cpp or cluster of .cpp files, as described in the oxen-logging README. As part of spdlog we get fmt, which gives us nice format strings, where are applied generously in this commit. Making types printable now requires two steps: - add a ToString() method - add this specialization: template <> constexpr inline bool llarp::IsToStringFormattable<llarp::Whatever> = true; This will then allow the type to be printed as a "{}" value in a fmt::format string. This is applied to all our printable types here, and all of the `operator<<` are removed. This commit also: - replaces various uses of `operator<<` to ToString() - replaces various uses of std::stringstream with either fmt::format or plain std::string - Rename some to_string and toString() methods to ToString() for consistency (and to work with fmt) - Replace `stringify(...)` and `make_exception` usage with fmt::format (and remove stringify/make_exception from util/str.hpp).
124 lines
5.1 KiB
CMake
124 lines
5.1 KiB
CMake
|
|
option(SUBMODULE_CHECK "Enables checking that vendored library submodules are up to date" ON)
|
|
if(SUBMODULE_CHECK)
|
|
find_package(Git)
|
|
if(GIT_FOUND)
|
|
function(check_submodule relative_path)
|
|
execute_process(COMMAND git rev-parse "HEAD" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path} OUTPUT_VARIABLE localHead)
|
|
execute_process(COMMAND git rev-parse "HEAD:external/${relative_path}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE checkedHead)
|
|
string(COMPARE EQUAL "${localHead}" "${checkedHead}" upToDate)
|
|
if (upToDate)
|
|
message(STATUS "Submodule 'external/${relative_path}' is up-to-date")
|
|
else()
|
|
message(FATAL_ERROR "Submodule 'external/${relative_path}' is not up-to-date. Please update with\ngit submodule update --init --recursive\nor run cmake with -DSUBMODULE_CHECK=OFF")
|
|
endif()
|
|
|
|
# Extra arguments check nested submodules
|
|
foreach(submod ${ARGN})
|
|
execute_process(COMMAND git rev-parse "HEAD" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path}/${submod} OUTPUT_VARIABLE localHead)
|
|
execute_process(COMMAND git rev-parse "HEAD:${submod}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${relative_path} OUTPUT_VARIABLE checkedHead)
|
|
string(COMPARE EQUAL "${localHead}" "${checkedHead}" upToDate)
|
|
if (NOT upToDate)
|
|
message(FATAL_ERROR "Nested submodule '${relative_path}/${submod}' is not up-to-date. Please update with\ngit submodule update --init --recursive\nor run cmake with -DSUBMODULE_CHECK=OFF")
|
|
endif()
|
|
endforeach()
|
|
endfunction ()
|
|
|
|
message(STATUS "Checking submodules")
|
|
check_submodule(nlohmann)
|
|
check_submodule(cxxopts)
|
|
check_submodule(ghc-filesystem)
|
|
check_submodule(oxen-logging fmt spdlog)
|
|
check_submodule(pybind11)
|
|
check_submodule(sqlite_orm)
|
|
check_submodule(oxen-mq)
|
|
check_submodule(oxen-encoding)
|
|
check_submodule(uvw)
|
|
check_submodule(cpr)
|
|
check_submodule(ngtcp2)
|
|
endif()
|
|
endif()
|
|
|
|
macro(system_or_submodule BIGNAME smallname pkgconf subdir)
|
|
option(FORCE_${BIGNAME}_SUBMODULE "force using ${smallname} submodule" OFF)
|
|
if(NOT STATIC AND NOT FORCE_${BIGNAME}_SUBMODULE)
|
|
pkg_check_modules(${BIGNAME} ${pkgconf} IMPORTED_TARGET)
|
|
endif()
|
|
if(${BIGNAME}_FOUND)
|
|
add_library(${smallname} INTERFACE)
|
|
if(NOT TARGET PkgConfig::${BIGNAME} AND CMAKE_VERSION VERSION_LESS "3.21")
|
|
# Work around cmake bug 22180 (PkgConfig::THING not set if no flags needed)
|
|
else()
|
|
target_link_libraries(${smallname} INTERFACE PkgConfig::${BIGNAME})
|
|
endif()
|
|
message(STATUS "Found system ${smallname} ${${BIGNAME}_VERSION}")
|
|
else()
|
|
message(STATUS "using ${smallname} submodule")
|
|
add_subdirectory(${subdir})
|
|
endif()
|
|
if(NOT TARGET ${smallname}::${smallname})
|
|
add_library(${smallname}::${smallname} ALIAS ${smallname})
|
|
endif()
|
|
endmacro()
|
|
|
|
system_or_submodule(OXENC oxenc liboxenc>=1.0.3 oxen-encoding)
|
|
system_or_submodule(OXENMQ oxenmq liboxenmq>=1.2.12 oxen-mq)
|
|
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
|
system_or_submodule(NLOHMANN nlohmann_json nlohmann_json>=3.7.0 nlohmann)
|
|
|
|
if (STATIC OR FORCE_SPDLOG_SUBMODULE OR FORCE_FMT_SUBMODULE)
|
|
set(OXEN_LOGGING_FORCE_SUBMODULES ON CACHE INTERNAL "")
|
|
endif()
|
|
set(OXEN_LOGGING_SOURCE_ROOT "${PROJECT_SOURCE_DIR}" CACHE INTERNAL "")
|
|
add_subdirectory(oxen-logging)
|
|
|
|
if(WITH_HIVE)
|
|
add_subdirectory(pybind11 EXCLUDE_FROM_ALL)
|
|
endif()
|
|
|
|
add_subdirectory(cxxopts EXCLUDE_FROM_ALL)
|
|
|
|
add_library(sqlite_orm INTERFACE)
|
|
target_include_directories(sqlite_orm SYSTEM INTERFACE sqlite_orm/include)
|
|
if(NOT TARGET sqlite3)
|
|
add_library(sqlite3 INTERFACE)
|
|
pkg_check_modules(SQLITE3 REQUIRED IMPORTED_TARGET sqlite3)
|
|
target_link_libraries(sqlite3 INTERFACE PkgConfig::SQLITE3)
|
|
endif()
|
|
target_link_libraries(sqlite_orm INTERFACE sqlite3)
|
|
|
|
add_library(uvw INTERFACE)
|
|
target_include_directories(uvw INTERFACE uvw/src)
|
|
target_link_libraries(uvw INTERFACE libuv)
|
|
|
|
# ngtcp2 needs some massaging to build nicely:
|
|
include(ngtcp2_lib)
|
|
add_ngtcp2_lib()
|
|
|
|
# cpr configuration. Ideally we'd just do this via add_subdirectory, but cpr's cmake requires
|
|
# 3.15+, and we target lower than that (and this is fairly simple to build).
|
|
if(WITH_BOOTSTRAP)
|
|
if(NOT BUILD_STATIC_DEPS)
|
|
find_package(CURL REQUIRED COMPONENTS HTTP HTTPS SSL)
|
|
|
|
# CURL::libcurl wasn't added to FindCURL until cmake 3.12, so add it if necessary
|
|
if (CMAKE_VERSION VERSION_LESS 3.12 AND NOT TARGET CURL::libcurl)
|
|
add_library(libcurl UNKNOWN IMPORTED GLOBAL)
|
|
set_target_properties(libcurl PROPERTIES
|
|
IMPORTED_LOCATION ${CURL_LIBRARIES}
|
|
INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}")
|
|
add_library(CURL_libcurl INTERFACE)
|
|
target_link_libraries(CURL_libcurl INTERFACE libcurl)
|
|
add_library(CURL::libcurl ALIAS CURL_libcurl)
|
|
endif()
|
|
endif()
|
|
|
|
file(GLOB cpr_sources ${conf_depends} cpr/cpr/*.cpp)
|
|
|
|
add_library(cpr STATIC EXCLUDE_FROM_ALL ${cpr_sources})
|
|
target_link_libraries(cpr PUBLIC CURL::libcurl)
|
|
target_include_directories(cpr PUBLIC cpr/include)
|
|
target_compile_definitions(cpr PUBLIC CPR_CURL_NOSIGNAL)
|
|
add_library(cpr::cpr ALIAS cpr)
|
|
endif()
|