Skip to content

Commit

Permalink
Merge pull request #43 from boschglobal/fix/cmocka-dependency
Browse files Browse the repository at this point in the history
Fix build problems in absence of cmocka
  • Loading branch information
nayakned authored Sep 19, 2024
2 parents f9a6623 + 42db405 commit debe4e5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
37 changes: 21 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,27 @@ target_link_libraries(hello-world-listener open1722 open1722examples)

enable_testing()

# find_package(cmocka 1.1.0 REQUIRED)

list(APPEND TEST_TARGETS test-aaf)
list(APPEND TEST_TARGETS test-avtp)
list(APPEND TEST_TARGETS test-can)
list(APPEND TEST_TARGETS test-crf)
list(APPEND TEST_TARGETS test-cvf)
list(APPEND TEST_TARGETS test-rvf)
# list(APPEND TEST_TARGETS test-stream)

foreach(TEST_TARGET IN LISTS TEST_TARGETS)
add_executable(${TEST_TARGET} "unit/${TEST_TARGET}.c")
target_include_directories(${TEST_TARGET} PRIVATE "include")
target_link_libraries(${TEST_TARGET} open1722 cmocka m)
add_test(NAME ${TEST_TARGET} COMMAND "${PROJECT_BINARY_DIR}/${TEST_TARGET}")
endforeach()
if (UNIT_TESTING)

find_package(cmocka 1.1.0 REQUIRED)

if (cmocka_FOUND)
list(APPEND TEST_TARGETS test-aaf)
list(APPEND TEST_TARGETS test-avtp)
list(APPEND TEST_TARGETS test-can)
list(APPEND TEST_TARGETS test-crf)
list(APPEND TEST_TARGETS test-cvf)
list(APPEND TEST_TARGETS test-rvf)

foreach(TEST_TARGET IN LISTS TEST_TARGETS)
add_executable(${TEST_TARGET} "unit/${TEST_TARGET}.c")
target_include_directories(${TEST_TARGET} PRIVATE "include")
target_link_libraries(${TEST_TARGET} open1722 cmocka m)
add_test(NAME ${TEST_TARGET} COMMAND "${PROJECT_BINARY_DIR}/${TEST_TARGET}")
endforeach()
endif(cmocka_FOUND)
endif(UNIT_TESTING)


#### Install ##################################################################

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ This repository is organized as follows:

Before building Open1722 make sure you have installed the following software :
* CMake >= 3.20
* CMocka >= 1.1.0
* CMocka >= 1.1.0 (For running unit tests. This can be installed on Debian/Ubuntu using ```sudo apt install libcmocka-dev```)

Alternatively, you can use VS Code to run the provided dev container which takes care of the dependencies.

Expand All @@ -61,6 +61,12 @@ $ cmake ..
$ make
```

To execute available unit tests, set the Cmake variable UNIT_TESTING.
```
$ cmake .. -DUNIT_TESTING=on
$ make
```

The build can be cleaned using the following command:
```
$ make clean
Expand Down
10 changes: 6 additions & 4 deletions test_all.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash
set -ev
#!/bin/bash
set -ev

./build_all.sh
rm -rf build
mkdir build
cd build
cmake .. -DUNIT_TESTING=on
make -j`nproc`
make test
# ninja coverage-html

0 comments on commit debe4e5

Please sign in to comment.