Skip to content

Commit 0cd3448

Browse files
authored
Add C++ skeleton (#4)
1 parent 1d814bc commit 0cd3448

19 files changed

+2561
-0
lines changed

cpp/.clang-format

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
Language: Cpp
3+
Standard: Cpp11
4+
BasedOnStyle: Google
5+
6+
AccessModifierOffset: -2
7+
TabWidth: 2
8+
UseTab: Never
9+
BreakConstructorInitializers: BeforeComma
10+
ColumnLimit: 100
11+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
12+
DerivePointerAlignment: false
13+
FixNamespaceComments: true
14+
PointerAlignment: Left
15+
ReflowComments: true
16+
SortIncludes: true
17+
...

cpp/.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
build/
3+
*.profdata
4+
*.profraw
5+
.vs
6+
.vscode
7+
CMakeCache.txt
8+
CMakeFiles/
9+
CMakeSettings.json

cpp/CMakeLists.txt

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(foxsocketpp LANGUAGES CXX)
3+
set(CMAKE_CXX_STANDARD 17)
4+
set(CMAKE_CXX_STANDARD_REQUIRED on)
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
7+
option(WERROR "Add -Werror flag to build (turns warnings into errors)" ON)
8+
9+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
10+
11+
if(CONAN_EXPORTED) # in conan local cache
12+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
13+
conan_basic_setup()
14+
else() # in user space
15+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/conan.cmake)
16+
conan_cmake_run(CONANFILE conanfile.py
17+
BASIC_SETUP
18+
CMAKE_TARGETS
19+
BUILD missing)
20+
endif()
21+
22+
if(NOT CMAKE_BUILD_TYPE)
23+
set(CMAKE_BUILD_TYPE Debug)
24+
endif()
25+
26+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
27+
set(OPTIMIZATION_FLAGS "-DDEBUG")
28+
if(NOT MSVC)
29+
set(OPTIMIZATION_FLAGS "${OPTIMIZATION_FLAGS} -O0")
30+
endif()
31+
message("-- Configuring debug build")
32+
else()
33+
if(MSVC)
34+
set(OPTIMIZATION_FLAGS "-DNDEBUG -O2 -Zi")
35+
else()
36+
set(OPTIMIZATION_FLAGS "-DNDEBUG -g")
37+
endif()
38+
message("-- Configuring release build")
39+
endif()
40+
41+
if(MSVC)
42+
set(DESIRED_WARNINGS "-WX")
43+
else()
44+
set(DESIRED_WARNINGS "-Wall -Wextra -Wconversion -Wunreachable-code -Wuninitialized -pedantic-errors -Wold-style-cast -Wno-error=unused-variable -Wshadow -Wfloat-equal")
45+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
46+
set(DESIRED_WARNINGS "${DESIRED_WARNINGS} -Wmost")
47+
endif()
48+
if (WERROR)
49+
set(DESIRED_WARNINGS "${DESIRED_WARNINGS} -Werror")
50+
endif()
51+
endif()
52+
53+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS} ${DESIRED_WARNINGS}")
54+
55+
include_directories("${PROJECT_SOURCE_DIR}/include")
56+
57+
add_executable(foxsocketpp src/main.cpp src/foxsocketpp.cpp src/rosmsg.cpp)
58+
target_link_libraries(foxsocketpp CONAN_PKG::nlohmann_json CONAN_PKG::websocketpp)
59+
60+
file(GLOB TEST_SOURCES test/*.cpp src/rosmsg.cpp)
61+
add_executable(unit-tests ${TEST_SOURCES})
62+
target_link_libraries(unit-tests CONAN_PKG::catch2)

cpp/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Foxglove Technologies Inc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

cpp/Makefile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Whether to turn compiler warnings into errors
2+
export WERROR ?= true
3+
export BUILD_DIR ?= build
4+
5+
default: release
6+
7+
.PHONY: release
8+
release:
9+
mkdir -p ./$(BUILD_DIR) && cd ./$(BUILD_DIR) && cmake ../ -DCMAKE_BUILD_TYPE=Release -DWERROR=$(WERROR) && VERBOSE=1 cmake --build .
10+
11+
.PHONY: debug
12+
debug:
13+
mkdir -p ./$(BUILD_DIR) && cd ./$(BUILD_DIR) && cmake ../ -DCMAKE_BUILD_TYPE=Debug -DWERROR=$(WERROR) && VERBOSE=1 cmake --build .
14+
15+
.PHONY: test
16+
test:
17+
@if [ -f ./$(BUILD_DIR)/bin/unit-tests ]; then ./$(BUILD_DIR)/bin/unit-tests; else echo "Please run 'make release' or 'make debug' first" && exit 1; fi
18+
19+
.PHONY: coverage
20+
coverage:
21+
./scripts/coverage.sh
22+
23+
.PHONY: clean
24+
clean:
25+
rm -rf ./$(BUILD_DIR)
26+
# remove remains from running 'make coverage'
27+
rm -f *.profraw
28+
rm -f *.profdata
29+
30+
.PHONY: format
31+
format:
32+
./scripts/format.sh

cpp/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# C++ implementation of the Foxglove WebSocket protocol
2+
3+
## Instructions
4+
5+
- Install [conan](https://docs.conan.io/en/latest/installation.html) (ex: `pip install conan`, `brew install conan`)
6+
- Run `make`
7+
- Run `./build/bin/foxsocketpp`

0 commit comments

Comments
 (0)