Skip to content

Commit daac779

Browse files
authored
Merge pull request #45 from apl-ocean-engineering/dev/remove_g3log
Replace g3log with spdlog
2 parents 43c7d4c + bb8578d commit daac779

36 files changed

+14114
-520
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
env:
18-
- {UPSTREAM_WORKSPACE: liboculus.repos, ROS_DISTRO: noetic}
19-
- {UPSTREAM_WORKSPACE: liboculus.repos, ROS_DISTRO: kilted}
20-
- {UPSTREAM_WORKSPACE: liboculus.repos, ROS_DISTRO: rolling}
18+
- {ROS_DISTRO: noetic}
19+
# We include humble because there are still 22.04 systems (Jetson) out there
20+
- {ROS_DISTRO: humble}
21+
- {ROS_DISTRO: kilted}
22+
- {ROS_DISTRO: rolling}
2123

2224
steps:
2325
- name: Checkout repository

CMakeLists.txt

Lines changed: 15 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.8)
1+
cmake_minimum_required(VERSION 3.14.4)
22
project(liboculus)
33

44
set(CMAKE_CXX_STANDARD 17)
@@ -9,113 +9,28 @@ add_compile_options(-std=c++17)
99
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
1010

1111
set(oculus_SRCS
12-
lib/DataRx.cpp
13-
lib/SonarConfiguration.cpp
14-
lib/SonarStatus.cpp
15-
lib/StatusRx.cpp
16-
lib/SonarPlayer.cpp
17-
lib/OculusMessageHandler.cpp
18-
lib/SimpleFireMessage.cpp
19-
lib/IoServiceThread.cpp
12+
src/DataRx.cpp
13+
src/SonarConfiguration.cpp
14+
src/SonarStatus.cpp
15+
src/StatusRx.cpp
16+
src/SonarPlayer.cpp
17+
src/OculusMessageHandler.cpp
18+
src/SimpleFireMessage.cpp
19+
src/IoServiceThread.cpp
2020
)
2121

2222
# ROS build, determine which version...
23-
# QUIET will squelch the warning if the package isn't found
24-
find_package(ros_environment QUIET)
23+
if(DEFINED ENV{ROS_DISTRO})
24+
find_package(ros_environment)
2525

26-
if(${ros_environment_FOUND})
2726
set(ROS_VERSION $ENV{ROS_VERSION})
2827

2928
if(${ROS_VERSION} EQUAL 2)
30-
# == ament/ROS2 section =================================
31-
32-
find_package(ament_cmake REQUIRED)
33-
find_package(Boost REQUIRED COMPONENTS system)
34-
find_package(g3log_ros REQUIRED)
35-
36-
add_library(oculus SHARED ${oculus_SRCS})
37-
target_link_libraries(oculus PUBLIC Boost::system g3log_ros::g3log)
38-
39-
target_include_directories(
40-
oculus
41-
PUBLIC
42-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
43-
"$<INSTALL_INTERFACE:include/>"
44-
)
45-
46-
install(
47-
TARGETS oculus
48-
EXPORT export_${PROJECT_NAME}
49-
ARCHIVE DESTINATION lib
50-
LIBRARY DESTINATION lib
51-
RUNTIME DESTINATION bin
52-
)
53-
54-
install(
55-
DIRECTORY include/
56-
DESTINATION include
57-
FILES_MATCHING
58-
PATTERN "*.hpp"
59-
PATTERN "*.h"
60-
PATTERN ".git" EXCLUDE
61-
)
62-
63-
ament_export_dependencies(g3log_ros)
64-
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
65-
ament_export_libraries(oculus)
66-
67-
ament_package()
29+
message(NOTICE "!! Performing ROS2 build !!")
30+
include(cmake/BuildROS2.cmake)
6831
elseif(${ROS_VERSION} EQUAL 1)
69-
# Catkin/ROS1 section =====
70-
find_package(catkin REQUIRED COMPONENTS g3log_ros)
71-
find_package(Boost REQUIRED COMPONENTS system)
72-
73-
catkin_package(
74-
CATKIN_DEPENDS g3log_ros
75-
INCLUDE_DIRS include
76-
LIBRARIES liboculus
77-
)
78-
79-
add_library(liboculus ${oculus_SRCS})
80-
81-
include_directories(liboculus include ${catkin_INCLUDE_DIRS})
82-
83-
target_link_libraries(liboculus ${catkin_LIBRARIES})
84-
85-
install(
86-
TARGETS liboculus
87-
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
88-
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
89-
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
90-
)
91-
92-
## Install headers
93-
install(
94-
DIRECTORY include/${PROJECT_NAME}/
95-
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
96-
FILES_MATCHING
97-
PATTERN "*.hpp"
98-
PATTERN "*.h"
99-
PATTERN ".git" EXCLUDE
100-
)
101-
102-
if(CATKIN_ENABLE_TESTING)
103-
add_definitions(
104-
-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/test/data"
105-
)
106-
include_directories(test/data/)
107-
108-
file(GLOB oculus_test_SRCS test/unit/*cpp)
109-
110-
catkin_add_gtest(oculus_test ${oculus_test_SRCS})
111-
112-
target_link_libraries(
113-
oculus_test
114-
${catkin_LIBRARIES}
115-
liboculus
116-
Boost::system
117-
)
118-
endif()
32+
message(NOTICE "!! Performing ROS1 build !!")
33+
include(cmake/BuildROS1.cmake)
11934
else()
12035
message(
12136
"Unsure what sort of build to do. Not in a ROS1 or ROS2 environment"

README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
>
66
> January 2026
77
>
8-
> This is the primary, 'v3' [`main` branch](https://github.com/apl-ocean-engineering/liboculus), which replaces G3Log with [`spdlog`](https://github.com/gabime/spdlog) along with other changes under the good.
8+
> This is the [main/`v3` branch](https://github.com/apl-ocean-engineering/liboculus), which replaces G3Log with [`spdlog`](https://github.com/gabime/spdlog) along with other changes under the good.
99
>
1010
> The 'v2' branch of this liboculus; with a matching 'v2' branch for [oculus_sonar_driver](https://gitlab.com/apl-ocean-engineering/oculus_sonar_driver/-/commits/v2) includes a hybrid CMakeLists.txt which can build for ROS1, ROS2 or in a plain CMake environment. G3Log is still used as the main logger.
1111
>
@@ -39,17 +39,6 @@ This is a hybrid repository which builds in either ROS1 or ROS2, though there ar
3939

4040
We hope the code is still useful for others looking to talk to the Oculus.
4141

42-
> [!NOTE] [fips](http://floooh.github.io/fips/) support has been removed from this branch.
43-
44-
The primary dependency is on [g3log](https://github.com/KjellKod/g3log).
45-
* If using either ROS1 or ROS2, use the provided `liboculus.rosinstall` file:
46-
47-
```
48-
cd <catkin_ws>/src`; `vcs import --recursive --input liboculus/liboculus.repos
49-
```
50-
51-
The `main` branch of `g3log_ros` is also a ROS1-ROS2 hybrid.
52-
5342
The (optional) test suite also requires Googletest and the (also optional)
5443
binary `oc_client` requires [CLI11](https://github.com/CLIUtils/CLI11).
5544

@@ -68,6 +57,29 @@ make
6857

6958
Note the `CMakelists.txt` attempts to auto-detect ROS. Cmake build should be done in a session where ROS has not been loaded.
7059

60+
## Logging
61+
62+
> [!NOTE] [fips](http://floooh.github.io/fips/) support has been removed from this version.
63+
> [!NOTE] The dependency on [g3log](https://github.com/KjellKod/g3log) has been removed.
64+
65+
Internally the library uses [spdlog](https://github.com/gabime/spdlog). By default logger `"liboculus"` does not have any registered sinks and does not output to the console.
66+
67+
If the calling application uses spdlog, either the library's logger can be reset:
68+
69+
```
70+
liboculus::Logger::set_logger( spdlog::default_logger() );
71+
```
72+
73+
or a sink can be added to the library's logger:
74+
75+
```
76+
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt >(); liboculus::Logger::add_sink( stdout_sink );
77+
```
78+
79+
80+
81+
82+
7183
---
7284
## oc_client binary
7385

@@ -149,3 +161,7 @@ Other files/classes:
149161
This code is released under the [BSD 3-clause license](LICENSE).
150162

151163
This repository contains one file provided by Blueprint as part of their free "Oculus Viewer" sample application: ([include/liboculus/thirdparty/Oculus/Oculus.h](thirdpart/Oculus/Oculus.h)). It describes their protocol and data formats. This file is distributed under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html).
164+
165+
It includes the header-only version of [CLI11](https://github.com/CLIUtils/CLI11) at [`include/liboculus/thirdparty/CLI11/`](include/liboculus/thirdparty/CLI11/)
166+
167+
It includes the header-only version of TartanLlama's [`expected` implementation](https://github.com/TartanLlama/expected) at [`include/liboculus/thirdparty/expected.hpp`](include/liboculus/thirdparty/expected.hpp)

cmake/BuildNonROS.cmake

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Specify the minimum version for CMake
22
cmake_minimum_required(VERSION 3.8)
3-
4-
# Project's name
53
project(liboculus)
64

75
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native -Wl,--no-as-needed")
@@ -13,36 +11,18 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
1311
# ###########################################
1412
# The following folders will be included #
1513
# ###########################################
16-
include_directories(
17-
"${PROJECT_SOURCE_DIR}/include/"
18-
"${PROJECT_SOURCE_DIR}/thirdparty/"
19-
)
14+
include_directories("${PROJECT_SOURCE_DIR}/include/")
2015

2116
# Threading
2217
find_package(Threads)
18+
find_package(spdlog)
19+
find_package(fmt)
2320

2421
# Boost
2522
find_package(Boost 1.57 REQUIRED COMPONENTS system)
2623
include_directories(${Boost_INCLUDE_DIR})
2724
message("Boost_INCLUDE_DIR: " ${Boost_INCLUDE_DIR})
2825

29-
# Install g3log as an external package
30-
include(cmake/IncludeProject.cmake)
31-
32-
if(NOT GIT_TAG)
33-
set(GIT_TAG "2.6")
34-
endif()
35-
36-
include(ExternalProject)
37-
ExternalProject_Add(
38-
g3log
39-
GIT_REPOSITORY https://github.com/KjellKod/g3log
40-
GIT_TAG ${GIT_TAG}
41-
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/install/g3log"
42-
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
43-
)
44-
45-
ExternalProject_Get_Property(g3log install_dir)
4626
include_directories(${install_dir}/include/)
4727

4828
# #####################
@@ -53,13 +33,17 @@ link_directories(${Boost_LIBRARY_DIRS})
5333
# Create Library
5434
add_library(oculus SHARED ${oculus_SRCS})
5535
set_target_properties(oculus PROPERTIES LIBRARY_OUTPUT_NAME oculus)
36+
target_link_libraries(oculus PUBLIC fmt::fmt spdlog::spdlog)
37+
38+
add_executable(occlient ${PROJECT_SOURCE_DIR}/tools/oculus_client.cpp)
39+
target_link_libraries(occlient oculus)
5640

5741
# =============================================
5842
# to allow find_package()
5943
# =============================================
6044
#
6145
# The following is borrowed heavily from:
62-
# https://github.com/RossHartley/invariant-ekf
46+
# https://github.com/RossHartley/invariant-ekf
6347
# I am responsible for all mistakes
6448
#
6549
# the following case be used in an external project requiring oculus:
@@ -102,7 +86,7 @@ configure_file(
10286

10387
message("PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR})
10488

105-
# # 2- installation build #
89+
# 2- installation build #
10690

10791
# Change the include location for the case of an install location
10892
set(oculus_include_dirs ${CMAKE_INSTALL_PREFIX}/include ${EIGEN_INCLUDE_DIR})

cmake/BuildROS1.cmake

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Catkin/ROS1 section =====
2+
find_package(Boost REQUIRED COMPONENTS system)
3+
4+
catkin_package(
5+
INCLUDE_DIRS include
6+
LIBRARIES liboculus
7+
)
8+
9+
add_library(liboculus ${oculus_SRCS})
10+
11+
include_directories(liboculus include ${catkin_INCLUDE_DIRS})
12+
13+
target_link_libraries(liboculus ${catkin_LIBRARIES})
14+
15+
install(
16+
TARGETS liboculus
17+
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
18+
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
19+
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
20+
)
21+
22+
## Install headers
23+
install(
24+
DIRECTORY include/${PROJECT_NAME}/
25+
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
26+
FILES_MATCHING
27+
PATTERN "*.hpp"
28+
PATTERN "*.h"
29+
PATTERN ".git" EXCLUDE
30+
)
31+
32+
if(CATKIN_ENABLE_TESTING)
33+
add_definitions(-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/test/data")
34+
include_directories(test/data/)
35+
36+
file(GLOB oculus_test_SRCS test/unit/*cpp)
37+
38+
catkin_add_gtest(oculus_test ${oculus_test_SRCS})
39+
40+
target_link_libraries(
41+
oculus_test
42+
${catkin_LIBRARIES}
43+
liboculus
44+
Boost::system
45+
)
46+
endif()

cmake/BuildROS2.cmake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# == ament/ROS2 section =================================
2+
3+
find_package(ament_cmake REQUIRED)
4+
find_package(Boost REQUIRED COMPONENTS system)
5+
6+
add_library(oculus SHARED ${oculus_SRCS})
7+
target_link_libraries(oculus PUBLIC Boost::system)
8+
9+
target_include_directories(
10+
oculus
11+
PUBLIC
12+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
13+
"$<INSTALL_INTERFACE:include/>"
14+
)
15+
16+
install(
17+
TARGETS oculus
18+
EXPORT export_${PROJECT_NAME}
19+
ARCHIVE DESTINATION lib
20+
LIBRARY DESTINATION lib
21+
RUNTIME DESTINATION bin
22+
)
23+
24+
install(
25+
DIRECTORY include/
26+
DESTINATION include
27+
FILES_MATCHING
28+
PATTERN "*.hpp"
29+
PATTERN "*.h"
30+
PATTERN ".git" EXCLUDE
31+
)
32+
33+
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
34+
ament_export_libraries(oculus)
35+
36+
ament_package()

0 commit comments

Comments
 (0)