diff --git a/.gitignore b/.gitignore index d70dbe4..63f2da4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,20 @@ -build +# Generated directories +/build +/bin +/lib +/release + +# CMake +/CMakeFiles +/CMakeCache.txt +/CTestTestfile.cmake +/cmake_install.cmake +/Makefile +/Testing +/CPackConfig.cmake +/CPackSourceConfig.cmake +/install_manifest.txt +/_CPack_Packages + *~ -.vscode \ No newline at end of file +.vscode diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e05b2bd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,171 @@ +cmake_minimum_required(VERSION 3.20) + +project(open1722 VERSION 0.1) + +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED TRUE) + +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") +set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib") + +#### Libraries ################################################################ + +# PDU parsing library +add_library(open1722pdu SHARED + "src/avtp_ieciidc.c" + "src/avtp_stream.c" + "src/avtp.c" + "src/avtp/CommonHeader.c" + "src/avtp/Crf.c" + "src/avtp/Rvf.c" + "src/avtp/Udp.c" + "src/avtp/Utils.c" + "src/avtp/aaf/CommonStream.c" + "src/avtp/aaf/PcmStream.c" + "src/avtp/acf/Can.c" + "src/avtp/acf/CanBrief.c" + "src/avtp/acf/Common.c" + "src/avtp/acf/Ntscf.c" + "src/avtp/acf/Sensor.c" + "src/avtp/acf/SensorBrief.c" + "src/avtp/acf/Tscf.c" + "src/avtp/cvf/Cvf.c" + "src/avtp/cvf/H264.c" + "src/avtp/cvf/Jpeg2000.c" + "src/avtp/cvf/Mjpeg.c") +target_include_directories(open1722pdu PRIVATE "${PROJECT_BINARY_DIR}/include") + +# link_directories(lib) + +#### Examples ################################################################# + +# Common library accross all examples +add_library(open1722examples STATIC "examples/common/common.c") +target_include_directories(open1722examples PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") + +# AAF listener app +add_executable(aaf-listener "examples/aaf/aaf-listener.c") +target_include_directories(aaf-listener PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(aaf-listener open1722pdu open1722examples) + +# AAF talker app +add_executable(aaf-talker "examples/aaf/aaf-talker.c") +target_include_directories(aaf-talker PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(aaf-talker open1722pdu open1722examples) + +# CAN talker app +add_executable(acf-can-talker "examples/acf-can/acf-can-talker.c") +target_include_directories(acf-can-talker PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(acf-can-talker open1722pdu open1722examples) + +# CAN listener app +add_executable(acf-can-listener "examples/acf-can/acf-can-listener.c") +target_include_directories(acf-can-listener PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(acf-can-listener open1722pdu open1722examples) + +# CRF talker app +add_executable(crf-talker "examples/crf/crf-talker.c") +target_include_directories(crf-talker PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(crf-talker open1722pdu open1722examples m) + +# CRF listener app +add_executable(crf-listener "examples/crf/crf-listener.c") +target_include_directories(crf-listener PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(crf-listener open1722pdu open1722examples m) + +# CVF talker app +add_executable(cvf-talker "examples/cvf/cvf-talker.c") +target_include_directories(cvf-talker PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(cvf-talker open1722pdu open1722examples) + +# CVF listener app +add_executable(cvf-listener "examples/cvf/cvf-listener.c") +target_include_directories(cvf-listener PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(cvf-listener open1722pdu open1722examples) + +# IEC 61883/IIDC talker app +add_executable(ieciidc-talker "examples/ieciidc/ieciidc-talker.c") +target_include_directories(ieciidc-talker PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(ieciidc-talker open1722pdu open1722examples) + +# IEC 61883/IIDC listener app +add_executable(ieciidc-listener "examples/ieciidc/ieciidc-listener.c") +target_include_directories(ieciidc-listener PRIVATE + "${PROJECT_BINARY_DIR}/examples" + "${PROJECT_BINARY_DIR}/include") +target_link_libraries(ieciidc-listener open1722pdu open1722examples) + +#### Tests #################################################################### + +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-ieciidc) +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 "${PROJECT_BINARY_DIR}/include") + target_link_libraries(${TEST_TARGET} open1722pdu cmocka m) + add_test(NAME ${TEST_TARGET} COMMAND "${PROJECT_BINARY_DIR}/bin/${TEST_TARGET}") +endforeach() + +#### Install ################################################################## + +install(TARGETS open1722pdu DESTINATION lib) +install(TARGETS + aaf-listener + aaf-talker + acf-can-listener + acf-can-talker + crf-listener + crf-talker + cvf-listener + cvf-talker + ieciidc-listener + ieciidc-talker + DESTINATION bin) +install(DIRECTORY include/ DESTINATION include) + +#### Packaging ################################################################ + +include(InstallRequiredSystemLibraries) +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_PACKAGE_VERSION_MAJOR "${open1722_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${open1722_VERSION_MINOR}") +set(CPACK_PACKAGE_DIRECTORY "${PROJECT_BINARY_DIR}/release") +set(CPACK_GENERATOR "TGZ" "DEB") +set(CPACK_SOURCE_GENERATOR "TGZ" "DEB") + +# Debian package +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Adriaan Niess [Robert Bosch GmbH]") + +include(CPack) diff --git a/build_all.sh b/build_all.sh index 447d3bf..e65bf96 100755 --- a/build_all.sh +++ b/build_all.sh @@ -1,16 +1,4 @@ #!/bin/bash set -ev -mkdir -p build -meson . build -Db_coverage=true -meson compile -C build/ \ - examples/aaf/aaf-listener \ - examples/aaf/aaf-talker \ - examples/acf-can/acf-can-listener \ - examples/acf-can/acf-can-talker \ - examples/crf/crf-talker \ - examples/crf/crf-listener \ - examples/cvf/cvf-talker \ - examples/cvf/cvf-listener \ - examples/ieciidc/ieciidc-talker \ - examples/ieciidc/ieciidc-listener \ No newline at end of file +cmake . && make diff --git a/examples/aaf/aaf-listener.c b/examples/aaf/aaf-listener.c index a8541b7..f8b2329 100644 --- a/examples/aaf/aaf-listener.c +++ b/examples/aaf/aaf-listener.c @@ -71,7 +71,7 @@ #include "avtp.h" #include "avtp/aaf/PcmStream.h" -#include "common.h" +#include "common/common.h" #include "avtp/CommonHeader.h" #define STREAM_ID 0xAABBCCDDEEFF0001 diff --git a/examples/aaf/aaf-talker.c b/examples/aaf/aaf-talker.c index 0b59859..d0e9a95 100644 --- a/examples/aaf/aaf-talker.c +++ b/examples/aaf/aaf-talker.c @@ -66,7 +66,7 @@ #include "avtp.h" #include "avtp/aaf/PcmStream.h" -#include "common.h" +#include "common/common.h" #include "avtp/CommonHeader.h" #define STREAM_ID 0xAABBCCDDEEFF0001 diff --git a/examples/aaf/meson.build b/examples/aaf/meson.build deleted file mode 100644 index 94b1ea8..0000000 --- a/examples/aaf/meson.build +++ /dev/null @@ -1,15 +0,0 @@ -executable( - 'aaf-talker', - 'aaf-talker.c', - - dependencies: [avtp_dep, avtp_utils_dep], - build_by_default: false, -) - -executable( - 'aaf-listener', - 'aaf-listener.c', - - dependencies: [avtp_dep, avtp_utils_dep], - build_by_default: false, -) \ No newline at end of file diff --git a/examples/acf-can/acf-can-listener.c b/examples/acf-can/acf-can-listener.c index 25c8626..1e4503c 100644 --- a/examples/acf-can/acf-can-listener.c +++ b/examples/acf-can/acf-can-listener.c @@ -41,7 +41,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "avtp/Udp.h" #include "avtp/acf/Ntscf.h" #include "avtp/acf/Tscf.h" diff --git a/examples/acf-can/acf-can-talker.c b/examples/acf-can/acf-can-talker.c index bdb285b..396d4df 100644 --- a/examples/acf-can/acf-can-talker.c +++ b/examples/acf-can/acf-can-talker.c @@ -43,7 +43,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "avtp/Udp.h" #include "avtp/acf/Ntscf.h" #include "avtp/acf/Tscf.h" diff --git a/examples/acf-can/meson.build b/examples/acf-can/meson.build deleted file mode 100644 index faa1f1a..0000000 --- a/examples/acf-can/meson.build +++ /dev/null @@ -1,15 +0,0 @@ -executable( - 'acf-can-talker', - 'acf-can-talker.c', - - dependencies: [avtp_dep, avtp_utils_dep], - build_by_default: false, -) - -executable( - 'acf-can-listener', - 'acf-can-listener.c', - - dependencies: [avtp_dep, avtp_utils_dep], - build_by_default: false, -) \ No newline at end of file diff --git a/examples/common.c b/examples/common/common.c similarity index 99% rename from examples/common.c rename to examples/common/common.c index 4f68069..69896db 100644 --- a/examples/common.c +++ b/examples/common/common.c @@ -41,7 +41,7 @@ #include #include -#include "common.h" +#include "common/common.h" #define NSEC_PER_SEC 1000000000ULL #define NSEC_PER_MSEC 1000000ULL diff --git a/examples/common.h b/examples/common/common.h similarity index 100% rename from examples/common.h rename to examples/common/common.h diff --git a/examples/crf/crf-listener.c b/examples/crf/crf-listener.c index 83d70f2..149b04b 100644 --- a/examples/crf/crf-listener.c +++ b/examples/crf/crf-listener.c @@ -102,7 +102,7 @@ #include "avtp.h" #include "avtp/Crf.h" #include "avtp/aaf/PcmStream.h" -#include "common.h" +#include "common/common.h" #include "avtp/CommonHeader.h" #define AAF_STREAM_ID 0xAABBCCDDEEFF0001 diff --git a/examples/crf/crf-talker.c b/examples/crf/crf-talker.c index 8b47257..8b85d82 100644 --- a/examples/crf/crf-talker.c +++ b/examples/crf/crf-talker.c @@ -64,7 +64,7 @@ #include "avtp.h" #include "avtp/Crf.h" -#include "common.h" +#include "common/common.h" #include "avtp/CommonHeader.h" #define STREAM_ID 0xAABBCCDDEEFF0002 diff --git a/examples/crf/meson.build b/examples/crf/meson.build deleted file mode 100644 index eb22e13..0000000 --- a/examples/crf/meson.build +++ /dev/null @@ -1,18 +0,0 @@ -cc = meson.get_compiler('c') -mdep = cc.find_library('m', required : false) - -executable( - 'crf-talker', - 'crf-talker.c', - - dependencies: [avtp_dep, avtp_utils_dep, mdep], - build_by_default: false, -) - -executable( - 'crf-listener', - 'crf-listener.c', - - dependencies: [avtp_dep, avtp_utils_dep, mdep], - build_by_default: false, -) diff --git a/examples/cvf/cvf-listener.c b/examples/cvf/cvf-listener.c index ddf2bbb..16da340 100644 --- a/examples/cvf/cvf-listener.c +++ b/examples/cvf/cvf-listener.c @@ -76,7 +76,7 @@ #include "avtp/cvf/Cvf.h" #include "avtp/cvf/H264.h" #include "avtp/CommonHeader.h" -#include "common.h" +#include "common/common.h" #define STREAM_ID 0xAABBCCDDEEFF0001 #define DATA_LEN 1400 diff --git a/examples/cvf/cvf-talker.c b/examples/cvf/cvf-talker.c index 5a36d5c..8865a1a 100644 --- a/examples/cvf/cvf-talker.c +++ b/examples/cvf/cvf-talker.c @@ -78,7 +78,7 @@ #include "avtp.h" #include "avtp/cvf/Cvf.h" #include "avtp/cvf/H264.h" -#include "common.h" +#include "common/common.h" #include "avtp/CommonHeader.h" #define STREAM_ID 0xAABBCCDDEEFF0001 diff --git a/examples/cvf/meson.build b/examples/cvf/meson.build deleted file mode 100644 index a0f4846..0000000 --- a/examples/cvf/meson.build +++ /dev/null @@ -1,15 +0,0 @@ -executable( - 'cvf-talker', - 'cvf-talker.c', - - dependencies: [avtp_dep, avtp_utils_dep], - build_by_default: false, -) - -executable( - 'cvf-listener', - 'cvf-listener.c', - - dependencies: [avtp_dep, avtp_utils_dep], - build_by_default: false, -) \ No newline at end of file diff --git a/examples/ieciidc/ieciidc-listener.c b/examples/ieciidc/ieciidc-listener.c index 36e66b1..655658a 100644 --- a/examples/ieciidc/ieciidc-listener.c +++ b/examples/ieciidc/ieciidc-listener.c @@ -72,7 +72,7 @@ #include "avtp.h" #include "avtp_ieciidc.h" -#include "common.h" +#include "common/common.h" #include "avtp/CommonHeader.h" #define STREAM_ID 0xAABBCCDDEEFF0001 diff --git a/examples/ieciidc/ieciidc-talker.c b/examples/ieciidc/ieciidc-talker.c index bc823a2..afe160f 100644 --- a/examples/ieciidc/ieciidc-talker.c +++ b/examples/ieciidc/ieciidc-talker.c @@ -72,7 +72,7 @@ #include "avtp.h" #include "avtp_ieciidc.h" -#include "common.h" +#include "common/common.h" #include "avtp/CommonHeader.h" #define STREAM_ID 0xAABBCCDDEEFF0001 diff --git a/examples/meson.build b/examples/meson.build deleted file mode 100644 index 07cdbff..0000000 --- a/examples/meson.build +++ /dev/null @@ -1,16 +0,0 @@ -avtp_utils_lib = library( - 'avtp_utils', - ['common.c'], - include_directories: include_directories('.'), -) - -avtp_utils_dep = declare_dependency( - link_with: avtp_utils_lib, - include_directories: include_directories('.'), -) - -subdir('aaf') -subdir('acf-can') -subdir('crf') -subdir('cvf') -subdir('ieciidc') \ No newline at end of file diff --git a/meson.build b/meson.build deleted file mode 100644 index bf4be5c..0000000 --- a/meson.build +++ /dev/null @@ -1,178 +0,0 @@ -project( - 'Open1722', - 'c', - version: '0.1.0', - license: 'BSD-3-Clause', - meson_version: '>=0.56.0', -) - -avtp_lib = library( - 'open1722', - [ - 'src/avtp.c', - 'src/avtp_ieciidc.c', - 'src/avtp_stream.c', - - 'src/avtp/Utils.c', - 'src/avtp/acf/Ntscf.c', - 'src/avtp/acf/Tscf.c', - 'src/avtp/CommonHeader.c', - 'src/avtp/acf/Common.c', - 'src/avtp/acf/Can.c', - 'src/avtp/acf/CanBrief.c', - 'src/avtp/acf/Sensor.c', - 'src/avtp/acf/SensorBrief.c', - 'src/avtp/aaf/PcmStream.c', - 'src/avtp/aaf/CommonStream.c', - 'src/avtp/Udp.c', - 'src/avtp/Rvf.c', - 'src/avtp/Crf.c', - 'src/avtp/cvf/Cvf.c', - 'src/avtp/cvf/H264.c', - 'src/avtp/cvf/Jpeg2000.c', - 'src/avtp/cvf/Mjpeg.c', - ], - version: meson.project_version(), - include_directories: include_directories('include'), - install: true, -) - -avtp_dep = declare_dependency( - link_with: avtp_lib, - include_directories: include_directories('include'), -) - -install_headers( - 'include/avtp/Byteorder.h', - 'include/avtp/Defines.h', - 'include/avtp/CommonHeader.h', - 'include/avtp/Udp.h', - 'include/avtp/Utils.h', - 'include/avtp/Rvf.h', - 'include/avtp/Crf.h', - subdir : 'avtp' -) - -install_headers( - 'include/avtp/acf/CanBrief.h', - 'include/avtp/acf/Can.h', - 'include/avtp/acf/Common.h', - 'include/avtp/acf/Ntscf.h', - 'include/avtp/acf/SensorBrief.h', - 'include/avtp/acf/Sensor.h', - 'include/avtp/acf/Tscf.h', - subdir : 'avtp/acf' -) - -install_headers( - 'include/avtp/aaf/PcmStream.h', - 'include/avtp/aaf/CommonStream.h', - subdir : 'avtp/aaf' -) - -install_headers( - 'src/avtp/cvf/Cvf.c', - 'src/avtp/cvf/H264.c', - 'src/avtp/cvf/Jpeg2000.c', - 'src/avtp/cvf/Mjpeg.c', - subdir : 'avtp/cvf' -) - -pkg = import('pkgconfig') -pkg.generate(avtp_lib, - description: 'AVTP packetization library', - url: 'github.com/COVESA/Open1722', -) - -if get_option('tests') == 'disabled' - cmocka = disabler() -else - cmocka = dependency('cmocka', required: get_option('tests') == 'enabled') -endif - -if cmocka.found() - test_avtp = executable( - 'test-avtp', - 'unit/test-avtp.c', - include_directories: include_directories('include'), - link_with: avtp_lib, - dependencies: cmocka, - build_by_default: false, - ) - - test_can = executable( - 'test-can', - 'unit/test-can.c', - include_directories: include_directories('include'), - link_with: avtp_lib, - link_args : '-lm', - dependencies: cmocka, - build_by_default: false, - ) - - test_aaf = executable( - 'test-aaf', - 'unit/test-aaf.c', - include_directories: include_directories('include'), - link_with: avtp_lib, - dependencies: cmocka, - build_by_default: false, - ) - - test_crf = executable( - 'test-crf', - 'unit/test-crf.c', - include_directories: include_directories('include'), - link_with: avtp_lib, - dependencies: cmocka, - build_by_default: false, - ) - - test_stream = executable( - 'test-stream', - 'unit/test-stream.c', - 'src/avtp_stream.c', - include_directories: include_directories('include', 'src'), - link_with: avtp_lib, - dependencies: cmocka, - build_by_default: false, - ) - - test_cvf = executable( - 'test-cvf', - 'unit/test-cvf.c', - include_directories: include_directories('include'), - link_with: avtp_lib, - dependencies: cmocka, - build_by_default: false, - ) - - test_rvf = executable( - 'test-rvf', - 'unit/test-rvf.c', - include_directories: include_directories('include'), - link_with: avtp_lib, - dependencies: cmocka, - build_by_default: false, - ) - - test_ieciidc = executable( - 'test-ieciidc', - 'unit/test-ieciidc.c', - include_directories: include_directories('include'), - link_with: avtp_lib, - dependencies: cmocka, - build_by_default: false, - ) - - test('AVTP API', test_avtp) - test('Stream API', test_stream) - test('AAF API', test_aaf) - test('CRF API', test_crf) - test('CVF API', test_cvf) - test('RVF API', test_rvf) - test('IEC61883/IIDC API', test_ieciidc) - test('ACF CAN API', test_can) -endif - -subdir('examples') \ No newline at end of file diff --git a/meson_options.txt b/meson_options.txt deleted file mode 100644 index 1db06b4..0000000 --- a/meson_options.txt +++ /dev/null @@ -1,7 +0,0 @@ -# Port to 'feature' once we depend on meson 0.47.0 -option( - 'tests', - type : 'combo', - value : 'auto', - choices : ['enabled', 'disabled', 'auto'], - description : 'Build unit test libraries') diff --git a/test_all.sh b/test_all.sh index 2477e74..9a406a2 100755 --- a/test_all.sh +++ b/test_all.sh @@ -1,7 +1,6 @@ #!/bin/bash set -ev -./build_all.sh -cd ./build -meson test -ninja coverage-html \ No newline at end of file +./build_all.sh +make test +# ninja coverage-html