Skip to content

Commit 3c637dd

Browse files
authored
Add a primitive cmake build (#41)
1 parent bb38a2b commit 3c637dd

8 files changed

Lines changed: 362 additions & 128 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ on:
1010
jobs:
1111
industrial-ci:
1212
name: Run Industrial CI
13-
13+
runs-on: ubuntu-latest
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
ros_distro: ["noetic", "kilted", "rolling"]
17+
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}
1821

1922
steps:
2023
- name: Checkout repository
@@ -24,6 +27,4 @@ jobs:
2427

2528
- name: Run ROS Industrial CI
2629
uses: ros-industrial/industrial_ci@master
27-
environment:
28-
CI_ROS_DISTRO: ${{ matrix.ros_distro }}
29-
UPSTREAM_WORKSPACE: liboculus.repos
30+
env: ${{matrix.env}}

.github/workflows/ci_cmake.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: ROS Industrial CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
cmake:
12+
name: Build with CMake
13+
runs-on: ubuntu-24.04
14+
15+
steps:
16+
- name: Install dependencesi with awalsh128/cache-apt-pkgs-action
17+
uses: awalsh128/cache-apt-pkgs-action@latest
18+
with:
19+
packages: libboost-all-dev
20+
version: 1.0
21+
22+
- name: Checkout repository
23+
uses: actions/checkout@v5
24+
with:
25+
submodules: recursive
26+
27+
- name: Build Project
28+
uses: threeal/cmake-action@v2.1.0

CMakeLists.txt

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

4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
add_compile_options(-std=c++17)
7+
48
# == Code common to all builds =======================================
59
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
610

7-
# ROS build, determine which version...
8-
find_package(ros_environment REQUIRED)
9-
set(ROS_VERSION $ENV{ROS_VERSION})
10-
1111
set(oculus_SRCS
1212
lib/DataRx.cpp
1313
lib/SonarConfiguration.cpp
@@ -19,106 +19,110 @@ set(oculus_SRCS
1919
lib/IoServiceThread.cpp
2020
)
2121

22-
if(${ROS_VERSION} EQUAL 2)
23-
# == ament/ROS2 section =================================
24-
25-
find_package(ament_cmake REQUIRED)
26-
find_package(Boost REQUIRED COMPONENTS system)
27-
find_package(g3log_ros REQUIRED)
28-
29-
set(CMAKE_CXX_STANDARD 17)
30-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
31-
add_compile_options(-std=c++17)
32-
33-
add_library(oculus SHARED ${oculus_SRCS})
34-
35-
target_include_directories(
36-
oculus
37-
PUBLIC
38-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
39-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty>"
40-
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
41-
"$<INSTALL_INTERFACE:include/thirdparty>"
42-
)
43-
44-
target_link_libraries(oculus PUBLIC Boost::system g3log_ros::g3log)
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/${PROJECT_NAME} thirdparty
56-
DESTINATION include
57-
FILES_MATCHING
58-
PATTERN "*.hpp"
59-
PATTERN "*.h"
60-
PATTERN ".git" EXCLUDE
61-
)
62-
63-
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
64-
ament_export_libraries(oculus)
65-
66-
ament_package()
67-
elseif(${ROS_VERSION} EQUAL 1)
68-
# Catkin/ROS1 section =====
69-
find_package(catkin REQUIRED COMPONENTS g3log_ros)
70-
find_package(Boost REQUIRED COMPONENTS system)
71-
72-
catkin_package(
73-
CATKIN_DEPENDS g3log_ros
74-
INCLUDE_DIRS include thirdparty
75-
LIBRARIES liboculus
76-
)
77-
78-
add_compile_options(-std=c++14)
79-
80-
add_library(liboculus ${oculus_SRCS})
81-
82-
include_directories(liboculus include thirdparty ${catkin_INCLUDE_DIRS})
83-
84-
target_link_libraries(liboculus ${catkin_LIBRARIES})
85-
86-
install(
87-
TARGETS liboculus
88-
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
89-
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
90-
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
91-
)
92-
93-
## Install headers
94-
install(
95-
DIRECTORY include/${PROJECT_NAME}/ thirdparty/
96-
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
97-
FILES_MATCHING
98-
PATTERN "*.hpp"
99-
PATTERN "*.h"
100-
PATTERN ".git" EXCLUDE
101-
)
102-
103-
if(CATKIN_ENABLE_TESTING)
104-
add_definitions(
105-
-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/test/data"
22+
# ROS build, determine which version...
23+
# QUIET will squelch the warning if the package isn't found
24+
find_package(ros_environment QUIET)
25+
26+
if(${ros_environment_FOUND})
27+
set(ROS_VERSION $ENV{ROS_VERSION})
28+
29+
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+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty>"
44+
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
45+
"$<INSTALL_INTERFACE:include/thirdparty>"
46+
)
47+
48+
install(
49+
TARGETS oculus
50+
EXPORT export_${PROJECT_NAME}
51+
ARCHIVE DESTINATION lib
52+
LIBRARY DESTINATION lib
53+
RUNTIME DESTINATION bin
10654
)
107-
include_directories(test/data/)
10855

109-
file(GLOB oculus_test_SRCS test/unit/*cpp)
56+
install(
57+
DIRECTORY include/${PROJECT_NAME} thirdparty
58+
DESTINATION include
59+
FILES_MATCHING
60+
PATTERN "*.hpp"
61+
PATTERN "*.h"
62+
PATTERN ".git" EXCLUDE
63+
)
64+
65+
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
66+
ament_export_libraries(oculus)
67+
68+
ament_package()
69+
elseif(${ROS_VERSION} EQUAL 1)
70+
# Catkin/ROS1 section =====
71+
find_package(catkin REQUIRED COMPONENTS g3log_ros)
72+
find_package(Boost REQUIRED COMPONENTS system)
73+
74+
catkin_package(
75+
CATKIN_DEPENDS g3log_ros
76+
INCLUDE_DIRS include thirdparty
77+
LIBRARIES liboculus
78+
)
79+
80+
add_library(liboculus ${oculus_SRCS})
11081

111-
catkin_add_gtest(oculus_test ${oculus_test_SRCS})
82+
include_directories(liboculus include thirdparty ${catkin_INCLUDE_DIRS})
83+
84+
target_link_libraries(liboculus ${catkin_LIBRARIES})
85+
86+
install(
87+
TARGETS liboculus
88+
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
89+
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
90+
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
91+
)
92+
93+
## Install headers
94+
install(
95+
DIRECTORY include/${PROJECT_NAME}/ thirdparty/
96+
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
97+
FILES_MATCHING
98+
PATTERN "*.hpp"
99+
PATTERN "*.h"
100+
PATTERN ".git" EXCLUDE
101+
)
112102

113-
target_link_libraries(
114-
oculus_test
115-
${catkin_LIBRARIES}
116-
liboculus
117-
Boost::system
103+
if(CATKIN_ENABLE_TESTING)
104+
add_definitions(
105+
-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/test/data"
106+
)
107+
include_directories(test/data/)
108+
109+
file(GLOB oculus_test_SRCS test/unit/*cpp)
110+
111+
catkin_add_gtest(oculus_test ${oculus_test_SRCS})
112+
113+
target_link_libraries(
114+
oculus_test
115+
${catkin_LIBRARIES}
116+
liboculus
117+
Boost::system
118+
)
119+
endif()
120+
else()
121+
message(
122+
"Unsure what sort of build to do. Not in a ROS1 or ROS2 environment"
118123
)
119124
endif()
120125
else()
121-
message(
122-
"Unsure what sort of build to do. Not in a ROS1 or ROS2 environment"
123-
)
126+
message(NOTICE "!! Performing non-ROS build !!")
127+
include(cmake/BuildNonROS.cmake)
124128
endif()

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ This library contains code for:
1717
- Raw streams of binary packets.
1818
- **Note:** This repo includes scaffold code for reading `.oculus` files saved from the Blueprint GUI, but that format is proprietary and undocumented. **We cannot parse `.oculus` files!!**
1919

20-
This package is designed to build in both ROS1 (catkin) and ROS2 (colcon) environments, however it contains no ROS-specific code and could be integrated into other non-ROS environments with some work.
20+
This package is designed to build in both ROS1 (catkin) and ROS2 (colcon) environments, however it contains no ROS-specific code and could be integrated into other non-ROS environments with some work.
21+
22+
It also contains the options to build a "bare" library with `cmake`.
2123

2224
The library contains no special provisions for *saving* sonar data,
2325
but it's straightforward to write packets as a raw binary stream
@@ -48,6 +50,18 @@ binary `oc_client` requires [CLI11](https://github.com/CLIUtils/CLI11).
4850
Internally, the ethernet interface uses
4951
[Boost::asio](https://www.boost.org/doc/libs/1_66_0/doc/html/boost_asio.html).
5052

53+
## Build with cmake
54+
55+
This package can be built with the standard cmake process:
56+
57+
```
58+
mkdir build && cd build
59+
cmake ..
60+
make
61+
```
62+
63+
Note the `CMakelists.txt` attempts to auto-detect ROS. Cmake build should be done in a session where ROS has not been loaded.
64+
5165
---
5266
## oc_client binary
5367

0 commit comments

Comments
 (0)