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

Fix gcc errors #14

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
ffcaaaa
Move LICENSE to root
Magolves Apr 20, 2021
96eccd0
Increased version to 3.15
Magolves Apr 20, 2021
541b513
Move test to separate directory
Magolves Apr 20, 2021
5584d03
Make all functions const noexcept
Magolves Apr 20, 2021
847be3a
Introduce templated print
Magolves Apr 20, 2021
8950bce
Add print for complex types, special template for string
Magolves Apr 20, 2021
07fcc68
Merge branch 'feature/replace-printf' into develop
Magolves Apr 20, 2021
3cbef23
Convert enum decoder_state into enum class
Magolves Apr 20, 2021
accdad3
Remove enum prefix and l'cased values
Magolves Apr 20, 2021
8ba4272
Merge branch 'feature/Refactor-state-enum' into develop
Magolves Apr 20, 2021
c953f30
Refactor _listener
Magolves Apr 20, 2021
4a15cce
Refactor _in
Magolves Apr 20, 2021
95d7d52
Refactor _state and _currentLength
Magolves Apr 20, 2021
c141513
Refactor _out
Magolves Apr 20, 2021
42bcb44
Refactor _bufer, _capacity and _offset
Magolves Apr 20, 2021
e95f3c5
Merge branch 'feature/remove-leading-underscore' into develop
Magolves Apr 20, 2021
6d11183
Make ctors with singl arg explicit
Magolves Apr 20, 2021
14f4414
Remove log.h
Magolves Apr 20, 2021
4e8524b
Create cmake.yml
Magolves Apr 20, 2021
d920c73
Merge pull request #1 from Magolves/develop
Magolves Apr 20, 2021
3dae8b4
Set C++ standard to 14, use cmake property for setting it
Magolves Apr 20, 2021
541d8fe
Export compile commands
Magolves Apr 20, 2021
87c722b
Merge branch 'feature/update-cmake' into develop
Magolves Apr 20, 2021
2d90bcd
Merge pull request #2 from Magolves/develop
Magolves Apr 20, 2021
c6e77a7
Fix template decl acc. to stackoverflow
Magolves Apr 20, 2021
5a9eae0
Merge pull request #3 from Magolves/develop
Magolves Apr 20, 2021
6552e1b
Fixed template decl
Magolves Apr 20, 2021
620e8fa
Merge pull request #4 from Magolves/develop
Magolves Apr 20, 2021
9830d10
Replace guard clauses with pragma once
Magolves Apr 21, 2021
f178e6f
Make listener shared pointer
Magolves Apr 22, 2021
5de7f03
Use value semantics for decode, remove unused members
Magolves Apr 22, 2021
ce45295
Merge branch 'feature/shared-ptr' into develop
Magolves Apr 22, 2021
522664d
Merge pull request #5 from Magolves/develop
Magolves Apr 22, 2021
554a5bf
Remove listener_ptr
Magolves Apr 22, 2021
608db33
Replace static/dynamic outpiut by common impl using a std::vector
Magolves Apr 22, 2021
6c738f4
Merge pull request #6 from Magolves/develop
Magolves Apr 22, 2021
b470058
unsigned char -> unit8_t
Magolves Apr 22, 2021
b44ac73
Use size_t
Magolves Apr 22, 2021
db4ccfc
Pass string as const ref
Magolves Apr 22, 2021
9138349
Pass string as const ref
Magolves Apr 22, 2021
5a81e29
Replace pointer with vector
Magolves Apr 22, 2021
287c39c
Replace pointer with vector
Magolves Apr 22, 2021
0f168df
Merge branch 'feature/std-int-types' into develop
Magolves Apr 22, 2021
376648f
Merge pull request #7 from Magolves/develop
Magolves Apr 22, 2021
f9b35fd
Add missing include, offset now size_t
Magolves Apr 22, 2021
5220768
Merge pull request #8 from Magolves/develop
Magolves Apr 22, 2021
68a19fb
Add string.h
Magolves Apr 22, 2021
05de94c
Merge pull request #9 from Magolves/develop
Magolves Apr 22, 2021
2928265
Add cmake badge
Magolves Apr 23, 2021
7647ebb
Merge pull request #10 from Magolves/develop
Magolves Apr 23, 2021
92c82fa
Add cmake badge (2nd try)
Magolves Apr 23, 2021
9bb017d
Add cmake badge (3rd try)
Magolves Apr 23, 2021
81c0c41
Add cmake badge (4th try)
Magolves Apr 23, 2021
78d11a1
Add cmake badge (5th try)
Magolves Apr 23, 2021
187bcd3
Remove obsolete badge
Magolves Apr 23, 2021
f98d18b
Merge pull request #11 from Magolves/develop
Magolves Apr 23, 2021
20a5c55
Add cmake files from cpp_start_project
Magolves Apr 23, 2021
d347423
Activated project settings and warnings
Magolves Apr 23, 2021
24e7ed4
Lower C++ standard to 14
Magolves Apr 23, 2021
742779e
Setup conan
Magolves Apr 23, 2021
19fe5d6
Remove test dir
Magolves Apr 23, 2021
7ba4b59
Add Catch2
Magolves Apr 23, 2021
7ec20ef
Fix compiler warnings; add catch2
Magolves Apr 23, 2021
b339d69
Merge branch 'feature/cmake-scripts' into develop
Magolves Apr 23, 2021
4a9a19e
Merge pull request #12 from Magolves/develop
Magolves Apr 23, 2021
18971fe
Add coann to workflow
Magolves Apr 23, 2021
a5c83e9
Merge pull request #13 from Magolves/develop
Magolves Apr 23, 2021
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
56 changes: 56 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CMake

on: [push]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Download Conan package manager.
run: |
pwd
pip3 install wheel setuptools
pip3 install conan
export PATH=$PATH:/home/runner/.local/bin
echo $PATH
conan --version
ls

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{github.workspace}}/build

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
working-directory: ${{github.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE

- name: Test
working-directory: ${{github.workspace}}/build
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea/
*.xcodeproj/
*.dSYM
test

38 changes: 29 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.15)
project(cborcpp)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include(cmake/StandardProjectSettings.cmake)

# Link this 'library' to set the c++ standard / compile-time options requested
add_library(project_options INTERFACE)
target_compile_features(project_options INTERFACE cxx_std_14)

# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
add_library(project_warnings INTERFACE)
# standard compiler warnings
include(cmake/CompilerWarnings.cmake)
set_project_warnings(project_warnings)

set(CMAKE_BUILD_TYPE Release)
set(EXPORT_COMPILE_COMMANDS ON)
option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)

# Set up some extra Conan dependencies based on our needs before loading Conan
set(CONAN_EXTRA_REQUIRES "")
set(CONAN_EXTRA_OPTIONS "")
include(cmake/Conan.cmake)
run_conan()


set(SOURCE_FILES
src/encoder.cpp
src/decoder.cpp
src/input.cpp
src/listener_debug.cpp
src/output_dynamic.cpp
src/output_static.cpp
)

set(TEST_SOURCE_FILES
src/tests.cpp
src/output.cpp
)

add_library(cborcpp SHARED ${SOURCE_FILES})
add_executable(testing ${SOURCE_FILES} ${TEST_SOURCE_FILES})
target_link_libraries(cborcpp INTERFACE project_options)
target_include_directories(cborcpp PUBLIC src)
set_property(TARGET cborcpp PROPERTY CXX_STANDARD 14)

enable_testing()
add_subdirectory(test)
File renamed without changes.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cbor-cpp

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/naphaso/cbor-cpp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

![cmake](https://github.com/Magolves/cbor-cpp/actions/workflows/cmake.yml/badge.svg)

CBOR C++ serialization library

Just a simple SAX-like Concise Binary Object Representation (CBOR).
Expand Down
29 changes: 29 additions & 0 deletions cmake/Cache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
option(ENABLE_CACHE "Enable cache if available" ON)
if(NOT ENABLE_CACHE)
return()
endif()

set(CACHE_OPTION
"ccache"
CACHE STRING "Compiler cache to be used")
set(CACHE_OPTION_VALUES "ccache" "sccache")
set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES})
list(
FIND
CACHE_OPTION_VALUES
${CACHE_OPTION}
CACHE_OPTION_INDEX)

if(${CACHE_OPTION_INDEX} EQUAL -1)
message(
STATUS
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}")
endif()

find_program(CACHE_BINARY ${CACHE_OPTION})
if(CACHE_BINARY)
message(STATUS "${CACHE_OPTION} found and enabled")
set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BINARY})
else()
message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it")
endif()
78 changes: 78 additions & 0 deletions cmake/CompilerWarnings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# from here:
#
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md

function(set_project_warnings project_name)
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)

set(MSVC_WARNINGS
/W4 # Baseline reasonable warnings
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
/w14263 # 'function': member function does not override any base class virtual member function
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not
# be destructed correctly
/w14287 # 'operator': unsigned/negative constant mismatch
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside
# the for-loop scope
/w14296 # 'operator': expression is always 'boolean_value'
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
/w14545 # expression before comma evaluates to a function which is missing an argument list
/w14546 # function call before comma missing argument list
/w14547 # 'operator': operator before comma has no effect; expected operator with side-effect
/w14549 # 'operator': operator before comma has no effect; did you intend 'operator'?
/w14555 # expression has no effect; expected expression with side- effect
/w14619 # pragma warning: there is no warning number 'number'
/w14640 # Enable warning on thread un-safe static member initialization
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior.
/w14905 # wide string literal cast to 'LPSTR'
/w14906 # string literal cast to 'LPWSTR'
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
/permissive- # standards conformance mode for MSVC compiler.
)

set(CLANG_WARNINGS
-Wall
-Wextra # reasonable and standard
-Wshadow # warn the user if a variable declaration shadows one from a parent context
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps
# catch hard to track down memory errors
-Wold-style-cast # warn for c-style casts
-Wcast-align # warn for potential performance problem casts
-Wunused # warn on anything being unused
-Woverloaded-virtual # warn if you overload (not override) a virtual function
-Wpedantic # warn if non-standard C++ is used
-Wconversion # warn on type conversions that may lose data
-Wsign-conversion # warn on sign conversions
-Wnull-dereference # warn if a null dereference is detected
-Wdouble-promotion # warn if float is implicit promoted to double
-Wformat=2 # warn on security issues around functions that format output (ie printf)
)

if(WARNINGS_AS_ERRORS)
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
endif()

set(GCC_WARNINGS
${CLANG_WARNINGS}
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
-Wduplicated-cond # warn if if / else chain has duplicated conditions
-Wduplicated-branches # warn if if / else branches have duplicated code
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted
-Wuseless-cast # warn if you perform a cast to the same type
)

if(MSVC)
set(PROJECT_WARNINGS ${MSVC_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(PROJECT_WARNINGS ${CLANG_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(PROJECT_WARNINGS ${GCC_WARNINGS})
else()
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
endif()

target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS})

endfunction()
29 changes: 29 additions & 0 deletions cmake/Conan.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
macro(run_conan)
# Download automatically, you can also just copy the conan.cmake file
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.15/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
endif()

include(${CMAKE_BINARY_DIR}/conan.cmake)

conan_add_remote(
NAME
bincrafters
URL
https://api.bintray.com/conan/bincrafters/public-conan)

conan_cmake_run(
REQUIRES
${CONAN_EXTRA_REQUIRES}
catch2/2.13.3
#docopt.cpp/0.6.2
#fmt/6.2.0
#spdlog/1.5.0
OPTIONS
${CONAN_EXTRA_OPTIONS}
BASIC_SETUP
CMAKE_TARGETS # individual targets to link to
BUILD
missing)
endmacro()
11 changes: 11 additions & 0 deletions cmake/Doxygen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function(enable_doxygen)
option(ENABLE_DOXYGEN "Enable doxygen doc builds of source" OFF)
if(ENABLE_DOXYGEN)
set(DOXYGEN_CALLER_GRAPH YES)
set(DOXYGEN_CALL_GRAPH YES)
set(DOXYGEN_EXTRACT_ALL YES)
find_package(Doxygen REQUIRED dot)
doxygen_add_docs(doxygen-docs ${PROJECT_SOURCE_DIR})

endif()
endfunction()
18 changes: 18 additions & 0 deletions cmake/PreventInSourceBuilds.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# This function will prevent in-source builds
function(AssureOutOfSourceBuilds)
# make sure the user doesn't play dirty with symlinks
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)

# disallow in-source builds
if("${srcdir}" STREQUAL "${bindir}")
message("######################################################")
message("Warning: in-source builds are disabled")
message("Please create a separate build directory and run cmake from there")
message("######################################################")
message(FATAL_ERROR "Quitting configuration")
endif()
endfunction()

assureoutofsourcebuilds()
66 changes: 66 additions & 0 deletions cmake/Sanitizers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
function(enable_sanitizers project_name)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE)

if(ENABLE_COVERAGE)
target_compile_options(${project_name} INTERFACE --coverage -O0 -g)
target_link_libraries(${project_name} INTERFACE --coverage)
endif()

set(SANITIZERS "")

option(ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" FALSE)
if(ENABLE_SANITIZER_ADDRESS)
list(APPEND SANITIZERS "address")
endif()

option(ENABLE_SANITIZER_LEAK "Enable leak sanitizer" FALSE)
if(ENABLE_SANITIZER_LEAK)
list(APPEND SANITIZERS "leak")
endif()

option(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "Enable undefined behavior sanitizer" FALSE)
if(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR)
list(APPEND SANITIZERS "undefined")
endif()

option(ENABLE_SANITIZER_THREAD "Enable thread sanitizer" FALSE)
if(ENABLE_SANITIZER_THREAD)
if("address" IN_LIST SANITIZERS OR "leak" IN_LIST SANITIZERS)
message(WARNING "Thread sanitizer does not work with Address and Leak sanitizer enabled")
else()
list(APPEND SANITIZERS "thread")
endif()
endif()

option(ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" FALSE)
if(ENABLE_SANITIZER_MEMORY AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
if("address" IN_LIST SANITIZERS
OR "thread" IN_LIST SANITIZERS
OR "leak" IN_LIST SANITIZERS)
message(WARNING "Memory sanitizer does not work with Address, Thread and Leak sanitizer enabled")
else()
list(APPEND SANITIZERS "memory")
endif()
endif()

list(
JOIN
SANITIZERS
","
LIST_OF_SANITIZERS)

endif()

if(LIST_OF_SANITIZERS)
if(NOT
"${LIST_OF_SANITIZERS}"
STREQUAL
"")
target_compile_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS})
target_link_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS})
endif()
endif()

endfunction()
24 changes: 24 additions & 0 deletions cmake/StandardProjectSettings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE
RelWithDebInfo
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui, ccmake
set_property(
CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS
"Debug"
"Release"
"MinSizeRel"
"RelWithDebInfo")
endif()

# Generate compile_commands.json to make it easier to work with clang based tools
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# On Mac OS 'CXX_STANDARD' is not evaluated
# Instead we have to set the compiler flag
if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif()
Loading