Skip to content

Commit 35a9502

Browse files
committed
Removing the custom debug option for in favor of CMAKE_BUILD_TYPE arg. Added an option to enable the locale testing since it is platform specific and dependent
1 parent 5e1a8fc commit 35a9502

3 files changed

Lines changed: 32 additions & 23 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 3.16)
33
project(dbc VERSION 0.2.0 DESCRIPTION "C++ DBC Parser")
44

55
# -- PROJECT OPTIONS -- #
6-
option(DEBUG "use debug flag" NO)
76
option(DBC_ENABLE_TESTS "Enable Unittests" ON)
7+
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)
88
# Turn OFF, if you are using FetchContent to include it to your project
99
option(DBC_FETCH_CONTENT_INCLUSION "Include project with FetchContent_Declare in another project. In this case the headers and the cmake files are not needed, only the library" OFF)
1010
option(DBC_GENERATE_DOCS "Use doxygen if installed to generated documentation files" OFF)
@@ -45,22 +45,17 @@ set(GCC_COMPILE_FLAGS "-Wextra -Wall -Wfloat-equal -Wundef -Wshadow \
4545
-Waggregate-return -Wcast-qual -Wswitch-default -Wswitch-enum -Wconversion \
4646
-Wunreachable-code -Wformat=2 -Werror -Wuninitialized -Winit-self")
4747

48-
if(DEBUG)
49-
set(GCC_COMPILE_FLAGS ${GCC_COMPILE_FLAGS}" -g")
50-
else()
51-
set(GCC_COMPILE_FLAGS ${GCC_COMPILE_FLAGS}" -O2")
52-
endif()
53-
5448
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
5549

5650
# add where to find the source files
57-
# file(GLOB_RECURSE SOURCE ${PROJECT_SOURCE_DIR}/src/ *.cpp)
58-
list(APPEND SOURCE ${PROJECT_SOURCE_DIR}/src/utils.cpp
59-
${PROJECT_SOURCE_DIR}/src/message.cpp
60-
${PROJECT_SOURCE_DIR}/src/signal.cpp
61-
${PROJECT_SOURCE_DIR}/src/dbc.cpp)
51+
list(APPEND SOURCE_FILES
52+
${PROJECT_SOURCE_DIR}/src/utils.cpp
53+
${PROJECT_SOURCE_DIR}/src/message.cpp
54+
${PROJECT_SOURCE_DIR}/src/signal.cpp
55+
${PROJECT_SOURCE_DIR}/src/dbc.cpp
56+
)
6257

63-
set(HEADER_FILES
58+
list(APPEND HEADER_FILES
6459
${PROJECT_SOURCE_DIR}/include/libdbc/dbc.hpp
6560
${PROJECT_SOURCE_DIR}/include/libdbc/message.hpp
6661
${PROJECT_SOURCE_DIR}/include/libdbc/signal.hpp
@@ -77,7 +72,7 @@ if(DBC_GENERATE_DOCS)
7772
add_subdirectory(doc)
7873
endif()
7974

80-
add_library(${PROJECT_NAME} STATIC ${SOURCE})
75+
add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
8176
target_link_libraries(${PROJECT_NAME} FastFloat::fast_float)
8277
target_include_directories(${PROJECT_NAME} PUBLIC
8378
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>

‎README.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ from the python dbc library here: https://pypi.org/project/cantools/
77
## Building
88

99
I am using Cmake to be able to build the tests and the lib. I plan on doing more with it but this is what it
10-
is for now. I am doing developement on the WSL Ubuntu 18.04 kernel. This doesn't mean that IDEs aren't
10+
is for now. This doesn't mean that IDEs aren't
1111
welcome but the build process might not be suited for this. You will need to modify it for your
1212
needs. Feel free to submit changes so the building process will be more robust.
1313

1414
Here are the steps to get started:
1515
```bash
16+
# Release Build
1617
cmake -DCMAKE_BUILD_TYPE=Release -Bbuild -H.
18+
19+
# Debug Build
20+
cmake -DCMAKE_BUILD_TYPE=Debug -Bbuild -H.
21+
22+
# Run the build
1723
cmake --build build
1824
```
1925

@@ -35,6 +41,10 @@ cmake -LAH ..
3541
I am trying to always make sure that this is very well tested code. I am using Catch2 to do this
3642
testing and if you aren't familiar here is the documentation: https://github.com/catchorg/Catch2/blob/master/docs/Readme.md#top
3743

44+
There is one option you will want for testing: `DBC_TEST_LOCALE_INDEPENDENCE`. This requires the `de_DE.UTF-8` locale installed to test. It is for checking we don't rely on locale to convert floats. i.e. 1.23 vs 1,23
45+
46+
You will need to configure the project to enable this: `cmake -DCMAKE_BUILD_TYPE=Release -DDBC_TEST_LOCALE_INDEPENDENCE=ON -Bbuild -H.`. You will get a warning if it isn't enabled because it isn't enabled by default.
47+
3848
To run the tests locally you can use the following. Assuming you have built the project you should get a test executable.
3949
```bash
4050
ctest --output-on-failure --test-dir build

‎test/CMakeLists.txt‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ catch_discover_tests(dbcParserTests)
2525

2626
# We want a seperate binary for this test. We setup global locals which mess with all of the testing.
2727
# Opting for a sperate test running so we don't conflict
28-
add_executable(dbcLocaleTests
29-
locale_testing/test_locale_main.cpp
30-
common.cpp
31-
)
28+
if(DBC_TEST_LOCALE_INDEPENDENCE)
29+
add_executable(dbcLocaleTests
30+
locale_testing/test_locale_main.cpp
31+
common.cpp
32+
)
3233

33-
target_compile_definitions(dbcLocaleTests PRIVATE TESTDBCFILES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/dbcs")
34-
target_link_libraries(dbcLocaleTests PRIVATE dbc Catch2::Catch2WithMain)
35-
target_include_directories(dbcLocaleTests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
34+
target_compile_definitions(dbcLocaleTests PRIVATE TESTDBCFILES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/dbcs")
35+
target_link_libraries(dbcLocaleTests PRIVATE dbc Catch2::Catch2WithMain)
36+
target_include_directories(dbcLocaleTests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
3637

37-
catch_discover_tests(dbcLocaleTests)
38+
catch_discover_tests(dbcLocaleTests)
39+
else()
40+
message(WARNING "Locale independent testing is turned off!")
41+
endif()

0 commit comments

Comments
 (0)