OpenHD
OpenHD copied to clipboard
Add missing spdlog includes
After #1242 (Same as https://github.com/OpenHD/OpenHD/pull/1220 which was closed for no reason.)
When packaging this with Nix, I want to avoid compiling nlohmann_json and spdlog by avoiding to use the submodules pinned in this repository. Nix provides pre-compiled, cached libraries.
To achieve this, I had to patch the ohd_common/CMakeLists.txt:
--- a/ohd_common/CMakeLists.txt
+++ b/ohd_common/CMakeLists.txt
@@ -28,23 +28,9 @@ endif()
#----------------------------------------------------------------------------------------------------------------------
# Dependencies: spdlog and nlohmann::json
#----------------------------------------------------------------------------------------------------------------------
-set(SPDLOG_MASTER_PROJECT OFF)
-set(SPDLOG_PROJECT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/spdlog)
-set(SPDLOG_SOURCES_DIRECTORY ${SPDLOG_PROJECT_DIRECTORY}/src)
-
-set(spdlog_sources
- "${SPDLOG_SOURCES_DIRECTORY}/bundled_fmtlib_format.cpp"
-)
-
-target_precompile_headers(OHDCommonLib PRIVATE ${SPDLOG_PROJECT_DIRECTORY}/include/spdlog/spdlog.h)
-target_include_directories(OHDCommonLib PUBLIC ${SPDLOG_PROJECT_DIRECTORY}/include)
-
-# Add nlohmann::json
-add_subdirectory(lib/json)
-target_link_libraries(OHDCommonLib PUBLIC nlohmann_json::nlohmann_json)
-
-# Add pthread support
-find_package(Threads REQUIRED)
+find_package(spdlog CONFIG REQUIRED)
+find_package(nlohmann_json CONFIG REQUIRED)
+target_link_libraries(OHDCommonLib PUBLIC spdlog::spdlog nlohmann_json::nlohmann_json)
target_link_libraries(OHDCommonLib PUBLIC Threads::Threads)
This then caused errors of the following to arise:
/nix/store/13dxcy8kwcvvg765hj01kf29j3l0qmr3-spdlog-1.15.2-dev/include/spdlog/fwd.h:7:7: note: forward declaration of 'using std::__shared_ptr_access<spdlog::logger, __gnu_cxx::_S_atomic, false, false>::element_type = class spdlog::logger'>
7 | class logger;
| ^~~~~~
/build/source/OpenHD/ohd_common/src/openhd_util_filesystem.cpp:180:31: error: invalid use of incomplete type 'using std::__shared_ptr_access<spdlog::logger, __gnu_cxx::_S_atomic, false, false>::element_type = class spdlog::logger' {aka 'c>
180 | openhd::log::get_default()->warn("Cannot change file {} rw anybody, ret:{}",
In order to fix this I had to explicitly include spdlog.