Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code style #71

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ jobs:
- name: Build
run: cmake --build out/build --parallel --config ${{ env.BUILD_TYPE }}

- name: Inspect build outputs
if: env.OPERATING_SYSTEM == 'linux'
run: |
ls -lh out/build/bin/*
(cd out/build/bin/* && for f in *; do echo $f; objdump -p $f | grep -P 'RUNPATH|RPATH' || true; done)

- name: Unit Tests
run: ctest --test-dir out/build --build-config ${{ env.BUILD_TYPE }} --output-on-failure

Expand Down Expand Up @@ -103,7 +109,7 @@ jobs:
sudo apt-get install -y clang-format

- name: Check code formatting
run: find src examples \( -name '*.cpp' -o -name '*.hpp' \) -exec clang-format -Werror --style=file -n {} + || (echo "Clang-format failed! See the README if you don't know how to fix this." && exit 1)
run: find include src examples \( -name '*.cpp' -o -name '*.hpp' \) -exec clang-format -Werror --style=file -n {} + || (echo "Clang-format failed! See the README if you don't know how to fix this." && exit 1)

# =========================================================
# Editor Config Job
Expand All @@ -122,7 +128,7 @@ jobs:
run: find . \( -name 'CMakeLists.txt' \) -exec editorconfig-checker {} \+ || { echo "EditorConfig check failed! See the README if you don't know how to fix this."; exit 1; }

- name: Check C++ formatting
run: find src examples \( -name '*.cpp' -o -name '*.hpp' \) -exec editorconfig-checker {} \+ || { echo "EditorConfig check failed! See the README if you don't know how to fix this."; exit 1; }
run: find include src examples \( -name '*.cpp' -o -name '*.hpp' \) -exec editorconfig-checker {} \+ || { echo "EditorConfig check failed! See the README if you don't know how to fix this."; exit 1; }

# =========================================================
# Clang Tidy Job
Expand Down Expand Up @@ -185,10 +191,10 @@ jobs:
- name: Generate HTML code coverage reports
run: |
mkdir out/build/code-coverage
gcovr -r ./src/ ./out/build/ --exclude='.*/test/.*' --exclude='.*/dynamic_library/.*' --exclude='.*/version.h' --html --html-details -o ./out/build/code-coverage/index.html
gcovr -r ./src/ ./out/build/ --exclude='.*/test/.*' --exclude='.*/version.h' --html --html-details -o ./out/build/code-coverage/index.html

- name: Coverage visualization in pipeline summary
run: gcovr -r ./src/ ./out/build/ --exclude='.*/test/.*' --exclude='.*/dynamic_library/.*' --exclude='.*/version.h' --exclude-unreachable-branches --print-summary -o ./out/build/coverage.xml
run: gcovr -r ./src/ ./out/build/ --exclude='.*/test/.*' --exclude='.*/version.h' --exclude-unreachable-branches --print-summary -o ./out/build/coverage.xml

- name: Upload Artifacts
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ bin/
venv/
CMakeSettings.json
CMakeUserPresets.json
/src/version.h
/include/novatel_edie/version.h
edie.*.log
edie.log
160 changes: 47 additions & 113 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,144 +1,78 @@
cmake_minimum_required(VERSION 3.15)
include(cmake/ThirdParty.cmake)
project(novatel_edie VERSION 3.3.7 LANGUAGES CXX)

option(BUILD_TESTS "Build tests" ON)
option(BUILD_EXAMPLES "Build examples" ON)
option(CMAKE_POSITION_INDEPENDENT_CODE "Set -fPIC" ON)
option(WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
option(COVERAGE "Coverage" OFF)
option(USE_STATIC_LIBS "Statically link dependencies" OFF)

if(USE_STATIC_LIBS)
# Set Conan statically link dependencies
unset(CONAN_INSTALL_ARGS CACHE)
set(CONAN_OPTIONS -o spdlog/*:shared=False -o fmt/*:shared=False)
else()
# Set Conan dynamically link dependencies
unset(CONAN_INSTALL_ARGS CACHE)
set(CONAN_OPTIONS -o spdlog/*:shared=True -o fmt/*:shared=True)
endif()

include(cmake/third_party.cmake)
project(novatel-edie VERSION 3.3.7 LANGUAGES CXX)

if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

# Check platforms
if(CMAKE_HOST_WIN32)
set(WINDOWS 1)
cmake_host_system_information(RESULT OS_NAME QUERY OS_NAME)
set(DISTRIB_NAME ${OS_NAME})
elseif(CMAKE_HOST_UNIX)
set(LINUX 1)
cmake_host_system_information(RESULT DISTRIB_NAME QUERY DISTRIB_NAME)
cmake_host_system_information(RESULT DISTRIB_VERSION_ID QUERY DISTRIB_VERSION_ID)
set(DISTRIB_NAME "${DISTRIB_NAME}-${DISTRIB_VERSION_ID}")
else()
message(WARNING "Unable to identify OS. Update script to support distribution or OS")
endif()

if(MSVC)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
# shared spdlog requires MultiThreadedDLL
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
add_definitions(-DWIN32 -D_WINDOWS)
add_compile_options(/W4 /GR /EHsc /utf-8 /wd4244 /wd4996)
add_compile_options("$<$<CONFIG:Release>:/Ox;/Ob2>")
if(WARNINGS_AS_ERRORS)
add_compile_options(/WX)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$")
add_compile_options(-Wall -Wextra -pedantic)
add_compile_options("$<$<CONFIG:Release>:-O3>")

if(WINDOWS)
# TODO: we shouldn't have to do this, something is bloating an object file
add_compile_options($<$<CONFIG:Debug>:-O1>)
endif()
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wno-format-truncation)
endif()

if(WARNINGS_AS_ERRORS)
add_compile_options(-Werror)
endif()

if(COVERAGE)
message("Coverage is On")
add_compile_options(--coverage)
add_link_options(--coverage)
endif()
else()
message(WARNING "Unable to identify compiler.")
endif()
include(GNUInstallDirs)
include(cmake/SetDefaultProfile.cmake)
include(cmake/CompilerOptions.cmake)
include(cmake/Utils.cmake)
# For custom Find*.cmake modules
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")

# Output all binaries in the same directory for easier testing
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
string(TOLOWER ${CMAKE_SYSTEM_NAME} OPERATING_SYSTEM)
string(TOLOWER ${CMAKE_CXX_COMPILER_ID} COMPILER)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${BUILD_TYPE} "${CMAKE_BINARY_DIR}/bin/${OPERATING_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR}-${COMPILER}-${CMAKE_BUILD_TYPE}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${BUILD_TYPE} "${CMAKE_BINARY_DIR}/bin/${OPERATING_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR}-${COMPILER}-${CMAKE_BUILD_TYPE}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${BUILD_TYPE} "${CMAKE_BINARY_DIR}/bin/${OPERATING_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR}-${COMPILER}-${CMAKE_BUILD_TYPE}")
set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin/${OPERATING_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR}-${COMPILER}-${CMAKE_BUILD_TYPE}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${BUILD_TYPE} "${OUTPUT_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${BUILD_TYPE} "${OUTPUT_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${BUILD_TYPE} "${OUTPUT_DIR}")

# Find Git package, if not need to install manually or through .yml file
find_package(Git)
if(NOT Git_FOUND)
message(FATAL_ERROR "Git was not found. Install Git and make sure it is in your PATH.")
endif()
# Look for shared libs in the same directory as the executable when running tests
set(CMAKE_BUILD_RPATH "\$ORIGIN")

find_package(Git REQUIRED)
if(NOT DEFINED GIT_BRANCH)
set(GIT_BRANCH "main")
endif()

# Build version of EDIE through cmake
if(GIT_EXECUTABLE)
execute_process(COMMAND ${CMAKE_COMMAND}
-D SRC=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
-D DST=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
-D GIT_BRANCH=${GIT_BRANCH}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateVersionHeader.cmake)
endif()

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src
)
execute_process(COMMAND ${CMAKE_COMMAND}
-D SRC=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
-D DST=${CMAKE_CURRENT_SOURCE_DIR}/include/novatel_edie/version.h
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
-D GIT_BRANCH=${GIT_BRANCH}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateVersionHeader.cmake)

# Build EDIE components
add_subdirectory(src/hw_interface)
add_subdirectory(src/decoders)
add_subdirectory(src/common)
add_subdirectory(src/stream_interface)
add_subdirectory(src/decoders/common)
add_subdirectory(src/decoders/oem)

# Add an aggregate target for all components
add_library(novatel_edie INTERFACE)
add_library(novatel_edie::novatel_edie ALIAS novatel_edie)
target_link_libraries(novatel_edie INTERFACE
common
stream_interface
decoders_common
oem_decoder
)

if(BUILD_TESTS)
enable_testing()
add_subdirectory(src/common/test)
add_subdirectory(src/stream_interface/test)
add_subdirectory(src/decoders/common/test)
add_subdirectory(src/decoders/novatel/test)
add_subdirectory(src/hw_interface/stream_interface/test)
add_subdirectory(src/decoders/oem/test)
endif()

if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if(WIN32)
# Copy third-party DLLs to the build directory for tests
copy_third_party_dlls()
# Copy C++ runtime DLL for non-MSVC compilers
if(NOT MSVC)
if(NOT EXISTS CMAKE_CXX_COMPILER)
find_program(CXX_COMPILER_PATH NAMES "${CMAKE_CXX_COMPILER}")
else()
set(CXX_COMPILER_PATH "${CMAKE_CXX_COMPILER}")
endif()
get_filename_component(COMPILER_BIN_DIR "${CXX_COMPILER_PATH}" DIRECTORY)
foreach(stdcpp_library libstdc++-6.dll libc++.dll)
if(EXISTS "${COMPILER_BIN_DIR}/${stdcpp_library}")
file(COPY "${COMPILER_BIN_DIR}/${stdcpp_library}" DESTINATION "${CMAKE_BINARY_DIR}/bin/${OPERATING_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR}-${COMPILER}-${CMAKE_BUILD_TYPE}")
endif()
endforeach()
endif()
endif()
# Copy shared libs to the build output directory for tests
copy_cpp_runtime_dlls("${OUTPUT_DIR}")
copy_third_party_shared_libs("${OUTPUT_DIR}")

# Install
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES database/messages_public.json DESTINATION ${CMAKE_INSTALL_DATADIR}/novatel_edie)
install_novatel_edie_cmake_config()
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ The FileParser class provides an interface for parsing GPS files.
```cpp
#include <iostream>

#include "decoders/novatel/api/fileparser.hpp"
#include <novatel_edie/decoders/oem/fileparser.hpp>

using namespace novatel::edie;
using namespace novatel::edie::oem;
Expand Down Expand Up @@ -209,7 +209,7 @@ Note that all fields must be provided in the abbreviated ASCII string command in
```cpp
#include <iostream>

#include "decoders/novatel/api/commander.hpp"
#include <novatel_edie/decoders/oem/commander.hpp>

using namespace novatel::edie;
using namespace novatel::edie::oem;
Expand Down
32 changes: 32 additions & 0 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
if(MSVC)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_definitions(-DWIN32 -D_WINDOWS)
add_compile_options(/W4 /GR /EHsc /utf-8 /wd4244 /wd4996)
add_compile_options("$<$<CONFIG:Release>:/Ox;/Ob2>")
if(WARNINGS_AS_ERRORS)
add_compile_options(/WX)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$")
add_compile_options(-Wall -Wextra -pedantic)
add_compile_options("$<$<CONFIG:Release>:-O3>")

if(CMAKE_HOST_WIN32)
add_compile_options($<$<CONFIG:Debug>:-Wa,-mbig-obj>)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wno-format-truncation)
endif()

if(WARNINGS_AS_ERRORS)
add_compile_options(-Werror)
endif()

if(COVERAGE)
message("Coverage is On")
add_compile_options(--coverage)
add_link_options(--coverage)
endif()
else()
message(WARNING "Unable to identify compiler.")
endif()
13 changes: 13 additions & 0 deletions cmake/SetDefaultProfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(MSVC AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
65 changes: 65 additions & 0 deletions cmake/ThirdParty.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
include(CMakeDependentOption)

if(CMAKE_TOOLCHAIN_FILE MATCHES "conan_toolchain.cmake")
set(CONAN_ALREADY_ACTIVE 1)
endif()

cmake_dependent_option(USE_CONAN "Use Conan to automatically manage dependencies" ON
"NOT DEFINED VCPKG_TOOLCHAIN AND NOT CONAN_ALREADY_ACTIVE" OFF)

if(USE_CONAN)
if(CMAKE_VERSION VERSION_LESS 3.24)
message(FATAL_ERROR "Automatic Conan integration requires CMake 3.24 or later.")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/SetDefaultProfile.cmake")
list(APPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/conan_provider.cmake)
endif()

# Copy third-party shared libs to the build directory for tests
function(copy_third_party_shared_libs target_dir)
if(USE_CONAN)
get_property(conan_generators_folder GLOBAL PROPERTY CONAN_GENERATORS_FOLDER)
include("${conan_generators_folder}/conan_runtime_paths.cmake")
endif()
if(NOT DEFINED CONAN_RUNTIME_LIB_DIRS)
if(USE_CONAN)
message(FATAL_ERROR "Failed to load CONAN_RUNTIME_LIB_DIRS")
endif()
# TODO: Add support for vcpkg
message(STATUS "Not using Conan, skipping copying third-party shared libraries.")
return()
endif()

message(STATUS "Copying third-party shared libraries to ${target_dir}...")

if(WIN32)
set(pattern "*.dll")
elseif(APPLE)
set(pattern "*.dylib")
else()
set(pattern "*.so*")
endif()

set(copied_files)
foreach(path ${CONAN_RUNTIME_LIB_DIRS})
message(STATUS "Copying shared libraries from ${path}")
file(GLOB libs "${path}/${pattern}")
file(COPY ${libs} DESTINATION "${target_dir}")
list(APPEND copied_files ${libs})
endforeach()

# Set RPATH to $ORIGIN for the copied libraries
if(NOT WIN32)
find_program(PATCHELF_EXECUTABLE patchelf REQUIRED)
foreach(lib ${copied_files})
get_filename_component(lib_name ${lib} NAME)
if(APPLE)
execute_process(COMMAND install_name_tool -add_rpath @loader_path "${target_dir}/${lib_name}"
COMMAND_ERROR_IS_FATAL ANY)
else()
execute_process(COMMAND "${PATCHELF_EXECUTABLE}" --set-rpath \$ORIGIN "${target_dir}/${lib_name}"
COMMAND_ERROR_IS_FATAL ANY)
endif()
endforeach()
endif()
endfunction()
Loading
Loading