Skip to content

Commit 74b2750

Browse files
committed
Adding warnings and errors for each compiler and fixing code based on those. Removed option DBC_GENERATE_PKGCONFIG
1 parent 5a7a226 commit 74b2750

6 files changed

Lines changed: 37 additions & 19 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ project(dbc
88
# -- PROJECT OPTIONS -- #
99
option(DBC_ENABLE_TESTS "Enable Unittests" ON)
1010
option(DBC_TEST_LOCALE_INDEPENDENCE "Used to deterime if the libary is locale agnostic when it comes to converting floats. You need `de_DE.UTF-8` locale installed for this testing." OFF)
11-
# Turn OFF, if you are using FetchContent to include it to your project
12-
option(DBC_GENERATE_PKGCONFIG "Include project with FetchContent_Declare in another project. In this case the headers and the cmake files are not needed, only the library" OFF)
1311
option(DBC_GENERATE_DOCS "Use doxygen if installed to generated documentation files" OFF)
1412
# ---------------------- #
1513

@@ -65,36 +63,42 @@ if(DBC_GENERATE_DOCS)
6563
add_subdirectory(doc)
6664
endif()
6765

66+
if (MSVC)
67+
add_compile_options(/W4 /WX)
68+
else()
69+
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
70+
endif()
71+
6872
add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
6973
target_link_libraries(${PROJECT_NAME} FastFloat::fast_float)
7074
target_include_directories(${PROJECT_NAME} PUBLIC
7175
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
7276
$<INSTALL_INTERFACE:include>
7377
)
78+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
7479

7580
target_sources(${PROJECT_NAME} INTERFACE FILE_SET HEADERS
7681
TYPE HEADERS
7782
BASE_DIRS ${PROJECT_SOURCE_DIR}/include/libdbc
78-
FILES ${HEADER_FILES})
83+
FILES ${HEADER_FILES}
84+
)
7985

8086
add_custom_target(release
8187
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
8288
COMMAND ${CMAKE_SOURCE_DIR}/scripts/create_single_header.sh
83-
DEPENDS ${PROJECT_NAME})
89+
DEPENDS ${PROJECT_NAME}
90+
)
8491

8592
## Installation
8693
# install lib
8794
install(TARGETS ${PROJECT_NAME}
8895
DESTINATION ${CMAKE_INSTALL_LIBDIR})
8996

9097
# install headers
91-
nstall(DIRECTORY ${PROJECT_SOURCE_DIR}/include/libdbc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
92-
98+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/libdbc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
9399

94-
if (NOT DBC_GENERATE_PKGCONFIG)
95-
# Generate pkg-config file
96-
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
97-
install(
98-
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
99-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
100-
endif()
100+
# Generate pkg-config file
101+
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
102+
install(
103+
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
104+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

‎include/libdbc/message.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace libdbc {
1111
struct Message {
1212
Message() = delete;
13+
virtual ~Message() = default;
1314
explicit Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node);
1415

1516
enum class ParseSignalsStatus {

‎include/libdbc/signal.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct Signal {
2929
std::vector<SignalValueDescriptions> svDescriptions;
3030

3131
Signal() = delete;
32+
virtual ~Signal() = default;
3233
explicit Signal(std::string name,
3334
bool is_multiplexed,
3435
uint32_t start_bit,

‎test/CMakeLists.txt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ FetchContent_Declare(
1010
FetchContent_MakeAvailable(Catch2)
1111
include(Catch)
1212

13+
if (MSVC)
14+
add_compile_options(/W4 /WX)
15+
else()
16+
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
17+
endif()
18+
19+
# Code coverage compiler specific
20+
if (GCC)
21+
add_compile_options(--coverage)
22+
endif()
23+
1324
add_executable(dbcParserTests
1425
test_dbc.cpp
1526
test_utils.cpp

‎test/test_dbc.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <catch2/catch_test_macros.hpp>
55
#include <catch2/matchers/catch_matchers.hpp>
66
#include <libdbc/dbc.hpp>
7+
#include <string>
78

89
TEST_CASE("Testing dbc file loading error issues", "[fileio][error]") {
910
auto parser = std::unique_ptr<libdbc::DbcParser>(new libdbc::DbcParser());
@@ -28,10 +29,10 @@ TEST_CASE("Testing dbc file loading error issues", "[fileio][error]") {
2829

2930
SECTION("Verify that what() method is accessible for all exceptions", "[error]") {
3031
auto generic_error = libdbc::exception();
31-
REQUIRE(generic_error.what() == "libdbc exception occurred");
32+
REQUIRE(std::string{generic_error.what()} == "libdbc exception occurred");
3233

3334
auto validity_check = libdbc::validity_error();
34-
REQUIRE(validity_check.what() == "Invalid DBC file");
35+
REQUIRE(std::string{validity_check.what()} == "Invalid DBC file");
3536
}
3637
}
3738

‎test/test_parseMessage.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BO_ 123 MSG2: 8 Vector__XXX
2424

2525
parser.parse_file(filename);
2626

27-
SECTION("Evaluating unknown message id") {
27+
SECTION("Evaluating unknown` message id") {
2828
std::vector<double> out_values;
2929
CHECK(parser.parseMessage(578, std::vector<uint8_t>({0xFF, 0xA2}), out_values) == libdbc::Message::ParseSignalsStatus::ErrorUnknownID);
3030
}
@@ -54,7 +54,7 @@ TEST_CASE("Parse Message Big Number not aligned little endian") {
5454
std::vector<double> refData{2, 0, 0, 1, 0, 0, 0};
5555
CHECK(refData.size() == 7);
5656
CHECK(out_values.size() == refData.size());
57-
for (int i = 0; i < refData.size(); i++) {
57+
for (size_t i = 0; i < refData.size(); i++) {
5858
CHECK(out_values.at(i) == refData.at(i));
5959
}
6060
}
@@ -65,7 +65,7 @@ TEST_CASE("Parse Message Big Number not aligned little endian") {
6565
std::vector<double> refData{3, 32, 0, 1, 0, 0, 47};
6666
CHECK(refData.size() == 7);
6767
CHECK(out_values.size() == refData.size());
68-
for (int i = 0; i < refData.size(); i++) {
68+
for (size_t i = 0; i < refData.size(); i++) {
6969
CHECK(out_values.at(i) == refData.at(i));
7070
}
7171
}
@@ -76,7 +76,7 @@ TEST_CASE("Parse Message Big Number not aligned little endian") {
7676
std::vector<double> refData{3, 51, 0, 1, 0, 0, 57};
7777
CHECK(refData.size() == 7);
7878
CHECK(out_values.size() == refData.size());
79-
for (int i = 0; i < refData.size(); i++) {
79+
for (size_t i = 0; i < refData.size(); i++) {
8080
CHECK(out_values.at(i) == refData.at(i));
8181
}
8282
}

0 commit comments

Comments
 (0)